summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2022-02-16 23:17:56 -0600
committerCase Duckworth2022-02-16 23:17:56 -0600
commitfae8e9168fd716c2b05afe6e8b6ee45b407afc9f (patch)
treefcf133e362136d0c3f49eb274431b7f6d545f92e
parentChange org capture template (diff)
downloademacs-fae8e9168fd716c2b05afe6e8b6ee45b407afc9f.tar.gz
emacs-fae8e9168fd716c2b05afe6e8b6ee45b407afc9f.zip
Change modeline
-rw-r--r--init.el19
-rw-r--r--lisp/+modeline.el96
2 files changed, 68 insertions, 47 deletions
diff --git a/init.el b/init.el index 6c41689..2312109 100644 --- a/init.el +++ b/init.el
@@ -744,8 +744,8 @@
744 tab-bar-tab-name-ellipsis truncate-string-ellipsis 744 tab-bar-tab-name-ellipsis truncate-string-ellipsis
745 tab-bar-show t 745 tab-bar-show t
746 tab-bar-close-button-show t 746 tab-bar-close-button-show t
747 +tab-bar-menu-bar-icon " Ɛ " 747 +tab-bar-menu-bar-icon " "
748 tab-bar-close-button (propertize " - " 748 tab-bar-close-button (propertize " ¬ "
749 'display t 749 'display t
750 'close-tab t) 750 'close-tab t)
751 tab-bar-new-button (propertize "+ " 'display t)) 751 tab-bar-new-button (propertize "+ " 'display t))
@@ -1816,13 +1816,18 @@ See also `crux-reopen-as-root-mode'."
1816 :host github :repo "gexplorer/simple-modeline" 1816 :host github :repo "gexplorer/simple-modeline"
1817 :fork (:host github :repo "duckwork/simple-modeline"))) 1817 :fork (:host github :repo "duckwork/simple-modeline")))
1818 (:require +modeline) 1818 (:require +modeline)
1819 (:option +modeline-minions-icon ";" 1819 (:option +modeline-modified-icon-alist '((ephemeral . "🥞")
1820 (special . "🥐")
1821 (readonly . "🦞")
1822 (modified . "🥪")
1823 (t . "🍞"))
1824 +modeline-minions-icon ";"
1820 simple-modeline-segments 1825 simple-modeline-segments
1821 `(( ; left 1826 `(( ; left
1822 +modeline-ace-window-display 1827 +modeline-ace-window-display
1823 +modeline-modified 1828 +modeline-modified
1824 +modeline-buffer-name 1829 +modeline-buffer-name
1825 (lambda () (+modeline-vc ": ")) 1830 (lambda () (+modeline-vc " : "))
1826 ,(+modeline-concat 1831 ,(+modeline-concat
1827 '(+modeline-minions 1832 '(+modeline-minions
1828 +modeline-major-mode)) 1833 +modeline-major-mode))
@@ -1842,7 +1847,11 @@ See also `crux-reopen-as-root-mode'."
1842 +modeline-reading-mode 1847 +modeline-reading-mode
1843 +modeline-narrowed) 1848 +modeline-narrowed)
1844 ",") 1849 ",")
1845 +modeline-position))) 1850 ,(+modeline-concat
1851 '(+modeline-region
1852 +modeline-line-column
1853 +modeline-file-percentage))
1854 )))
1846 (simple-modeline-mode +1)) 1855 (simple-modeline-mode +1))
1847 1856
1848(setup (:straight slack) 1857(setup (:straight slack)
diff --git a/lisp/+modeline.el b/lisp/+modeline.el index 0cea55c..537c68b 100644 --- a/lisp/+modeline.el +++ b/lisp/+modeline.el
@@ -64,12 +64,9 @@ This function makes a lambda, so you can throw it straight into
64 64
65(defun +modeline-buffer-name (&optional spacer) ; gonsie 65(defun +modeline-buffer-name (&optional spacer) ; gonsie
66 "Display the buffer name." 66 "Display the buffer name."
67 (let ((bufname (string-replace "%" "" (buffer-name)))) 67 (let ((bufname (string-trim (string-replace "%" "" (buffer-name)))))
68 (concat (or spacer +modeline-default-spacer) 68 (concat (or spacer +modeline-default-spacer)
69 (propertize 69 (propertize bufname
70 (truncate-string-to-width bufname
71 (min 24 (/ (window-width) 3))
72 nil ?\ t)
73 'help-echo (or (buffer-file-name) 70 'help-echo (or (buffer-file-name)
74 (buffer-name)) 71 (buffer-name))
75 'mouse-face 'mode-line-highlight)))) 72 'mouse-face 'mode-line-highlight))))
@@ -142,16 +139,15 @@ The order of elements matters: whichever one matches first is applied."
142 +modeline-modified-icon-special-modes)) 139 +modeline-modified-icon-special-modes))
143 ('t t) 140 ('t t)
144 (_ nil)) 141 (_ nil))
145 (throw :icon (cdr cell))))))) 142 (throw :icon cell))))))
146 (concat (or spacer +modeline-default-spacer) 143 (concat (or spacer +modeline-default-spacer)
147 (propertize (or icon "") 144 (propertize (or (cdr-safe icon) "")
148 'mouse-face 'mode-line-highlight)))) 145 'help-echo (format "Buffer \"%s\" is %s."
149 146 (buffer-name)
150(defun +modeline-buffer-modes (&optional spacer) 147 (pcase (car-safe icon)
151 "Display various buffer-specific stuff cleanly." 148 ('t "unmodified")
152 ;; This is clunky and should probably be improved. 149 ('nil "unknown")
153 (concat (+modeline-reading-mode) 150 (_ (car-safe icon))))))))
154 (+modeline-narrowed (when reading-mode ","))))
155 151
156(defun +modeline-narrowed (&optional spacer) 152(defun +modeline-narrowed (&optional spacer)
157 "Display an indication that the buffer is narrowed." 153 "Display an indication that the buffer is narrowed."
@@ -193,9 +189,27 @@ The order of elements matters: whichever one matches first is applied."
193 189
194(defun +modeline-file-percentage (&optional spacer) 190(defun +modeline-file-percentage (&optional spacer)
195 "Display the position in the current file." 191 "Display the position in the current file."
196 (if file-percentage-mode 192 (when file-percentage-mode
197 (list (or spacer +modeline-default-spacer) '(-3 "%p") "%%") 193 (let* ((tot (count-lines (point-min) (point-max) :ignore-invisible))
198 '(" "))) 194 (perc (/ (* 100 (line-number-at-pos)) tot))
195 (window-min (save-excursion (move-to-window-line 0)
196 (point)))
197 (window-max (save-excursion (move-to-window-line -1)
198 (point))))
199 (propertize (concat (or spacer +modeline-default-spacer)
200 (cond
201 ((and (<= window-min (point-min))
202 (>= window-max (point-max)))
203 "█")
204 ((= perc 0) "▇")
205 ((< perc 20) "▆")
206 ((< perc 40) "▅")
207 ((< perc 60) "▄")
208 ((< perc 80) "▃")
209 ((< perc 100) "▂")
210 ((>= perc 100) "▁")))
211 'help-echo (format "Point is %d%% through the buffer."
212 perc)))))
199 213
200(define-minor-mode region-indicator-mode 214(define-minor-mode region-indicator-mode
201 "Toggle the region indicator in the mode line." 215 "Toggle the region indicator in the mode line."
@@ -203,33 +217,30 @@ The order of elements matters: whichever one matches first is applied."
203 217
204(defun +modeline-region (&optional spacer) 218(defun +modeline-region (&optional spacer)
205 "Display an indicator if the region is active." 219 "Display an indicator if the region is active."
206 (when (and region-indicator-mode 220 (if (and region-indicator-mode
207 (region-active-p)) 221 (region-active-p))
208 (list 222 (format "%s%s"
209 (format "%s%s" 223 (or spacer +modeline-default-spacer)
210 (or spacer +modeline-default-spacer) 224 (propertize (format "%s%d"
211 (propertize (format "%s%d" 225 (if (and (< (point) (mark))) "-" "+")
212 (if (and (< (point) (mark))) "-" "+") 226 (apply '+ (mapcar (lambda (pos)
213 (apply '+ (mapcar (lambda (pos) 227 (- (cdr pos)
214 (- (cdr pos) 228 (car pos)))
215 (car pos))) 229 (region-bounds))))
216 (region-bounds)))) 230 'font-lock-face 'font-lock-variable-name-face))
217 'font-lock-face 'font-lock-variable-name-face))))) 231 ""))
218 232
219(defun +modeline-line-column (&optional spacer) ; adapted from `simple-modeline' 233(defun +modeline-line-column (&optional spacer) ; adapted from `simple-modeline'
220 "Display the current cursor line and column depending on modes." 234 "Display the current cursor line and column depending on modes."
221 (let ((sep "|") (before " [") (after "]")) 235 (let ((sep "|") (before "") (after "")
222 `(,(or spacer +modeline-default-spacer) 236 (line-fmt (if line-number-mode "%2l" ""))
223 (:propertize (line-number-mode 237 (col-fmt (if column-number-mode
224 ((column-number-mode 238 (if column-number-indicator-zero-based
225 (column-number-indicator-zero-based 239 "%2c"
226 ,(concat before "%2l" sep "%2c" after) 240 "%2C")
227 ,(concat before "%2l" sep "%2C" after)) 241 "")))
228 ,(concat before "%2l" sep "" after))) 242 (concat (or spacer +modeline-default-spacer)
229 ((column-number-mode 243 before line-fmt sep col-fmt after)))
230 (column-number-indicator-zero-based
231 ,(concat before sep "%2c" after)
232 ,(concat before sep "%2C" after)))))))))
233 244
234(defun +modeline-position (&optional _) 245(defun +modeline-position (&optional _)
235 "Display the current cursor position. 246 "Display the current cursor position.
@@ -243,7 +254,8 @@ See `line-number-mode', `column-number-mode', `file-percentage-mode'"
243 ;; from https://www.gonsie.com/blorg/modeline.html, from Doom 254 ;; from https://www.gonsie.com/blorg/modeline.html, from Doom
244 (if-let ((backend (vc-backend buffer-file-name))) 255 (if-let ((backend (vc-backend buffer-file-name)))
245 (concat (or spacer +modeline-default-spacer) 256 (concat (or spacer +modeline-default-spacer)
246 (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2))))) 257 (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2)))
258 ""))
247 259
248(defun +modeline-track (&optional spacer) 260(defun +modeline-track (&optional spacer)
249 "Display `tracking-mode' information." 261 "Display `tracking-mode' information."