mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-24 14:30:43 -08:00
Support keymap symbol in bind-key
GitHub-reference: fix https://github.com/jwiegley/use-package/issues/845
This commit is contained in:
parent
3e96664ffe
commit
950068809b
1 changed files with 8 additions and 5 deletions
|
|
@ -154,11 +154,13 @@ spelled-out keystrokes, e.g., \"C-c C-z\". See documentation of
|
|||
|
||||
COMMAND must be an interactive function or lambda form.
|
||||
|
||||
KEYMAP, if present, should be a keymap and not a quoted symbol.
|
||||
KEYMAP, if present, should be a keymap variable or symbol.
|
||||
For example:
|
||||
|
||||
(bind-key \"M-h\" #'some-interactive-function my-mode-map)
|
||||
|
||||
(bind-key \"M-h\" #'some-interactive-function 'my-mode-map)
|
||||
|
||||
If PREDICATE is non-nil, it is a form evaluated to determine when
|
||||
a key should be bound. It must return non-nil in such cases.
|
||||
Emacs can evaluate this form at any time that it does redisplay
|
||||
|
|
@ -171,10 +173,11 @@ can safely be called at any time."
|
|||
`(let* ((,namevar ,key-name)
|
||||
(,keyvar (if (vectorp ,namevar) ,namevar
|
||||
(read-kbd-macro ,namevar)))
|
||||
(kmap (if (and ,keymap (symbolp ,keymap)) (symbol-value ,keymap) ,keymap))
|
||||
(,kdescvar (cons (if (stringp ,namevar) ,namevar
|
||||
(key-description ,namevar))
|
||||
(quote ,keymap)))
|
||||
(,bindingvar (lookup-key (or ,keymap global-map) ,keyvar)))
|
||||
(if (symbolp ,keymap) ,keymap (quote ,keymap))))
|
||||
(,bindingvar (lookup-key (or kmap global-map) ,keyvar)))
|
||||
(let ((entry (assoc ,kdescvar personal-keybindings))
|
||||
(details (list ,command
|
||||
(unless (numberp ,bindingvar)
|
||||
|
|
@ -183,11 +186,11 @@ can safely be called at any time."
|
|||
(setcdr entry details)
|
||||
(add-to-list 'personal-keybindings (cons ,kdescvar details))))
|
||||
,(if predicate
|
||||
`(define-key (or ,keymap global-map) ,keyvar
|
||||
`(define-key (or kmap global-map) ,keyvar
|
||||
'(menu-item "" nil :filter (lambda (&optional _)
|
||||
(when ,predicate
|
||||
,command))))
|
||||
`(define-key (or ,keymap global-map) ,keyvar ,command)))))
|
||||
`(define-key (or kmap global-map) ,keyvar ,command)))))
|
||||
|
||||
;;;###autoload
|
||||
(defmacro unbind-key (key-name &optional keymap)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue