From 00a9c50ad7c82f72b422100624f7f125d717c00f Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Fri, 20 Aug 2021 15:07:24 +0200 Subject: [PATCH] Further tweaks to execute-extended-command * lisp/simple.el (execute-extended-command): Move finding the short command to the timer command, too (bug#50042). This further ensures that post-command-hook is run faster. --- lisp/simple.el | 78 ++++++++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/lisp/simple.el b/lisp/simple.el index 24e77eeb3f4..aa139dd6035 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -2220,7 +2220,8 @@ invoking, give a prefix argument to `execute-extended-command'." (binding (and suggest-key-bindings (not executing-kbd-macro) (where-is-internal function overriding-local-map t))) - (delay-before-suggest 0)) + (delay-before-suggest 0) + (find-shorter nil)) (unless (commandp function) (error "`%s' is not a valid command name" command-name)) ;; Some features, such as novice.el, rely on this-command-keys @@ -2235,12 +2236,12 @@ invoking, give a prefix argument to `execute-extended-command'." (setq real-this-command function) (let ((prefix-arg prefixarg)) (command-execute function 'record)) - ;; If enabled, show which key runs this command. - - ;; If this command displayed something in the echo area; - ;; then postpone display our suggestion message a bit. - ;; FIXME: If execute-extended-command--shorter were - ;; faster, we could compute the result here first too. + ;; Ensure that we never have two of the suggest-binding timers in + ;; flight. + (when execute-extended-command--binding-timer + (cancel-timer execute-extended-command--binding-timer)) + ;; If this command displayed something in the echo area; then + ;; postpone display our suggestion message a bit. (when (and suggest-key-bindings (or binding (and extended-command-suggest-shorter typed))) @@ -2248,36 +2249,39 @@ invoking, give a prefix argument to `execute-extended-command'." (cond ((zerop (length (current-message))) 0) ((numberp suggest-key-bindings) suggest-key-bindings) - (t 2)))) - (unless (or (not extended-command-suggest-shorter) - binding executing-kbd-macro (not (symbolp function)) - (<= (length (symbol-name function)) 2)) - ;; There's no binding for CMD. Let's try and find the shortest - ;; string to use in M-x. - ;; FIXME: Can be slow. Cache it maybe? - (while-no-input - (setq binding (execute-extended-command--shorter - (symbol-name function) typed)))) - ;; Ensure that we never have two of these timers in flight. - (when execute-extended-command--binding-timer - (cancel-timer execute-extended-command--binding-timer)) - (when binding - (setq execute-extended-command--binding-timer - (run-at-time - delay-before-suggest nil - (lambda () - ;; If the user has typed any other commands in the - ;; meantime, then don't display anything. - (when (eq function real-last-command) - (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))) - (sit-for (if (numberp suggest-key-bindings) - suggest-key-bindings - 2)))))))))) + (t 2))) + (when (and extended-command-suggest-shorter + (not binding) + (not executing-kbd-macro) + (symbolp function) + (> (length (symbol-name function)) 2)) + ;; There's no binding for CMD. Let's try and find the shortest + ;; string to use in M-x. + (setq find-shorter t)) + (when (or binding find-shorter) + (setq execute-extended-command--binding-timer + (run-at-time + delay-before-suggest nil + (lambda () + ;; If the user has typed any other commands in the + ;; meantime, then don't display anything. + (when (eq function real-last-command) + ;; Find shorter string. + (when find-shorter + (while-no-input + ;; FIXME: Can be slow. Cache it maybe? + (setq binding (execute-extended-command--shorter + (symbol-name function) typed)))) + (when binding + (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))) + (sit-for (if (numberp suggest-key-bindings) + suggest-key-bindings + 2)))))))))))) (defun execute-extended-command-for-buffer (prefixarg &optional command-name typed) -- 2.39.2