Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Proposal (with code) to fix breaking of history widgets on reset-prompt



> By the way, any chance you could take a look at
> https://www.zsh.org/mla/workers//2019/msg00204.html or ping someone who
> might?

On Sat, 2019-03-23 at 14:09 +0100, Roman Perepelitsa wrote:
> If your [up] key is bound to up-line-or-beginning-search, like most people
> have it, try the following experiment. Type sleep 6& and hit [enter]. Then
> quickly press [up] and wait for the job to finish. Once it finishes, press
> [up] again. Oh no! History doesn’t work. You are supposed to see the
> command you’d typed before sleep 6& but you are likely still seeing sleep 6&
> .
>
> Here’s what’s going on. When jobs finish, zle .reset-prompt is called to
> re-expand and display prompt. This sets LASTWIDGET to .reset-prompt. When
> you press [up] after that, up-line-or-beginning-search will behave as if
> you’ve typed sleep 6& in your prompt and then pressed [up]. That is, it’ll
> search for the previous command in your history that starts with sleep
> 6&.
>...
> One potential fix for this issue is to change reset-prompt widget so that
> it keeps LASTWIDGET unchanged. I’ve implemented this change in
> https://github.com/romkatv/zsh/tree/gentle-reset-prompt. Diff against
> upstream:
> https://github.com/zsh-users/zsh/compare/master...romkatv:gentle-reset-prompt
> .

Don't see any problem with doing that.  I suppose we really need a
list of widgets that should have this behaviour.

Ideally, this would be encapsulated as anything that happens not
as part of a user command --- in your example, that's the code executed
at the end of the job (I think as a result of setting "resetneeded" in
trahszle()) that calls last-prompt, rather than last-prompt itself.  But
that could be more major surgery, with largely the same effect since
it's that widget that's causing the problem.  So I'm perfectly happy to
get this fixed by the present means.

If you can produce this as a single change (with appropriate use of
rebase -i or whatever) we can apply it.  A patch to the list would be
fine, since other people get to see it, but I don't mind cherry-picking
/ rebasing from your repo if it's a single squashed change somewhere.

> The same branch also adds -W option to zle widget command. This option
> instructs zle to keep LASTWIDGET unchanged. I added it because it’s a
> natural extension of what I’ve done with .reset-prompt and because it has
> solved a long-standing issue I had in my zsh config.

The functionality certainly seems useful.

It might be easier simply to make LASTWIDGET read-write.  Then you could
do

  local LASTWIDGET=$LASTWIDGET

(you only need the assignment if you expect something down below to look
at it) and no new syntax is needed.  The save/restore just uses existing
mechanisms intended for doing that with variables, which seems more
efficient, too.

pws



Messages sorted by: Reverse Date, Date, Thread, Author