emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 42a98fe: Run execute-extended-command key binding suggestion from


From: Lars Ingebrigtsen
Subject: master 42a98fe: Run execute-extended-command key binding suggestion from a timer
Date: Sun, 15 Aug 2021 07:36:36 -0400 (EDT)

branch: master
commit 42a98feb5b8ff2d60701da4462864699c434562c
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Run execute-extended-command key binding suggestion from a timer
    
    * lisp/simple.el (execute-extended-command): Run the key binding
    suggestion from a timer instead of in the program flow -- this
    allows `post-command-hook' to be executed immediately (bug#50042).
---
 lisp/simple.el | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/lisp/simple.el b/lisp/simple.el
index 985beb0..1661346 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -2194,6 +2194,8 @@ Also see `suggest-key-bindings'."
           (setq binding candidate))))
     binding))
 
+(defvar execute-extended-command--binding-timer nil)
+
 (defun execute-extended-command (prefixarg &optional command-name typed)
   ;; Based on Fexecute_extended_command in keyboard.c of Emacs.
   ;; Aaron S. Hawley <aaron.s.hawley(at)gmail.com> 2009-08-24
@@ -2258,15 +2260,24 @@ invoking, give a prefix argument to 
`execute-extended-command'."
             (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))))))))
+          ;; 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)))))))))))
 
 (defun execute-extended-command-for-buffer (prefixarg &optional
                                                       command-name typed)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]