mirror of
https://github.com/masscollaborationlabs/emacs.git
synced 2025-07-05 11:49:37 +00:00
unbind-key: Ensure that keys are removed from the keymap
* The removal from the keymap is performed by bind-key--remove * Use the same argument normalization as bind-key
This commit is contained in:
parent
ec750952f4
commit
5ca7bc321d
1 changed files with 41 additions and 11 deletions
|
@ -199,17 +199,47 @@ can safely be called at any time."
|
||||||
(defmacro unbind-key (key-name &optional keymap)
|
(defmacro unbind-key (key-name &optional keymap)
|
||||||
"Unbind the given KEY-NAME, within the KEYMAP (if specified).
|
"Unbind the given KEY-NAME, within the KEYMAP (if specified).
|
||||||
See `bind-key' for more details."
|
See `bind-key' for more details."
|
||||||
`(progn
|
(let ((namevar (make-symbol "name"))
|
||||||
(bind-key ,key-name nil ,keymap)
|
(kdescvar (make-symbol "kdesc")))
|
||||||
|
`(let* ((,namevar ,key-name)
|
||||||
|
(,kdescvar (cons (if (stringp ,namevar) ,namevar
|
||||||
|
(key-description ,namevar))
|
||||||
|
(if (symbolp ,keymap) ,keymap (quote ,keymap)))))
|
||||||
|
(bind-key--remove (if (vectorp ,namevar) ,namevar
|
||||||
|
(read-kbd-macro ,namevar))
|
||||||
|
(or (if (and ,keymap (symbolp ,keymap))
|
||||||
|
(symbol-value ,keymap) ,keymap)
|
||||||
|
global-map))
|
||||||
(setq personal-keybindings
|
(setq personal-keybindings
|
||||||
(cl-delete-if #'(lambda (k)
|
(cl-delete-if (lambda (k) (equal (car k) ,kdescvar))
|
||||||
,(if keymap
|
personal-keybindings))
|
||||||
`(and (consp (car k))
|
nil)))
|
||||||
(string= (caar k) ,key-name)
|
|
||||||
(eq (cdar k) ',keymap))
|
(defun bind-key--remove (key keymap)
|
||||||
`(and (stringp (car k))
|
"Remove KEY from KEYMAP.
|
||||||
(string= (car k) ,key-name))))
|
|
||||||
personal-keybindings))))
|
In contrast to `define-key', this function removes the binding from the keymap."
|
||||||
|
(define-key keymap key nil)
|
||||||
|
;; Split M-key in ESC key
|
||||||
|
(setq key (mapcan (lambda (k)
|
||||||
|
(if (and (integerp k) (/= (logand k ?\M-\0) 0))
|
||||||
|
(list ?\e (logxor k ?\M-\0))
|
||||||
|
(list k)))
|
||||||
|
key))
|
||||||
|
;; Delete single keys directly
|
||||||
|
(if (= (length key) 1)
|
||||||
|
(delete key keymap)
|
||||||
|
;; Lookup submap and delete key from there
|
||||||
|
(let* ((prefix (vconcat (butlast key)))
|
||||||
|
(submap (lookup-key keymap prefix)))
|
||||||
|
(unless (keymapp submap)
|
||||||
|
(error "Not a keymap for %s" key))
|
||||||
|
(when (symbolp submap)
|
||||||
|
(setq submap (symbol-function submap)))
|
||||||
|
(delete (last key) submap)
|
||||||
|
;; Delete submap if it is empty
|
||||||
|
(when (= 1 (length submap))
|
||||||
|
(bind-key--remove prefix keymap)))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defmacro bind-key* (key-name command &optional predicate)
|
(defmacro bind-key* (key-name command &optional predicate)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue