mirror of
https://github.com/masscollaborationlabs/emacs.git
synced 2025-07-05 03:39:38 +00:00
Merge pull request from wyuenho/patch-1
GitHub-reference: https://github.com/jwiegley/use-package/issues/846
This commit is contained in:
commit
10c6400d34
2 changed files with 20 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)
|
||||
|
|
|
@ -1940,6 +1940,18 @@
|
|||
(define-prefix-command 'my/map)
|
||||
(bind-key "<f1>" 'my/map nil nil))))
|
||||
|
||||
|
||||
(ert-deftest bind-key/845 ()
|
||||
(defvar test-map (make-keymap))
|
||||
(bind-key "<f1>" 'ignore 'test-map)
|
||||
(should (eq (lookup-key test-map (kbd "<f1>")) 'ignore))
|
||||
(let ((binding (cl-find "<f1>" personal-keybindings :test 'string= :key 'caar)))
|
||||
(message "test-map %s" test-map)
|
||||
(message "binding %s" binding)
|
||||
(should (eq (cdar binding) 'test-map))
|
||||
(should (eq (nth 1 binding) 'ignore))
|
||||
(should (eq (nth 2 binding) nil))))
|
||||
|
||||
;; Local Variables:
|
||||
;; indent-tabs-mode: nil
|
||||
;; no-byte-compile: t
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue