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

Re: PATCH: history improvements for 3.1.5-pws-17 and 3.0.6-pre-2



Peter Stephenson writes:
> after I've typed something in one shell, and hit return in another
> shell, I expect to be able just to use up-line-or-history to get to
> what's in the other shell

I'm torn on the issue, because sometimes I want to up-arrow through
the total history, and sometimes I just want to press ^P and run the
last command that I ran in this window, no exceptions.  If you'd
like to change the current behavior for the up/down commands, apply
this patch:

Index: Src/Zle/zle_hist.c
@@ -461,7 +461,7 @@
 int
 zle_goto_hist(int ev, int n)
 {
-    Histent he = movehistent(quietgethist(ev), n, HIST_FOREIGN);
+    Histent he = movehistent(quietgethist(ev), n, 0);
     if (!he)
 	return 0;
     zle_setline(he);

Note that this change doesn't affect ! references, so !! would
still run the last command that was run in the current shell.

I'd be interested in suggestions for how we can let the user choose
between local-history and full-history movement.  Perhaps a toggle
command?  Or a bindable prefix (so I can have ^P ignore shared
history, and Up-Arrow include it)?  I like this idea.

> I'd like to suggest that any zle reference to the history [...]
> causes the newly imported stuff to be visible.

I think that some zle commands, such as accept_and_infer_next_
history, should remain unaffected by foreign commands.

> for some reason due to the internal handling it's not enough to
> make what I just typed in shell 1 appear [...] It only happens
> after I've typed a new command in shell 2, which can't be a
> history command or a blank line

I think you've misinterpreted what's going on.  The current code
waits until the command _finishes_ before adding it to the history
file.  I did this because the extended_history format contains the
finish time of the command.  I also don't like this delay in adding
the command, though, so I think we add the command after it is typed,
and just live with the fact that all the finish times will be the
same as the start times when using incremental_append_history (which
is used by shared_history).

Here's the change to append the history in hend() rather than
hbegin():

Index: Src/hist.c
@@ -671,8 +671,6 @@
     if (hist_ring && !hist_ring->ftim)
 	hist_ring->ftim = time(NULL);
     if (interact && isset(SHINSTDIN) && !strin) {
-	if (isset(SHAREHISTORY) || isset(INCREMENTALAPPENDHISTORY))
-	    savehistfile(NULL, 1, HFILE_USE_OPTIONS | HFILE_FAST);
 	histactive = HA_ACTIVE;
 	attachtty(mypgrp);
 	if (!hist_ring)
@@ -962,6 +960,8 @@
     zfree(chwords, chwordlen*sizeof(short));
     chline = NULL;
     histactive = 0;
+    if (isset(SHAREHISTORY) || isset(INCREMENTALAPPENDHISTORY))
+	savehistfile(NULL, 1, HFILE_USE_OPTIONS | HFILE_FAST);
     return !(flag & HISTFLAG_NOEXEC || errflag);
 }
 
Thanks for the feedback -- I appreciate it!

..wayne..



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