Refactor modeline

This commit is contained in:
Henrik Lissner 2015-11-19 05:52:22 -05:00
parent b8713f9707
commit 0cd60e5ae8

View file

@ -101,6 +101,15 @@
(add-hook! focus-out (set-frame-parameter nil 'alpha 80)) (add-hook! focus-out (set-frame-parameter nil 'alpha 80))
;; Plugins ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Plugins ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(use-package yascroll
:commands (yascroll-bar-mode)
:config
(add-to-list 'yascroll:enabled-window-systems 'mac)
(setq yascroll:scroll-bar 'right-fringe
yascroll:delay-to-hide nil)
(defun yascroll:before-change (beg end)))
(use-package hideshow (use-package hideshow
:commands (hs-minor-mode hs-toggle-hiding hs-already-hidden-p) :commands (hs-minor-mode hs-toggle-hiding hs-already-hidden-p)
:diminish hs-minor-mode :diminish hs-minor-mode
@ -205,7 +214,8 @@
:config :config
(setq-default (setq-default
powerline-default-separator nil powerline-default-separator nil
powerline-height 19) powerline-height 19
spaceline-highlight-face-func 'spaceline-highlight-face-evil-state)
(defface mode-line-is-modified nil "Face for mode-line modified symbol") (defface mode-line-is-modified nil "Face for mode-line modified symbol")
(defface mode-line-buffer-file nil "Face for mode-line buffer file path") (defface mode-line-buffer-file nil "Face for mode-line buffer file path")
@ -285,56 +295,54 @@
:face other-face :face other-face
:tight-right t) :tight-right t)
(defface mode-line-count-face nil "")
(make-variable-buffer-local 'anzu--state)
(spaceline-define-segment narf-anzu (spaceline-define-segment narf-anzu
"Show the current match number and the total number of matches. Requires "Show the current match number and the total number of matches. Requires
anzu to be enabled." anzu to be enabled."
(let ((here anzu--current-position) (let ((here anzu--current-position)
(total anzu--total-matched)) (total anzu--total-matched))
(when anzu--state (format " %s/%d%s "
(propertize (anzu--format-here-position here total)
(cl-case anzu--state total (if anzu--overflow-p "+" "")))
(search (format " %s/%d%s " :face (if active 'mode-line-count-face 'mode-line-inactive)
(anzu--format-here-position here total) :when (evil-ex-hl-active-p 'evil-ex-search)
total (if anzu--overflow-p "+" "")))
(replace-query (format " %d replace " total))
(replace (format " %d/%d " here total)))
'face highlight-face)))
:when (and active (bound-and-true-p anzu--state))
:skip-alternate t :skip-alternate t
:tight t) :tight t)
;; TODO mode-line-iedit-face default face ;; TODO mode-line-iedit-face default face
(defface mode-line-iedit-face nil "")
(spaceline-define-segment narf-iedit (spaceline-define-segment narf-iedit
"Show the number of matches and what match you're on (or after). Requires "Show the number of matches and what match you're on (or after). Requires
iedit." iedit."
(let ((this-oc (iedit-find-current-occurrence-overlay)) (let ((this-oc (iedit-find-current-occurrence-overlay))
(length (or (ignore-errors (length iedit-occurrences-overlays)) 0))) (length (or (ignore-errors (length iedit-occurrences-overlays)) 0)))
(if (zerop (iedit-occurrence-string-length)) (format "%s/%s"
"..." (save-excursion
(format "%s/%s" (unless this-oc
(save-excursion (iedit-prev-occurrence)
(unless this-oc (setq this-oc (iedit-find-current-occurrence-overlay)))
(iedit-prev-occurrence) (if this-oc
(setq this-oc (iedit-find-current-occurrence-overlay))) ;; NOTE: Not terribly reliable
(if this-oc (- length (-elem-index this-oc iedit-occurrences-overlays))
(- length (-elem-index this-oc iedit-occurrences-overlays)) "-"))
"-")) length))
(int-to-string length)))) :face (if active 'mode-line-count-face 'mode-line-inactive)
:face (if active 'mode-line-iedit-face 'mode-line-inactive)
:skip-alternate t :skip-alternate t
:when (and (featurep 'evil-iedit-state) evil-iedit-state-minor-mode)) :when (bound-and-true-p iedit-mode))
;; TODO mode-line-substitute-face default face ;; TODO mode-line-substitute-face default face
(defface mode-line-substitute-face nil "") (defface mode-line-substitute-face nil "")
;; TODO This is very hackish; refactor? ;; TODO This is very hackish; refactor?
(spaceline-define-segment narf-evil-substitute (spaceline-define-segment narf-evil-substitute
"Show number of :s matches in real time." "Show number of :s matches in real time."
(let ((highlights (cdar evil-ex-active-highlights-alist))) (let ((range (if evil-ex-range
(format "%s matches" (length (elt highlights (1- (length highlights)))))) (cons (car evil-ex-range) (cadr evil-ex-range))
:face (if active 'mode-line-substitute-face 'mode-line-inactive) (cons (line-beginning-position) (line-end-position))))
(pattern (car (evil-delimited-arguments evil-ex-argument 2))))
(format "%s matches" (count-matches pattern (car range) (cdr range)) evil-ex-argument))
:face (if active 'mode-line-count-face 'mode-line-inactive)
:skip-alternate t :skip-alternate t
:when (and (evil-ex-p) (string-equal evil-ex-cmd "s"))) :when (and (evil-ex-p) (evil-ex-hl-active-p 'evil-ex-substitute)))
(spaceline-define-segment narf-major-mode (spaceline-define-segment narf-major-mode
(concat "[" mode-name "]") (concat "[" mode-name "]")
@ -343,7 +351,8 @@ iedit."
;; Initialize modeline ;; Initialize modeline
(spaceline-install (spaceline-install
;; Left side ;; Left side
'(narf-anzu narf-iedit narf-evil-substitute '((evil-state :face highlight-face :when active :skip-alternate t)
narf-anzu narf-iedit narf-evil-substitute
(narf-buffer-path remote-host) (narf-buffer-path remote-host)
narf-buffer-modified narf-buffer-modified
narf-vc narf-vc