You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use around advice to deal with skipped post-command-hook
When a command uses the minibuffer and the user aborts, then
`post-command-hook' is not run after that command. See bug#61176.
We can recover from that because if a command uses the minibuffer,
then `post-command-hook' is also/instead run when the minibuffer
is first uses. We can distinguish this premature run because
`this-command-keys-vector' returns an empty vector in this case.
The previous approach already took advantage of this. The premature
`post-command-hook' run delayed work until a later `post-command-hook'
run of *another* command, namely the command that exits the
minibuffer. That relied on heuristics and was unreliable.
The new approach still uses `post-command-hook'. If the command does
not use the minibuffer, it still takes care of all the work that has
to happen after the command has run. But the premature run that is
causes by the use of the minibuffer, now redirects work to an around
advice instead of to another run of the hook.
The advice has to be put in place before the command is called, so it
is done on `pre-command-hook'. It also has to take care of removing
itself once the command is done running. We use an around advice that
wraps both the command body and its interactive form with
`unwind-protect'.
The advice always takes care of removing itself, and if the command
does not use the minibuffer, then that is all it does. However, if
a premature `post-command-hook' run happens, then that instructs the
advice, to also perform the work usually done in the hook. This is
done by setting the `unwind-suffix' slot of the prefix object to the
function that performs the appropriate cleanup.
If the command has third-party after advices, then those run after
that has happened and therefore such advices to not have access to
transient variables, provided the command also uses the minibuffer.
The implementation in this commit requires Emacs 30, or more precisely
c39c26e33f6bb45479bbd1a80df8c97cf750a56a, which fixes bug#61179. The
next commit changes it to also work in older Emacs versions.
0 commit comments