Update+optimize mode-line config (b/c of spaceline update)
This commit is contained in:
parent
6761a796f9
commit
8fa1aaa784
1 changed files with 117 additions and 111 deletions
228
core/core-ui.el
228
core/core-ui.el
|
@ -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))))
|
||||||
(if (> (length buffer-path) max-length)
|
(concat (projectile-project-name) "/"
|
||||||
(let ((path (reverse (split-string buffer-path "/")))
|
(if (> (length buffer-path) max-length)
|
||||||
(output ""))
|
(let ((path (reverse (split-string buffer-path "/" t)))
|
||||||
(when (and path (equal "" (car path)))
|
(output ""))
|
||||||
(setq path (cdr path)))
|
(when (and path (equal "" (car path)))
|
||||||
(while (and path (< (length output) (- max-length 4)))
|
(setq path (cdr path)))
|
||||||
(setq output (concat (car path) "/" output))
|
(while (and path (<= (length output) (- max-length 4)))
|
||||||
(setq path (cdr path)))
|
(setq output (concat (car path) "/" output))
|
||||||
(when path
|
(setq path (cdr path)))
|
||||||
(setq output (concat "../" output)))
|
(when path
|
||||||
output)
|
(setq output (concat "../" output)))
|
||||||
buffer-path))
|
(when (string-suffix-p "/" output)
|
||||||
|
(setq output (substring output 0 -1)))
|
||||||
|
output)
|
||||||
|
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
|
||||||
(propertize
|
(unless (string-prefix-p "*" (buffer-name))
|
||||||
(concat (when buffer-file-name
|
(propertize
|
||||||
(concat
|
(concat (when buffer-file-name
|
||||||
(if (buffer-modified-p) "[+]")
|
(concat
|
||||||
(if (not (file-exists-p buffer-file-name)) "[!]")))
|
(if (buffer-modified-p) "[+]")
|
||||||
(if buffer-read-only "[RO]"))
|
(if (not (file-exists-p buffer-file-name)) "[!]")))
|
||||||
'face 'mode-line-is-modified)
|
(if buffer-read-only "[RO]"))
|
||||||
:when (not (string-prefix-p "*" (buffer-name)))
|
'face 'mode-line-is-modified))
|
||||||
: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,93 +265,96 @@
|
||||||
(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."
|
||||||
(let ((here anzu--current-position)
|
(when (evil-ex-hl-active-p 'evil-ex-search)
|
||||||
(total anzu--total-matched))
|
(propertize
|
||||||
(format " %s/%d%s "
|
(let ((here anzu--current-position)
|
||||||
here total
|
(total anzu--total-matched))
|
||||||
(if anzu--overflow-p "+" "")))
|
(format " %s/%d%s "
|
||||||
:face (if active 'mode-line-count-face 'mode-line-inactive)
|
here total
|
||||||
:when (evil-ex-hl-active-p 'evil-ex-search)
|
(if anzu--overflow-p "+" "")))
|
||||||
|
'face (if active 'mode-line-count-face 'mode-line-inactive)))
|
||||||
: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."
|
||||||
(let ((this-oc (iedit-find-current-occurrence-overlay))
|
(when (bound-and-true-p iedit-mode)
|
||||||
(length (or (ignore-errors (length iedit-occurrences-overlays)) 0)))
|
(propertize
|
||||||
(format " %s/%s "
|
(let ((this-oc (iedit-find-current-occurrence-overlay))
|
||||||
(save-excursion
|
(length (or (ignore-errors (length iedit-occurrences-overlays)) 0)))
|
||||||
(unless this-oc
|
(format " %s/%s "
|
||||||
(iedit-prev-occurrence)
|
(save-excursion
|
||||||
(setq this-oc (iedit-find-current-occurrence-overlay)))
|
(unless this-oc
|
||||||
(if this-oc
|
(iedit-prev-occurrence)
|
||||||
;; NOTE: Not terribly reliable
|
(setq this-oc (iedit-find-current-occurrence-overlay)))
|
||||||
(- length (-elem-index this-oc iedit-occurrences-overlays))
|
(if this-oc
|
||||||
"-"))
|
;; NOTE: Not terribly reliable
|
||||||
length))
|
(- length (-elem-index this-oc iedit-occurrences-overlays))
|
||||||
:when (bound-and-true-p iedit-mode)
|
"-"))
|
||||||
:tight t
|
length))
|
||||||
:face (if active 'mode-line-count-face 'mode-line-inactive))
|
'face (if active 'mode-line-count-face 'mode-line-inactive)))
|
||||||
|
:tight t)
|
||||||
|
|
||||||
(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."
|
||||||
(let ((range (if evil-ex-range
|
(when (and (evil-ex-p) (evil-ex-hl-active-p 'evil-ex-substitute))
|
||||||
(cons (car evil-ex-range) (cadr evil-ex-range))
|
(propertize
|
||||||
(cons (line-beginning-position) (line-end-position))))
|
(let ((range (if evil-ex-range
|
||||||
(pattern (car-safe (evil-delimited-arguments evil-ex-argument 2))))
|
(cons (car evil-ex-range) (cadr evil-ex-range))
|
||||||
(if pattern
|
(cons (line-beginning-position) (line-end-position))))
|
||||||
(format " %s matches "
|
(pattern (car-safe (evil-delimited-arguments evil-ex-argument 2))))
|
||||||
(count-matches pattern (car range) (cdr range))
|
(if pattern
|
||||||
evil-ex-argument)
|
(format " %s matches "
|
||||||
" ... "))
|
(count-matches pattern (car range) (cdr range))
|
||||||
:when (and (evil-ex-p) (evil-ex-hl-active-p 'evil-ex-substitute))
|
evil-ex-argument)
|
||||||
:tight t
|
" ... "))
|
||||||
:face (if active 'mode-line-count-face 'mode-line-inactive))
|
'face (if active 'mode-line-count-face 'mode-line-inactive)))
|
||||||
|
:tight t)
|
||||||
|
|
||||||
(spaceline-define-segment *macro-recording
|
(spaceline-define-segment *macro-recording
|
||||||
"Show when recording macro"
|
"Show when recording macro"
|
||||||
(format " %s ▶ " (char-to-string evil-this-macro))
|
(when (and active defining-kbd-macro)
|
||||||
:when (and active defining-kbd-macro)
|
(propertize
|
||||||
:face highlight-face
|
(format " %s ▶ " (char-to-string evil-this-macro))
|
||||||
|
'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)
|
(/= text-scale-mode-amount 0)
|
||||||
(/= text-scale-mode-amount 0)
|
(format " (%+d)" text-scale-mode-amount)))
|
||||||
(format " (%+d)" text-scale-mode-amount)))
|
|
||||||
:tight-right t)
|
:tight-right t)
|
||||||
|
|
||||||
(spaceline-define-segment *selection-info
|
(spaceline-define-segment *selection-info
|
||||||
"Information about the current selection."
|
"Information about the current selection."
|
||||||
(let ((reg-beg (region-beginning))
|
(when (and active (evil-visual-state-p))
|
||||||
(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)))
|
||||||
:when (evil-visual-state-p)
|
(t (format "%dC" (if evil chars (1- chars))))))))
|
||||||
: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
|
:tight t)
|
||||||
:fallback ("%I" :tight-right t))
|
*buffer-path
|
||||||
*buffer-path
|
*buffer-modified
|
||||||
*buffer-modified
|
*vc)
|
||||||
*vc
|
;; Right side
|
||||||
)
|
'(*selection-info
|
||||||
;; Right side
|
*major-mode
|
||||||
'((*selection-info :when active)
|
*env-version
|
||||||
(*major-mode *env-version)
|
*buffer-encoding-abbrev
|
||||||
*buffer-encoding-abbrev
|
(global :when active)
|
||||||
(global :when active)
|
("%l/%c" :tight t)
|
||||||
("%l/%c" *buffer-position)
|
*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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue