]> git.eshelyaron.com Git - emacs.git/commitdiff
Remove even more waiting from execute-extended-command
authorLars Ingebrigtsen <larsi@gnus.org>
Fri, 20 Aug 2021 12:55:40 +0000 (14:55 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Fri, 20 Aug 2021 12:55:40 +0000 (14:55 +0200)
* 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

index 7da315e869221b6fcfbedea07460c21bd34934cb..24e77eeb3f4c524a8d5fb7318fb180fcd7f14b1e 100644 (file)
@@ -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)