diff options
author | Robert Pluim <rpluim@gmail.com> | 2023-01-19 15:58:51 +0100 |
---|---|---|
committer | Robert Pluim <rpluim@gmail.com> | 2023-01-20 15:14:45 +0100 |
commit | dcd59457b48f1fb115e9847eef1c983406885717 (patch) | |
tree | de8037377fea57b47a324249b1b735a24308375f | |
parent | 8904a26a9d227e464ac1c6b054a0e3cf1bfb3016 (diff) | |
download | emacs-dcd59457b48f1fb115e9847eef1c983406885717.tar.gz |
Use `key-parse' in `keymap-lookup'
It's stricter than `kbd', and doesn't try to do anything with key
sequences that look like macros.
* lisp/keymap.el (keymap-lookup): Use `key-parse' instead of `kbd'.
* test/src/keymap-tests.el (keymap-set-after-menus): Test the
`keymap-set-after' API.
-rw-r--r-- | lisp/keymap.el | 2 | ||||
-rw-r--r-- | test/src/keymap-tests.el | 16 |
2 files changed, 17 insertions, 1 deletions
diff --git a/lisp/keymap.el b/lisp/keymap.el index 2caaafabb94..89461416a9c 100644 --- a/lisp/keymap.el +++ b/lisp/keymap.el @@ -405,7 +405,7 @@ specified buffer position instead of point are used." (symbolp value)) (or (command-remapping value) value) value)) - (key-binding (kbd key) accept-default no-remap position))) + (key-binding (key-parse key) accept-default no-remap position))) (defun keymap-local-lookup (keys &optional accept-default) "Return the binding for command KEYS in current local keymap only. diff --git a/test/src/keymap-tests.el b/test/src/keymap-tests.el index b7715a280a6..d7be2cac53a 100644 --- a/test/src/keymap-tests.el +++ b/test/src/keymap-tests.el @@ -430,6 +430,22 @@ g .. h foo (make-non-key-event 'keymap-tests-event) (should (equal (where-is-internal 'keymap-tests-command) '([3 103])))) +(ert-deftest keymap-set-consistency () + (let ((k (make-sparse-keymap))) + ;; `keymap-set' returns the binding, `keymap-set-after' doesn't, + ;; so we need to check for nil. <sigh> + (should (keymap-set k "a" "a")) + (should (equal (keymap-lookup k "a") (key-parse "a"))) + (should-not (keymap-set-after k "b" "b")) + (should (equal (keymap-lookup k "b") (key-parse "b"))) + (should-not (keymap-set-after k "d" "d" t)) + (should (equal (keymap-lookup k "d") (key-parse "d"))) + (should-not (keymap-set-after k "e" "e" nil)) + (should (equal (keymap-lookup k "e") (key-parse "e"))) + ;; This doesn't fail, but it does not add the 'f' binding after 'a' + (should-not (keymap-set-after k "f" "f" "a")) + (should (equal (keymap-lookup k "f") (key-parse "f"))))) + (ert-deftest keymap-test-duplicate-definitions () "Check that defvar-keymap rejects duplicate key definitions." (should-error |