Refactor mode-line + fontify file name and path differently

This commit is contained in:
Henrik Lissner 2016-05-11 23:13:07 -04:00
parent 07c674572e
commit ac908b7cac
2 changed files with 85 additions and 79 deletions

View file

@ -197,11 +197,14 @@
:config :config
(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 name")
(defface mode-line-buffer-path nil "Face for mode-line buffer file path")
;; Custom modeline segments ;; Custom modeline segments
(spaceline-define-segment *buffer-path (spaceline-define-segment *buffer-path
(if buffer-file-name (concat (when buffer-file-name
(powerline-raw
(f-dirname
(let ((buffer-path (file-relative-name buffer-file-name (narf/project-root))) (let ((buffer-path (file-relative-name buffer-file-name (narf/project-root)))
(max-length (truncate (/ (window-body-width) 1.75)))) (max-length (truncate (/ (window-body-width) 1.75))))
(concat (projectile-project-name) "/" (concat (projectile-project-name) "/"
@ -218,25 +221,26 @@
(when (string-suffix-p "/" output) (when (string-suffix-p "/" output)
(setq output (substring output 0 -1))) (setq output (substring output 0 -1)))
output) output)
buffer-path))) buffer-path))))
"%b") (if active 'mode-line-buffer-path)))
:face other-face (powerline-raw "%b" (if active 'mode-line-buffer-file)))
:tight-right t) :tight-right t)
(spaceline-define-segment *buffer-modified (spaceline-define-segment *buffer-modified
(unless (string-prefix-p "*" (buffer-name)) (unless (string-prefix-p "*" (buffer-name))
(propertize (powerline-raw
(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)) 'mode-line-is-modified))
:skip-alternate t :skip-alternate t
:tight t) :tight t)
(spaceline-define-segment *buffer-position (spaceline-define-segment *buffer-position
"A more vim-like buffer position." "A more vim-like buffer position."
(concat "%l/%c "
(let ((start (window-start)) (let ((start (window-start))
(end (window-end)) (end (window-end))
(pend (point-max))) (pend (point-max)))
@ -246,14 +250,15 @@
(let ((perc (/ end 0.01 pend))) (let ((perc (/ end 0.01 pend)))
(cond ((= start 1) ":Top") (cond ((= start 1) ":Top")
((>= perc 100) ":Bot") ((>= perc 100) ":Bot")
(t (format ":%d%%%%" perc)))))) (t (format ":%d%%%%" perc)))))))
:skip-alternate t) :tight-left t)
(spaceline-define-segment *vc (spaceline-define-segment *vc
"Version control info" "Version control info"
(when (and active vc-mode) (when (and active vc-mode)
(substring vc-mode (+ 1 (length (symbol-name (vc-backend buffer-file-name)))))) (powerline-raw
:face other-face (substring vc-mode (+ 1 (length (symbol-name (vc-backend buffer-file-name)))))
other-face))
:tight-right t) :tight-right t)
;; search indicators ;; search indicators
@ -263,13 +268,13 @@
"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) (when (evil-ex-hl-active-p 'evil-ex-search)
(propertize (powerline-raw
(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))) (if active 'mode-line-count-face 'mode-line-inactive)))
:tight t) :tight t)
(spaceline-define-segment *iedit (spaceline-define-segment *iedit
@ -294,7 +299,7 @@ anzu to be enabled."
(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)) (when (and (evil-ex-p) (evil-ex-hl-active-p 'evil-ex-substitute))
(propertize (powerline-raw
(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))))
@ -304,15 +309,15 @@ anzu to be enabled."
(count-matches pattern (car range) (cdr range)) (count-matches pattern (car range) (cdr range))
evil-ex-argument) evil-ex-argument)
" ... ")) " ... "))
'face (if active 'mode-line-count-face 'mode-line-inactive))) (if active 'mode-line-count-face 'mode-line-inactive)))
:tight t) :tight t)
(spaceline-define-segment *macro-recording (spaceline-define-segment *macro-recording
"Show when recording macro" "Show when recording macro"
(when (and active defining-kbd-macro) (when (and active defining-kbd-macro)
(propertize (powerline-raw
(format " %s ▶ " (char-to-string evil-this-macro)) (format " %s ▶ " (char-to-string evil-this-macro))
'face highlight-face)) highlight-face))
:tight t) :tight t)
(spaceline-define-segment *buffer-encoding-abbrev (spaceline-define-segment *buffer-encoding-abbrev
@ -334,6 +339,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)) (when (and active (evil-visual-state-p))
(powerline-raw
(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)))
@ -351,8 +357,8 @@ 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)))))))
:face highlight-face) highlight-face)))
;; flycheck ;; flycheck
(defun narf--flycheck-count (state) (defun narf--flycheck-count (state)
@ -376,6 +382,9 @@ anzu to be enabled."
(defvar-local narf--flycheck-cache nil "") (defvar-local narf--flycheck-cache nil "")
(spaceline-define-segment *flycheck (spaceline-define-segment *flycheck
"Persistent and cached flycheck indicators in the mode-line." "Persistent and cached flycheck indicators in the mode-line."
(when (and (bound-and-true-p flycheck-mode)
(or flycheck-current-errors
(eq 'running flycheck-last-status-change)))
(or (and (or (eq narf--flycheck-err-cache narf--flycheck-cache) (or (and (or (eq narf--flycheck-err-cache narf--flycheck-cache)
(memq flycheck-last-status-change '(running not-checked))) (memq flycheck-last-status-change '(running not-checked)))
narf--flycheck-cache) narf--flycheck-cache)
@ -389,10 +398,7 @@ anzu to be enabled."
(if fe (propertize (format " ⚠%s " fe) 'face (if active 'spaceline-flycheck-error 'mode-line))) (if fe (propertize (format " ⚠%s " fe) 'face (if active 'spaceline-flycheck-error 'mode-line)))
(if fw (propertize (format " ⚠%s " fw) 'face (if active 'spaceline-flycheck-warning 'mode-line))) (if fw (propertize (format " ⚠%s " fw) 'face (if active 'spaceline-flycheck-warning 'mode-line)))
;; (if fi (propertize (format " ⚠%s " fi) 'face 'spaceline-flycheck-info)) ;; (if fi (propertize (format " ⚠%s " fi) 'face 'spaceline-flycheck-info))
))))) ))))))
:when (and (bound-and-true-p flycheck-mode)
(or flycheck-current-errors
(eq 'running flycheck-last-status-change)))
:tight t) :tight t)
(defvar narf--mode-line-padding (pl/percent-xpm powerline-height 100 0 100 0 1 nil nil)) (defvar narf--mode-line-padding (pl/percent-xpm powerline-height 100 0 100 0 1 nil nil))
@ -416,13 +422,12 @@ anzu to be enabled."
*env-version *env-version
*buffer-encoding-abbrev *buffer-encoding-abbrev
(global :when active) (global :when active)
("%l/%c" :tight t)
*buffer-position *buffer-position
*pad *pad
)) ))
;; Initialize modeline ;; Initialize modeline
(setq-default mode-line-format '(:eval (spaceline-ml-main)))) (setq-default mode-line-format '("%e" (:eval (spaceline-ml-main)))))
(provide 'core-ui) (provide 'core-ui)
;;; core-ui.el ends here ;;; core-ui.el ends here

View file

@ -165,7 +165,8 @@
`(mode-line-inactive ((,c (:foreground ,modeline-fg-inactive :background ,modeline-bg-inactive)))) `(mode-line-inactive ((,c (:foreground ,modeline-fg-inactive :background ,modeline-bg-inactive))))
`(mode-line-is-modified ((,c (:foreground ,magenta :background nil :bold t)))) `(mode-line-is-modified ((,c (:foreground ,magenta :background nil :bold t))))
`(mode-line-buffer-file ((,c (:foreground ,modeline-fg)))) `(mode-line-buffer-file ((,c (:foreground ,white :bold t))))
`(mode-line-buffer-path ((,c (:foreground ,grey))))
`(mode-line-count-face ((,c (:foreground ,black :background ,magenta)))) `(mode-line-count-face ((,c (:foreground ,black :background ,magenta))))
`(spaceline-flycheck-error ((,c (:underline nil :foreground ,black :background ,red)))) `(spaceline-flycheck-error ((,c (:underline nil :foreground ,black :background ,red))))