zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: Zle history feature like that of many IRC clients?
Date: Wed, 21 Dec 2011 01:07:47 -0800	[thread overview]
Message-ID: <111221010747.ZM12106@torch.brasslantern.com> (raw)
In-Reply-To: <CALu3U48TsPHcT97-GXJg5vC0jwziT5iRcNbCxUDX-acMrVxyuw@mail.gmail.com>

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

    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"
} <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.


      reply	other threads:[~2011-12-21  9:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-19 22:39 milk
2011-12-20  3:17 ` Bart Schaefer
2011-12-20 16:24   ` Bart Schaefer
2011-12-21  6:33     ` milk
2011-12-21  9:07       ` Bart Schaefer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=111221010747.ZM12106@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).