From 038e5de1adf2de6cdf28a428a44b0753813b928c Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 29 Dec 2021 22:55:55 -0600 Subject: Lots and lots of changes, oh jeez --- lisp/+modeline.el | 110 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 80 insertions(+), 30 deletions(-) (limited to 'lisp/+modeline.el') 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 @@ :prefix "+modeline-" :group 'simple-modeline) -(defun +modeline-buffer-name () ; gonsie +(defcustom +modeline-default-spacer " " + "Default spacer to use for modeline elements. +All modeline elements take an optional argument, `spacer', which +will default to this string.") + +;;; Combinators + +(defun +modeline-concat (segments &optional separator) + "Concatenate multiple `simple-modeline'-style SEGMENTS. +SEGMENTS is a list of either modeline segment-functions (see +`simple-modeline' functions for an example of types of +functions), though it can also contain cons cells of the +form (SEGMENT . PREDICATE). + +Segments are separated from each other using SEPARATOR, which +defaults to a \" \". space. Only segments that evaluate to a +non-trivial string (that is, a string not equal to \"\") will be +separated, for a cleaner look. + +This function makes a lambda, so you can throw it straight into +`simple-modeline-segments'." + (setq separator (or separator +modeline-default-spacer)) + (lambda () + (apply #'concat + (let (this-sep result-list) + (dolist (segment segments) + (push (funcall (or (car-safe segment) segment) + this-sep) + result-list) + (if (or (cdr-safe segment) + (and (car result-list) + (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)) + (nreverse result-list))))) + +;;; Modeline segments + +(defun +modeline-buffer-name (&optional spacer) ; gonsie "Display the buffer name." - (concat " " (propertize - (+string-align (buffer-name) 20 :before "" :ellipsis "~ ") - 'face 'bold - 'help-echo (or (buffer-file-name) - (buffer-name)) - 'mouse-face 'mode-line-highlight))) + (concat (or spacer +modeline-default-spacer) + (propertize + (+string-align (buffer-name) 20 :ellipsis nil) + 'help-echo (or (buffer-file-name) + (buffer-name)) + 'mouse-face 'mode-line-highlight))) (defcustom +modeline-minions-icon "&" "The \"icon\" for `+modeline-minions' button." :type 'string) -(defun +modeline-minions () +(defun +modeline-minions (&optional spacer) "Display a button for `minions-minor-modes-menu'." - (concat " " + (concat (or spacer +modeline-default-spacer) (propertize +modeline-minions-icon 'help-echo "Minor modes menu\nmouse-1: show menu." @@ -45,9 +85,9 @@ (minions-minor-modes-menu))))) 'mouse-face 'mode-line-highlight))) -(defun +modeline-major-mode () +(defun +modeline-major-mode (&optional spacer) "Display the current `major-mode'." - (concat " " + (concat (or spacer +modeline-default-spacer) (propertize (+string-truncate (format-mode-line mode-name) 12 "~") 'face 'bold @@ -80,7 +120,7 @@ The order of elements matters: whichever one matches first is applied." `+modeline-modified'." :type '(repeat function)) -(defun +modeline-modified () ; modified from `simple-modeline-status-modified' +(defun +modeline-modified (&optional spacer) ; modified from `simple-modeline-status-modified' "Display a color-coded \"icon\" indicator for the buffer's status." (let* ((icon (catch :icon (dolist (cell +modeline-modified-icon-alist) @@ -94,14 +134,20 @@ The order of elements matters: whichever one matches first is applied." ('t t) (_ nil)) (throw :icon (cdr cell))))))) - (concat " " + (concat (or spacer +modeline-default-spacer) (propertize (or icon "") 'mouse-face 'mode-line-highlight)))) -(defun +modeline-narrowed () +(defun +modeline-buffer-modes (&optional spacer) + "Display various buffer-specific stuff cleanly." + ;; This is clunky and should probably be improved. + (concat (+modeline-reading-mode) + (+modeline-narrowed (when reading-mode ",")))) + +(defun +modeline-narrowed (&optional spacer) "Display an indication that the buffer is narrowed." (when (buffer-narrowed-p) - (concat " " + (concat (or spacer +modeline-default-spacer) (propertize "N" 'help-echo (format "%s\n%s" "Buffer is narrowed." @@ -111,10 +157,10 @@ The order of elements matters: whichever one matches first is applied." 'face 'font-lock-doc-face 'mouse-face 'mode-line-highlight)))) -(defun +modeline-reading-mode () +(defun +modeline-reading-mode (&optional spacer) "Display an indication that the buffer is in `reading-mode'." (when reading-mode - (concat " " + (concat (or spacer +modeline-default-spacer) (propertize (concat "R" (when (bound-and-true-p +eww-readable-p) "w")) 'help-echo (format "%s\n%s" @@ -136,7 +182,7 @@ The order of elements matters: whichever one matches first is applied." "Toggle the percentage display in the mode line (File Percentage Mode)." :init-value t :global t :group 'mode-line) -(defun +modeline-position () ; adapted from `simple-modeline' +(defun +modeline-position (&optional _) ; adapted from `simple-modeline' "Display the current cursor position." (list '((line-number-mode ((column-number-mode @@ -160,34 +206,38 @@ The order of elements matters: whichever one matches first is applied." (region-bounds)))) 'font-lock-face 'font-lock-variable-name-face)))) -(defun +modeline-vc () +(defun +modeline-vc (&optional spacer) "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))) - (concat " " (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2))))) + (concat (or spacer +modeline-default-spacer) + (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2))))) -(defun +modeline-track () +(defun +modeline-track (&optional spacer) "Display `tracking-mode' information." - '(tracking-mode + (when tracking-mode tracking-mode-line-buffers)) -(defun +modeline-anzu () +(defun +modeline-anzu (&optional spacer) "Display `anzu--update-mode-line'." - (concat " " (anzu--update-mode-line))) + (concat (or spacer +modeline-default-spacer) + (anzu--update-mode-line))) -(defun +modeline-text-scale () +(defun +modeline-text-scale (&optional spacer) "Display text scaling level." ;; adapted from https://github.com/seagle0128/doom-modeline (when (and (boundp 'text-scale-mode-amount) (/= text-scale-mode-amount 0)) - (format (if (> text-scale-mode-amount 0) " (%+d)" " (%-d)") + (format (if (> text-scale-mode-amount 0) "%s(%+d)" "%s(%-d)") + (or spacer +modeline-default-spacer) text-scale-mode-amount))) -(defun +modeline-ace-window-display () +(defun +modeline-ace-window-display (&optional spacer) "Display `ace-window-display-mode' information in the modeline." - '(+ace-window-display-mode - (ace-window-mode - (" " (:eval (window-parameter (selected-window) 'ace-window-path)))))) + (when (and +ace-window-display-mode + ace-window-mode) + (concat (or spacer +modeline-default-spacer) + (window-parameter (selected-window) 'ace-window-path)))) (provide '+modeline) ;;; +modeline.el ends here -- cgit 1.4.1-21-gabe81