ui/doom-modeline: general refactor (especially anzu segment)
This commit is contained in:
parent
dd11790959
commit
5184c3ec35
1 changed files with 36 additions and 20 deletions
|
@ -37,7 +37,10 @@
|
||||||
:config
|
:config
|
||||||
(setq anzu-cons-mode-line-p nil
|
(setq anzu-cons-mode-line-p nil
|
||||||
anzu-minimum-input-length 1
|
anzu-minimum-input-length 1
|
||||||
anzu-search-threshold 250))
|
anzu-search-threshold 250)
|
||||||
|
;; Ensure anzu state is cleared when iedit is exited
|
||||||
|
(after! evil-multiedit
|
||||||
|
(add-hook 'iedit-mode-end-hook 'anzu--reset-mode-line)))
|
||||||
|
|
||||||
|
|
||||||
;;; Flash the mode-line on error
|
;;; Flash the mode-line on error
|
||||||
|
@ -256,6 +259,7 @@ buffer where knowing the current project directory is important."
|
||||||
(propertize (concat " " (abbreviate-file-name (doom-project-root)))
|
(propertize (concat " " (abbreviate-file-name (doom-project-root)))
|
||||||
'face face))))
|
'face face))))
|
||||||
|
|
||||||
|
;;
|
||||||
(def-modeline-segment! buffer-info
|
(def-modeline-segment! buffer-info
|
||||||
"Combined information about the current buffer, including the current working
|
"Combined information about the current buffer, including the current working
|
||||||
directory, the file name, and its state (modified, read-only or non-existent)."
|
directory, the file name, and its state (modified, read-only or non-existent)."
|
||||||
|
@ -285,6 +289,7 @@ directory, the file name, and its state (modified, read-only or non-existent)."
|
||||||
(propertize (+doom-modeline--buffer-path)
|
(propertize (+doom-modeline--buffer-path)
|
||||||
'face (if faces `(:inherit ,faces))))))
|
'face (if faces `(:inherit ,faces))))))
|
||||||
|
|
||||||
|
;;
|
||||||
(def-modeline-segment! buffer-encoding
|
(def-modeline-segment! buffer-encoding
|
||||||
"Displays the encoding and eol style of the buffer the same way Atom does."
|
"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)))
|
(concat (let ((eol-type (coding-system-eol-type buffer-file-coding-system)))
|
||||||
|
@ -299,6 +304,7 @@ directory, the file name, and its state (modified, read-only or non-existent)."
|
||||||
(t (upcase (symbol-name sys-name)))))
|
(t (upcase (symbol-name sys-name)))))
|
||||||
" "))
|
" "))
|
||||||
|
|
||||||
|
;;
|
||||||
(def-modeline-segment! major-mode
|
(def-modeline-segment! major-mode
|
||||||
"The major mode, including process, environment and text-scale info."
|
"The major mode, including process, environment and text-scale info."
|
||||||
(propertize
|
(propertize
|
||||||
|
@ -310,6 +316,7 @@ directory, the file name, and its state (modified, read-only or non-existent)."
|
||||||
(format " (%+d)" text-scale-mode-amount)))
|
(format " (%+d)" text-scale-mode-amount)))
|
||||||
'face (if (active) 'doom-modeline-buffer-major-mode)))
|
'face (if (active) 'doom-modeline-buffer-major-mode)))
|
||||||
|
|
||||||
|
;;
|
||||||
(def-modeline-segment! vcs
|
(def-modeline-segment! vcs
|
||||||
"Displays the current branch, colored based on its state."
|
"Displays the current branch, colored based on its state."
|
||||||
(when vc-mode
|
(when vc-mode
|
||||||
|
@ -349,6 +356,7 @@ directory, the file name, and its state (modified, read-only or non-existent)."
|
||||||
" "
|
" "
|
||||||
+doom-modeline-vspc))))
|
+doom-modeline-vspc))))
|
||||||
|
|
||||||
|
;;
|
||||||
(def-memoized! +doom-ml-icon (icon &optional text face)
|
(def-memoized! +doom-ml-icon (icon &optional text face)
|
||||||
"Displays an octicon ICON with FACE, followed by TEXT. Uses
|
"Displays an octicon ICON with FACE, followed by TEXT. Uses
|
||||||
`all-the-icons-octicon' to fetch the icon."
|
`all-the-icons-octicon' to fetch the icon."
|
||||||
|
@ -381,12 +389,13 @@ icons."
|
||||||
;; ('suspicious "")
|
;; ('suspicious "")
|
||||||
)))
|
)))
|
||||||
|
|
||||||
|
;;
|
||||||
(defsubst doom-column (pos)
|
(defsubst doom-column (pos)
|
||||||
(save-excursion (goto-char pos)
|
(save-excursion (goto-char pos)
|
||||||
(current-column)))
|
(current-column)))
|
||||||
|
|
||||||
(defvar evil-state)
|
(defvar evil-state nil)
|
||||||
(defvar evil-visual-selection)
|
(defvar evil-visual-selection nil)
|
||||||
(def-modeline-segment! selection-info
|
(def-modeline-segment! selection-info
|
||||||
"Information about the current selection, such as how many characters and
|
"Information about the current selection, such as how many characters and
|
||||||
lines are selected, or the NxM dimensions of a block selection."
|
lines are selected, or the NxM dimensions of a block selection."
|
||||||
|
@ -409,6 +418,7 @@ lines are selected, or the NxM dimensions of a block selection."
|
||||||
'face 'doom-modeline-highlight))))
|
'face 'doom-modeline-highlight))))
|
||||||
|
|
||||||
|
|
||||||
|
;;
|
||||||
(defun +doom-modeline--macro-recording ()
|
(defun +doom-modeline--macro-recording ()
|
||||||
"Display current Emacs or evil macro being recorded."
|
"Display current Emacs or evil macro being recorded."
|
||||||
(when (and (active) (or defining-kbd-macro executing-kbd-macro))
|
(when (and (active) (or defining-kbd-macro executing-kbd-macro))
|
||||||
|
@ -424,31 +434,37 @@ lines are selected, or the NxM dimensions of a block selection."
|
||||||
:v-adjust -0.05)
|
:v-adjust -0.05)
|
||||||
sep))))
|
sep))))
|
||||||
|
|
||||||
(make-variable-buffer-local 'anzu--state)
|
(defvar iedit-mode nil)
|
||||||
|
(defvar anzu--state nil)
|
||||||
(defsubst +doom-modeline--anzu ()
|
(defsubst +doom-modeline--anzu ()
|
||||||
"Show the match index and total number thereof. Requires `evil-anzu'."
|
"Show the match index and total number thereof. Requires `anzu', also
|
||||||
(when (and (bound-and-true-p anzu--current-position)
|
`evil-anzu' if using `evil-mode' for compatibility with `evil-search'."
|
||||||
(evil-ex-hl-active-p 'evil-ex-search))
|
(when (and anzu--state (not iedit-mode))
|
||||||
(propertize
|
(propertize
|
||||||
(format " %s/%d%s "
|
(let ((here anzu--current-position)
|
||||||
anzu--current-position anzu--total-matched
|
(total anzu--total-matched))
|
||||||
(if anzu--overflow-p "+" ""))
|
(pcase anzu--state
|
||||||
|
('replace-query (format " %d replace " total))
|
||||||
|
('replace (format " %d/%d " here total))
|
||||||
|
(_ (format " %s/%d%s " here total (if anzu--overflow-p "+" "")))))
|
||||||
'face (if (active) 'doom-modeline-panel))))
|
'face (if (active) 'doom-modeline-panel))))
|
||||||
|
;; Ensure anzu state is cleared when searches are aborted
|
||||||
|
(advice-add 'evil-ex-search-abort :after 'anzu--reset-mode-line)
|
||||||
|
|
||||||
|
(defvar evil-mode nil)
|
||||||
(defsubst +doom-modeline--evil-substitute ()
|
(defsubst +doom-modeline--evil-substitute ()
|
||||||
"Show number of :s matches in real time."
|
"Show number of :s matches in real time."
|
||||||
(when (and (featurep 'evil)
|
(when (and evil-mode
|
||||||
(evil-ex-p) (or (evil-ex-hl-active-p 'evil-ex-substitute)
|
(or (assq 'evil-ex-substitute evil-ex-active-highlights-alist)
|
||||||
(evil-ex-hl-active-p 'evil-ex-global-match)
|
(assq 'evil-ex-global-match evil-ex-active-highlights-alist)
|
||||||
(evil-ex-hl-active-p 'evil-ex-buffer-match)))
|
(assq 'evil-ex-buffer-match evil-ex-active-highlights-alist)))
|
||||||
(propertize
|
(propertize
|
||||||
(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))))
|
||||||
(pattern (car-safe (evil-delimited-arguments evil-ex-argument 2))))
|
(pattern (car-safe (evil-delimited-arguments evil-ex-argument 2))))
|
||||||
(if pattern
|
(if pattern
|
||||||
(format " %s matches "
|
(format " %s matches " (how-many pattern (car range) (cdr range)))
|
||||||
(count-matches pattern (car range) (cdr range)))
|
|
||||||
" ... "))
|
" ... "))
|
||||||
'face (if (active) 'doom-modeline-panel))))
|
'face (if (active) 'doom-modeline-panel))))
|
||||||
|
|
||||||
|
@ -482,12 +498,14 @@ with `evil-ex-substitute', and/or 4. The number of active `iedit' regions."
|
||||||
(or (and (not (string-empty-p meta)) meta)
|
(or (and (not (string-empty-p meta)) meta)
|
||||||
" %I ")))
|
" %I ")))
|
||||||
|
|
||||||
|
;; TODO Include other information
|
||||||
(def-modeline-segment! media-info
|
(def-modeline-segment! media-info
|
||||||
"Metadata regarding the current file, such as dimensions for images."
|
"Metadata regarding the current file, such as dimensions for images."
|
||||||
(cond ((eq major-mode 'image-mode)
|
(cond ((eq major-mode 'image-mode)
|
||||||
(let ((size (image-size (image-get-display-property) :pixels)))
|
(let ((size (image-size (image-get-display-property) :pixels)))
|
||||||
(format " %dx%d " (car size) (cdr size))))))
|
(format " %dx%d " (car size) (cdr size))))))
|
||||||
|
|
||||||
|
;;
|
||||||
(def-modeline-segment! eldoc
|
(def-modeline-segment! eldoc
|
||||||
"Used with `eldoc-eval' to show the eldoc string in the modeline, while using
|
"Used with `eldoc-eval' to show the eldoc string in the modeline, while using
|
||||||
`eval-expression'."
|
`eval-expression'."
|
||||||
|
@ -538,5 +556,3 @@ with `evil-ex-substitute', and/or 4. The number of active `iedit' regions."
|
||||||
(with-current-buffer "*scratch*"
|
(with-current-buffer "*scratch*"
|
||||||
(setq mode-line-format (doom-modeline 'main)))
|
(setq mode-line-format (doom-modeline 'main)))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue