diff options
| author | bard <[email protected]> | 2024-01-28 14:14:31 -0500 |
|---|---|---|
| committer | bard <[email protected]> | 2024-01-28 14:14:31 -0500 |
| commit | caa7ce932894fcf6894bde15eb6f8a4d0a4b5b1a (patch) | |
| tree | 43be241426082efc877270a89af0842f9bab85ff | |
| parent | ef14c2d91847c02066d1d272a95095cda092109f (diff) | |
added functionality for emacs 28
| -rw-r--r-- | bard-elisp/bard-modeline.el | 86 |
1 files changed, 12 insertions, 74 deletions
diff --git a/bard-elisp/bard-modeline.el b/bard-elisp/bard-modeline.el index 851d063..57855d0 100644 --- a/bard-elisp/bard-modeline.el +++ b/bard-elisp/bard-modeline.el @@ -41,6 +41,18 @@ "String length after which truncation should be done in small windows." :type 'natnum) +(defun mode-line-window-selected-p () + "Return non-nil if we're updating the mode line for the selected window. +This function is meant to be called in `:eval' mode line +constructs to allow altering the look of the mode line depending +on whether the mode line belongs to the currently selected window +or not." + (let ((window (selected-window))) + (or (eq window (old-selected-window)) + (and (minibuffer-window-active-p (minibuffer-window)) + (with-selected-window (minibuffer-window) + (eq window (minibuffer-selected-window))))))) + ;;;; Faces (defface prot-modeline-indicator-button nil @@ -252,9 +264,6 @@ Specific to the current window's mode line.") "Mode line construct to report the multilingual environment.") ;;;; Buffer status - -;; TODO 2023-07-05: What else is there beside remote files? If -;; nothing, this must be renamed accordingly. (defvar-local prot-modeline-buffer-status '(:eval (when (file-remote-p default-directory) @@ -263,77 +272,6 @@ Specific to the current window's mode line.") 'mouse-face 'mode-line-highlight))) "Mode line construct for showing remote file name.") -;;;; Evil state - -(defvar evil-state) -(defvar evil-visual-selection) - -(defconst prot-modeline-evil-state-tags - '((normal :short "<N>" :long "NORMAL") - (insert :short "<I>" :long "INSERT") - (visual :short "<V>" :long "VISUAL") - (vblock :short "<Vb>" :long "VBLOCK") - (vline :short "<Vl>" :long "VLINE") - (vsline :short "<Vsl>" :long "VSLINE") - (motion :short "<M>" :long "MOTION") - (emacs :short "<E>" :long "EMACS") - (operator :short "<O>" :long "OPERATE") - (replace :short "<R>" :long "REPLACE") - (prot-basic :short "<B>" :long "BASIC")) - "Short and long tags for Evil states.") - -(defun prot-modeline--evil-get-tag (state variant) - "Get Evil STATE tag of VARIANT :short or :long. -VARIANT of the state tag is either :short or :long, as defined in -`prot-modeline-evil-state-tags'." - (let ((tags (alist-get state prot-modeline-evil-state-tags))) - (plist-get tags (or variant :short)))) - -(defun prot-modeline--evil-get-format-specifier (variant) - "Return a `format' specifier for VARIANT. -VARIANT of the state tag is either :short or :long, as defined in -`prot-modeline-evil-state-tags'." - (if (eq variant :short) - " %-5s" - " %-8s")) - -(defun prot-modeline--evil-propertize-tag (state variant &optional face) - "Propertize STATE tag of VARIANT with optional FACE. -VARIANT of the state tag is either :short or :long, as defined in -`prot-modeline-evil-state-tags'. If FACE is nil, fall back to -`default'." - (propertize - (format (prot-modeline--evil-get-format-specifier variant) (prot-modeline--evil-get-tag state variant)) - 'face (or face 'mode-line) - 'mouse-face 'mode-line-highlight - 'help-echo (format "Evil `%s' state" state))) - -(defun prot-modeline-evil-state-tag (variant) - "Return mode line tag VARIANT depending on the Evil state. -VARIANT of the state tag is either :short or :long, as defined in -`prot-modeline-evil-state-tags'." - (pcase evil-state - ('normal (prot-modeline--evil-propertize-tag 'normal variant 'prot-modeline-indicator-blue)) - ('insert (prot-modeline--evil-propertize-tag 'insert variant)) ; I don't actually use an "insert" state: it switches to "emacs" - ('visual (pcase evil-visual-selection - ('line (prot-modeline--evil-propertize-tag 'vline variant 'prot-modeline-indicator-yellow)) - ('screen-line (prot-modeline--evil-propertize-tag 'vsline variant 'prot-modeline-indicator-yellow)) - ('block (prot-modeline--evil-propertize-tag 'vblock variant 'prot-modeline-indicator-yellow)) - (_ (prot-modeline--evil-propertize-tag 'visual variant 'prot-modeline-indicator-yellow)))) - ('motion (prot-modeline--evil-propertize-tag 'motion variant 'prot-modeline-indicator-yellow)) - ('emacs (prot-modeline--evil-propertize-tag 'emacs variant 'prot-modeline-indicator-magenta)) - ('operator (prot-modeline--evil-propertize-tag 'operator variant 'prot-modeline-indicator-red)) - ('replace (prot-modeline--evil-propertize-tag 'replace variant 'prot-modeline-indicator-red)) - ('prot-basic (prot-modeline--evil-propertize-tag 'prot-basic variant 'prot-modeline-indicator-green)))) - -(defvar-local prot-modeline-evil - '(:eval - (if (and (mode-line-window-selected-p) (bound-and-true-p evil-mode)) - (let ((variant (if (prot-modeline--truncate-p) :short :long))) - (prot-modeline-evil-state-tag variant)) - " ")) - "Mode line construct to display the Evil state.") - ;;;; Buffer name and modified status (defun prot-modeline-buffer-identification-face () |
