Clean up mode-line segments
This commit is contained in:
parent
d0770a0111
commit
35199496d4
1 changed files with 63 additions and 86 deletions
149
core/core-ui.el
149
core/core-ui.el
|
@ -1,12 +1,12 @@
|
||||||
;;; core-ui.el --- interface settings
|
;;; core-ui.el --- interface & mode-line config
|
||||||
|
|
||||||
(setq-default
|
(setq-default
|
||||||
blink-matching-paren nil ; don't blink matching delimiters--too distracting
|
blink-matching-paren nil ; don't blink--too distracting
|
||||||
show-paren-delay 0.075
|
show-paren-delay 0.075
|
||||||
|
|
||||||
cursor-in-non-selected-windows nil ; no cursors except in active buffer
|
;; Keep cursors and highlights in current window only
|
||||||
|
cursor-in-non-selected-windows nil
|
||||||
highlight-nonselected-windows nil
|
highlight-nonselected-windows nil
|
||||||
hl-line-sticky-flag nil ; only highlight in one window
|
|
||||||
|
|
||||||
uniquify-buffer-name-style nil ; my mode-line does this for me
|
uniquify-buffer-name-style nil ; my mode-line does this for me
|
||||||
visible-bell nil
|
visible-bell nil
|
||||||
|
@ -46,9 +46,7 @@
|
||||||
(y-or-n-p ">> Gee, I dunno Brain... Are you sure?")
|
(y-or-n-p ">> Gee, I dunno Brain... Are you sure?")
|
||||||
t))))
|
t))))
|
||||||
|
|
||||||
(blink-cursor-mode 1) ; blink cursor
|
(tooltip-mode -1) ; show tooltips in echo area
|
||||||
(tooltip-mode -1) ; show tooltips in echo area
|
|
||||||
|
|
||||||
;; set up minibuffer and fringe
|
;; set up minibuffer and fringe
|
||||||
(if (not window-system)
|
(if (not window-system)
|
||||||
(menu-bar-mode -1)
|
(menu-bar-mode -1)
|
||||||
|
@ -114,9 +112,11 @@
|
||||||
|
|
||||||
(use-package hl-line
|
(use-package hl-line
|
||||||
:init
|
:init
|
||||||
(add-hook! (prog-mode markdown-mode) 'hl-line-mode) ; line highlighting
|
(add-hook! (prog-mode markdown-mode) 'hl-line-mode)
|
||||||
:config
|
:config
|
||||||
(defvar-local narf--hl-line-mode nil)
|
(defvar-local narf--hl-line-mode nil)
|
||||||
|
(setq hl-line-sticky-flag nil
|
||||||
|
global-hl-line-sticky-flag nil)
|
||||||
|
|
||||||
(defun narf|hl-line-on () (if narf--hl-line-mode (hl-line-mode +1)))
|
(defun narf|hl-line-on () (if narf--hl-line-mode (hl-line-mode +1)))
|
||||||
(defun narf|hl-line-off () (if narf--hl-line-mode (hl-line-mode -1)))
|
(defun narf|hl-line-off () (if narf--hl-line-mode (hl-line-mode -1)))
|
||||||
|
@ -203,56 +203,41 @@
|
||||||
(defvar-local narf--env-version nil)
|
(defvar-local narf--env-version nil)
|
||||||
(defvar-local narf--env-command nil)
|
(defvar-local narf--env-command nil)
|
||||||
(defvar powerline-height 23)
|
(defvar powerline-height 23)
|
||||||
(setq-default
|
(defvar powerline-default-separator nil)
|
||||||
powerline-default-separator nil
|
|
||||||
spaceline-highlight-face-func 'spaceline-highlight-face-evil-state)
|
|
||||||
|
|
||||||
: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 path")
|
||||||
|
|
||||||
;; Custom modeline segments
|
;; Custom modeline segments
|
||||||
(spaceline-define-segment *buffer-size ""
|
|
||||||
"%I"
|
|
||||||
:when buffer-file-name
|
|
||||||
:tight-right t)
|
|
||||||
|
|
||||||
(spaceline-define-segment *buffer-path
|
(spaceline-define-segment *buffer-path
|
||||||
(if buffer-file-name
|
(if buffer-file-name
|
||||||
(let* ((project-path (narf/project-root))
|
(let ((buffer-path (f-relative buffer-file-name (f-dirname (narf/project-root))))
|
||||||
(buffer-path (f-relative buffer-file-name project-path))
|
(max-length 50))
|
||||||
(max-length 40))
|
(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 "/")))
|
(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))
|
||||||
output)
|
|
||||||
buffer-path)))
|
|
||||||
"%b")
|
"%b")
|
||||||
:face (if active 'mode-line-buffer-file 'mode-line-inactive)
|
:face other-face
|
||||||
:skip-alternate t
|
|
||||||
:tight-right t)
|
:tight-right t)
|
||||||
|
|
||||||
(spaceline-define-segment *remote-host
|
|
||||||
"Hostname for remote buffers."
|
|
||||||
(concat "@" (file-remote-p default-directory 'host))
|
|
||||||
:when (file-remote-p default-directory 'host))
|
|
||||||
|
|
||||||
(spaceline-define-segment *buffer-modified
|
(spaceline-define-segment *buffer-modified
|
||||||
(concat
|
(propertize
|
||||||
(when buffer-file-name
|
(concat (when buffer-file-name
|
||||||
(concat
|
(concat
|
||||||
(when (buffer-modified-p) "[+]")
|
(if (buffer-modified-p) "[+]")
|
||||||
(unless (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)))
|
:when (not (string-prefix-p "*" (buffer-name)))
|
||||||
:skip-alternate t
|
:skip-alternate t
|
||||||
:tight t)
|
:tight t)
|
||||||
|
@ -266,29 +251,18 @@
|
||||||
(eq end pend))
|
(eq end pend))
|
||||||
":All"
|
":All"
|
||||||
(let ((perc (/ end 0.01 pend)))
|
(let ((perc (/ end 0.01 pend)))
|
||||||
(cond ((eq start 1) ":Top")
|
(cond ((= start 1) ":Top")
|
||||||
((>= perc 100) ":Bot")
|
((>= perc 100) ":Bot")
|
||||||
(t (format ":%d%%%%" perc))))))
|
(t (format ":%d%%%%" perc))))))
|
||||||
:tight t)
|
:tight t)
|
||||||
|
|
||||||
(spaceline-define-segment *vc
|
(spaceline-define-segment *vc
|
||||||
"Version control info"
|
"Version control info"
|
||||||
(concat (replace-regexp-in-string
|
(substring vc-mode (+ 1 (length (symbol-name (vc-backend buffer-file-name)))))
|
||||||
(format "^ %s" (vc-backend buffer-file-name))
|
|
||||||
"" vc-mode))
|
|
||||||
:when (and active vc-mode)
|
:when (and active vc-mode)
|
||||||
:face other-face
|
:face other-face
|
||||||
:tight-right t)
|
:tight-right t)
|
||||||
|
|
||||||
(spaceline-define-segment *env-version
|
|
||||||
"Shows the environment version of a mode (e.g. pyenv for python or rbenv for ruby).
|
|
||||||
See `def-env-command!' to define one for a mode."
|
|
||||||
narf--env-version
|
|
||||||
:when narf--env-version
|
|
||||||
:face other-face
|
|
||||||
:skip-alternate t
|
|
||||||
:tight-right t)
|
|
||||||
|
|
||||||
;; search indicators
|
;; search indicators
|
||||||
(defface mode-line-count-face nil "")
|
(defface mode-line-count-face nil "")
|
||||||
(make-variable-buffer-local 'anzu--state)
|
(make-variable-buffer-local 'anzu--state)
|
||||||
|
@ -351,30 +325,32 @@ anzu to be enabled."
|
||||||
(symbol-name buffer-file-coding-system))))
|
(symbol-name buffer-file-coding-system))))
|
||||||
|
|
||||||
(spaceline-define-segment *major-mode
|
(spaceline-define-segment *major-mode
|
||||||
|
"The major mode, including process, environment and text-scale info."
|
||||||
(concat
|
(concat
|
||||||
(and (featurep 'face-remap) (/= text-scale-mode-amount 0) (format "(%+d) " text-scale-mode-amount))
|
(format "%s" mode-name)
|
||||||
(if (stringp mode-name) mode-name (car 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))
|
||||||
|
(and (featurep 'face-remap)
|
||||||
|
(/= text-scale-mode-amount 0)
|
||||||
|
(format " (%+d)" text-scale-mode-amount)))
|
||||||
:tight-right t)
|
:tight-right t)
|
||||||
|
|
||||||
(defun narf--col-at-pos (pos)
|
|
||||||
(save-excursion (goto-char pos) (current-column)))
|
|
||||||
(spaceline-define-segment *selection-info
|
(spaceline-define-segment *selection-info
|
||||||
"Information about the size of the current selection, when applicable.
|
"Information about the current selection."
|
||||||
Supports both Emacs and Evil cursor conventions."
|
|
||||||
(let ((reg-beg (region-beginning))
|
(let ((reg-beg (region-beginning))
|
||||||
(reg-end (region-end)))
|
(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 (- (narf--col-at-pos reg-end)
|
(chars (- (1+ reg-end) reg-beg))
|
||||||
(narf--col-at-pos reg-beg)))))
|
(cols (1+ (abs (- (evil-column reg-end)
|
||||||
(evil (eq 'visual evil-state))
|
(evil-column reg-beg))))))
|
||||||
(rect (or (bound-and-true-p rectangle-mark-mode)
|
|
||||||
(and evil (eq 'block evil-visual-selection))))
|
|
||||||
(multi-line (or (> lines 1) (eq 'line evil-visual-selection))))
|
|
||||||
(cond
|
(cond
|
||||||
(rect (format "%dx%dB" lines (if evil cols (1- cols))))
|
;; rectangle selection
|
||||||
(multi-line
|
((or (bound-and-true-p rectangle-mark-mode)
|
||||||
|
(and evil (eq 'block evil-visual-selection)))
|
||||||
|
(format "%dx%dB" lines (if evil cols (1- cols))))
|
||||||
|
;; line selection
|
||||||
|
((or (> lines 1) (eq 'line evil-visual-selection))
|
||||||
(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)))
|
||||||
|
@ -411,11 +387,13 @@ Supports both Emacs and Evil cursor conventions."
|
||||||
(setq narf--flycheck-cache
|
(setq narf--flycheck-cache
|
||||||
(let ((fe (narf--flycheck-count 'error))
|
(let ((fe (narf--flycheck-count 'error))
|
||||||
(fw (narf--flycheck-count 'warning))
|
(fw (narf--flycheck-count 'warning))
|
||||||
(fi (narf--flycheck-count 'info)))
|
;; (fi (narf--flycheck-count 'info))
|
||||||
|
)
|
||||||
(concat
|
(concat
|
||||||
(when fe (powerline-raw (format " ⚠%s " fe) 'spaceline-flycheck-error))
|
(if fe (propertize (format " ⚠%s " fe) 'face (if active 'spaceline-flycheck-error 'mode-line)))
|
||||||
(when fw (powerline-raw (format " ⚠%s " fw) 'spaceline-flycheck-warning))
|
(if fw (propertize (format " ⚠%s " fw) 'face (if active 'spaceline-flycheck-warning 'mode-line)))
|
||||||
(when fi (powerline-raw (format " ⚠%s " fi) 'spaceline-flycheck-info)))))))
|
;; (if fi (propertize (format " ⚠%s " fi) 'face 'spaceline-flycheck-info))
|
||||||
|
)))))
|
||||||
:when (and (bound-and-true-p flycheck-mode)
|
: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)))
|
||||||
|
@ -423,7 +401,7 @@ Supports both Emacs and Evil cursor conventions."
|
||||||
|
|
||||||
(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))
|
||||||
(spaceline-define-segment *pad
|
(spaceline-define-segment *pad
|
||||||
"A HUD that shows which part of the buffer is currently visible."
|
"Padding, to ensure the mode-line is `powerline-height' pixels tall"
|
||||||
narf--mode-line-padding
|
narf--mode-line-padding
|
||||||
:tight-right t)
|
:tight-right t)
|
||||||
|
|
||||||
|
@ -432,16 +410,15 @@ Supports both Emacs and Evil cursor conventions."
|
||||||
;; 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 *buffer-size)
|
:fallback ("%I" :tight-right t))
|
||||||
(*buffer-path *remote-host)
|
*buffer-path
|
||||||
*buffer-modified
|
*buffer-modified
|
||||||
*vc
|
*vc
|
||||||
)
|
)
|
||||||
;; Right side
|
;; Right side
|
||||||
'((*selection-info :when active)
|
'((*selection-info :when active)
|
||||||
|
(*major-mode *env-version)
|
||||||
*buffer-encoding-abbrev
|
*buffer-encoding-abbrev
|
||||||
*major-mode
|
|
||||||
*env-version
|
|
||||||
(global :when active)
|
(global :when active)
|
||||||
("%l/%c" *buffer-position)
|
("%l/%c" *buffer-position)
|
||||||
*pad
|
*pad
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue