[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master a5bf6fb526: Fix suggest-key-bindings displaying key as command
From: |
Stefan Kangas |
Subject: |
master a5bf6fb526: Fix suggest-key-bindings displaying key as command |
Date: |
Sun, 13 Nov 2022 13:46:12 -0500 (EST) |
branch: master
commit a5bf6fb526692e21b270145070a9e5f321f9eca7
Author: Stefan Kangas <stefankangas@gmail.com>
Commit: Stefan Kangas <stefankangas@gmail.com>
Fix suggest-key-bindings displaying key as command
* lisp/simple.el (execute-extended-command--describe-binding-msg):
New function factored out from...
(execute-extended-command): ...here. Fix bug where a key binding was
displayed as a command with 'suggest-key-bindings'. (Bug#59247)
* test/lisp/simple-tests.el
(simple-execute-extended-command--describe-binding-msg): New test.
---
lisp/simple.el | 20 ++++++++++++--------
test/lisp/simple-tests.el | 11 +++++++++++
2 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/lisp/simple.el b/lisp/simple.el
index 35fe130ab9..a53b7b1d0d 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -2491,6 +2491,13 @@ Also see `suggest-key-bindings'."
(defvar execute-extended-command--binding-timer nil)
+(defun execute-extended-command--describe-binding-msg (function binding
shorter)
+ (format-message "You can run the command `%s' with %s"
+ function
+ (cond (shorter (concat "M-x " shorter))
+ ((stringp binding) binding)
+ (t (key-description binding)))))
+
(defun execute-extended-command (prefixarg &optional command-name typed)
"Read a command name, then read the arguments and call the command.
To pass a prefix argument to the command you are
@@ -2514,7 +2521,7 @@ invoking, give a prefix argument to
`execute-extended-command'."
(not executing-kbd-macro)
(where-is-internal function overriding-local-map t)))
(delay-before-suggest 0)
- (find-shorter nil))
+ find-shorter shorter)
(unless (commandp function)
(error "`%s' is not a valid command name" command-name))
;; If we're executing a command that's remapped, we can't actually
@@ -2568,15 +2575,12 @@ invoking, give a prefix argument to
`execute-extended-command'."
(when find-shorter
(while-no-input
;; FIXME: Can be slow. Cache it maybe?
- (setq binding (execute-extended-command--shorter
+ (setq shorter (execute-extended-command--shorter
(symbol-name function) typed))))
- (when binding
+ (when (or binding shorter)
(with-temp-message
- (format-message "You can run the command `%s' with %s"
- function
- (if (stringp binding)
- (concat "M-x " binding " RET")
- (key-description binding)))
+ (execute-extended-command--describe-binding-msg
+ function binding shorter)
(sit-for (if (numberp suggest-key-bindings)
suggest-key-bindings
2))))))))))))
diff --git a/test/lisp/simple-tests.el b/test/lisp/simple-tests.el
index acb417b80b..d067f3e586 100644
--- a/test/lisp/simple-tests.el
+++ b/test/lisp/simple-tests.el
@@ -84,6 +84,17 @@
"display-line")
"di-n")))
+(ert-deftest simple-execute-extended-command--describe-binding-msg ()
+ (should (equal (execute-extended-command--describe-binding-msg
+ 'foo "m" nil)
+ "You can run the command ‘foo’ with m"))
+ (should (equal (execute-extended-command--describe-binding-msg
+ 'foo [14] nil)
+ "You can run the command ‘foo’ with C-n"))
+ (should (equal (execute-extended-command--describe-binding-msg
+ 'display-line-numbers-mode nil "di-n")
+ "You can run the command ‘display-line-numbers-mode’ with M-x
di-n")))
+
;;; `transpose-sexps'
(defmacro simple-test--transpositions (&rest body)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master a5bf6fb526: Fix suggest-key-bindings displaying key as command,
Stefan Kangas <=