1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -08:00

defvar-keymap: New ':prefix t' abbreviation

* lisp/keymap.el (defvar-keymap): New ':prefix t' abbreviation.
* lisp/emacs-lisp/helper.el (Helper-help-map):
* lisp/vc/pcvs.el (cvs-mode-diff-map):
* lisp/vc/vc-hooks.el (vc-prefix-map):
* lisp/vcursor.el (vcursor-map): Use it.
* doc/lispref/keymaps.texi (Creating Keymaps):
* etc/NEWS: Document it.
This commit is contained in:
Sean Whitton 2025-10-06 18:34:18 +01:00
parent 1df9cfdb13
commit 7f925b06ac
7 changed files with 56 additions and 20 deletions

View file

@ -650,11 +650,9 @@ and @var{pairs} to @code{define-keymap}, and uses the result as the
default value for the variable. It signals an error if there are
duplicate key bindings in @var{pairs}.
@var{options} is like the keywords in @code{define-keymap}, but
there's an additional @code{:doc} keyword that provides the doc
string for the defined variable.
Here's an example:
@var{options} is mostly like the keywords in @code{define-keymap}.
There's an additional @code{:doc} keyword that provides the doc string
for the defined variable. Here's an example:
@lisp
(defvar-keymap eww-textarea-map
@ -664,6 +662,24 @@ Here's an example:
"TAB" #'shr-next-link)
@end lisp
The @code{:prefix} keyword can take an additional value, @code{t}, which
is an abbreviation for using @var{name} as the value of that option.
I.e. instead of writing
@lisp
(defvar-keymap foo-map
:prefix 'foo-map
...)
@end lisp
you can write
@lisp
(defvar-keymap foo-map
:prefix t
...)
@end lisp
@kindex :repeat
@kindex repeat-mode
@cindex repeatable key bindings

View file

@ -3310,6 +3310,12 @@ a remote host. It must be used in conjunction with the function
The column number is no longer available; the line number will be
removed in next Emacs release.
+++
** defvar-keymap can now take a ':prefix t' option.
This is an abbreviation for using the name of the keymap as the prefix
command name. E.g. (defvar-keymap foo-map :prefix t) is equivalent to
(defvar-keymap foo-map :prefix 'foo-map).
* Changes in Emacs 31.1 on Non-Free Operating Systems

View file

@ -40,6 +40,7 @@
(defvar-keymap Helper-help-map
:prefix t
"m" #'Helper-describe-mode
"b" #'Helper-describe-bindings
"c" #'Helper-describe-key-briefly
@ -48,7 +49,6 @@
;;"v" #'Helper-describe-variable
"?" #'Helper-help-options
(help-key) #'Helper-help-options)
(fset 'Helper-help-map Helper-help-map)
(defun Helper-help-scroller ()
(let ((blurb (or (and (boundp 'Helper-return-blurb)

View file

@ -614,9 +614,11 @@ pairs. Available keywords are:
:name If non-nil, this should be a string to use as the menu for
the keymap in case you use it as a menu with `x-popup-menu'.
:prefix If non-nil, this should be a symbol to be used as a prefix
command (see `define-prefix-command'). If this is the case,
this symbol is returned instead of the map itself.
:prefix If non-nil, this should be a symbol to make into a prefix command
using the new keymap (see `define-prefix-command').
That is, store the keymap as the symbol's function definition.
In addition, when non-nil, return the symbol instead of the
new keymap.
KEY/DEFINITION pairs are as KEY and DEF in `keymap-set'. KEY can
also be the special symbol `:menu', in which case DEFINITION
@ -689,6 +691,9 @@ In addition to the keywords accepted by `define-keymap', this
macro also accepts a `:doc' keyword, which (if present) is used
as the variable documentation string.
The `:prefix' keyword can take an additional value, t, which is an
abbreviation for using VARIABLE-NAME as the prefix command name.
The `:repeat' keyword can also be specified; it controls the
`repeat-mode' behavior of the bindings in the keymap. When it is
non-nil, all commands in the map will have the `repeat-map'
@ -734,10 +739,17 @@ in the echo area.
(unless defs
(error "Uneven number of keywords"))
(cond
((eq keyword :doc) (setq doc (pop defs)))
((eq keyword :repeat) (setq repeat (pop defs)))
(t (push keyword opts)
(push (pop defs) opts)))))
((eq keyword :doc)
(setq doc (pop defs)))
((eq keyword :repeat)
(setq repeat (pop defs)))
((and (eq keyword :prefix) (eq (car defs) t))
(setq defs (cdr defs))
(push keyword opts)
(push `',variable-name opts))
(t
(push keyword opts)
(push (pop defs) opts)))))
(unless (zerop (% (length defs) 2))
(error "Uneven number of key/definition pairs: %s" defs))

View file

@ -140,6 +140,10 @@
(defvar-keymap cvs-mode-diff-map
:name "Diff"
;; This is necessary to allow correct handling of
;; \\[cvs-mode-diff-map] in substitute-command-keys.
:prefix t
"E" (cons "imerge" #'cvs-mode-imerge)
"=" #'cvs-mode-diff
"e" (cons "idiff" #'cvs-mode-idiff)
@ -150,9 +154,6 @@
"r" (cons "repository" #'cvs-mode-diff-repository)
"y" (cons "yesterday" #'cvs-mode-diff-yesterday)
"v" (cons "vendor" #'cvs-mode-diff-vendor))
;; This is necessary to allow correct handling of \\[cvs-mode-diff-map]
;; in substitute-command-keys.
(fset 'cvs-mode-diff-map cvs-mode-diff-map)
(defvar-keymap cvs-mode-map
:full t

View file

@ -965,6 +965,7 @@ In the latter case, VC mode is deactivated for this buffer."
;; in the menu because they don't exist yet when the menu is built.
;; (autoload 'vc-prefix-map "vc" nil nil 'keymap)
(defvar-keymap vc-prefix-map
:prefix t
"a" #'vc-update-change-log
"b c" #'vc-create-branch
"b l" #'vc-print-branch-log
@ -1003,7 +1004,6 @@ In the latter case, VC mode is deactivated for this buffer."
"w R" #'vc-move-working-tree
"w a" #'vc-apply-to-other-working-tree
"w A" #'vc-apply-root-to-other-working-tree)
(fset 'vc-prefix-map vc-prefix-map)
(define-key ctl-x-map "v" 'vc-prefix-map)
(defvar-keymap vc-incoming-prefix-map

View file

@ -467,6 +467,10 @@ scrolling set this. It is used by the `vcursor-auto-disable' code.")
(defvar-keymap vcursor-map
:doc "Keymap for vcursor command."
;; This seems unused but was done previously (Emacs 24), so is kept
;; for now.
:prefix t
"t" #'vcursor-use-vcursor-map
"C-p" #'vcursor-previous-line
@ -495,9 +499,6 @@ scrolling set this. It is used by the `vcursor-auto-disable' code.")
"c" #'vcursor-compare-windows
"k" #'vcursor-execute-key
"M-x" #'vcursor-execute-command)
;; This seems unused, but it was done as part of define-prefix-command,
;; so let's keep it for now.
(fset 'vcursor-map vcursor-map)
;; If vcursor-key-bindings is already set on loading, bind the keys now.
;; This hybrid way of doing it retains compatibility while allowing