Update+optimize mode-line config (b/c of spaceline update)

This commit is contained in:
Henrik Lissner 2016-05-10 23:03:41 -04:00
parent 6761a796f9
commit 8fa1aaa784

View file

@ -205,33 +205,36 @@
;; Custom modeline segments ;; Custom modeline segments
(spaceline-define-segment *buffer-path (spaceline-define-segment *buffer-path
(if buffer-file-name (if buffer-file-name
(let ((buffer-path (f-relative buffer-file-name (f-dirname (narf/project-root)))) (let ((buffer-path (file-relative-name buffer-file-name (narf/project-root)))
(max-length 50)) (max-length (truncate (/ (window-body-width) 1.75))))
(concat (projectile-project-name) "/"
(if (> (length buffer-path) max-length) (if (> (length buffer-path) max-length)
(let ((path (reverse (split-string buffer-path "/"))) (let ((path (reverse (split-string buffer-path "/" t)))
(output "")) (output ""))
(when (and path (equal "" (car path))) (when (and path (equal "" (car path)))
(setq path (cdr path))) (setq path (cdr path)))
(while (and path (< (length output) (- max-length 4))) (while (and path (<= (length output) (- max-length 4)))
(setq output (concat (car path) "/" output)) (setq output (concat (car path) "/" output))
(setq path (cdr path))) (setq path (cdr path)))
(when path (when path
(setq output (concat "../" output))) (setq output (concat "../" output)))
(when (string-suffix-p "/" output)
(setq output (substring output 0 -1)))
output) output)
buffer-path)) buffer-path)))
"%b") "%b")
:face other-face :face other-face
:tight-right t) :tight-right t)
(spaceline-define-segment *buffer-modified (spaceline-define-segment *buffer-modified
(unless (string-prefix-p "*" (buffer-name))
(propertize (propertize
(concat (when buffer-file-name (concat (when buffer-file-name
(concat (concat
(if (buffer-modified-p) "[+]") (if (buffer-modified-p) "[+]")
(if (not (file-exists-p buffer-file-name)) "[!]"))) (if (not (file-exists-p buffer-file-name)) "[!]")))
(if buffer-read-only "[RO]")) (if buffer-read-only "[RO]"))
'face 'mode-line-is-modified) 'face 'mode-line-is-modified))
:when (not (string-prefix-p "*" (buffer-name)))
:skip-alternate t :skip-alternate t
:tight t) :tight t)
@ -247,12 +250,12 @@
(cond ((= start 1) ":Top") (cond ((= start 1) ":Top")
((>= perc 100) ":Bot") ((>= perc 100) ":Bot")
(t (format ":%d%%%%" perc)))))) (t (format ":%d%%%%" perc))))))
:tight t) :skip-alternate t)
(spaceline-define-segment *vc (spaceline-define-segment *vc
"Version control info" "Version control info"
(substring vc-mode (+ 1 (length (symbol-name (vc-backend buffer-file-name))))) (when (and active vc-mode)
:when (and active vc-mode) (substring vc-mode (+ 1 (length (symbol-name (vc-backend buffer-file-name))))))
:face other-face :face other-face
:tight-right t) :tight-right t)
@ -262,17 +265,20 @@
(spaceline-define-segment *anzu (spaceline-define-segment *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."
(when (evil-ex-hl-active-p 'evil-ex-search)
(propertize
(let ((here anzu--current-position) (let ((here anzu--current-position)
(total anzu--total-matched)) (total anzu--total-matched))
(format " %s/%d%s " (format " %s/%d%s "
here total here total
(if anzu--overflow-p "+" ""))) (if anzu--overflow-p "+" "")))
:face (if active 'mode-line-count-face 'mode-line-inactive) 'face (if active 'mode-line-count-face 'mode-line-inactive)))
:when (evil-ex-hl-active-p 'evil-ex-search)
:tight t) :tight t)
(spaceline-define-segment *iedit (spaceline-define-segment *iedit
"Show the number of matches and what match you're on (or after). Requires iedit." "Show the number of matches and what match you're on (or after). Requires iedit."
(when (bound-and-true-p iedit-mode)
(propertize
(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)))
(format " %s/%s " (format " %s/%s "
@ -285,12 +291,13 @@ anzu to be enabled."
(- length (-elem-index this-oc iedit-occurrences-overlays)) (- length (-elem-index this-oc iedit-occurrences-overlays))
"-")) "-"))
length)) length))
:when (bound-and-true-p iedit-mode) 'face (if active 'mode-line-count-face 'mode-line-inactive)))
:tight t :tight t)
:face (if active 'mode-line-count-face 'mode-line-inactive))
(spaceline-define-segment *evil-substitute (spaceline-define-segment *evil-substitute
"Show number of :s matches in real time." "Show number of :s matches in real time."
(when (and (evil-ex-p) (evil-ex-hl-active-p 'evil-ex-substitute))
(propertize
(let ((range (if evil-ex-range (let ((range (if evil-ex-range
(cons (car evil-ex-range) (cadr evil-ex-range)) (cons (car evil-ex-range) (cadr evil-ex-range))
(cons (line-beginning-position) (line-end-position)))) (cons (line-beginning-position) (line-end-position))))
@ -300,27 +307,26 @@ anzu to be enabled."
(count-matches pattern (car range) (cdr range)) (count-matches pattern (car range) (cdr range))
evil-ex-argument) evil-ex-argument)
" ... ")) " ... "))
:when (and (evil-ex-p) (evil-ex-hl-active-p 'evil-ex-substitute)) 'face (if active 'mode-line-count-face 'mode-line-inactive)))
:tight t :tight t)
:face (if active 'mode-line-count-face 'mode-line-inactive))
(spaceline-define-segment *macro-recording (spaceline-define-segment *macro-recording
"Show when recording macro" "Show when recording macro"
(when (and active defining-kbd-macro)
(propertize
(format " %s ▶ " (char-to-string evil-this-macro)) (format " %s ▶ " (char-to-string evil-this-macro))
:when (and active defining-kbd-macro) 'face highlight-face))
:face highlight-face
:tight t) :tight t)
(spaceline-define-segment *buffer-encoding-abbrev (spaceline-define-segment *buffer-encoding-abbrev
"The line ending convention used in the buffer." "The line ending convention used in the buffer."
(format "%s" buffer-file-coding-system) (unless (string-match-p "\\(utf-8\\|undecided\\)"
:when (not (string-match-p "\\(utf-8\\|undecided\\)" (symbol-name buffer-file-coding-system))
(symbol-name buffer-file-coding-system)))) (format "%s" buffer-file-coding-system)))
(spaceline-define-segment *major-mode (spaceline-define-segment *major-mode
"The major mode, including process, environment and text-scale info." "The major mode, including process, environment and text-scale info."
(concat (concat (format "%s" mode-name)
(format "%s" mode-name)
(if (stringp mode-line-process) mode-line-process) (if (stringp mode-line-process) mode-line-process)
(if narf--env-version (concat " " narf--env-version)) (if narf--env-version (concat " " narf--env-version))
(and (featurep 'face-remap) (and (featurep 'face-remap)
@ -330,6 +336,7 @@ anzu to be enabled."
(spaceline-define-segment *selection-info (spaceline-define-segment *selection-info
"Information about the current selection." "Information about the current selection."
(when (and active (evil-visual-state-p))
(let ((reg-beg (region-beginning)) (let ((reg-beg (region-beginning))
(reg-end (region-end)) (reg-end (region-end))
(evil (eq 'visual evil-state))) (evil (eq 'visual evil-state)))
@ -347,8 +354,7 @@ anzu to be enabled."
(if (and (eq evil-state 'visual) (eq evil-this-type 'line)) (if (and (eq evil-state 'visual) (eq evil-this-type 'line))
(format "%dL" lines) (format "%dL" lines)
(format "%dC %dL" chars lines))) (format "%dC %dL" chars lines)))
(t (format "%dC" (if evil chars (1- chars))))))) (t (format "%dC" (if evil chars (1- chars))))))))
:when (evil-visual-state-p)
:face highlight-face) :face highlight-face)
;; flycheck ;; flycheck
@ -396,29 +402,29 @@ anzu to be enabled."
(spaceline-define-segment *pad (spaceline-define-segment *pad
"Padding, to ensure the mode-line is `powerline-height' pixels tall" "Padding, to ensure the mode-line is `powerline-height' pixels tall"
narf--mode-line-padding narf--mode-line-padding
:tight-right t) :tight t)
(defun narf-spaceline-init () (spaceline-compile
(spaceline-install
;; Left side ;; Left side
'(((*macro-recording *anzu *iedit *evil-substitute *flycheck) '(((*macro-recording *anzu *iedit *evil-substitute *flycheck)
:skip-alternate t :skip-alternate t
:fallback ("%I" :tight-right t)) :tight t)
*buffer-path *buffer-path
*buffer-modified *buffer-modified
*vc *vc)
)
;; Right side ;; Right side
'((*selection-info :when active) '(*selection-info
(*major-mode *env-version) *major-mode
*env-version
*buffer-encoding-abbrev *buffer-encoding-abbrev
(global :when active) (global :when active)
("%l/%c" *buffer-position) ("%l/%c" :tight t)
*buffer-position
*pad *pad
))) ))
;; Initialize modeline ;; Initialize modeline
(narf-spaceline-init)) (setq-default mode-line-format '(:eval (spaceline-ml-main))))
(provide 'core-ui) (provide 'core-ui)
;;; core-ui.el ends here ;;; core-ui.el ends here