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

Re: Zle history feature like that of many IRC clients?

On Dec 21,  6:33am, milk wrote:
} Bingo, thanks so much! The only change I have made is to comment out
} the "zle .send-break" in the fake-accept-line() so that the content of
} the line is not echoed back on hitting down.

Does that really do what you want?  Without the send-break, the line
added to the history by "print -S" is not available for recall until
after the next real accept-line (i.e., after you press enter).  That
is, without the send-break you should see that

 % test AAA<enter>
 % test BBB<down><up>

does not in fact recall "test BBB", rather it recalls "test AAA".

Also the operation of down-or-fake-accept-line depends on the action of
send-break to interrupt the following "zle .down-line-or-history", but
as it turns out that's a no-op when ((HISTNO == HISTCMD)) so there is
no visible change to the behavior, just a useless action.

You can replace "zle .send-break" with

    zle .accept-line

but then you'll still get an extra prompt.  There's no way to insert a
line into the recallable history without ending and restarting zle,
which means you must do one of send-break or accept-line (or one of
the variants thereof).

} There are issues with slightly more complex management though. "test 111"
} <down> "test 222" <up> <enter> then there's no more "test 222" in the
} buffer.

The only line that gets saved to the history is the one that was shown
at the prompt at the instant that you pressed enter.  Shell history is
not a text conversation, it's a series of events, and if you don't tell
the shell to execute the command, then it's not an event and is thrown
away.  "print -S" creates a phony event, but it's still only added to
the end of the history; you can't insert stuff in the middle, and you
can't remove stuff once it's been added (except by having it fall off
because the number of events has exceeded HISTSIZE).

You could write a function similar to down-or-fake-accept-line that is
called up-or-fake-accept-line and kicks in when you press <up>, but then
you'll always be adding at least two events to the history -- the phony
one when you <up>, followed by the real one when you <enter>.  So if you
did edit/<up>/<down>/edit/<up>/<down>/edit/<enter> you'd get *three*
events, one phony one at each <up> and a real one at <enter>.

Also, because of the need to end/restart zle to cause the history to
be permanently updated, there are a bunch of tricks necessary to get
the <up> to happen after the prompt is reprinted.

} Also "test 123" <down> "test 789" <up> alter "test 123" to "test
} 123456" <down> <enter> (on "test 789") <up> <up> gives "test 123" still.

Well, that's how zsh history works.  You can't alter the past (except
during a single editor "session", which remembers your changes until
you eventually hit enter, and then discards them).  You can only append
new events to the end.

You're going to be a lot happier if you get used to the event-based
semantics of shell history rather than attempt to coerce the shell
history into a text stream.

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