Refactor ui/doom-modeline
This commit is contained in:
parent
a002f7025c
commit
06b5ee8fb8
1 changed files with 86 additions and 97 deletions
|
@ -3,12 +3,20 @@
|
|||
(def-package! eldoc-eval
|
||||
:demand t
|
||||
:config
|
||||
(defun +doom-modeline-eldoc (text)
|
||||
(concat (when (display-graphic-p)
|
||||
(+doom-modeline--make-xpm
|
||||
(face-background 'doom-modeline-eldoc-bar nil t)
|
||||
+doom-modeline-height
|
||||
+doom-modeline-bar-width))
|
||||
text))
|
||||
|
||||
;; Show eldoc in the mode-line with `eval-expression'
|
||||
(defun +doom-modeline--show-eldoc (input)
|
||||
"Display string STR in the mode-line next to minibuffer."
|
||||
(with-current-buffer (eldoc-current-buffer)
|
||||
(let* ((str (and (stringp input) input))
|
||||
(mode-line-format (or (and str (or (doom-modeline 'eldoc) str))
|
||||
(mode-line-format (or (and str (or (+doom-modeline-eldoc str) str))
|
||||
mode-line-format))
|
||||
mode-line-in-non-selected-windows)
|
||||
(force-mode-line-update)
|
||||
|
@ -35,10 +43,9 @@
|
|||
anzu--last-isearch-string anzu--overflow-p))
|
||||
|
||||
;; Ensure anzu state is cleared when searches & iedit are done
|
||||
(add-hook! :append '(isearch-mode-end-hook +evil-esc-hook)
|
||||
#'anzu--reset-status)
|
||||
(after! iedit
|
||||
(add-hook 'iedit-mode-end-hook #'anzu--reset-status)))
|
||||
(add-hook 'isearch-mode-end-hook #'anzu--reset-status t)
|
||||
(add-hook '+evil-esc-hook #'anzu--reset-status t)
|
||||
(add-hook 'iedit-mode-end-hook #'anzu--reset-status))
|
||||
|
||||
|
||||
;; Keep `+doom-modeline-current-window' up-to-date
|
||||
|
@ -303,16 +310,14 @@ directory, the file name, and its state (modified, read-only or non-existent)."
|
|||
;;
|
||||
(def-modeline-segment! buffer-encoding
|
||||
"Displays the encoding and eol style of the buffer the same way Atom does."
|
||||
(concat (let ((eol-type (coding-system-eol-type buffer-file-coding-system)))
|
||||
(cond ((eq eol-type 0) "LF ")
|
||||
((eq eol-type 1) "CRLF ")
|
||||
((eq eol-type 2) "CR ")))
|
||||
(let* ((sys (coding-system-plist buffer-file-coding-system))
|
||||
(sys-name (plist-get sys :name))
|
||||
(sys-cat (plist-get sys :category)))
|
||||
(cond ((memq sys-cat '(coding-category-undecided coding-category-utf-8))
|
||||
(concat (pcase (coding-system-eol-type buffer-file-coding-system)
|
||||
(0 "LF ")
|
||||
(1 "CRLF ")
|
||||
(2 "CR "))
|
||||
(let ((sys (coding-system-plist buffer-file-coding-system)))
|
||||
(cond ((memq (plist-get sys :category) '(coding-category-undecided coding-category-utf-8))
|
||||
"UTF-8")
|
||||
(t (upcase (symbol-name sys-name)))))
|
||||
(t (upcase (symbol-name (plist-get sys :name))))))
|
||||
" "))
|
||||
|
||||
;;
|
||||
|
@ -320,8 +325,10 @@ directory, the file name, and its state (modified, read-only or non-existent)."
|
|||
"The major mode, including process, environment and text-scale info."
|
||||
(propertize
|
||||
(concat (format-mode-line mode-name)
|
||||
(if (stringp mode-line-process) mode-line-process)
|
||||
(if +doom-modeline-env-version (concat " " +doom-modeline-env-version))
|
||||
(when (stringp mode-line-process)
|
||||
mode-line-process)
|
||||
(when +doom-modeline-env-version
|
||||
(concat " " +doom-modeline-env-version))
|
||||
(and (featurep 'face-remap)
|
||||
(/= text-scale-mode-amount 0)
|
||||
(format " (%+d)" text-scale-mode-amount)))
|
||||
|
@ -331,55 +338,53 @@ directory, the file name, and its state (modified, read-only or non-existent)."
|
|||
(def-modeline-segment! vcs
|
||||
"Displays the current branch, colored based on its state."
|
||||
(when (and vc-mode buffer-file-name)
|
||||
(let ((backend (vc-backend buffer-file-name))
|
||||
(state (vc-state buffer-file-name))
|
||||
(face 'mode-line-inactive)
|
||||
(active (active))
|
||||
(all-the-icons-scale-factor 1.0)
|
||||
(all-the-icons-default-adjust -0.1))
|
||||
(concat " "
|
||||
(cond ((memq state '(edited added))
|
||||
(if active (setq face 'doom-modeline-info))
|
||||
(all-the-icons-octicon
|
||||
"git-compare"
|
||||
:face face
|
||||
:height 1.2
|
||||
:v-adjust -0.05))
|
||||
((eq state 'needs-merge)
|
||||
(if active (setq face 'doom-modeline-info))
|
||||
(all-the-icons-octicon "git-merge" :face face))
|
||||
((eq state 'needs-update)
|
||||
(if active (setq face 'doom-modeline-warning))
|
||||
(all-the-icons-octicon "arrow-down" :face face))
|
||||
((memq state '(removed conflict unregistered))
|
||||
(if active (setq face 'doom-modeline-urgent))
|
||||
(all-the-icons-octicon "alert" :face face))
|
||||
(t
|
||||
(if active (setq face 'font-lock-doc-face))
|
||||
(all-the-icons-octicon
|
||||
"git-compare"
|
||||
:face face
|
||||
:height 1.2
|
||||
:v-adjust -0.05)))
|
||||
" "
|
||||
(propertize (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2))
|
||||
'face (if active face))
|
||||
" "))))
|
||||
(let* ((backend (vc-backend buffer-file-name))
|
||||
(state (vc-state buffer-file-name backend)))
|
||||
(let ((face 'mode-line-inactive)
|
||||
(active (active))
|
||||
(all-the-icons-scale-factor 1.0)
|
||||
(all-the-icons-default-adjust -0.1))
|
||||
(concat " "
|
||||
(cond ((memq state '(edited added))
|
||||
(if active (setq face 'doom-modeline-info))
|
||||
(all-the-icons-octicon
|
||||
"git-compare"
|
||||
:face face
|
||||
:height 1.2
|
||||
:v-adjust -0.05))
|
||||
((eq state 'needs-merge)
|
||||
(if active (setq face 'doom-modeline-info))
|
||||
(all-the-icons-octicon "git-merge" :face face))
|
||||
((eq state 'needs-update)
|
||||
(if active (setq face 'doom-modeline-warning))
|
||||
(all-the-icons-octicon "arrow-down" :face face))
|
||||
((memq state '(removed conflict unregistered))
|
||||
(if active (setq face 'doom-modeline-urgent))
|
||||
(all-the-icons-octicon "alert" :face face))
|
||||
(t
|
||||
(if active (setq face 'font-lock-doc-face))
|
||||
(all-the-icons-octicon
|
||||
"git-compare"
|
||||
:face face
|
||||
:height 1.2
|
||||
:v-adjust -0.05)))
|
||||
" "
|
||||
(propertize (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2))
|
||||
'face (if active face))
|
||||
" ")))))
|
||||
|
||||
;;
|
||||
(defun +doom-ml-icon (icon &optional text face voffset)
|
||||
"Displays an octicon ICON with FACE, followed by TEXT. Uses
|
||||
`all-the-icons-octicon' to fetch the icon."
|
||||
(concat
|
||||
(if vc-mode " " " ")
|
||||
(when icon
|
||||
(concat
|
||||
(all-the-icons-material icon :face face :height 1.1 :v-adjust (or voffset -0.2))
|
||||
;; (all-the-icons-octicon icon :face face :height 1.0 :v-adjust 0)
|
||||
(if text +doom-modeline-vspc)))
|
||||
(when text
|
||||
(propertize text 'face face))
|
||||
(if vc-mode " " " ")))
|
||||
(concat (if vc-mode " " " ")
|
||||
(when icon
|
||||
(concat
|
||||
(all-the-icons-material icon :face face :height 1.1 :v-adjust (or voffset -0.2))
|
||||
(if text +doom-modeline-vspc)))
|
||||
(when text
|
||||
(propertize text 'face face))
|
||||
(if vc-mode " " " ")))
|
||||
|
||||
(def-modeline-segment! flycheck
|
||||
"Displays color-coded flycheck error status in the current buffer with pretty
|
||||
|
@ -461,7 +466,7 @@ lines are selected, or the NxM dimensions of a block selection."
|
|||
'face (if (active) 'doom-modeline-panel))))
|
||||
|
||||
(defsubst +doom-modeline--evil-substitute ()
|
||||
"Show number of :s matches in real time."
|
||||
"Show number of matches for evil-ex substitutions and highlights in real time."
|
||||
(when (and evil-mode
|
||||
(or (assq 'evil-ex-substitute evil-ex-active-highlights-alist)
|
||||
(assq 'evil-ex-global-match evil-ex-active-highlights-alist)
|
||||
|
@ -473,9 +478,12 @@ lines are selected, or the NxM dimensions of a block selection."
|
|||
(pattern (car-safe (evil-delimited-arguments evil-ex-argument 2))))
|
||||
(if pattern
|
||||
(format " %s matches " (how-many pattern (car range) (cdr range)))
|
||||
" ... "))
|
||||
" - "))
|
||||
'face (if (active) 'doom-modeline-panel))))
|
||||
|
||||
(defun doom-themes--overlay-sort (a b)
|
||||
(< (overlay-start a) (overlay-start b)))
|
||||
|
||||
(defsubst +doom-modeline--iedit ()
|
||||
"Show the number of iedit regions matches + what match you're on."
|
||||
(when (and iedit-mode iedit-occurrences-overlays)
|
||||
|
@ -488,9 +496,9 @@ lines are selected, or the NxM dimensions of a block selection."
|
|||
(format " %s/%d "
|
||||
(if this-oc
|
||||
(- length
|
||||
(length (cdr
|
||||
(memq this-oc (sort (append iedit-occurrences-overlays (list))
|
||||
(lambda (x y) (< (overlay-start x) (overlay-start y))))))))
|
||||
(length (memq this-oc (sort (append iedit-occurrences-overlays nil)
|
||||
#'doom-themes--overlay-sort)))
|
||||
-1)
|
||||
"-")
|
||||
length))
|
||||
'face (if (active) 'doom-modeline-panel))))
|
||||
|
@ -503,42 +511,27 @@ with `evil-ex-substitute', and/or 4. The number of active `iedit' regions."
|
|||
(+doom-modeline--anzu)
|
||||
(+doom-modeline--evil-substitute)
|
||||
(+doom-modeline--iedit))))
|
||||
(or (and (not (string= meta "")) meta)
|
||||
(or (and (not (equal meta "")) meta)
|
||||
(if buffer-file-name " %I "))))
|
||||
|
||||
;; TODO Include other information
|
||||
(def-modeline-segment! media-info
|
||||
"Metadata regarding the current file, such as dimensions for images."
|
||||
(cond ((eq major-mode 'image-mode)
|
||||
(let ((size (image-size (image-get-display-property) :pixels)))
|
||||
(format " %dx%d " (car size) (cdr size))))))
|
||||
(cl-destructuring-bind (width . height)
|
||||
(image-size (image-get-display-property) :pixels)
|
||||
(format " %dx%d " width height)))))
|
||||
|
||||
;;
|
||||
(def-modeline-segment! eldoc
|
||||
"Display eldoc documentation in the mode-line while using the minibuffer (e.g.
|
||||
`eval-expression')."
|
||||
(bound-and-true-p str))
|
||||
|
||||
;; These bars regulate the height of the mode-line in GUI Emacs.
|
||||
;; The bar regulates the height of the mode-line in GUI Emacs.
|
||||
(def-modeline-segment! bar
|
||||
(if (display-graphic-p)
|
||||
(+doom-modeline--make-xpm
|
||||
(face-background (if (active)
|
||||
'doom-modeline-bar
|
||||
'doom-modeline-inactive-bar)
|
||||
nil t)
|
||||
+doom-modeline-height
|
||||
+doom-modeline-bar-width)
|
||||
""))
|
||||
|
||||
(def-modeline-segment! eldoc-bar
|
||||
"A differently colored bar, to signify an eldoc display."
|
||||
(if (display-graphic-p)
|
||||
(+doom-modeline--make-xpm
|
||||
(face-background 'doom-modeline-eldoc-bar nil t)
|
||||
+doom-modeline-height
|
||||
+doom-modeline-bar-width)
|
||||
""))
|
||||
(when (display-graphic-p)
|
||||
(+doom-modeline--make-xpm
|
||||
(face-background (if (active)
|
||||
'doom-modeline-bar
|
||||
'doom-modeline-inactive-bar)
|
||||
nil t)
|
||||
+doom-modeline-height
|
||||
+doom-modeline-bar-width)))
|
||||
|
||||
|
||||
;;
|
||||
|
@ -549,10 +542,6 @@ with `evil-ex-substitute', and/or 4. The number of active `iedit' regions."
|
|||
(bar matches " " buffer-info " %l:%c %p " selection-info)
|
||||
(buffer-encoding major-mode vcs flycheck))
|
||||
|
||||
(def-modeline! eldoc
|
||||
(eldoc-bar " " eldoc)
|
||||
(media-info major-mode))
|
||||
|
||||
(def-modeline! minimal
|
||||
(bar matches " " buffer-info)
|
||||
(media-info major-mode))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue