From 998cd7ec8ef5180cb877805a4f796637eea9a29e Mon Sep 17 00:00:00 2001 From: Trevor Richards Date: Fri, 29 Jul 2022 09:07:53 -0700 Subject: [PATCH 1/7] * mood-line.el: Added evil-mode support Also laid some ground work for adding other modal editing systems. Moved the buffer modified segment, but only when some modal-editing mode is being used. It felt right to give modal-editing the front of the mode-line. --- mood-line.el | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/mood-line.el b/mood-line.el index edfad36..9b69c0c 100644 --- a/mood-line.el +++ b/mood-line.el @@ -87,6 +87,23 @@ :group 'mood-line :type 'boolean) +(defcustom mood-line-evil-state-alist + '((normal . ("" . font-lock-variable-name-face)) + (insert . ("" . font-lock-string-face)) + (visual . ("" . font-lock-keyword-face)) + (replace . ("" . font-lock-type-face)) + (motion . ("" . font-lock-constant-face)) + (operator . ("" . font-lock-function-name-face)) + (emacs . ("" . font-lock-builtin-face))) + "Set the string and corresponding face for many `evil-mode' state. +The `Face' may be either a face symbol or a property list of key-value pairs + e.g. (:foreground \"red\")." + :group 'mood-line + :type '(alist + :key-type symbol + :value-type + (cons (string :tag "Display Text") (choice :tag "Face" face plist)))) + (defface mood-line-buffer-name '((t (:inherit (mode-line-buffer-id)))) "Face used for major mode indicator in the mode-line." @@ -303,6 +320,16 @@ (unless (string= (mood-line--string-trim process-info) "") (concat (mood-line--string-trim process-info) " ")))) +(defun mood-line-segment-evil () + "Display the current evil-mode state." + (when evil-state + (let ((mode-cons (alist-get evil-state mood-line-evil-state-alist))) + (concat (propertize (car mode-cons) 'face (cdr mode-cons)) " ")))) + +(defun mood-line--modal-editing-p () + "Determine if modal editing is being used." + (mood-line-segment-modified)) ; (or) is for future modal additions. + ;; ;; Activation function ;; @@ -343,8 +370,14 @@ ;; Left (format-mode-line '(" " - (:eval (mood-line-segment-modified)) + (:eval (if (mood-line--modal-editing-p) + (progn + (mood-line-segment-evil)) + (mood-line-segment-modified))) (:eval (mood-line-segment-buffer-name)) + (:eval (if (mood-line--modal-editing-p) + (concat + (mood-line-segment-modified) " "))) (:eval (mood-line-segment-anzu)) (:eval (mood-line-segment-multiple-cursors)) (:eval (mood-line-segment-position)))) From 7c30e1cada60b58a4770dd5f56d6bca4fc2c0988 Mon Sep 17 00:00:00 2001 From: Trevor Richards Date: Fri, 29 Jul 2022 09:14:14 -0700 Subject: [PATCH 2/7] * mood-line.el (mood-line-evil-state-alist): Fixed typo --- mood-line.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mood-line.el b/mood-line.el index 9b69c0c..1879c8f 100644 --- a/mood-line.el +++ b/mood-line.el @@ -95,7 +95,7 @@ (motion . ("" . font-lock-constant-face)) (operator . ("" . font-lock-function-name-face)) (emacs . ("" . font-lock-builtin-face))) - "Set the string and corresponding face for many `evil-mode' state. + "Set the string and corresponding face for any `evil-mode' state. The `Face' may be either a face symbol or a property list of key-value pairs e.g. (:foreground \"red\")." :group 'mood-line From 855ea2760eaf30a8ff0e8418403aed3e4c077bf7 Mon Sep 17 00:00:00 2001 From: Trevor Richards Date: Fri, 29 Jul 2022 09:44:03 -0700 Subject: [PATCH 3/7] * mood-line.el (mood-line--modal-editing-p): Fixed incorrect test We should be looking for bound-and-true minor modes. Not sure what happened here. --- mood-line.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mood-line.el b/mood-line.el index 1879c8f..d2dc871 100644 --- a/mood-line.el +++ b/mood-line.el @@ -328,7 +328,7 @@ The `Face' may be either a face symbol or a property list of key-value pairs (defun mood-line--modal-editing-p () "Determine if modal editing is being used." - (mood-line-segment-modified)) ; (or) is for future modal additions. + (or (bound-and-true-p evil-mode))) ; (or) is for future modal additions. ;; ;; Activation function From fe26101881564e8d5c3fb1c9d0ed440d6271322c Mon Sep 17 00:00:00 2001 From: Trevor Richards Date: Fri, 29 Jul 2022 10:54:04 -0700 Subject: [PATCH 4/7] * mood-line.el: Added meow-edit support --- mood-line.el | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/mood-line.el b/mood-line.el index d2dc871..a4cdbfe 100644 --- a/mood-line.el +++ b/mood-line.el @@ -104,6 +104,21 @@ The `Face' may be either a face symbol or a property list of key-value pairs :value-type (cons (string :tag "Display Text") (choice :tag "Face" face plist)))) +(defcustom mood-line-meow-state-alist + '((normal . ("" . font-lock-variable-name-face)) + (insert . ("" . font-lock-string-face)) + (keypad . ("" . font-lock-keyword-face)) + (beacon . ("" . font-lock-type-face)) + (motion . ("" . font-lock-constant-face))) + "Set the string and corresponding face for any `meow-mode' state. +The `Face' may be either a face symbol or a property list of key-value pairs + e.g. (:foreground \"red\")." + :group 'mood-line + :type '(alist + :key-type symbol + :value-type + (cons (string :tag "Display Text") (choice :tag "Face" face plist)))) + (defface mood-line-buffer-name '((t (:inherit (mode-line-buffer-id)))) "Face used for major mode indicator in the mode-line." @@ -326,9 +341,17 @@ The `Face' may be either a face symbol or a property list of key-value pairs (let ((mode-cons (alist-get evil-state mood-line-evil-state-alist))) (concat (propertize (car mode-cons) 'face (cdr mode-cons)) " ")))) +(defun mood-line-segment-meow () + (when meow--current-state + (let ((mode-cons (alist-get + meow--current-state + mood-line-meow-state-alist))) + (concat (propertize (car mode-cons) 'face (cdr mode-cons)) " ")))) + (defun mood-line--modal-editing-p () "Determine if modal editing is being used." - (or (bound-and-true-p evil-mode))) ; (or) is for future modal additions. + (or (bound-and-true-p evil-mode) + (bound-and-true-p meow-mode))) ;; ;; Activation function @@ -372,7 +395,8 @@ The `Face' may be either a face symbol or a property list of key-value pairs '(" " (:eval (if (mood-line--modal-editing-p) (progn - (mood-line-segment-evil)) + (mood-line-segment-evil) + (mood-line-segment-meow)) (mood-line-segment-modified))) (:eval (mood-line-segment-buffer-name)) (:eval (if (mood-line--modal-editing-p) From f94b098b341fb814e08c68494fb861aa88edd650 Mon Sep 17 00:00:00 2001 From: Trevor Richards Date: Sat, 30 Jul 2022 07:11:21 -0700 Subject: [PATCH 5/7] * mood-line.el: Changed mode-line segment control flow I realized while doing other things that I had convoluted the the generation of the modeline needlessly with my modal implementation. By moving my modal tests into a cond form and simply shuffling `mode-line-segment-modified', we get a cleaner, simpler implementation. --- mood-line.el | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/mood-line.el b/mood-line.el index a4cdbfe..93a4cae 100644 --- a/mood-line.el +++ b/mood-line.el @@ -348,10 +348,10 @@ The `Face' may be either a face symbol or a property list of key-value pairs mood-line-meow-state-alist))) (concat (propertize (car mode-cons) 'face (cdr mode-cons)) " ")))) -(defun mood-line--modal-editing-p () - "Determine if modal editing is being used." - (or (bound-and-true-p evil-mode) - (bound-and-true-p meow-mode))) +(defun mood-line-segment-modal () + "Call the correct mode-line segment when the first modal-mode is found." + (cond ((bound-and-true-p evil-mode) (mood-line-segment-evil)) + ((bound-and-true-p meow-mode) (mood-line-segment-meow)))) ;; ;; Activation function @@ -393,15 +393,9 @@ The `Face' may be either a face symbol or a property list of key-value pairs ;; Left (format-mode-line '(" " - (:eval (if (mood-line--modal-editing-p) - (progn - (mood-line-segment-evil) - (mood-line-segment-meow)) - (mood-line-segment-modified))) + (:eval (mood-line-segment-modal)) + (:eval (mood-line-segment-modified)) (:eval (mood-line-segment-buffer-name)) - (:eval (if (mood-line--modal-editing-p) - (concat - (mood-line-segment-modified) " "))) (:eval (mood-line-segment-anzu)) (:eval (mood-line-segment-multiple-cursors)) (:eval (mood-line-segment-position)))) From 214263c0fc1f8015e9d2b8dfc8ad36a45c6e91a8 Mon Sep 17 00:00:00 2001 From: Trevor Richards Date: Sat, 30 Jul 2022 07:38:35 -0700 Subject: [PATCH 6/7] * mood-line.el: Added god-mode support --- mood-line.el | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mood-line.el b/mood-line.el index 93a4cae..0b32857 100644 --- a/mood-line.el +++ b/mood-line.el @@ -348,10 +348,18 @@ The `Face' may be either a face symbol or a property list of key-value pairs mood-line-meow-state-alist))) (concat (propertize (car mode-cons) 'face (cdr mode-cons)) " ")))) +(defun mood-line-segment-god () + "Indicate whether or not god-mode is active." + (if (bound-and-true-p god-local-mode) + '(:propertize " " + face (:inherit mood-line-status-warning)) + "--- ")) + (defun mood-line-segment-modal () "Call the correct mode-line segment when the first modal-mode is found." (cond ((bound-and-true-p evil-mode) (mood-line-segment-evil)) - ((bound-and-true-p meow-mode) (mood-line-segment-meow)))) + ((bound-and-true-p meow-mode) (mood-line-segment-meow)) + ((featurep 'god-mode) (mood-line-segment-god)))) ;; ;; Activation function From 7a8f3ccee3540a7c146df39ccca6ab472020a3b1 Mon Sep 17 00:00:00 2001 From: Trevor Richards Date: Sat, 30 Jul 2022 07:41:33 -0700 Subject: [PATCH 7/7] * mood-line.el: Fixed checks for meow and evil-segments Should no longer get warnings for unbound variables. Also, added a missing comment. --- mood-line.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mood-line.el b/mood-line.el index 0b32857..5717bb4 100644 --- a/mood-line.el +++ b/mood-line.el @@ -337,12 +337,13 @@ The `Face' may be either a face symbol or a property list of key-value pairs (defun mood-line-segment-evil () "Display the current evil-mode state." - (when evil-state + (when (boundp 'evil-state) (let ((mode-cons (alist-get evil-state mood-line-evil-state-alist))) (concat (propertize (car mode-cons) 'face (cdr mode-cons)) " ")))) (defun mood-line-segment-meow () - (when meow--current-state + "Display the current meow-mode state." + (when (boundp 'meow--current-state) (let ((mode-cons (alist-get meow--current-state mood-line-meow-state-alist)))