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

Re: Append cancelled commands to history



On Mar 15,  6:42pm, Nadav Har'El wrote:
>
> Does anyone know why zsh saves interrupted partial multiline commands,
> but without their last line?

Every time a new prompt is printed -- even if it's the PS2 prompt rather
than the top-level prompt -- is a new "instance" of the line editor.
Looked at another way, as soon as you hit "enter" (accept-line) the
current $BUFFER is stored in the "pending history".  You can't yet
scroll back to it from the following PS2 prompt, but it has been
remembered as something you input and might want to revisit later.

Conversely, if you hit the interrupt key or ctrl-g (send-break), the
current buffer has not been stored and ZLE presumes that interruption
means you DON'T want to revisit this later.  You can subvert the latter
behavior, but because a new ZLE instance started at accept-line, it's
already too late to subvert the former.

> Can this be avoided? And what was the rationale to save the beginning
> of a multiline command and not everything - or not at all for a single
> line command?

There's a reason the widget is called "accept-line".  If the line has
been accepted (even if it doesn't form a complete command yet), it's
something you want; if you "send-break" or do an interrupt, it's not
accepted and therefore something you don't want.

> I thought this would be simple - just replace the print line with
> 	print -s -r -- "$PREBUFFER$BUFFER"

Hmm.  When I use TRAPINT, $PREBUFFER is always empty.

torch% print $ZSH_VERSION $ZSH_PATCHLEVEL 
4.3.10-dev-1 1.4940



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