Refactor mode-line + fontify file name and path differently
This commit is contained in:
parent
07c674572e
commit
ac908b7cac
2 changed files with 85 additions and 79 deletions
161
core/core-ui.el
161
core/core-ui.el
|
@ -197,63 +197,68 @@
|
||||||
|
|
||||||
: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
|
||||||
(let ((buffer-path (file-relative-name buffer-file-name (narf/project-root)))
|
(powerline-raw
|
||||||
(max-length (truncate (/ (window-body-width) 1.75))))
|
(f-dirname
|
||||||
(concat (projectile-project-name) "/"
|
(let ((buffer-path (file-relative-name buffer-file-name (narf/project-root)))
|
||||||
(if (> (length buffer-path) max-length)
|
(max-length (truncate (/ (window-body-width) 1.75))))
|
||||||
(let ((path (reverse (split-string buffer-path "/" t)))
|
(concat (projectile-project-name) "/"
|
||||||
(output ""))
|
(if (> (length buffer-path) max-length)
|
||||||
(when (and path (equal "" (car path)))
|
(let ((path (reverse (split-string buffer-path "/" t)))
|
||||||
(setq path (cdr path)))
|
(output ""))
|
||||||
(while (and path (<= (length output) (- max-length 4)))
|
(when (and path (equal "" (car path)))
|
||||||
(setq output (concat (car path) "/" output))
|
(setq path (cdr path)))
|
||||||
(setq path (cdr path)))
|
(while (and path (<= (length output) (- max-length 4)))
|
||||||
(when path
|
(setq output (concat (car path) "/" output))
|
||||||
(setq output (concat "../" output)))
|
(setq path (cdr path)))
|
||||||
(when (string-suffix-p "/" output)
|
(when path
|
||||||
(setq output (substring output 0 -1)))
|
(setq output (concat "../" output)))
|
||||||
output)
|
(when (string-suffix-p "/" output)
|
||||||
buffer-path)))
|
(setq output (substring output 0 -1)))
|
||||||
"%b")
|
output)
|
||||||
:face other-face
|
buffer-path))))
|
||||||
|
(if active 'mode-line-buffer-path)))
|
||||||
|
(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."
|
||||||
(let ((start (window-start))
|
(concat "%l/%c "
|
||||||
(end (window-end))
|
(let ((start (window-start))
|
||||||
(pend (point-max)))
|
(end (window-end))
|
||||||
(if (and (eq start 1)
|
(pend (point-max)))
|
||||||
(eq end pend))
|
(if (and (eq start 1)
|
||||||
":All"
|
(eq end pend))
|
||||||
(let ((perc (/ end 0.01 pend)))
|
":All"
|
||||||
(cond ((= start 1) ":Top")
|
(let ((perc (/ end 0.01 pend)))
|
||||||
((>= perc 100) ":Bot")
|
(cond ((= start 1) ":Top")
|
||||||
(t (format ":%d%%%%" perc))))))
|
((>= perc 100) ":Bot")
|
||||||
:skip-alternate t)
|
(t (format ":%d%%%%" perc)))))))
|
||||||
|
: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,25 +339,26 @@ 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))
|
||||||
(let ((reg-beg (region-beginning))
|
(powerline-raw
|
||||||
(reg-end (region-end))
|
(let ((reg-beg (region-beginning))
|
||||||
(evil (eq 'visual evil-state)))
|
(reg-end (region-end))
|
||||||
(let ((lines (count-lines reg-beg (min (1+ reg-end) (point-max))))
|
(evil (eq 'visual evil-state)))
|
||||||
(chars (- (1+ reg-end) reg-beg))
|
(let ((lines (count-lines reg-beg (min (1+ reg-end) (point-max))))
|
||||||
(cols (1+ (abs (- (evil-column reg-end)
|
(chars (- (1+ reg-end) reg-beg))
|
||||||
(evil-column reg-beg))))))
|
(cols (1+ (abs (- (evil-column reg-end)
|
||||||
(cond
|
(evil-column reg-beg))))))
|
||||||
;; rectangle selection
|
(cond
|
||||||
((or (bound-and-true-p rectangle-mark-mode)
|
;; rectangle selection
|
||||||
(and evil (eq 'block evil-visual-selection)))
|
((or (bound-and-true-p rectangle-mark-mode)
|
||||||
(format "%dx%dB" lines (if evil cols (1- cols))))
|
(and evil (eq 'block evil-visual-selection)))
|
||||||
;; line selection
|
(format "%dx%dB" lines (if evil cols (1- cols))))
|
||||||
((or (> lines 1) (eq 'line evil-visual-selection))
|
;; line selection
|
||||||
(if (and (eq evil-state 'visual) (eq evil-this-type 'line))
|
((or (> lines 1) (eq 'line evil-visual-selection))
|
||||||
(format "%dL" lines)
|
(if (and (eq evil-state 'visual) (eq evil-this-type 'line))
|
||||||
(format "%dC %dL" chars lines)))
|
(format "%dL" lines)
|
||||||
(t (format "%dC" (if evil chars (1- chars))))))))
|
(format "%dC %dL" chars lines)))
|
||||||
:face highlight-face)
|
(t (format "%dC" (if evil chars (1- chars)))))))
|
||||||
|
highlight-face)))
|
||||||
|
|
||||||
;; flycheck
|
;; flycheck
|
||||||
(defun narf--flycheck-count (state)
|
(defun narf--flycheck-count (state)
|
||||||
|
@ -376,23 +382,23 @@ 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."
|
||||||
(or (and (or (eq narf--flycheck-err-cache narf--flycheck-cache)
|
(when (and (bound-and-true-p flycheck-mode)
|
||||||
(memq flycheck-last-status-change '(running not-checked)))
|
|
||||||
narf--flycheck-cache)
|
|
||||||
(and (setq narf--flycheck-err-cache flycheck-current-errors)
|
|
||||||
(setq narf--flycheck-cache
|
|
||||||
(let ((fe (narf--flycheck-count 'error))
|
|
||||||
(fw (narf--flycheck-count 'warning))
|
|
||||||
;; (fi (narf--flycheck-count 'info))
|
|
||||||
)
|
|
||||||
(concat
|
|
||||||
(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 fi (propertize (format " ⚠%s " fi) 'face 'spaceline-flycheck-info))
|
|
||||||
)))))
|
|
||||||
:when (and (bound-and-true-p flycheck-mode)
|
|
||||||
(or flycheck-current-errors
|
(or flycheck-current-errors
|
||||||
(eq 'running flycheck-last-status-change)))
|
(eq 'running flycheck-last-status-change)))
|
||||||
|
(or (and (or (eq narf--flycheck-err-cache narf--flycheck-cache)
|
||||||
|
(memq flycheck-last-status-change '(running not-checked)))
|
||||||
|
narf--flycheck-cache)
|
||||||
|
(and (setq narf--flycheck-err-cache flycheck-current-errors)
|
||||||
|
(setq narf--flycheck-cache
|
||||||
|
(let ((fe (narf--flycheck-count 'error))
|
||||||
|
(fw (narf--flycheck-count 'warning))
|
||||||
|
;; (fi (narf--flycheck-count 'info))
|
||||||
|
)
|
||||||
|
(concat
|
||||||
|
(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 fi (propertize (format " ⚠%s " fi) 'face 'spaceline-flycheck-info))
|
||||||
|
))))))
|
||||||
: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
|
||||||
|
|
|
@ -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))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue