From 7318301b3b2d75494243fa9b26f22dc9e1aecf83 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Sat, 15 Mar 2025 13:39:45 +0100 Subject: [PATCH] Use defvar-keymap for some trivial keymaps * lisp/bindings.el (mode-line-window-dedicated-keymap) (mode-line-buffer-identification-keymap): * lisp/emulation/cua-rect.el (cua--overlay-keymap, cua--overlay-key): * lisp/mh-e/mh-mime.el (mh-mime-security-button-map): * lisp/mh-e/mh-utils.el (mh-hidden-header-keymap): * lisp/net/eudc-bob.el (eudc-bob-generic-keymap, eudc-bob-image-keymap) (eudc-bob-sound-keymap, eudc-bob-url-keymap, eudc-bob-mail-keymap): * lisp/progmodes/etags-regen.el (etags-regen-mode-map): * lisp/progmodes/octave.el (octave-help-mode-map): * lisp/replace.el (multi-query-replace-map): * lisp/simple.el (process-menu-mode-map, messages-buffer-mode-map): * lisp/startup.el (splash-screen-keymap): * lisp/tab-bar.el (tab-bar-mode-map): * lisp/textmodes/ispell.el (ispell-minor-keymap): * lisp/textmodes/tex-mode.el (latex-mode-map, plain-tex-mode-map): * lisp/tree-widget.el (tree-widget-button-keymap): * lisp/vc/vc-hooks.el (vc-mode-line-map): Use defvar-keymap. (cherry picked from commit d8d524071d78d6499278546cf13ae261c05cadf3) --- lisp/bindings.el | 30 ++++++++--------- lisp/emulation/cua-rect.el | 5 ++- lisp/net/eudc-bob.el | 62 +++++++++++++++-------------------- lisp/progmodes/etags-regen.el | 2 +- lisp/progmodes/octave.el | 10 +++--- lisp/replace.el | 14 ++++---- lisp/simple.el | 14 +++----- lisp/startup.el | 17 ++++------ lisp/tab-bar.el | 4 +-- lisp/textmodes/ispell.el | 10 +++--- lisp/textmodes/tex-mode.el | 20 +++++------ lisp/tree-widget.el | 12 +++---- lisp/vc/vc-hooks.el | 6 ++-- 13 files changed, 85 insertions(+), 121 deletions(-) diff --git a/lisp/bindings.el b/lisp/bindings.el index c7d7bdd607c..845ff1b24df 100644 --- a/lisp/bindings.el +++ b/lisp/bindings.el @@ -300,11 +300,9 @@ Value is used for `mode-line-frame-identification', which see." ;;;###autoload (put 'mode-line-frame-identification 'risky-local-variable t) -(defvar mode-line-window-dedicated-keymap - (let ((map (make-sparse-keymap))) - (define-key map [mode-line mouse-1] #'toggle-window-dedicated) - map) - "Keymap for what is displayed by `mode-line-window-dedicated'.") +(defvar-keymap mode-line-window-dedicated-keymap + :doc "Keymap for what is displayed by `mode-line-window-dedicated'." + " " #'toggle-window-dedicated) (defun mode-line-window-control () "Compute mode line construct for window dedicated state. @@ -625,20 +623,18 @@ Normally displays the buffer percentage and, optionally, the buffer size, the line number and the column number.") (put 'mode-line-position 'risky-local-variable t) -(defvar mode-line-buffer-identification-keymap +(defvar-keymap mode-line-buffer-identification-keymap + :doc "Keymap for what is displayed by `mode-line-buffer-identification'." ;; Add menu of buffer operations to the buffer identification part ;; of the mode line.or header line. - (let ((map (make-sparse-keymap))) - ;; Bind down- events so that the global keymap won't ``shine - ;; through''. - (define-key map [mode-line mouse-1] 'mode-line-previous-buffer) - (define-key map [header-line down-mouse-1] 'ignore) - (define-key map [header-line mouse-1] 'mode-line-previous-buffer) - (define-key map [mode-line mouse-3] 'mode-line-next-buffer) - (define-key map [header-line down-mouse-3] 'ignore) - (define-key map [header-line mouse-3] 'mode-line-next-buffer) - map) "\ -Keymap for what is displayed by `mode-line-buffer-identification'.") + ;; Bind down- events so that the global keymap won't ``shine + ;; through''. + " " #'mode-line-previous-buffer + " " #'ignore + " " #'mode-line-previous-buffer + " " #'mode-line-next-buffer + " " #'ignore + " " #'mode-line-next-buffer) (defun propertized-buffer-identification (fmt) "Return a list suitable for `mode-line-buffer-identification'. diff --git a/lisp/emulation/cua-rect.el b/lisp/emulation/cua-rect.el index 7783d18f6e4..b7e01324ce4 100644 --- a/lisp/emulation/cua-rect.el +++ b/lisp/emulation/cua-rect.el @@ -88,9 +88,8 @@ See `cua--rectangle'.") "List of overlays used to display current rectangle.") (put 'cua--rectangle-overlays 'permanent-local t) -(defvar cua--overlay-keymap - (let ((map (make-sparse-keymap))) - (define-key map "\r" #'cua-rotate-rectangle))) +(defvar-keymap cua--overlay-keymap + "RET" #'cua-rotate-rectangle) (defvar cua--virtual-edges-debug nil) diff --git a/lisp/net/eudc-bob.el b/lisp/net/eudc-bob.el index b7289868625..58a3e02430d 100644 --- a/lisp/net/eudc-bob.el +++ b/lisp/net/eudc-bob.el @@ -39,42 +39,32 @@ (require 'eudc) -(defvar eudc-bob-generic-keymap - (let ((map (make-sparse-keymap))) - (define-key map "s" #'eudc-bob-save-object) - (define-key map "!" #'eudc-bob-pipe-object-to-external-program) - (define-key map [down-mouse-3] #'eudc-bob-popup-menu) - map) - "Keymap for multimedia objects.") - -(defvar eudc-bob-image-keymap - (let ((map (make-sparse-keymap))) - (set-keymap-parent map eudc-bob-generic-keymap) - (define-key map "t" #'eudc-bob-toggle-inline-display) - map) - "Keymap for inline images.") - -(defvar eudc-bob-sound-keymap - (let ((map (make-sparse-keymap))) - (set-keymap-parent map eudc-bob-generic-keymap) - (define-key map (kbd "RET") #'eudc-bob-play-sound-at-point) - (define-key map [down-mouse-2] #'eudc-bob-play-sound-at-mouse) - map) - "Keymap for inline sounds.") - -(defvar eudc-bob-url-keymap - (let ((map (make-sparse-keymap))) - (define-key map (kbd "RET") #'browse-url-at-point) - (define-key map [down-mouse-2] #'browse-url-at-mouse) - map) - "Keymap for inline urls.") - -(defvar eudc-bob-mail-keymap - (let ((map (make-sparse-keymap))) - (define-key map (kbd "RET") #'goto-address-at-point) - (define-key map [down-mouse-2] #'goto-address-at-point) - map) - "Keymap for inline e-mail addresses.") +(defvar-keymap eudc-bob-generic-keymap + :doc "Keymap for multimedia objects." + "s" #'eudc-bob-save-object + "!" #'eudc-bob-pipe-object-to-external-program + "" #'eudc-bob-popup-menu) + +(defvar-keymap eudc-bob-image-keymap + :doc "Keymap for inline images." + :parent eudc-bob-generic-keymap + "t" #'eudc-bob-toggle-inline-display) + +(defvar-keymap eudc-bob-sound-keymap + :doc "Keymap for inline sounds." + :parent eudc-bob-generic-keymap + "RET" #'eudc-bob-play-sound-at-point + "" #'eudc-bob-play-sound-at-mouse) + +(defvar-keymap eudc-bob-url-keymap + :doc "Keymap for inline urls." + "RET" #'browse-url-at-point + "" #'browse-url-at-mouse) + +(defvar-keymap eudc-bob-mail-keymap + :doc "Keymap for inline e-mail addresses." + "RET" #'goto-address-at-point + "" #'goto-address-at-point) (defvar eudc-bob-generic-menu '("EUDC Binary Object Menu" diff --git a/lisp/progmodes/etags-regen.el b/lisp/progmodes/etags-regen.el index 7994303284b..cde82956c24 100644 --- a/lisp/progmodes/etags-regen.el +++ b/lisp/progmodes/etags-regen.el @@ -409,7 +409,7 @@ File extensions to generate the tags for." (remove-hook 'after-save-hook #'etags-regen--update-file) (remove-hook 'before-save-hook #'etags-regen--mark-as-new)) -(defvar etags-regen-mode-map (make-sparse-keymap)) +(defvar-keymap etags-regen-mode-map) ;;;###autoload (define-minor-mode etags-regen-mode diff --git a/lisp/progmodes/octave.el b/lisp/progmodes/octave.el index 7b101b702df..85cdac46626 100644 --- a/lisp/progmodes/octave.el +++ b/lisp/progmodes/octave.el @@ -1660,12 +1660,10 @@ code line." 'follow-link t 'action (compf octave-help button-label)) -(defvar octave-help-mode-map - (let ((map (make-sparse-keymap))) - (define-key map "\M-." 'octave-find-definition) - (define-key map "\C-hd" 'octave-help) - (define-key map "\C-ha" 'octave-lookfor) - map)) +(defvar-keymap octave-help-mode-map + "M-." #'octave-find-definition + "C-h d" #'octave-help + "C-h a" #'octave-lookfor) (define-derived-mode octave-help-mode help-mode "OctHelp" "Major mode for displaying Octave documentation." diff --git a/lisp/replace.el b/lisp/replace.el index 1d9a884e577..73c3b523382 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -2514,19 +2514,17 @@ The valid answers include `act', `skip', `act-and-show', This keymap is used by `y-or-n-p' as well as `query-replace'.") -(defvar multi-query-replace-map - (let ((map (make-sparse-keymap))) - (set-keymap-parent map query-replace-map) - (define-key map "Y" 'automatic-all) - (define-key map "N" 'exit-current) - map) - "Keymap that defines additional bindings for multi-buffer replacements. +(defvar-keymap multi-query-replace-map + :doc "Keymap that defines additional bindings for multi-buffer replacements. It extends its parent map `query-replace-map' with new bindings to operate on a set of buffers/files. The difference with its parent map is the additional answers `automatic-all' to replace all remaining matches in all remaining buffers with no more questions, and `exit-current' to skip remaining matches in the current buffer -and to continue with the next buffer in the sequence.") +and to continue with the next buffer in the sequence." + :parent query-replace-map + "Y" 'automatic-all + "N" 'exit-current) (defun replace-match-string-symbols (n) "Process a list (and any sub-lists), expanding certain symbols. diff --git a/lisp/simple.el b/lisp/simple.el index c7a8d24a70c..a872cbe54a3 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -5116,10 +5116,8 @@ File name handlers might not support pty association, if PROGRAM is nil." (defvar process-menu-query-only nil) -(defvar process-menu-mode-map - (let ((map (make-sparse-keymap))) - (define-key map [?d] 'process-menu-delete-process) - map)) +(defvar-keymap process-menu-mode-map + "d" #'process-menu-delete-process) (define-derived-mode process-menu-mode tabulated-list-mode "Process Menu" "Major mode for listing the processes called by Emacs." @@ -10673,11 +10671,9 @@ and setting it to nil." (setq buffer-invisibility-spec nil))) -(defvar messages-buffer-mode-map - (let ((map (make-sparse-keymap))) - (set-keymap-parent map special-mode-map) - (define-key map "g" nil) ; nothing to revert - map)) +(defvar-keymap messages-buffer-mode-map + :parent special-mode-map + "g" nil) ; nothing to revert (define-derived-mode messages-buffer-mode special-mode "Messages" "Major mode used in the \"*Messages*\" buffer." diff --git a/lisp/startup.el b/lisp/startup.el index b277db9d8be..c472f8a2f63 100644 --- a/lisp/startup.el +++ b/lisp/startup.el @@ -1864,16 +1864,13 @@ Each element in the list should be a list of strings or pairs (file :tag "File"))) -(defvar splash-screen-keymap - (let ((map (make-sparse-keymap))) - (suppress-keymap map) - (set-keymap-parent map button-buffer-map) - (define-key map "\C-?" #'scroll-down-command) - (define-key map [?\S-\ ] #'scroll-down-command) - (define-key map " " #'scroll-up-command) - (define-key map "q" #'exit-splash-screen) - map) - "Keymap for splash screen buffer.") +(defvar-keymap splash-screen-keymap + :doc "Keymap for splash screen buffer." + :suppress t :parent button-buffer-map + "DEL" #'scroll-down-command + "S-SPC" #'scroll-down-command + "SPC" #'scroll-up-command + "q" #'exit-splash-screen) ;; These are temporary storage areas for the splash screen display. diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el index 44184682901..3050da03479 100644 --- a/lisp/tab-bar.el +++ b/lisp/tab-bar.el @@ -97,8 +97,8 @@ -(defvar tab-bar-mode-map (make-sparse-keymap) - "Tab Bar mode map.") +(defvar-keymap tab-bar-mode-map + :doc "Tab Bar mode map.") (defcustom tab-bar-define-keys t "Define specified tab-bar key bindings. diff --git a/lisp/textmodes/ispell.el b/lisp/textmodes/ispell.el index 5640aa93efa..532b7906704 100644 --- a/lisp/textmodes/ispell.el +++ b/lisp/textmodes/ispell.el @@ -3697,12 +3697,10 @@ available on the net." ;;; Ispell Minor Mode ;;; ********************************************************************** -(defvar ispell-minor-keymap - (let ((map (make-sparse-keymap))) - (define-key map " " 'ispell-minor-check) - (define-key map "\r" 'ispell-minor-check) - map) - "Keymap used for Ispell minor mode.") +(defvar-keymap ispell-minor-keymap + :doc "Keymap used for Ispell minor mode." + "SPC" #'ispell-minor-check + "RET" #'ispell-minor-check) ;;;###autoload (define-minor-mode ispell-minor-mode diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el index f4af1441d1d..ea318db9779 100644 --- a/lisp/textmodes/tex-mode.el +++ b/lisp/textmodes/tex-mode.el @@ -892,18 +892,14 @@ START is the position of the \\ and DELIM is the delimiter char." map) "Keymap shared by TeX modes.") -(defvar latex-mode-map - (let ((map (make-sparse-keymap))) - (set-keymap-parent map tex-mode-map) - (define-key map "\C-c\C-s" #'latex-split-block) - map) - "Keymap for `latex-mode'. See also `tex-mode-map'.") - -(defvar plain-tex-mode-map - (let ((map (make-sparse-keymap))) - (set-keymap-parent map tex-mode-map) - map) - "Keymap for `plain-tex-mode'. See also `tex-mode-map'.") +(defvar-keymap latex-mode-map + :doc "Keymap for `latex-mode'. See also `tex-mode-map'." + :parent tex-mode-map + "C-c C-s" #'latex-split-block) + +(defvar-keymap plain-tex-mode-map + :doc "Keymap for `plain-tex-mode'. See also `tex-mode-map'." + :parent tex-mode-map) (defvar tex-shell-map (let ((m (make-sparse-keymap))) diff --git a/lisp/tree-widget.el b/lisp/tree-widget.el index 3b20d795ea8..d958bd0e96d 100644 --- a/lisp/tree-widget.el +++ b/lisp/tree-widget.el @@ -392,13 +392,11 @@ EVENT is the mouse event received." (if (get-char-property pos 'button) (widget-button-click event)))) -(defvar tree-widget-button-keymap - (let ((km (make-sparse-keymap))) - (set-keymap-parent km widget-keymap) - (define-key km [down-mouse-1] 'tree-widget-button-click) - km) - "Keymap used inside node buttons. -Handle mouse button 1 click on buttons.") +(defvar-keymap tree-widget-button-keymap + :doc "Keymap used inside node buttons. +Handle mouse button 1 click on buttons." + :parent widget-keymap + "" #'tree-widget-button-click) (define-widget 'tree-widget-icon 'push-button "Basic widget other tree-widget icons are derived from." diff --git a/lisp/vc/vc-hooks.el b/lisp/vc/vc-hooks.el index 7fd15bb1331..401ccb066e0 100644 --- a/lisp/vc/vc-hooks.el +++ b/lisp/vc/vc-hooks.el @@ -694,10 +694,8 @@ Before doing that, check if there are any old backups and get rid of them." ;; and this will simply use it. (define-key menu-bar-tools-menu [vc] vc-menu-entry)) -(defconst vc-mode-line-map - (let ((map (make-sparse-keymap))) - (define-key map [mode-line down-mouse-1] vc-menu-entry) - map)) +(defvar-keymap vc-mode-line-map + " " vc-menu-entry) (defun vc-mode-line (file &optional backend) "Set `vc-mode' to display type of version control for FILE. -- 2.39.5