Subject: Re: bug#50042: 26.3; Post-command hooks slow with M-x commands

From: Lars Ingebrigtsen <[email-masked]>
Date: Sat, 14 Aug 2021 18:36:21 +0200

Lars Ingebrigtsen <[email-masked]> writes:

> Simpler repro:
>
> (add-hook 'post-command-hook
> 	  (lambda ()
> 	    (let ((inhibit-message t))
> 	      (message "foo: %s" this-command))))
> (display-buffer "*Messages*")
>
> M-x previous-line

[...]

> `execute-extended-command' ends with
>
>         (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))))))))
>
> So presumably `post-command-hook' isn't run after that timeout has
> completed.

[...]

> Could we yank this out of the flow and run it from a timer (fired
> immediately) instead?

Stefan, I forgot to put you on the CCs here -- I wondered whether you
had any ideas here.  I think lifting this out of
`execute-extended-command' should be possible -- either by doing
something a la

(run-at-time 0 nil (lambda ()
                     (with-temp-message "The binding is foo"
		       (sit-for 1))))

or making `execute-extended-command' set a variable and do the messaging
from the "command loop" after running post-command-hook.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no