summary refs log tree commit diff stats
path: root/lisp/+modeline.el
diff options
context:
space:
mode:
authorCase Duckworth2021-12-29 22:55:55 -0600
committerCase Duckworth2021-12-29 22:55:55 -0600
commit038e5de1adf2de6cdf28a428a44b0753813b928c (patch)
treebeb71cc3157ac2af3dc586fc02b74b906605e338 /lisp/+modeline.el
parentRe-install (new and improved!) filldent.el (diff)
downloademacs-038e5de1adf2de6cdf28a428a44b0753813b928c.tar.gz
emacs-038e5de1adf2de6cdf28a428a44b0753813b928c.zip
Lots and lots of changes, oh jeez
Diffstat (limited to 'lisp/+modeline.el')
-rw-r--r--lisp/+modeline.el110
1 files changed, 80 insertions, 30 deletions
diff --git a/lisp/+modeline.el b/lisp/+modeline.el index 5354e5b..5f46a75 100644 --- a/lisp/+modeline.el +++ b/lisp/+modeline.el
@@ -17,22 +17,62 @@
17 :prefix "+modeline-" 17 :prefix "+modeline-"
18 :group 'simple-modeline) 18 :group 'simple-modeline)
19 19
20(defun +modeline-buffer-name () ; gonsie 20(defcustom +modeline-default-spacer " "
21 "Default spacer to use for modeline elements.
22All modeline elements take an optional argument, `spacer', which
23will default to this string.")
24
25;;; Combinators
26
27(defun +modeline-concat (segments &optional separator)
28 "Concatenate multiple `simple-modeline'-style SEGMENTS.
29SEGMENTS is a list of either modeline segment-functions (see
30`simple-modeline' functions for an example of types of
31functions), though it can also contain cons cells of the
32form (SEGMENT . PREDICATE).
33
34Segments are separated from each other using SEPARATOR, which
35defaults to a \" \". space. Only segments that evaluate to a
36non-trivial string (that is, a string not equal to \"\") will be
37separated, for a cleaner look.
38
39This function makes a lambda, so you can throw it straight into
40`simple-modeline-segments'."
41 (setq separator (or separator +modeline-default-spacer))
42 (lambda ()
43 (apply #'concat
44 (let (this-sep result-list)
45 (dolist (segment segments)
46 (push (funcall (or (car-safe segment) segment)
47 this-sep)
48 result-list)
49 (if (or (cdr-safe segment)
50 (and (car result-list)
51 (not (equal (car result-list) ""))))
52 (setq this-sep separator)
53 (setq this-sep nil)))
54 (unless (seq-some #'null result-list)
55 (push +modeline-default-spacer result-list))
56 (nreverse result-list)))))
57
58;;; Modeline segments
59
60(defun +modeline-buffer-name (&optional spacer) ; gonsie
21 "Display the buffer name." 61 "Display the buffer name."
22 (concat " " (propertize 62 (concat (or spacer +modeline-default-spacer)
23 (+string-align (buffer-name) 20 :before "" :ellipsis "~ ") 63 (propertize
24 'face 'bold 64 (+string-align (buffer-name) 20 :ellipsis nil)
25 'help-echo (or (buffer-file-name) 65 'help-echo (or (buffer-file-name)
26 (buffer-name)) 66 (buffer-name))
27 'mouse-face 'mode-line-highlight))) 67 'mouse-face 'mode-line-highlight)))
28 68
29(defcustom +modeline-minions-icon "&" 69(defcustom +modeline-minions-icon "&"
30 "The \"icon\" for `+modeline-minions' button." 70 "The \"icon\" for `+modeline-minions' button."
31 :type 'string) 71 :type 'string)
32 72
33(defun +modeline-minions () 73(defun +modeline-minions (&optional spacer)
34 "Display a button for `minions-minor-modes-menu'." 74 "Display a button for `minions-minor-modes-menu'."
35 (concat " " 75 (concat (or spacer +modeline-default-spacer)
36 (propertize 76 (propertize
37 +modeline-minions-icon 77 +modeline-minions-icon
38 'help-echo "Minor modes menu\nmouse-1: show menu." 78 'help-echo "Minor modes menu\nmouse-1: show menu."
@@ -45,9 +85,9 @@
45 (minions-minor-modes-menu))))) 85 (minions-minor-modes-menu)))))
46 'mouse-face 'mode-line-highlight))) 86 'mouse-face 'mode-line-highlight)))
47 87
48(defun +modeline-major-mode () 88(defun +modeline-major-mode (&optional spacer)
49 "Display the current `major-mode'." 89 "Display the current `major-mode'."
50 (concat " " 90 (concat (or spacer +modeline-default-spacer)
51 (propertize (+string-truncate (format-mode-line mode-name) 91 (propertize (+string-truncate (format-mode-line mode-name)
52 12 "~") 92 12 "~")
53 'face 'bold 93 'face 'bold
@@ -80,7 +120,7 @@ The order of elements matters: whichever one matches first is applied."
80`+modeline-modified'." 120`+modeline-modified'."
81 :type '(repeat function)) 121 :type '(repeat function))
82 122
83(defun +modeline-modified () ; modified from `simple-modeline-status-modified' 123(defun +modeline-modified (&optional spacer) ; modified from `simple-modeline-status-modified'
84 "Display a color-coded \"icon\" indicator for the buffer's status." 124 "Display a color-coded \"icon\" indicator for the buffer's status."
85 (let* ((icon (catch :icon 125 (let* ((icon (catch :icon
86 (dolist (cell +modeline-modified-icon-alist) 126 (dolist (cell +modeline-modified-icon-alist)
@@ -94,14 +134,20 @@ The order of elements matters: whichever one matches first is applied."
94 ('t t) 134 ('t t)
95 (_ nil)) 135 (_ nil))
96 (throw :icon (cdr cell))))))) 136 (throw :icon (cdr cell)))))))
97 (concat " " 137 (concat (or spacer +modeline-default-spacer)
98 (propertize (or icon "") 138 (propertize (or icon "")
99 'mouse-face 'mode-line-highlight)))) 139 'mouse-face 'mode-line-highlight))))
100 140
101(defun +modeline-narrowed () 141(defun +modeline-buffer-modes (&optional spacer)
142 "Display various buffer-specific stuff cleanly."
143 ;; This is clunky and should probably be improved.
144 (concat (+modeline-reading-mode)
145 (+modeline-narrowed (when reading-mode ","))))
146
147(defun +modeline-narrowed (&optional spacer)
102 "Display an indication that the buffer is narrowed." 148 "Display an indication that the buffer is narrowed."
103 (when (buffer-narrowed-p) 149 (when (buffer-narrowed-p)
104 (concat " " 150 (concat (or spacer +modeline-default-spacer)
105 (propertize "N" 151 (propertize "N"
106 'help-echo (format "%s\n%s" 152 'help-echo (format "%s\n%s"
107 "Buffer is narrowed." 153 "Buffer is narrowed."
@@ -111,10 +157,10 @@ The order of elements matters: whichever one matches first is applied."
111 'face 'font-lock-doc-face 157 'face 'font-lock-doc-face
112 'mouse-face 'mode-line-highlight)))) 158 'mouse-face 'mode-line-highlight))))
113 159
114(defun +modeline-reading-mode () 160(defun +modeline-reading-mode (&optional spacer)
115 "Display an indication that the buffer is in `reading-mode'." 161 "Display an indication that the buffer is in `reading-mode'."
116 (when reading-mode 162 (when reading-mode
117 (concat " " 163 (concat (or spacer +modeline-default-spacer)
118 (propertize 164 (propertize
119 (concat "R" (when (bound-and-true-p +eww-readable-p) "w")) 165 (concat "R" (when (bound-and-true-p +eww-readable-p) "w"))
120 'help-echo (format "%s\n%s" 166 'help-echo (format "%s\n%s"
@@ -136,7 +182,7 @@ The order of elements matters: whichever one matches first is applied."
136 "Toggle the percentage display in the mode line (File Percentage Mode)." 182 "Toggle the percentage display in the mode line (File Percentage Mode)."
137 :init-value t :global t :group 'mode-line) 183 :init-value t :global t :group 'mode-line)
138 184
139(defun +modeline-position () ; adapted from `simple-modeline' 185(defun +modeline-position (&optional _) ; adapted from `simple-modeline'
140 "Display the current cursor position." 186 "Display the current cursor position."
141 (list '((line-number-mode 187 (list '((line-number-mode
142 ((column-number-mode 188 ((column-number-mode
@@ -160,34 +206,38 @@ The order of elements matters: whichever one matches first is applied."
160 (region-bounds)))) 206 (region-bounds))))
161 'font-lock-face 'font-lock-variable-name-face)))) 207 'font-lock-face 'font-lock-variable-name-face))))
162 208
163(defun +modeline-vc () 209(defun +modeline-vc (&optional spacer)
164 "Display the version control branch of the current buffer in the modeline." 210 "Display the version control branch of the current buffer in the modeline."
165 ;; from https://www.gonsie.com/blorg/modeline.html, from Doom 211 ;; from https://www.gonsie.com/blorg/modeline.html, from Doom
166 (if-let ((backend (vc-backend buffer-file-name))) 212 (if-let ((backend (vc-backend buffer-file-name)))
167 (concat " " (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2))))) 213 (concat (or spacer +modeline-default-spacer)
214 (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2)))))
168 215
169(defun +modeline-track () 216(defun +modeline-track (&optional spacer)
170 "Display `tracking-mode' information." 217 "Display `tracking-mode' information."
171 '(tracking-mode 218 (when tracking-mode
172 tracking-mode-line-buffers)) 219 tracking-mode-line-buffers))
173 220
174(defun +modeline-anzu () 221(defun +modeline-anzu (&optional spacer)
175 "Display `anzu--update-mode-line'." 222 "Display `anzu--update-mode-line'."
176 (concat " " (anzu--update-mode-line))) 223 (concat (or spacer +modeline-default-spacer)
224 (anzu--update-mode-line)))
177 225
178(defun +modeline-text-scale () 226(defun +modeline-text-scale (&optional spacer)
179 "Display text scaling level." 227 "Display text scaling level."
180 ;; adapted from https://github.com/seagle0128/doom-modeline 228 ;; adapted from https://github.com/seagle0128/doom-modeline
181 (when (and (boundp 'text-scale-mode-amount) 229 (when (and (boundp 'text-scale-mode-amount)
182 (/= text-scale-mode-amount 0)) 230 (/= text-scale-mode-amount 0))
183 (format (if (> text-scale-mode-amount 0) " (%+d)" " (%-d)") 231 (format (if (> text-scale-mode-amount 0) "%s(%+d)" "%s(%-d)")
232 (or spacer +modeline-default-spacer)
184 text-scale-mode-amount))) 233 text-scale-mode-amount)))
185 234
186(defun +modeline-ace-window-display () 235(defun +modeline-ace-window-display (&optional spacer)
187 "Display `ace-window-display-mode' information in the modeline." 236 "Display `ace-window-display-mode' information in the modeline."
188 '(+ace-window-display-mode 237 (when (and +ace-window-display-mode
189 (ace-window-mode 238 ace-window-mode)
190 (" " (:eval (window-parameter (selected-window) 'ace-window-path)))))) 239 (concat (or spacer +modeline-default-spacer)
240 (window-parameter (selected-window) 'ace-window-path))))
191 241
192(provide '+modeline) 242(provide '+modeline)
193;;; +modeline.el ends here 243;;; +modeline.el ends here