about summary refs log tree commit diff stats
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/+modeline.el96
1 files changed, 54 insertions, 42 deletions
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."