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

Re: Append cancelled commands to history



On Wed, Mar 24, 2010, Bart Schaefer wrote about "Re: Append cancelled commands to history":
> } So apparently, that interrupted multiline editing is *not* in the
> } history, and never was. So where is it? Why do I see it when I go "up"
> } for the first time? How do I prevent this?
> 
> Oh, of course.  Zsh *always* makes the immediately preceding accepted
> input available for scrollback in the line editor, even if it was not
> put into the history (because of HIST_IGNORE_ALL_DUPS, HIST_NO_STORE,
> or HIST_IGNORE_SPACE, etc.).
> 
> There is no way to prevent this.

Thanks. I think I understand better now what is happening. What I still find
a bit odd is the fact that this behavior (of saving the partially entered
command in a special place outside the history) is only applied to whole
lines of multiline commands, and not to interrupted single line commands,
or to the last partially-written line of a multiline command. I have two
reservations about this behavior:

1. Why this should apply only to multi-line commands

2. Why is that special (out of history) memory location for one last command
   is needed, or even desired. If it was added, I assume people wanted to
   scroll back to it. Now, what happens if you accidentally run some other
   command and only then wish to scroll back to that interrupted command?
   You can't. So what's wrong with just using the normal history to store it?

> You could, however, stop using the interrupt signal and its trap, and
> instead re-bind ctrl-C (or whatever your interrupt key is) to a zle
> function that, whenever $PREBUFER is non-empty, does a no-op equivalent
> of accept-line followed by a send-break.

Thanks! Maybe I'll indeed try that. I'm a bit reluctant, though, to go
through all this complexity just to avoid that extra partial history
(or not really history :-)) entry. Because, like I said, the simple 4-line

TRAPINT() {
        zle && [[ $HISTNO -eq $HISTCMD ]] && print -sr -- "$PREBUFFER$BUFFER"
        return $1
}

already saves the partial command (single or multi-line) correctly.

Thanks again for your explanations, and I'll try your trick later.

Nadav.


-- 
Nadav Har'El                        |       Friday, Mar 26 2010, 12 Nisan 5770
nyh@xxxxxxxxxxxxxxxxxxx             |-----------------------------------------
Phone +972-523-790466, ICQ 13349191 |Strike not only while the iron is hot,
http://nadav.harel.org.il           |make the iron hot by striking it.



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