Further mode line changes

This commit is contained in:
Case Duckworth 2022-05-10 13:57:19 -05:00
parent a6085b58a2
commit 1492d153f0
1 changed files with 163 additions and 162 deletions

View File

@ -51,8 +51,8 @@ This function makes a lambda, so you can throw it straight into
(not (equal (car result-list) ""))))
(setq this-sep separator)
(setq this-sep nil)))
(unless (seq-some #'null result-list)
(push +modeline-default-spacer result-list))
;; (unless (seq-some #'null result-list)
;; (push +modeline-default-spacer result-list))
(nreverse result-list)))))
(defun +modeline-spacer (&optional n spacer &rest strings)
@ -64,11 +64,12 @@ should form a mode-line construct when `concat'ed."
(declare (indent 2))
(let ((spacer (or spacer +modeline-default-spacer))
(n (or n 1))
(strings (cond ((null strings) '(""))
(strings (cond((null strings) '(""))
((equal strings '("")) nil)
((atom strings) (list strings))
(t strings)))
r)
(dotimes (_ n) (push spacer r))
(when strings (dotimes (_ n) (push spacer r)))
(apply #'concat (apply #'concat r) strings)))
;;; Modeline segments
@ -96,7 +97,7 @@ and appended with `truncate-string-ellipsis'."
(defun +modeline-buffer-name (&optional spacer) ; gonsie
"Display the buffer name."
(let ((bufname (string-trim (string-replace "%" "" (buffer-name)))))
(+modeline-spacer nil nil
(+modeline-spacer nil spacer
(if (and +modeline-buffer-position (fboundp +modeline-buffer-position))
(funcall +modeline-buffer-position)
(propertize (cond
@ -123,7 +124,7 @@ and appended with `truncate-string-ellipsis'."
(defun +modeline-minions (&optional spacer)
"Display a button for `minions-minor-modes-menu'."
(+modeline-spacer nil nil
(+modeline-spacer nil spacer
(propertize
+modeline-minions-icon
'help-echo "Minor modes menu\nmouse-1: show menu."
@ -147,7 +148,7 @@ in the cdr will be applied to the major-mode in the mode line."
(defun +modeline-major-mode (&optional spacer)
"Display the current `major-mode'."
(+modeline-spacer nil nil
(+modeline-spacer nil spacer
"("
(propertize ;; (+string-truncate (format-mode-line mode-name) 16)
(format-mode-line mode-name)
@ -160,7 +161,7 @@ in the cdr will be applied to the major-mode in the mode line."
(when (derived-mode-p (car cel))
(throw :done (cdr cel))))
(alist-get t +modeline-major-mode-faces))
'mode-line-inactive)
'unspecified)
'keymap (let ((map (make-sparse-keymap)))
(bindings--define-key map [mode-line down-mouse-1]
`(menu-item "Menu Bar" ignore
@ -216,7 +217,7 @@ The order of elements matters: whichever one matches first is applied."
('t t)
(_ nil))
(throw :icon cell))))))
(+modeline-spacer nil nil
(+modeline-spacer nil spacer
(propertize (or (cdr-safe icon) "")
'help-echo (format "Buffer \"%s\" is %s."
(buffer-name)
@ -228,7 +229,7 @@ The order of elements matters: whichever one matches first is applied."
(defun +modeline-narrowed (&optional spacer)
"Display an indication that the buffer is narrowed."
(when (buffer-narrowed-p)
(+modeline-spacer nil nil
(+modeline-spacer nil spacer
(propertize "N"
'help-echo (format "%s\n%s"
"Buffer is narrowed."
@ -241,7 +242,7 @@ The order of elements matters: whichever one matches first is applied."
(defun +modeline-reading-mode (&optional spacer)
"Display an indication that the buffer is in `reading-mode'."
(when reading-mode
(+modeline-spacer nil nil
(+modeline-spacer nil spacer
(propertize
(concat "R" (when (bound-and-true-p +eww-readable-p) "w"))
'help-echo (format "%s\n%s"
@ -279,7 +280,7 @@ The order of elements matters: whichever one matches first is applied."
"Display the position in the current file."
(when file-percentage-mode
;; (let ((perc (+modeline--percentage)))
;; (propertize (+modeline-spacer nil nil
;; (propertize (+modeline-spacer nil spacer
;; (cond
;; ((+modeline--buffer-contained-in-window-p) "All")
;; ((= (line-number-at-pos) (line-number-at-pos (point-min))) "Top")
@ -293,16 +294,18 @@ The order of elements matters: whichever one matches first is applied."
;; ;; TODO: add scroll-up and scroll-down bindings.
;; ))
(let ((perc (format-mode-line '(-3 "%p"))))
(+modeline-spacer nil nil
(+modeline-spacer nil spacer
(pcase perc
((or "Top" "Bot" "All") perc)
("Top" ".^^")
("Bot" ".__")
("All" ".::")
(_ (format ".%02d" (string-to-number (substring perc 0 2)))))))))
(defun +modeline-file-percentage-icon (&optional spacer)
"Display the position in the current file as an icon."
(when file-percentage-mode
(let ((perc (+modeline--percentage)))
(propertize (+modeline-spacer nil nil
(propertize (+modeline-spacer nil spacer
(cond
((+modeline--buffer-contained-in-window-p) "")
((= perc 0) "")
@ -321,31 +324,29 @@ The order of elements matters: whichever one matches first is applied."
(defun +modeline-region (&optional spacer)
"Display an indicator if the region is active."
(if (and region-indicator-mode
(when (and region-indicator-mode
(region-active-p))
(format "%s%s"
(or spacer +modeline-default-spacer)
(+modeline-spacer nil spacer
(propertize (format "%s%d"
(if (and (< (point) (mark))) "-" "+")
(apply '+ (mapcar (lambda (pos)
(- (cdr pos)
(car pos)))
(region-bounds))))
'font-lock-face 'font-lock-variable-name-face))
""))
'font-lock-face 'font-lock-variable-name-face))))
(defun +modeline-line (&optional spacer)
(when line-number-mode
(+modeline-spacer nil nil "%2l")))
(+modeline-spacer nil spacer "%2l")))
(defun +modeline-column (&optional spacer)
(when column-number-mode
(+modeline-spacer nil nil
(+modeline-spacer nil spacer
(if column-number-indicator-zero-based "%2c" "%2C"))))
(defun +modeline-line-column (&optional spacer) ; adapted from `simple-modeline'
"Display the current cursor line and column depending on modes."
(+modeline-spacer nil nil
(+modeline-spacer nil spacer
(+modeline-line "")
"|"
(+modeline-column "")))
@ -361,7 +362,7 @@ The order of elements matters: whichever one matches first is applied."
See `line-number-mode', `column-number-mode', and
`file-percentage-mode'. If `+modeline-position-function' is set
to a function in the current buffer, call that function instead."
(+modeline-spacer nil nil
(+modeline-spacer nil spacer
(cond ((functionp +modeline-position-function)
(funcall +modeline-position-function))
(t (concat (+modeline-region)
@ -371,7 +372,7 @@ to a function in the current buffer, call that function instead."
"Display the version control branch of the current buffer in the modeline."
;; from https://www.gonsie.com/blorg/modeline.html, from Doom
(if-let ((backend (vc-backend buffer-file-name)))
(+modeline-spacer nil nil
(+modeline-spacer nil spacer
(substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2)))
""))
@ -382,7 +383,7 @@ to a function in the current buffer, call that function instead."
(defun +modeline-anzu (&optional spacer)
"Display `anzu--update-mode-line'."
(+modeline-spacer nil nil
(+modeline-spacer nil spacer
(anzu--update-mode-line)))
(defun +modeline-text-scale (&optional spacer)
@ -398,13 +399,13 @@ to a function in the current buffer, call that function instead."
"Display `ace-window-display-mode' information in the modeline."
(when (and +ace-window-display-mode
ace-window-mode)
(+modeline-spacer nil nil
(+modeline-spacer nil spacer
(window-parameter (selected-window) 'ace-window-path))))
(defun +modeline-god-mode (&optional spacer)
"Display an icon when `god-mode' is active."
(when (and (boundp 'god-local-mode) god-local-mode)
(+modeline-spacer nil nil
(+modeline-spacer nil spacer
(propertize "Ω"
'help-echo (concat "God mode is active."
"\nmouse-1: exit God mode.")
@ -422,7 +423,7 @@ to a function in the current buffer, call that function instead."
(defun +modeline-input-method (&optional spacer)
"Display which input method is active."
(when current-input-method
(+modeline-spacer nil nil
(+modeline-spacer nil spacer
(propertize current-input-method-title
'help-echo (format
(concat "Current input method: %s\n"
@ -450,7 +451,7 @@ to a function in the current buffer, call that function instead."
(defun +modeline-kmacro-indicator (&optional spacer)
"Display an indicator when recording a kmacro."
(when defining-kbd-macro
(+modeline-spacer nil nil
(+modeline-spacer nil spacer
(propertize ""
'face '+modeline-kmacro-indicator
'help-echo (format (concat "Defining a macro\n"