Simplify/polish modeline
This commit is contained in:
parent
13fe3f8d00
commit
465ee1a238
1 changed files with 47 additions and 61 deletions
108
core/core-ui.el
108
core/core-ui.el
|
@ -175,56 +175,36 @@
|
||||||
powerline-default-separator nil
|
powerline-default-separator nil
|
||||||
powerline-height 18)
|
powerline-height 18)
|
||||||
|
|
||||||
;; Modeline cache
|
|
||||||
(defvar narf--spaceline-file-path nil)
|
|
||||||
(make-variable-buffer-local 'narf--spaceline-file-path)
|
|
||||||
(add-hook! focus-in (setq narf--spaceline-file-path nil))
|
|
||||||
|
|
||||||
(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")
|
||||||
(defface mode-line-buffer-dir nil "Face for mode-line buffer dirname")
|
(defface mode-line-buffer-dir nil "Face for mode-line buffer dirname")
|
||||||
|
|
||||||
;; Custom modeline segments
|
;; Custom modeline segments
|
||||||
(spaceline-define-segment narf-buffer-path
|
(spaceline-define-segment narf-buffer-path
|
||||||
"Buffer file path."
|
(if buffer-file-name
|
||||||
(let ((buffer (propertize "%b" 'face
|
(let* ((project-path (let (projectile-require-project-root) (projectile-project-root)))
|
||||||
(if (powerline-selected-window-active)
|
(buffer-path (file-relative-name buffer-file-name project-path))
|
||||||
'mode-line-buffer-file
|
(max-length (/ (window-width) 2))
|
||||||
'mode-line-inactive))))
|
(path-len (length buffer-path)))
|
||||||
(if buffer-file-name
|
(concat (file-name-nondirectory (directory-file-name project-path))
|
||||||
(concat (propertize
|
"/"
|
||||||
(or narf--spaceline-file-path
|
(if (> path-len max-length)
|
||||||
(setq narf--spaceline-file-path
|
(concat "…" (replace-regexp-in-string
|
||||||
(let* ((max-length (/ (window-width) 2))
|
"^.*?/" "/"
|
||||||
(project-path (let ((p (narf/project-root)))
|
(substring buffer-path (- path-len max-length) path-len)))
|
||||||
(if (string-match "/+\\'" p)
|
buffer-path)))
|
||||||
(replace-match "" t t p)
|
"%b")
|
||||||
p)))
|
:face (if active 'mode-line-buffer-file 'mode-line-inactive)
|
||||||
(path (f-dirname (f-relative buffer-file-truename (f-dirname project-path))))
|
:tight-right t)
|
||||||
(path-len (length path)))
|
|
||||||
(if (> path-len max-length)
|
|
||||||
(concat "…" (replace-regexp-in-string
|
|
||||||
"^.*?/" "/"
|
|
||||||
(substring path (- path-len max-length) path-len)))
|
|
||||||
path))))
|
|
||||||
'face (if (powerline-selected-window-active)
|
|
||||||
'mode-line-buffer-dir
|
|
||||||
'mode-line-inactive))
|
|
||||||
buffer
|
|
||||||
(when buffer-file-name
|
|
||||||
(propertize
|
|
||||||
(concat
|
|
||||||
(when (buffer-modified-p) "[+]")
|
|
||||||
(when buffer-read-only "[RO]")
|
|
||||||
(unless (file-exists-p buffer-file-name) "[!]"))
|
|
||||||
'face (if active 'mode-line-is-modified 'mode-line-inactive))))
|
|
||||||
buffer)))
|
|
||||||
|
|
||||||
(spaceline-define-segment narf-buffer-project-name
|
(spaceline-define-segment narf-buffer-modified
|
||||||
"The project name."
|
(concat
|
||||||
(file-name-nondirectory (f-expand (narf/project-root)))
|
(if (and buffer-file-name (buffer-modified-p)) "[+]")
|
||||||
:when (and (not (derived-mode-p 'special-mode))
|
(if buffer-read-only "[RO]")
|
||||||
(string-match-p "^ ?\\*" (buffer-name))))
|
(if (and buffer-file-name (not (file-exists-p buffer-file-name))) "[!]"))
|
||||||
|
:face mode-line-is-modified
|
||||||
|
:when (not (string-match-p "^\\s*\\*" (buffer-name)))
|
||||||
|
:tight t)
|
||||||
|
|
||||||
(spaceline-define-segment narf-buffer-encoding-abbrev
|
(spaceline-define-segment narf-buffer-encoding-abbrev
|
||||||
"The line ending convention used in the buffer."
|
"The line ending convention used in the buffer."
|
||||||
|
@ -240,16 +220,18 @@
|
||||||
(let ((perc (/ (window-end) 0.01 (point-max))))
|
(let ((perc (/ (window-end) 0.01 (point-max))))
|
||||||
(cond ((eq (window-start) 1) ":Top")
|
(cond ((eq (window-start) 1) ":Top")
|
||||||
((>= perc 100) ":Bot")
|
((>= perc 100) ":Bot")
|
||||||
(t (format ":%d%%%%" perc)))))
|
(t (format ":%d%%%%" perc))))
|
||||||
|
:tight-right t)
|
||||||
|
|
||||||
(spaceline-define-segment narf-vc
|
(spaceline-define-segment narf-vc
|
||||||
"Version control info"
|
"Version control info"
|
||||||
(let ((vc (vc-working-revision buffer-file-name)))
|
(let ((vc (vc-working-revision buffer-file-name)))
|
||||||
(when vc
|
(when vc
|
||||||
(format " %s %s%s " (char-to-string #xe0a0) vc
|
(format "%s%s" vc (case (vc-state buffer-file-name)
|
||||||
(case (vc-state buffer-file-name) ('edited "+") ('conflict "!!!") (t "")))))
|
('edited "+")
|
||||||
:when (and active vc-mode)
|
('conflict "!!!")
|
||||||
:tight t)
|
(t "")))))
|
||||||
|
:when (and active vc-mode))
|
||||||
|
|
||||||
;; Display version string
|
;; Display version string
|
||||||
(defvar narf--env-version nil)
|
(defvar narf--env-version nil)
|
||||||
|
@ -267,7 +249,7 @@
|
||||||
(spaceline-define-segment narf-hud
|
(spaceline-define-segment narf-hud
|
||||||
"A HUD that shows which part of the buffer is currently visible."
|
"A HUD that shows which part of the buffer is currently visible."
|
||||||
(powerline-hud highlight-face default-face 1)
|
(powerline-hud highlight-face default-face 1)
|
||||||
:tight t)
|
:tight-right t)
|
||||||
|
|
||||||
(spaceline-define-segment narf-anzu
|
(spaceline-define-segment narf-anzu
|
||||||
"Show the current match number and the total number of matches. Requires anzu
|
"Show the current match number and the total number of matches. Requires anzu
|
||||||
|
@ -275,28 +257,32 @@ to be enabled."
|
||||||
(let ((here anzu--current-position)
|
(let ((here anzu--current-position)
|
||||||
(total anzu--total-matched))
|
(total anzu--total-matched))
|
||||||
(when anzu--state
|
(when anzu--state
|
||||||
(cl-case anzu--state
|
(concat
|
||||||
(search (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 "
|
||||||
(replace-query (format "%d replace" total))
|
(anzu--format-here-position here total)
|
||||||
(replace (format "%d/%d" here total)))))
|
total (if anzu--overflow-p "+" "")))
|
||||||
:when (and active (bound-and-true-p anzu--state)))
|
(replace-query (format " %d replace " total))
|
||||||
|
(replace (format " %d/%d " here total)))
|
||||||
|
'face highlight-face)
|
||||||
|
" ")))
|
||||||
|
:when (and active (bound-and-true-p anzu--state))
|
||||||
|
:tight t)
|
||||||
|
|
||||||
;; Initialize modeline
|
;; Initialize modeline
|
||||||
(spaceline-install
|
(spaceline-install
|
||||||
;; Left side
|
;; Left side
|
||||||
'((narf-anzu :face highlight-face)
|
'(narf-anzu
|
||||||
(narf-buffer-path remote-host)
|
(narf-buffer-path remote-host)
|
||||||
|
narf-buffer-modified
|
||||||
narf-vc
|
narf-vc
|
||||||
narf-buffer-project-name
|
|
||||||
((flycheck-error flycheck-warning flycheck-info) :when active))
|
((flycheck-error flycheck-warning flycheck-info) :when active))
|
||||||
;; Right side
|
;; Right side
|
||||||
'((selection-info :face highlight-face)
|
'((selection-info :face highlight-face)
|
||||||
narf-env-version
|
narf-env-version
|
||||||
narf-buffer-encoding-abbrev
|
narf-buffer-encoding-abbrev
|
||||||
((" " :tight t)
|
(major-mode (minor-modes :tight t :separator "")
|
||||||
major-mode (minor-modes :tight t :separator " ")
|
|
||||||
process :when active)
|
process :when active)
|
||||||
(global :when active)
|
(global :when active)
|
||||||
("%l/%c" narf-buffer-position)
|
("%l/%c" narf-buffer-position)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue