mirror of
https://gitlab.com/dwt1/dotfiles.git
synced 2026-04-24 12:00:24 +10:00
Updating Doom Emacs.
This commit is contained in:
@@ -50,17 +50,17 @@ side of the modeline, and whose CDR is the right-hand side.")
|
||||
;;
|
||||
;;; Faces
|
||||
|
||||
(defface +modeline-bar '((t (:inherit highlight)))
|
||||
(defface doom-modeline-bar '((t (:inherit highlight)))
|
||||
"Face used for left-most bar on the mode-line of an active window.")
|
||||
|
||||
(defface +modeline-bar-inactive '((t (:inherit mode-line-inactive)))
|
||||
(defface doom-modeline-bar-inactive '((t (:inherit mode-line-inactive)))
|
||||
"Face used for left-most bar on the mode-line of an inactive window.")
|
||||
|
||||
(defface +modeline-highlight
|
||||
(defface doom-modeline-highlight
|
||||
'((t (:inherit mode-line-highlight)))
|
||||
"Face used for highlighted modeline panels (like search counts).")
|
||||
|
||||
(defface +modeline-alternate-highlight
|
||||
(defface doom-modeline-alternate-highlight
|
||||
'((t (:inherit mode-line-highlight)))
|
||||
"Alternative face used for highlighted modeline panels (like search counts).")
|
||||
|
||||
@@ -68,14 +68,6 @@ side of the modeline, and whose CDR is the right-hand side.")
|
||||
;;
|
||||
;;; Helpers
|
||||
|
||||
(defvar +modeline--redisplayed-p nil)
|
||||
(defadvice! modeline-recalculate-height-a (&optional _force &rest _ignored)
|
||||
"Ensure that window resizing functions take modeline height into account."
|
||||
:before '(fit-window-to-buffer resize-temp-buffer-window)
|
||||
(unless +modeline--redisplayed-p
|
||||
(setq-local +modeline--redisplayed-p t)
|
||||
(redisplay t)))
|
||||
|
||||
;;; `active'
|
||||
(defvar +modeline--active-window (selected-window))
|
||||
|
||||
@@ -144,19 +136,20 @@ If DEFAULT is non-nil, apply to all future buffers. Modelines are defined with
|
||||
See `def-modeline!' on how modelines are defined."
|
||||
(let ((fn (intern (format "+modeline-set-%s-format-h" name))))
|
||||
(dolist (hook (doom-enlist hooks))
|
||||
(when after-init-time
|
||||
(dolist (name (mapcar #'car +modeline-format-alist))
|
||||
(remove-hook hook (intern (format "+modeline-set-%s-format-h" name)))))
|
||||
(add-hook hook fn))))
|
||||
|
||||
(defmacro def-modeline! (name lhs rhs)
|
||||
(defun def-modeline! (name lhs rhs)
|
||||
"Define a modeline format by NAME.
|
||||
LHS and RHS are the formats representing the left and right hand side of the
|
||||
mode-line, respectively. See the variable `format-mode-line' for details on what
|
||||
LHS and RHS will accept."
|
||||
`(progn
|
||||
(setf (alist-get ',name +modeline-format-alist)
|
||||
(cons ,lhs ,rhs))
|
||||
(defun ,(intern (format "+modeline-set-%s-format-h" name)) (&rest _)
|
||||
"TODO"
|
||||
(set-modeline! ',name))))
|
||||
(setf (alist-get name +modeline-format-alist)
|
||||
(cons lhs rhs))
|
||||
(fset (intern (format "+modeline-set-%s-format-h" name))
|
||||
(lambda (&rest _) (set-modeline! name))))
|
||||
|
||||
(defmacro def-modeline-var! (name body &optional docstring &rest plist)
|
||||
"TODO"
|
||||
@@ -182,178 +175,177 @@ LHS and RHS will accept."
|
||||
|
||||
|
||||
;;; `+modeline-bar'
|
||||
(progn
|
||||
(def-modeline-var! +modeline-bar "")
|
||||
(def-modeline-var! +modeline-inactive-bar "")
|
||||
(def-modeline-var! +modeline-bar "")
|
||||
|
||||
(add-hook! '(doom-init-ui-hook doom-load-theme-hook) :append
|
||||
(defun +modeline-refresh-bars-h ()
|
||||
(let ((width (or +modeline-bar-width 1))
|
||||
(height (max +modeline-height 0)))
|
||||
(setq +modeline-bar
|
||||
(+modeline--make-xpm
|
||||
(and +modeline-bar-width
|
||||
(face-background '+modeline-bar nil 'inherit))
|
||||
width height)
|
||||
+modeline-inactive-bar
|
||||
(+modeline--make-xpm
|
||||
(and +modeline-bar-width
|
||||
(face-background '+modeline-bar-inactive nil 'inherit))
|
||||
width height)))))
|
||||
(defvar +modeline-active-bar "")
|
||||
(defvar +modeline-inactive-bar "")
|
||||
|
||||
(add-hook! 'doom-change-font-size-hook
|
||||
(defun +modeline-adjust-height-h ()
|
||||
(defvar +modeline--old-height +modeline-height)
|
||||
(let ((default-height +modeline--old-height)
|
||||
(scale (or (frame-parameter nil 'font-scale) 0)))
|
||||
(setq +modeline-height
|
||||
(if (> scale 0)
|
||||
(+ default-height (* (or (frame-parameter nil 'font-scale) 1)
|
||||
doom-font-increment))
|
||||
default-height))
|
||||
(when doom-init-time
|
||||
(+modeline-refresh-bars-h))))))
|
||||
(add-hook! '(doom-init-ui-hook doom-load-theme-hook) :append
|
||||
(defun +modeline-refresh-bars-h ()
|
||||
(let ((width (or +modeline-bar-width 1))
|
||||
(height (max +modeline-height 0))
|
||||
(active-bg (face-background 'doom-modeline-bar nil t))
|
||||
(inactive-bg (face-background 'doom-modeline-bar-inactive nil t)))
|
||||
(when (or (null +modeline-bar-width)
|
||||
(= +modeline-bar-width 0))
|
||||
(setq active-bg nil
|
||||
inactive-bg nil))
|
||||
(setq +modeline-active-bar
|
||||
(+modeline--make-xpm (and +modeline-bar-width active-bg)
|
||||
width height)
|
||||
+modeline-inactive-bar
|
||||
(+modeline--make-xpm (and +modeline-bar-width inactive-bg)
|
||||
width height)
|
||||
+modeline-bar
|
||||
'(:eval (if (+modeline-active)
|
||||
+modeline-active-bar
|
||||
+modeline-inactive-bar))))))
|
||||
|
||||
(add-hook! 'doom-change-font-size-hook
|
||||
(defun +modeline-adjust-height-h ()
|
||||
(defvar +modeline--old-height +modeline-height)
|
||||
(let ((default-height +modeline--old-height)
|
||||
(scale (or (frame-parameter nil 'font-scale) 0)))
|
||||
(setq +modeline-height
|
||||
(if (> scale 0)
|
||||
(+ default-height (* (or (frame-parameter nil 'font-scale) 1)
|
||||
doom-font-increment))
|
||||
default-height))
|
||||
(when doom-init-time
|
||||
(+modeline-refresh-bars-h)))))
|
||||
|
||||
|
||||
;;; `+modeline-matches'
|
||||
(progn
|
||||
(use-package! anzu
|
||||
:after-call isearch-mode
|
||||
:config
|
||||
;; anzu and evil-anzu expose current/total state that can be displayed in the
|
||||
;; mode-line.
|
||||
(defadvice! +modeline-fix-anzu-count-a (positions here)
|
||||
"Calulate anzu counts via POSITIONS and HERE."
|
||||
:override #'anzu--where-is-here
|
||||
(cl-loop for (start . end) in positions
|
||||
collect t into before
|
||||
when (and (>= here start) (<= here end))
|
||||
return (length before)
|
||||
finally return 0))
|
||||
(use-package! anzu
|
||||
:after-call isearch-mode
|
||||
:config
|
||||
;; We manage our own modeline segments
|
||||
(setq anzu-cons-mode-line-p nil)
|
||||
;; Ensure anzu state is cleared when searches & iedit are done
|
||||
(add-hook 'iedit-mode-end-hook #'anzu--reset-status)
|
||||
(advice-add #'evil-force-normal-state :before #'anzu--reset-status)
|
||||
;; Fix matches segment mirroring across all buffers
|
||||
(mapc #'make-variable-buffer-local
|
||||
'(anzu--total-matched
|
||||
anzu--current-position
|
||||
anzu--state
|
||||
anzu--cached-count
|
||||
anzu--cached-positions anzu--last-command
|
||||
anzu--last-isearch-string anzu--overflow-p)))
|
||||
|
||||
(setq anzu-cons-mode-line-p nil) ; manage modeline segment ourselves
|
||||
;; Ensure anzu state is cleared when searches & iedit are done
|
||||
(add-hook 'isearch-mode-end-hook #'anzu--reset-status 'append)
|
||||
(add-hook 'iedit-mode-end-hook #'anzu--reset-status)
|
||||
(advice-add #'evil-force-normal-state :before #'anzu--reset-status)
|
||||
;; Fix matches segment mirroring across all buffers
|
||||
(mapc #'make-variable-buffer-local
|
||||
'(anzu--total-matched anzu--current-position anzu--state
|
||||
anzu--cached-count anzu--cached-positions anzu--last-command
|
||||
anzu--last-isearch-string anzu--overflow-p)))
|
||||
(use-package! evil-anzu
|
||||
:when (featurep! :editor evil)
|
||||
:after-call evil-ex-start-search evil-ex-start-word-search evil-ex-search-activate-highlight
|
||||
:config (global-anzu-mode +1))
|
||||
|
||||
(use-package! evil-anzu
|
||||
:when (featurep! :editor evil)
|
||||
:after-call (evil-ex-start-search evil-ex-start-word-search evil-ex-search-activate-highlight))
|
||||
|
||||
(defun +modeline--anzu ()
|
||||
"Show the match index and total number thereof.
|
||||
(defun +modeline--anzu ()
|
||||
"Show the match index and total number thereof.
|
||||
Requires `anzu', also `evil-anzu' if using `evil-mode' for compatibility with
|
||||
`evil-search'."
|
||||
(when (and (bound-and-true-p anzu--state)
|
||||
(not (bound-and-true-p iedit-mode)))
|
||||
(propertize
|
||||
(let ((here anzu--current-position)
|
||||
(total anzu--total-matched))
|
||||
(cond ((eq anzu--state 'replace-query)
|
||||
(format " %d replace " anzu--cached-count))
|
||||
((eq anzu--state 'replace)
|
||||
(format " %d/%d " here total))
|
||||
(anzu--overflow-p
|
||||
(format " %s+ " total))
|
||||
(t
|
||||
(format " %s/%d " here total))))
|
||||
'face (if (+modeline-active) '+modeline-highlight))))
|
||||
(when (and (bound-and-true-p anzu--state)
|
||||
(not (bound-and-true-p iedit-mode)))
|
||||
(propertize
|
||||
(let ((here anzu--current-position)
|
||||
(total anzu--total-matched))
|
||||
(cond ((eq anzu--state 'replace-query)
|
||||
(format " %d replace " anzu--cached-count))
|
||||
((eq anzu--state 'replace)
|
||||
(format " %d/%d " (1+ here) total))
|
||||
(anzu--overflow-p
|
||||
(format " %s+ " total))
|
||||
(t
|
||||
(format " %s/%d " here total))))
|
||||
'face (if (+modeline-active) 'doom-modeline-highlight))))
|
||||
|
||||
(defun +modeline--evil-substitute ()
|
||||
"Show number of matches for evil-ex substitutions and highlights in real time."
|
||||
(when (and (bound-and-true-p evil-local-mode)
|
||||
(or (assq 'evil-ex-substitute evil-ex-active-highlights-alist)
|
||||
(assq 'evil-ex-global-match evil-ex-active-highlights-alist)
|
||||
(assq 'evil-ex-buffer-match evil-ex-active-highlights-alist)))
|
||||
(propertize
|
||||
(let ((range (if evil-ex-range
|
||||
(cons (car evil-ex-range) (cadr evil-ex-range))
|
||||
(cons (line-beginning-position) (line-end-position))))
|
||||
(pattern (car-safe (evil-delimited-arguments evil-ex-argument 2))))
|
||||
(if pattern
|
||||
(format " %s matches " (how-many pattern (car range) (cdr range)))
|
||||
" - "))
|
||||
'face (if (+modeline-active) '+modeline-highlight))))
|
||||
(defun +modeline--evil-substitute ()
|
||||
"Show number of matches for evil-ex substitutions and highlights in real time."
|
||||
(when (and (bound-and-true-p evil-local-mode)
|
||||
(or (assq 'evil-ex-substitute evil-ex-active-highlights-alist)
|
||||
(assq 'evil-ex-global-match evil-ex-active-highlights-alist)
|
||||
(assq 'evil-ex-buffer-match evil-ex-active-highlights-alist)))
|
||||
(propertize
|
||||
(let ((range (if evil-ex-range
|
||||
(cons (car evil-ex-range) (cadr evil-ex-range))
|
||||
(cons (line-beginning-position) (line-end-position))))
|
||||
(pattern (car-safe (evil-delimited-arguments evil-ex-argument 2))))
|
||||
(if pattern
|
||||
(format " %s matches " (how-many pattern (car range) (cdr range)))
|
||||
" - "))
|
||||
'face (if (+modeline-active) 'doom-modeline-highlight))))
|
||||
|
||||
(defun +modeline--multiple-cursors ()
|
||||
"Show the number of multiple cursors."
|
||||
(when (bound-and-true-p evil-mc-cursor-list)
|
||||
(let ((count (length evil-mc-cursor-list)))
|
||||
(when (> count 0)
|
||||
(let ((face (cond ((not (+modeline-active)) 'mode-line-inactive)
|
||||
(evil-mc-frozen '+modeline-highlight)
|
||||
('+modeline-alternate-highlight))))
|
||||
(concat (propertize " " 'face face)
|
||||
(all-the-icons-faicon "i-cursor" :face face :v-adjust -0.0575)
|
||||
(propertize " " 'face `(:inherit (variable-pitch ,face)))
|
||||
(propertize (format "%d " count)
|
||||
'face face)))))))
|
||||
(defun +modeline--multiple-cursors ()
|
||||
"Show the number of multiple cursors."
|
||||
(when (bound-and-true-p evil-mc-cursor-list)
|
||||
(let ((count (length evil-mc-cursor-list)))
|
||||
(when (> count 0)
|
||||
(let ((face (cond ((not (+modeline-active)) 'mode-line-inactive)
|
||||
(evil-mc-frozen 'doom-modeline-highlight)
|
||||
('doom-modeline-alternate-highlight))))
|
||||
(concat (propertize " " 'face face)
|
||||
(all-the-icons-faicon "i-cursor" :face face :v-adjust -0.0575)
|
||||
(propertize " " 'face `(:inherit (variable-pitch ,face)))
|
||||
(propertize (format "%d " count)
|
||||
'face face)))))))
|
||||
|
||||
(defun +modeline--overlay< (a b)
|
||||
"Sort overlay A and B."
|
||||
(< (overlay-start a) (overlay-start b)))
|
||||
(defun +modeline--overlay< (a b)
|
||||
"Sort overlay A and B."
|
||||
(< (overlay-start a) (overlay-start b)))
|
||||
|
||||
(defun +modeline--iedit ()
|
||||
"Show the number of iedit regions matches + what match you're on."
|
||||
(when (and (bound-and-true-p iedit-mode)
|
||||
(bound-and-true-p iedit-occurrences-overlays))
|
||||
(propertize
|
||||
(let ((this-oc (or (let ((inhibit-message t))
|
||||
(iedit-find-current-occurrence-overlay))
|
||||
(save-excursion
|
||||
(iedit-prev-occurrence)
|
||||
(iedit-find-current-occurrence-overlay))))
|
||||
(length (length iedit-occurrences-overlays)))
|
||||
(format " %s/%d "
|
||||
(if this-oc
|
||||
(- length
|
||||
(length (memq this-oc (sort (append iedit-occurrences-overlays nil)
|
||||
#'+modeline--overlay<)))
|
||||
-1)
|
||||
"-")
|
||||
length))
|
||||
'face (if (+modeline-active) '+modeline-highlight))))
|
||||
(defun +modeline--iedit ()
|
||||
"Show the number of iedit regions matches + what match you're on."
|
||||
(when (and (bound-and-true-p iedit-mode)
|
||||
(bound-and-true-p iedit-occurrences-overlays))
|
||||
(propertize
|
||||
(let ((this-oc (or (let ((inhibit-message t))
|
||||
(iedit-find-current-occurrence-overlay))
|
||||
(save-excursion
|
||||
(iedit-prev-occurrence)
|
||||
(iedit-find-current-occurrence-overlay))))
|
||||
(length (length iedit-occurrences-overlays)))
|
||||
(format " %s/%d "
|
||||
(if this-oc
|
||||
(- length
|
||||
(length (memq this-oc (sort (append iedit-occurrences-overlays nil)
|
||||
#'+modeline--overlay<)))
|
||||
-1)
|
||||
"-")
|
||||
length))
|
||||
'face (if (+modeline-active) 'doom-modeline-highlight))))
|
||||
|
||||
(defun +modeline--macro-recording ()
|
||||
"Display current Emacs or evil macro being recorded."
|
||||
(when (and (+modeline-active)
|
||||
(or defining-kbd-macro
|
||||
executing-kbd-macro))
|
||||
(let ((sep (propertize " " 'face '+modeline-highlight)))
|
||||
(concat sep
|
||||
(propertize (if (bound-and-true-p evil-this-macro)
|
||||
(char-to-string evil-this-macro)
|
||||
"Macro")
|
||||
'face '+modeline-highlight)
|
||||
sep
|
||||
(all-the-icons-octicon "triangle-right"
|
||||
:face '+modeline-highlight
|
||||
:v-adjust -0.05)
|
||||
sep))))
|
||||
(defun +modeline--macro-recording ()
|
||||
"Display current Emacs or evil macro being recorded."
|
||||
(when (and (+modeline-active)
|
||||
(or defining-kbd-macro
|
||||
executing-kbd-macro))
|
||||
(let ((sep (propertize " " 'face 'doom-modeline-highlight)))
|
||||
(concat sep
|
||||
(propertize (if (bound-and-true-p evil-this-macro)
|
||||
(char-to-string evil-this-macro)
|
||||
"Macro")
|
||||
'face 'doom-modeline-highlight)
|
||||
sep
|
||||
(all-the-icons-octicon "triangle-right"
|
||||
:face 'doom-modeline-highlight
|
||||
:v-adjust -0.05)
|
||||
sep))))
|
||||
|
||||
(def-modeline-var! +modeline-matches
|
||||
'(:eval
|
||||
(let ((meta (concat (+modeline--macro-recording)
|
||||
(+modeline--anzu)
|
||||
(+modeline--evil-substitute)
|
||||
(+modeline--iedit)
|
||||
(+modeline--multiple-cursors))))
|
||||
(or (and (not (equal meta "")) meta)
|
||||
" %I ")))))
|
||||
(def-modeline-var! +modeline-matches
|
||||
'(:eval
|
||||
(let ((meta (concat (+modeline--macro-recording)
|
||||
(+modeline--anzu)
|
||||
(+modeline--evil-substitute)
|
||||
(+modeline--iedit)
|
||||
(+modeline--multiple-cursors))))
|
||||
(or (and (not (equal meta "")) meta)
|
||||
" %I "))))
|
||||
|
||||
|
||||
;;; `+modeline-modes'
|
||||
(def-modeline-var! +modeline-modes ; remove minor modes
|
||||
'(""
|
||||
(:propertize mode-name
|
||||
face bold
|
||||
mouse-face +modeline-highlight)
|
||||
face bold
|
||||
mouse-face doom-modeline-highlight)
|
||||
mode-line-process
|
||||
"%n"
|
||||
" "))
|
||||
@@ -382,103 +374,104 @@ Requires `anzu', also `evil-anzu' if using `evil-mode' for compatibility with
|
||||
|
||||
|
||||
;;; `+modeline-checker'
|
||||
(progn
|
||||
(def-modeline-var! +modeline-checker nil
|
||||
"Displays color-coded error status & icon for the current buffer."
|
||||
:local t)
|
||||
(def-modeline-var! +modeline-checker nil
|
||||
"Displays color-coded error status & icon for the current buffer."
|
||||
:local t)
|
||||
|
||||
(add-hook! '(flycheck-status-changed-functions
|
||||
flycheck-mode-hook)
|
||||
(defun +modeline-checker-update (&optional status)
|
||||
"Update flycheck text via STATUS."
|
||||
(setq +modeline-checker
|
||||
(pcase status
|
||||
(`finished
|
||||
(if flycheck-current-errors
|
||||
(let-alist (flycheck-count-errors flycheck-current-errors)
|
||||
(let ((error (or .error 0))
|
||||
(warning (or .warning 0))
|
||||
(info (or .info 0)))
|
||||
(+modeline-format-icon "do_not_disturb_alt"
|
||||
(number-to-string (+ error warning info))
|
||||
(cond ((> error 0) 'error)
|
||||
((> warning 0) 'warning)
|
||||
('success))
|
||||
(format "Errors: %d, Warnings: %d, Debug: %d"
|
||||
error
|
||||
warning
|
||||
info))))
|
||||
(+modeline-format-icon "check" "" 'success)))
|
||||
(`running (+modeline-format-icon "access_time" "*" 'font-lock-comment-face "Running..."))
|
||||
(`errored (+modeline-format-icon "sim_card_alert" "!" 'error "Errored!"))
|
||||
(`interrupted (+modeline-format-icon "pause" "!" 'font-lock-comment-face "Interrupted"))
|
||||
(`suspicious (+modeline-format-icon "priority_high" "!" 'error "Suspicious")))))))
|
||||
(add-hook! '(flycheck-status-changed-functions
|
||||
flycheck-mode-hook)
|
||||
(defun +modeline-checker-update (&optional status)
|
||||
"Update flycheck text via STATUS."
|
||||
(setq +modeline-checker
|
||||
(pcase status
|
||||
(`finished
|
||||
(if flycheck-current-errors
|
||||
(let-alist (flycheck-count-errors flycheck-current-errors)
|
||||
(let ((error (or .error 0))
|
||||
(warning (or .warning 0))
|
||||
(info (or .info 0)))
|
||||
(+modeline-format-icon "do_not_disturb_alt"
|
||||
(number-to-string (+ error warning info))
|
||||
(cond ((> error 0) 'error)
|
||||
((> warning 0) 'warning)
|
||||
('success))
|
||||
(format "Errors: %d, Warnings: %d, Debug: %d"
|
||||
error
|
||||
warning
|
||||
info))))
|
||||
(+modeline-format-icon "check" "" 'success)))
|
||||
(`running (+modeline-format-icon "access_time" "*" 'font-lock-comment-face "Running..."))
|
||||
(`errored (+modeline-format-icon "sim_card_alert" "!" 'error "Errored!"))
|
||||
(`interrupted (+modeline-format-icon "pause" "!" 'font-lock-comment-face "Interrupted"))
|
||||
(`suspicious (+modeline-format-icon "priority_high" "!" 'error "Suspicious"))))))
|
||||
|
||||
|
||||
;;; `+modeline-selection-info'
|
||||
(progn
|
||||
(defsubst +modeline--column (pos)
|
||||
"Get the column of the position `POS'."
|
||||
(save-excursion (goto-char pos)
|
||||
(current-column)))
|
||||
(defsubst +modeline--column (pos)
|
||||
"Get the column of the position `POS'."
|
||||
(save-excursion (goto-char pos)
|
||||
(current-column)))
|
||||
|
||||
(def-modeline-var! +modeline-selection-info
|
||||
'(:eval
|
||||
(when (or mark-active
|
||||
(and (bound-and-true-p evil-local-mode)
|
||||
(eq evil-state 'visual)))
|
||||
(cl-destructuring-bind (beg . end)
|
||||
(if (boundp 'evil-local-mode)
|
||||
(cons evil-visual-beginning evil-visual-end)
|
||||
(cons (region-beginning) (region-end)))
|
||||
(propertize
|
||||
(let ((lines (count-lines beg (min end (point-max)))))
|
||||
(concat " "
|
||||
(cond ((or (bound-and-true-p rectangle-mark-mode)
|
||||
(and (bound-and-true-p evil-visual-selection)
|
||||
(eq 'block evil-visual-selection)))
|
||||
(let ((cols (abs (- (+modeline--column end)
|
||||
(+modeline--column beg)))))
|
||||
(format "%dx%dB" lines cols)))
|
||||
((and (bound-and-true-p evil-visual-selection)
|
||||
(eq evil-visual-selection 'line))
|
||||
(format "%dL" lines))
|
||||
((> lines 1)
|
||||
(format "%dC %dL" (- end beg) lines))
|
||||
((format "%dC" (- end beg))))
|
||||
(when (derived-mode-p 'text-mode)
|
||||
(format " %dW" (count-words beg end)))
|
||||
" "))
|
||||
'face (if (+modeline-active) 'success)))))
|
||||
"Information about the current selection, such as how many characters and
|
||||
(def-modeline-var! +modeline-selection-info
|
||||
'(:eval
|
||||
(when (or (and (bound-and-true-p evil-local-mode)
|
||||
(eq evil-state 'visual))
|
||||
mark-active)
|
||||
(cl-destructuring-bind (beg . end)
|
||||
(if (bound-and-true-p evil-visual-selection)
|
||||
(cons evil-visual-beginning evil-visual-end)
|
||||
(cons (region-beginning) (region-end)))
|
||||
(propertize
|
||||
(let ((lines (count-lines beg (min end (point-max)))))
|
||||
(concat " "
|
||||
(cond ((or (bound-and-true-p rectangle-mark-mode)
|
||||
(and (bound-and-true-p evil-visual-selection)
|
||||
(eq 'block evil-visual-selection)))
|
||||
(let ((cols (abs (- (+modeline--column end)
|
||||
(+modeline--column beg)))))
|
||||
(format "%dx%dB" lines cols)))
|
||||
((and (bound-and-true-p evil-visual-selection)
|
||||
(eq evil-visual-selection 'line))
|
||||
(format "%dL" lines))
|
||||
((> lines 1)
|
||||
(format "%dC %dL" (- end beg) lines))
|
||||
((format "%dC" (- end beg))))
|
||||
(when (derived-mode-p 'text-mode)
|
||||
(format " %dW" (count-words beg end)))
|
||||
" "))
|
||||
'face (if (+modeline-active) 'success)))))
|
||||
"Information about the current selection, such as how many characters and
|
||||
lines are selected, or the NxM dimensions of a block selection.")
|
||||
|
||||
(defun +modeline-add-selection-segment-h ()
|
||||
(add-to-list '+modeline-format-left '+modeline-selection-info 'append))
|
||||
(defun +modeline-remove-selection-segment-h ()
|
||||
(delq! '+modeline-selection-info +modeline-format-left))
|
||||
(defun +modeline-add-selection-segment-h ()
|
||||
(add-to-list '+modeline-format-left '+modeline-selection-info 'append))
|
||||
(defun +modeline-remove-selection-segment-h ()
|
||||
(delq! '+modeline-selection-info +modeline-format-left))
|
||||
|
||||
(if (featurep 'evil)
|
||||
(progn
|
||||
(add-hook 'evil-visual-state-entry-hook #'+modeline-add-selection-segment-h)
|
||||
(add-hook 'evil-visual-state-exit-hook #'+modeline-remove-selection-segment-h))
|
||||
(add-hook 'activate-mark-hook #'+modeline-add-selection-segment-h)
|
||||
(add-hook 'deactivate-mark-hook #'+modeline-remove-selection-segment-h)))
|
||||
(if (featurep 'evil)
|
||||
(progn
|
||||
(add-hook 'evil-visual-state-entry-hook #'+modeline-add-selection-segment-h)
|
||||
(add-hook 'evil-visual-state-exit-hook #'+modeline-remove-selection-segment-h))
|
||||
(add-hook 'activate-mark-hook #'+modeline-add-selection-segment-h)
|
||||
(add-hook 'deactivate-mark-hook #'+modeline-remove-selection-segment-h))
|
||||
|
||||
|
||||
;;; `+modeline-encoding'
|
||||
(def-modeline-var! +modeline-encoding
|
||||
'(:eval
|
||||
(concat (pcase (coding-system-eol-type buffer-file-coding-system)
|
||||
(0 " LF ")
|
||||
(1 " RLF ")
|
||||
(2 " CR "))
|
||||
(concat (coding-system-eol-type-mnemonic buffer-file-coding-system)
|
||||
" "
|
||||
(let ((sys (coding-system-plist buffer-file-coding-system)))
|
||||
(if (memq (plist-get sys :category)
|
||||
'(coding-category-undecided coding-category-utf-8))
|
||||
"UTF-8"
|
||||
(upcase (symbol-name (plist-get sys :name)))))
|
||||
" ")))
|
||||
(upcase (symbol-name (plist-get sys :name))))))))
|
||||
|
||||
;; Clearer mnemonic labels for EOL styles
|
||||
(setq eol-mnemonic-dos "CRLF"
|
||||
eol-mnemonic-mac "CR"
|
||||
eol-mnemonic-unix "LF"
|
||||
eol-mnemonic-undecided "??")
|
||||
|
||||
|
||||
;;
|
||||
@@ -490,33 +483,35 @@ lines are selected, or the NxM dimensions of a block selection.")
|
||||
" "
|
||||
+modeline-buffer-identification
|
||||
+modeline-position)
|
||||
'(""
|
||||
`(""
|
||||
mode-line-misc-info
|
||||
+modeline-modes
|
||||
(vc-mode (" "
|
||||
,(all-the-icons-octicon "git-branch" :v-adjust 0.0)
|
||||
vc-mode " "))
|
||||
" "
|
||||
" "
|
||||
+modeline-encoding
|
||||
" "
|
||||
(+modeline-checker ("" +modeline-checker " "))))
|
||||
|
||||
(def-modeline! project
|
||||
(def-modeline! 'project
|
||||
`(" "
|
||||
,(all-the-icons-octicon
|
||||
"file-directory"
|
||||
:face 'bold
|
||||
:v-adjust -0.05
|
||||
:height 1.25)
|
||||
:v-adjust -0.06
|
||||
:height 1.1)
|
||||
(:propertize (" " (:eval (abbreviate-file-name default-directory)))
|
||||
face bold))
|
||||
'("" +modeline-modes))
|
||||
'("" mode-line-misc-info +modeline-modes))
|
||||
|
||||
(def-modeline! special
|
||||
(def-modeline! 'special
|
||||
'("" +modeline-matches
|
||||
" " +modeline-buffer-identification)
|
||||
'("" +modeline-modes))
|
||||
|
||||
;; TODO (def-modeline! pdf ...)
|
||||
;; (def-modeline! pdf
|
||||
;; '("" +modeline-matches))
|
||||
;; TODO (def-modeline! helm ...)
|
||||
|
||||
|
||||
@@ -545,7 +540,7 @@ lines are selected, or the NxM dimensions of a block selection.")
|
||||
;; Other modes
|
||||
(set-modeline! :main 'default)
|
||||
(set-modeline-hook! '+doom-dashboard-mode-hook 'project)
|
||||
(set-modeline-hook! 'pdf-tools-enabled-hook 'pdf)
|
||||
;; (set-modeline-hook! 'pdf-tools-enabled-hook 'pdf)
|
||||
(set-modeline-hook! '(special-mode-hook
|
||||
image-mode-hook
|
||||
circe-mode-hook)
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
- [[#troubleshooting][Troubleshooting]]
|
||||
- [[#where-are-my-minor-modes][Where are my minor modes?]]
|
||||
- [[#icons-in-my-modeline-look-strange][Icons in my modeline look strange]]
|
||||
- [[#the-right-side-of-the-modeline-is-cut-off][The right side of the modeline is cut off]]
|
||||
- [[#appendix][Appendix]]
|
||||
- [[#autodefs][Autodefs]]
|
||||
- [[#variables][Variables]]
|
||||
@@ -30,7 +31,8 @@ This module provides an Atom-inspired, minimalistic modeline for Doom Emacs,
|
||||
powered by [[https://github.com/seagle0128/doom-modeline][the doom-modeline package]] (where you can find screenshots).
|
||||
|
||||
** Module Flags
|
||||
This module provides no flags.
|
||||
+ =+light= Enables a lighter, less featureful version of the modeline that does
|
||||
not depend on ~doom-modeline~, which has performances issues in some cases.
|
||||
|
||||
** Plugins
|
||||
+ [[https://github.com/seagle0128/doom-modeline][doom-modeline]]
|
||||
@@ -62,6 +64,31 @@ I rarely need to know what minor modes are active, so I removed them. ~M-x
|
||||
doom/describe-active-minor-mode~ was written to substitute for it.
|
||||
|
||||
** TODO Icons in my modeline look strange
|
||||
** TODO The right side of the modeline is cut off
|
||||
I believe the consensus is: this is due to oversized icons, i.e. a font issue. Some possible solutions:
|
||||
|
||||
1. Tweak ~all-the-icons-scale-factor~ (1.2 by default): ~(setq
|
||||
all-the-icons-scale-factor 1.1)~
|
||||
|
||||
2. Add some padding to the modeline definition:
|
||||
|
||||
#+BEGIN_SRC elisp
|
||||
(after! doom-modeline
|
||||
(doom-modeline-def-modeline 'main
|
||||
'(bar matches buffer-info remote-host buffer-position parrot selection-info)
|
||||
'(misc-info minor-modes checker input-method buffer-encoding major-mode process vcs " "))) ; <-- added padding here
|
||||
#+END_SRC
|
||||
|
||||
3. Use another font for the mode line (or a different ~:height~) (source)
|
||||
|
||||
#+BEGIN_SRC elisp
|
||||
(custom-set-faces!
|
||||
'(mode-line :family "Noto Sans" :height 0.9)
|
||||
'(mode-line-inactive :family "Noto Sans" :height 0.9))
|
||||
#+END_SRC
|
||||
|
||||
(Mentioned in #1680, #278 and seagle0128/doom-modeline#334)
|
||||
|
||||
|
||||
* Appendix
|
||||
** Autodefs
|
||||
|
||||
@@ -1,15 +1,5 @@
|
||||
;;; ui/modeline/autoload/modeline.el -*- lexical-binding: t; -*-
|
||||
|
||||
;;;###autodef
|
||||
(defalias 'def-modeline-format! #'doom-modeline-def-modeline)
|
||||
|
||||
;;;###autodef
|
||||
(defalias 'def-modeline-segment! #'doom-modeline-def-segment)
|
||||
|
||||
;;;###autodef
|
||||
(defalias 'set-modeline! #'doom-modeline-set-modeline)
|
||||
|
||||
|
||||
(defvar +modeline--old-bar-height nil)
|
||||
;;;###autoload
|
||||
(defun +modeline-resize-for-font-h ()
|
||||
@@ -21,28 +11,26 @@ Meant for `doom-change-font-size-hook'."
|
||||
(setq +modeline--old-bar-height doom-modeline-height))
|
||||
(let ((default-height +modeline--old-bar-height)
|
||||
(scale (or (frame-parameter nil 'font-scale) 0)))
|
||||
(if (> scale 0)
|
||||
(let* ((font-size (string-to-number
|
||||
(aref (doom--font-name (frame-parameter nil 'font)
|
||||
(selected-frame))
|
||||
xlfd-regexp-pixelsize-subnum)))
|
||||
(scale (frame-parameter nil 'font-scale)))
|
||||
(setq doom-modeline-height (+ default-height (* scale doom-font-increment))))
|
||||
(setq doom-modeline-height default-height))))
|
||||
(setq doom-modeline-height
|
||||
(if (> scale 0)
|
||||
(+ default-height (* scale doom-font-increment))
|
||||
default-height))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +modeline-update-env-in-all-windows-h (&rest _)
|
||||
"Update version strings in all buffers."
|
||||
(dolist (window (window-list))
|
||||
(with-selected-window window
|
||||
(doom-modeline-update-env)
|
||||
(when (fboundp 'doom-modeline-update-env)
|
||||
(doom-modeline-update-env))
|
||||
(force-mode-line-update))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +modeline-clear-env-in-all-windows-h (&rest _)
|
||||
"Blank out version strings in all buffers."
|
||||
(dolist (buffer (buffer-list))
|
||||
(with-current-buffer buffer
|
||||
(setq doom-modeline-env--version
|
||||
(bound-and-true-p doom-modeline-load-string))))
|
||||
(unless (featurep! +light)
|
||||
(dolist (buffer (buffer-list))
|
||||
(with-current-buffer buffer
|
||||
(setq doom-modeline-env--version
|
||||
(bound-and-true-p doom-modeline-load-string)))))
|
||||
(force-mode-line-update t))
|
||||
|
||||
@@ -4,9 +4,20 @@
|
||||
(load! "+light"))
|
||||
|
||||
|
||||
(defvar +modeline--redisplayed-p nil)
|
||||
(defadvice! modeline-recalculate-height-a (&optional _force &rest _ignored)
|
||||
"Ensure that window resizing functions take modeline height into account."
|
||||
:before '(fit-window-to-buffer resize-temp-buffer-window)
|
||||
(unless +modeline--redisplayed-p
|
||||
(setq-local +modeline--redisplayed-p t)
|
||||
(redisplay t)))
|
||||
|
||||
|
||||
(use-package! doom-modeline
|
||||
:unless (featurep! +light)
|
||||
:hook (after-init . doom-modeline-mode)
|
||||
:hook (doom-modeline-mode . size-indication-mode) ; filesize in modeline
|
||||
:hook (doom-modeline-mode . column-number-mode) ; cursor column in modeline
|
||||
:init
|
||||
(unless after-init-time
|
||||
;; prevent flash of unstyled modeline at startup
|
||||
@@ -34,10 +45,7 @@
|
||||
(defvar mouse-wheel-down-event nil)
|
||||
(defvar mouse-wheel-up-event nil)
|
||||
|
||||
(size-indication-mode +1) ; filesize in modeline
|
||||
(column-number-mode +1) ; cursor column in modeline
|
||||
|
||||
(add-hook 'doom-change-font-size-hook #'+modeline-resize-for-font-h)
|
||||
(add-hook 'after-setting-font-hook #'+modeline-resize-for-font-h)
|
||||
(add-hook 'doom-load-theme-hook #'doom-modeline-refresh-bars)
|
||||
|
||||
(add-hook '+doom-dashboard-mode-hook #'doom-modeline-set-project-modeline)
|
||||
@@ -46,22 +54,9 @@
|
||||
(defun +modeline-hide-in-non-status-buffer-h ()
|
||||
"Show minimal modeline in magit-status buffer, no modeline elsewhere."
|
||||
(if (eq major-mode 'magit-status-mode)
|
||||
(doom-modeline-set-project-modeline)
|
||||
(doom-modeline-set-vcs-modeline)
|
||||
(hide-mode-line-mode))))
|
||||
|
||||
;; Remove unused segments & extra padding
|
||||
(doom-modeline-def-modeline 'main
|
||||
'(bar window-number matches buffer-info remote-host buffer-position selection-info)
|
||||
'(objed-state misc-info persp-name irc mu4e github debug input-method buffer-encoding lsp major-mode process vcs checker))
|
||||
|
||||
(doom-modeline-def-modeline 'special
|
||||
'(bar window-number matches buffer-info-simple buffer-position selection-info)
|
||||
'(objed-state misc-info persp-name debug input-method irc-buffers buffer-encoding lsp major-mode process checker))
|
||||
|
||||
(doom-modeline-def-modeline 'project
|
||||
'(bar window-number buffer-default-directory)
|
||||
'(misc-info mu4e github debug battery " " major-mode process))
|
||||
|
||||
;; Some functions modify the buffer, causing the modeline to show a false
|
||||
;; modified state, so force them to behave.
|
||||
(defadvice! +modeline--inhibit-modification-hooks-a (orig-fn &rest args)
|
||||
@@ -76,4 +71,5 @@
|
||||
|
||||
(use-package! evil-anzu
|
||||
:when (featurep! :editor evil)
|
||||
:after-call evil-ex-start-search evil-ex-start-word-search evil-ex-search-activate-highlight))
|
||||
:after-call evil-ex-start-search evil-ex-start-word-search evil-ex-search-activate-highlight
|
||||
:config (global-anzu-mode +1)))
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
;;; ui/modeline/packages.el
|
||||
|
||||
(unless (featurep! +light)
|
||||
(package! doom-modeline))
|
||||
(package! anzu)
|
||||
(package! doom-modeline :pin "2b308857677e983ca4eaedc36438ed94aadf9e65"))
|
||||
(package! anzu :pin "7b8688c84d6032300d0c415182c7c1ad6cb7f819")
|
||||
(when (featurep! :editor evil)
|
||||
(package! evil-anzu))
|
||||
(package! evil-anzu :pin "d3f6ed4773b48767bd5f4708c7f083336a8a8a86"))
|
||||
|
||||
Reference in New Issue
Block a user