From: Robert Pluim Date: Thu, 19 Jan 2023 14:58:51 +0000 (+0100) Subject: Use `key-parse' in `keymap-lookup' X-Git-Tag: emacs-29.0.90~645 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=dcd59457b48f1fb115e9847eef1c983406885717;p=emacs.git 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. --- 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. + (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