From 969c3135d6998903d640353cb039da4945c71f79 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Fri, 20 Aug 2021 14:55:40 +0200 Subject: [PATCH] Remove even more waiting from execute-extended-command * lisp/simple.el (execute-extended-command): Remove all the waiting from the command and do it all with timers (bug#50042). This ensures that post-command-hook is run immediately also when the command has messaged something. --- lisp/simple.el | 88 +++++++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/lisp/simple.el b/lisp/simple.el index 7da315e8692..24e77eeb3f4 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -2219,7 +2219,8 @@ invoking, give a prefix argument to `execute-extended-command'." (let* ((function (and (stringp command-name) (intern-soft command-name))) (binding (and suggest-key-bindings (not executing-kbd-macro) - (where-is-internal function overriding-local-map t)))) + (where-is-internal function overriding-local-map t))) + (delay-before-suggest 0)) (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,49 +2236,48 @@ invoking, give a prefix argument to `execute-extended-command'." (let ((prefix-arg prefixarg)) (command-execute function 'record)) ;; If enabled, show which key runs this command. - ;; But first wait, and skip the message if there is input. - (let* ((waited - ;; If this command displayed something in the echo area; - ;; wait a few seconds, then display our suggestion message. - ;; FIXME: Wait *after* running post-command-hook! - ;; FIXME: If execute-extended-command--shorter were - ;; faster, we could compute the result here first too. - (when (and suggest-key-bindings - (or binding - (and extended-command-suggest-shorter typed))) - (sit-for (cond - ((zerop (length (current-message))) 0) - ((numberp suggest-key-bindings) suggest-key-bindings) - (t 2)))))) - (when (and waited (not (consp unread-command-events))) - (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)))) - (when binding - ;; This is normally not necessary -- the timer should run - ;; immediately, but be defensive and ensure that we never - ;; have two of these timers in flight. - (when execute-extended-command--binding-timer - (cancel-timer execute-extended-command--binding-timer)) - (setq execute-extended-command--binding-timer - (run-at-time - 0 nil - (lambda () - (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))))))))))) + + ;; 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. + (when (and suggest-key-bindings + (or binding + (and extended-command-suggest-shorter typed))) + (setq delay-before-suggest + (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)))))))))) (defun execute-extended-command-for-buffer (prefixarg &optional command-name typed) -- 2.39.5