From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14033 invoked by alias); 21 Dec 2011 09:08:11 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 16660 Received: (qmail 16937 invoked from network); 21 Dec 2011 09:08:08 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <111221010747.ZM12106@torch.brasslantern.com> Date: Wed, 21 Dec 2011 01:07:47 -0800 In-reply-to: Comments: In reply to milk "Re: Zle history feature like that of many IRC clients?" (Dec 21, 6:33am) References: <111219191758.ZM9817@torch.brasslantern.com> <111220082438.ZM10913@torch.brasslantern.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: Zle history feature like that of many IRC clients? MIME-version: 1.0 Content-type: text/plain; charset=us-ascii 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 % test BBB 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 BUFFER='' 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" } "test 222" 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 , but then you'll always be adding at least two events to the history -- the phony one when you , followed by the real one when you . So if you did edit///edit///edit/ you'd get *three* events, one phony one at each and a real one at . 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 to happen after the prompt is reprinted. } Also "test 123" "test 789" alter "test 123" to "test } 123456" (on "test 789") 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.