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

Re: history search bug{,fix}



Zefram writes:
> The solution is to ignore the previous command, and look at the
> actual first word anyway.  As this was the only thing the
> ZLE_HISTSEACH flag was used for, that can be removed.

Unfortunately this changes the way searching works in some cases.
For instance, if you type an 's' and then use history-search-backward
it will find a command that starts with the letter 's' (as before).
However, if you type the command again it searches for a command
that matches the current command instead of continuing to look for
commands that start with the letter 's'.  The only time the new
behavior matches the old is when the initial search is for a full
word (i.e. it was terminated by a space).

A better fix is to remove ZLE_HISTSEARCH from just history-beginning-
serach-{for,back}ward (which haven't used histpos for quite some time
now) and to fix {up,down}-line-or-search so that they indicate if
they did a search or not.  I chose to have them set histpos to -1
when it is not valid.  You'll have to back out your changes before
applying the appended patch.

..wayne..
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
Index: Src/Zle/zle_bindings.c
@@ -80,8 +80,8 @@
     {"forward-word", forwardword, ZLE_MOVEMENT},
     {"get-line", getline, 0},
     {"gosmacs-transpose-chars", gosmacstransposechars, 0},
-    {"history-beginning-search-backward", historybeginningsearchbackward, ZLE_HISTSEARCH},
-    {"history-beginning-search-forward", historybeginningsearchforward, ZLE_HISTSEARCH},
+    {"history-beginning-search-backward", historybeginningsearchbackward, 0},
+    {"history-beginning-search-forward", historybeginningsearchforward, 0},
     {"history-incremental-search-backward", historyincrementalsearchbackward, 0},
     {"history-incremental-search-forward", historyincrementalsearchforward, 0},
     {"history-search-backward", historysearchbackward, ZLE_HISTSEARCH},
Index: Src/Zle/zle_hist.c
@@ -153,6 +153,7 @@
     lastcol = cs - findbol();
 }
 
+static int histpos;
 
 /**/
 void
@@ -179,6 +180,7 @@
 	cs = ocs;
 	if (virangeflag || in_vared) {
 	    feep();
+	    histpos = -1;
 	    return;
 	}
 	historysearchbackward();
@@ -190,6 +192,7 @@
 	    if (cs && bindtab == altbindtab)
 		cs--;
 	}
+	histpos = -1;
     }
 }
 
@@ -218,6 +221,7 @@
 	cs = ocs;
 	if (virangeflag || in_vared) {
 	    feep();
+	    histpos = -1;
 	    return;
 	}
 	downhistory();
@@ -229,6 +233,7 @@
 	    if (cs > findbol() && bindtab == altbindtab)
 		cs--;
 	}
+	histpos = -1;
     }
 }
 
@@ -339,8 +344,6 @@
     setline(s);
 }
 
-static int histpos;
-
 /**/
 void
 historysearchbackward(void)
@@ -349,7 +352,7 @@
     char *s;
 
     remember_edits();
-    if (lastcmd & ZLE_HISTSEARCH)
+    if ((lastcmd & ZLE_HISTSEARCH) && histpos >= 0)
 	t0 = histpos;
     else {
 	for (t0 = 0; t0 < ll && !iblank(line[t0]); t0++);
@@ -379,7 +382,7 @@
     char *s;
 
     remember_edits();
-    if (lastcmd & ZLE_HISTSEARCH)
+    if ((lastcmd & ZLE_HISTSEARCH) && histpos >= 0)
 	t0 = histpos;
     else {
 	for (t0 = 0; t0 < ll && !iblank(line[t0]); t0++);
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---



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