From cee9a2cbe0cd2cb1af602077727c03f2ae62fa90 Mon Sep 17 00:00:00 2001 From: Robert Pluim Date: Wed, 21 Sep 2022 09:12:53 +0200 Subject: [PATCH] Fix substitute-command-keys for global binding lookup The previous change forgot to account for the (rare) case of doing a lookup for a global binding when a specific keymap is in force. * lisp/help.el (substitute-command-keys): Redo lookup in global map if lookup in specific map fails. * test/lisp/help-tests.el (help-tests-substitute-command-keys/keymap-change): Add testcase for specific map overriding advertised-binding. --- lisp/help.el | 6 ++++++ test/lisp/help-tests.el | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lisp/help.el b/lisp/help.el index 0ec5b9c85b8..b4b9120da3e 100644 --- a/lisp/help.el +++ b/lisp/help.el @@ -1208,6 +1208,12 @@ Otherwise, return a new string." (and keymap (list keymap)) t)))) + ;; If we're looking in a particular keymap which has + ;; no binding, then we need to redo the lookup, with + ;; the global map as well this time. + (when (and (not key) keymap) + (setq key (with-current-buffer orig-buf + (where-is-internal fun keymap t)))) (if (not key) ;; Function is not on any key. (let ((op (point))) diff --git a/test/lisp/help-tests.el b/test/lisp/help-tests.el index 6f1dcfa5b6b..0fcaacb6443 100644 --- a/test/lisp/help-tests.el +++ b/test/lisp/help-tests.el @@ -181,8 +181,12 @@ M-g M-c switch-to-completions (ert-deftest help-tests-substitute-command-keys/keymap-change () (with-substitute-command-keys-test + ;; Global binding should be found even if specifying a specific map (test "\\\\[abort-recursive-edit]" "C-]") - (test "\\\\[eval-defun]" "C-M-x"))) + (test "\\\\[eval-defun]" "C-M-x") + ;; Specific map overrides advertised-binding + (test "\\\\[undo]" "u") + (test "\\[undo]" "C-x u"))) (defvar-keymap help-tests-remap-map :full t -- 2.39.2