[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/transient ef921d3 2/5: transient--post-command: Deal wi
From: |
Jonas Bernoulli |
Subject: |
[elpa] externals/transient ef921d3 2/5: transient--post-command: Deal with mystery quits |
Date: |
Tue, 15 Jun 2021 19:03:13 -0400 (EDT) |
branch: externals/transient
commit ef921d304871ab3ab029b8ddc8bdfa1173143a84
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>
transient--post-command: Deal with mystery quits
Sometimes when `post-command-hook' is run, then `this-command' and
`this-original-command' are nil and `pre-command-hook' was not run.
This appears to be due to something(tm) setting `quit-flag' to t.
One such situation that I could semi-reliably reproduce is entering
some transient prefix and then immediately quitting with `C-g'. For
some (but not all) prefixes, that would often (but not always) bypass
`pre-command-hook', fail to invoke `transient-quit-one', and go
straight to the `post-command-hook' (but only the first time around
and not after invoking some other suffix first).
Here is such a failed invocation using (setq transient--debug t):
,----
| -- setup (cmd: notmuch-search-stash-transient, event: "c",
exit: nil)
| -- stack-zap (cmd: notmuch-search-stash-transient, event: "c",
exit: nil)
| -- init-transient (cmd: notmuch-search-stash-transient, event: "c",
exit: nil)
| push transient--transient-map
| push transient--redisplay-map
| -- post-command (cmd: notmuch-search-stash-transient, event: "c",
exit: nil)
| pop transient--redisplay-map
| push transient--redisplay-map
| Quit
| -- post-command (cmd: (nil nil notmuch-search-stash-transient),
event: "", exit: nil)
| Error during redisplay: (mode-line-default-help-echo #<window 3 on ...)
signaled (quit)
`----
It should look like this instead:
,----
| -- setup (cmd: notmuch-search-stash-transient, event: "c",
exit: nil)
| -- stack-zap (cmd: notmuch-search-stash-transient, event: "c",
exit: nil)
| -- init-transient (cmd: notmuch-search-stash-transient, event: "c",
exit: nil)
| push transient--transient-map
| push transient--redisplay-map
| -- post-command (cmd: notmuch-search-stash-transient, event: "c",
exit: nil)
| pop transient--redisplay-map
| push transient--redisplay-map
| -- pre-command (cmd: transient-quit-one, event: "C-g", exit: nil)
| -- pre-exit (cmd: transient-quit-one, event: "C-g", exit: t)
| pop transient--transient-map
| pop transient--redisplay-map
| -- post-command (cmd: transient-quit-one, event: "C-g", exit: t)
`----
For now at least deal with `this-command' being nil by taking extra
steps to allow quitting the transient. This might not always be the
right thing to do but in the one case that I could reproduce, it is.
Show message "Quit transient!" in the hope that this will make it into
bug-reports, if appropriate, while still being silent enough to not be
a bother when quitting was actually the right thing to do.
---
lisp/transient.el | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/lisp/transient.el b/lisp/transient.el
index e4026d8..50a8109 100644
--- a/lisp/transient.el
+++ b/lisp/transient.el
@@ -1973,6 +1973,11 @@ value. Otherwise return CHILDREN as is."
(defun transient--post-command ()
(transient--debug 'post-command)
+ (unless this-command
+ (transient--debug "-- force pre-exit from post-command")
+ (message "Quit transient!")
+ (transient--pre-exit)
+ (setq transient--exitp t))
(if transient--exitp
(progn
(unless (and (eq transient--exitp 'replace)
@@ -2048,7 +2053,8 @@ value. Otherwise return CHILDREN as is."
(if (symbolp arg)
(message "-- %-16s (cmd: %s, event: %S, exit: %s)"
arg
- (transient--suffix-symbol this-command)
+ (or (transient--suffix-symbol this-command)
+ (list this-command this-original-command last-command))
(key-description (this-command-keys-vector))
transient--exitp)
(apply #'message arg args))))