diff options
author | JSDurand <mmemmew@gmail.com> | 2022-01-12 22:49:08 +0800 |
---|---|---|
committer | JSDurand <mmemmew@gmail.com> | 2022-01-13 21:50:18 +0800 |
commit | 249de03acdc876eade36b873766dc176584dbab3 (patch) | |
tree | c01bc921975b865b2bbaff35a30330afd4f0b4eb | |
parent | 1f6ce7201597b84c646280ca7fe838498319c3be (diff) |
keycast-conf: Display in the active window
* keycast-conf.el (keycast-window-predicate): Use the function
`modeline-active-window-p' from my custom file "modeline.el" to
determine whether a window is the currently active window, and then
display the key cast information in that active window only.
* modeline.el (modeline-get-active-window, modeline-format-keycast): A
slight refactor.
(modeline-format-keycast): Use bound-and-true-p to test the mode
variable, so as to avoid errors when durand-keycast-mode has not yet
been loaded.
-rw-r--r-- | keycast-conf.el | 11 | ||||
-rw-r--r-- | modeline.el | 59 |
2 files changed, 48 insertions, 22 deletions
diff --git a/keycast-conf.el b/keycast-conf.el index b71f9c9..a7bb5c6 100644 --- a/keycast-conf.el +++ b/keycast-conf.el @@ -24,19 +24,22 @@ ;;; Code: -;;; The original minor mode tries to insert an element to the -;;; `mode-line-format'. But my mode line format consists of one -;;; custom element only, so it is not going to work that way. Rather, -;;; I shall define my own minor mode to just skip this part. +;; The original minor mode tries to insert an element to the +;; `mode-line-format'. But my mode line format consists of one custom +;; element only, so it is not going to work that way. Rather, I shall +;; define my own minor mode to just skip this part. (autoload 'use-package "basic") (use-package "keycast" 'keycast) (require 'keycast) +(require 'modeline) (setq keycast-separator-width 0) +(setq keycast-window-predicate #'modeline-active-window-p) + (setq keycast-substitute-alist (list (list #'self-insert-command (string #x2e) "Typing..."))) diff --git a/modeline.el b/modeline.el index 804442e..bbf75b2 100644 --- a/modeline.el +++ b/modeline.el @@ -152,9 +152,10 @@ MAP is the local keymap of the text." ;;;###autoload (defun modeline-get-active-window (&optional frame) "The active window excluding the child windows." - (if (and (fboundp 'frame-parent) (frame-parent frame)) - (frame-selected-window (frame-parent frame)) - (frame-selected-window frame))) + (cond + ((and (fboundp #'frame-parent) (frame-parent frame)) + (frame-selected-window (frame-parent frame))) + ((frame-selected-window frame)))) ;;;###autoload (defvar modeline-active-window (modeline-get-active-window) @@ -231,6 +232,8 @@ MAP is the local keymap of the text." ;;; Various sections of the mode line +;;;; Directory + ;;;###autoload (defun modeline-format-directory () "Display the default directory on the mode line." @@ -245,6 +248,8 @@ MAP is the local keymap of the text." (lambda () (interactive) (dired default-directory))) map))) +;;;; Space + ;;;###autoload (defun modeline-spc () "A space with the appropriate face." @@ -253,6 +258,8 @@ MAP is the local keymap of the text." 'mode-line) (t 'mode-line-inactive)))) +;;;; Buffer status + ;;;###autoload (defun modeline-format-buffer-status () "The status of the buffer displayed on the mode-line." @@ -279,6 +286,8 @@ MAP is the local keymap of the text." 'doom-modeline-warning) (t 'mode-line-inactive)))))))) +;;;; Buffer position + ;;;###autoload (defun modeline-format-position () "The position of the cursor to be displayed in the mode line." @@ -321,6 +330,8 @@ MAP is the local keymap of the text." "Buffer position\nmouse-1: Display Line and Column Mode Menu" mode-line-column-line-number-mode-map)))) +;;;; Buffer size + ;;;###autoload (defun modeline-format-buffer-size () "The size of the buffer to be displayed in the mode line." @@ -334,6 +345,8 @@ MAP is the local keymap of the text." "Buffer size\nmouse-1: Display Line and Column Mode Menu" mode-line-column-line-number-mode-map)) +;;;; Minor modes + ;;;###autoload (defvar modeline-minor-modes-name-len-max 150 "The maximal length for the display of minor modes in the mode line.") @@ -368,21 +381,7 @@ mouse-2: Show help for minor mode mouse-3: Toggle minor modes" mode-line-minor-mode-keymap)) -(defun modeline-format-keycast () - "Format the keycast information." - (declare (side-effect-free t)) - (cond - (durand-keycast-mode - (modeline-propertize - (format-mode-line mode-line-keycast) - nil - "Minor mode -mouse-1: Display minor mode menu -mouse-2: Show help for minor mode -mouse-3: Toggle minor modes" - mode-line-minor-mode-keymap)))) - -;;; NOTE: The minor mode menu does not work with my custom mode line. +;; NOTE: The minor mode menu does not work with my custom mode line. ;;;###autoload (defun durand-mouse-minor-mode-menu (event) @@ -414,6 +413,24 @@ Modified for my custom mode line." (advice-add 'mouse-minor-mode-menu :override #'durand-mouse-minor-mode-menu) +;;;; Keycast + +(defun modeline-format-keycast () + "Format the keycast information." + (declare (side-effect-free t)) + (cond + ((bound-and-true-p durand-keycast-mode) + (modeline-propertize + (format-mode-line mode-line-keycast) + nil + "Minor mode +mouse-1: Display minor mode menu +mouse-2: Show help for minor mode +mouse-3: Toggle minor modes" + mode-line-minor-mode-keymap)))) + +;;;; Buffer name + ;;;###autoload (defvar modeline-buffer-name-len-max 40 "The maximal length of the name of the buffer to be displayed in the mode line.") @@ -449,6 +466,8 @@ This will be displayed in the mode line." "mouse-1: ibuffer") mode-line-buffer-identification-keymap)) +;;;; Major mode + ;;;###autoload (defun modeline-format-major-mode () "The major mode to display in the mode line." @@ -466,6 +485,8 @@ This will be displayed in the mode line." (format-mode-line global-mode-string face)) (modeline-spc)))) +;;;; VCS + ;;;###autoload (defvar-local modeline-vcs-str "" "Display the version control system information on the mode line.") @@ -541,6 +562,8 @@ This will be displayed in the mode line." (get-text-property 1 'local-map vc-mode)) (modeline-spc))))) +;;;; Input method + ;;;###autoload (defun modeline-format-input-method () "Display the current input method on the mode line." |