Move modal editing segment to its own file

This commit is contained in:
Jessie Hildebrandt 2023-01-26 04:17:55 -05:00
parent 60faca6943
commit 58e85c8150
2 changed files with 137 additions and 80 deletions

125
mood-line-segment-modal.el Normal file
View File

@ -0,0 +1,125 @@
;;; mood-line-segment-modal.el --- A modal editing segment for mood-line -*- lexical-binding: t; -*-
;;
;; Author: trevDev() <trev@trevdev.ca>
;; Jessie Hildebrandt <jessieh.net>
;; Homepage: https://gitlab.com/jessieh/mood-line
;; This file is not part of GNU Emacs.
;;; Commentary:
;;
;; This segment displays modal editing information for the current buffer.
;;; License:
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
;;; Code:
;; -------------------------------------------------------------------------- ;;
;;
;; Custom definitions
;;
;; -------------------------------------------------------------------------- ;;
;; ---------------------------------- ;;
;; Variable definitions
;; ---------------------------------- ;;
(defcustom mood-line-evil-state-alist
'((normal . ("<N>" . font-lock-variable-name-face))
(insert . ("<I>" . font-lock-string-face))
(visual . ("<V>" . font-lock-keyword-face))
(replace . ("<R>" . font-lock-type-face))
(motion . ("<M>" . font-lock-constant-face))
(operator . ("<O>" . font-lock-function-name-face))
(emacs . ("<E>" . font-lock-builtin-face)))
"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
:type '(alist
:key-type symbol
:value-type
(cons (string :tag "Display Text") (choice :tag "Face" face plist))))
(defcustom mood-line-meow-state-alist
'((normal . ("<N>" . font-lock-variable-name-face))
(insert . ("<I>" . font-lock-string-face))
(keypad . ("<K>" . font-lock-keyword-face))
(beacon . ("<B>" . font-lock-type-face))
(motion . ("<M>" . 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))))
;; -------------------------------------------------------------------------- ;;
;;
;; Modal editing segment
;;
;; -------------------------------------------------------------------------- ;;
;; ---------------------------------- ;;
;; Evil segment function
;; ---------------------------------- ;;
(defun mood-line-segment-modal--evil ()
"Display the current evil-mode 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))
" "))))
;; ---------------------------------- ;;
;; Meow segment function
;; ---------------------------------- ;;
(defun mood-line-segment-modal--meow ()
"Display the current meow-mode state."
(when (boundp '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))
" "))))
;; ---------------------------------- ;;
;; God segment function
;; ---------------------------------- ;;
(defun mood-line-segment-modal--god ()
"Indicate whether or not god-mode is active."
(if (bound-and-true-p god-local-mode)
'(:propertize "<G> "
face (:inherit mood-line-status-warning))
"--- "))
;; -------------------------------------------------------------------------- ;;
;;
;; Provide package
;;
;; -------------------------------------------------------------------------- ;;
(provide 'mood-line-segment-modal)
;;; mood-line-segment-modal.el ends here

View File

@ -80,6 +80,10 @@
(declare-function mood-line-segment-indentation--segment "mood-line-segment-indentation" ()) (declare-function mood-line-segment-indentation--segment "mood-line-segment-indentation" ())
(declare-function mood-line-segment-modal--evil "mood-line-segment-modal" ())
(declare-function mood-line-segment-modal--meow "mood-line-segment-modal" ())
(declare-function mood-line-segment-modal--god "mood-line-segment-modal" ())
(declare-function mc/num-cursors "multiple-cursors" ()) (declare-function mc/num-cursors "multiple-cursors" ())
(declare-function string-blank-p "subr-x" (string)) (declare-function string-blank-p "subr-x" (string))
@ -246,38 +250,6 @@ found to be missing in `mood-line-glyph-alist'."
:key-type (symbol :tag "Glyph name") :key-type (symbol :tag "Glyph name")
:value-type (character :tag "Character to use"))) :value-type (character :tag "Character to use")))
(defcustom mood-line-evil-state-alist
'((normal . ("<N>" . font-lock-variable-name-face))
(insert . ("<I>" . font-lock-string-face))
(visual . ("<V>" . font-lock-keyword-face))
(replace . ("<R>" . font-lock-type-face))
(motion . ("<M>" . font-lock-constant-face))
(operator . ("<O>" . font-lock-function-name-face))
(emacs . ("<E>" . font-lock-builtin-face)))
"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
:type '(alist
:key-type symbol
:value-type
(cons (string :tag "Display Text") (choice :tag "Face" face plist))))
(defcustom mood-line-meow-state-alist
'((normal . ("<N>" . font-lock-variable-name-face))
(insert . ("<I>" . font-lock-string-face))
(keypad . ("<K>" . font-lock-keyword-face))
(beacon . ("<B>" . font-lock-type-face))
(motion . ("<M>" . 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))))
;; ---------------------------------- ;; ;; ---------------------------------- ;;
;; Face definitions ;; Face definitions
;; ---------------------------------- ;; ;; ---------------------------------- ;;
@ -378,7 +350,7 @@ The mode line should fit the `window-width' with space between the lists."
;; -------------------------------------------------------------------------- ;; ;; -------------------------------------------------------------------------- ;;
;; ;;
;; Optional segments ;; Optional/lazy loaded segments
;; ;;
;; -------------------------------------------------------------------------- ;; ;; -------------------------------------------------------------------------- ;;
@ -392,51 +364,8 @@ The mode line should fit the `window-width' with space between the lists."
(require 'mood-line-segment-indentation) (require 'mood-line-segment-indentation)
(mood-line-segment-indentation--segment))) (mood-line-segment-indentation--segment)))
;; -------------------------------------------------------------------------- ;;
;;
;; Modal editing segment
;;
;; -------------------------------------------------------------------------- ;;
;; ---------------------------------- ;; ;; ---------------------------------- ;;
;; Evil segment function ;; Modal editing
;; ---------------------------------- ;;
(defun mood-line-segment-modal-evil ()
"Display the current evil-mode 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))
" "))))
;; ---------------------------------- ;;
;; Meow segment function
;; ---------------------------------- ;;
(defun mood-line-segment-modal-meow ()
"Display the current meow-mode state."
(when (boundp '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))
" "))))
;; ---------------------------------- ;;
;; God segment function
;; ---------------------------------- ;;
(defun mood-line-segment-modal-god ()
"Indicate whether or not god-mode is active."
(if (bound-and-true-p god-local-mode)
'(:propertize "<G> "
face (:inherit mood-line-status-warning))
"--- "))
;; ---------------------------------- ;;
;; Modal segment function
;; ---------------------------------- ;; ;; ---------------------------------- ;;
(defun mood-line-segment-modal () (defun mood-line-segment-modal ()
@ -445,11 +374,14 @@ The mode line should fit the `window-width' with space between the lists."
Modal modes checked, in order: `evil-mode', `meow-mode', `god-mode'." Modal modes checked, in order: `evil-mode', `meow-mode', `god-mode'."
(cond (cond
((bound-and-true-p evil-mode) ((bound-and-true-p evil-mode)
(mood-line-segment-modal-evil)) (require 'mood-line-segment-modal)
(mood-line-segment-modal--evil))
((bound-and-true-p meow-mode) ((bound-and-true-p meow-mode)
(mood-line-segment-modal-meow)) (require 'mood-line-segment-modal)
(mood-line-segment-modal--meow))
((featurep 'god-mode) ((featurep 'god-mode)
(mood-line-segment-modal-god)))) (require 'mood-line-segment-modal)
(mood-line-segment-modal--god))))
;; -------------------------------------------------------------------------- ;; ;; -------------------------------------------------------------------------- ;;
;; ;;