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

PATCH: revamped history-search-{for,back}ward for 3.1.4



> It's my assertion that history-search-*ward are now broken and
> should be made to behave the way they used to (but not implemented
> the way they used to be implemented).

Here's one way to implement most of the old behavior without using a
special ZLE flag:

My idea is that most of the time the search gets initialized when we
first leave the "curhist" line, and then we continue to execute the
last search when we're moving around in the history.  This makes the
search more modal than before, since the 3.0.x code used to start a
new search if you did anything but another search.

The new code allows two exceptions to start a new search while up in
the history:  if you set the mark away from the start of the line, or
if the current line becomes too short for the current search to
succeed.

Let me know what you think of the idea.

Since this behavior relies on having a working spaceinline() function
(my code depends on the mark being set to the start of the line),
either apply that patch or just change line 87 of zle_utils.c to be:

    if (mark > cs)

instead of:

    if (mark >= cs)

I happened to find and fix a few other minor problems in zle_hist.c,
but I'll send that stuff separately from this.

..wayne..

---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
Index: Src/Zle/zle_hist.c
@@ -369,17 +369,20 @@
 	feep();
 }
 
+static int histpos;
+
 /**/
 void
 historysearchbackward(void)
 {
-    int histpos, histmpos, hl = histline;
+    int hl = histline;
     char *s;
 
-    for (histpos = histmpos = 0; histpos < ll && !iblank(line[histpos]);
-	histpos++, histmpos++)
-	if(imeta(line[histpos]))
-	    histmpos++;
+    if (histline == curhist || ll < histpos || mark != 0) {
+	for (histpos = 0; histpos < ll && !iblank(line[histpos]); histpos++) ;
+	if (histpos < ll)
+	    histpos++;
+    }
     for (;;) {
 	hl--;
 	if (!(s = zle_get_event(hl))) {
@@ -387,7 +390,6 @@
 	    return;
 	}
 	if (metadiffer(s, (char *) line, histpos) < 0 &&
-	    iblank(s[histmpos] == Meta ? s[histmpos+1]^32 : s[histmpos]) &&
 	    metadiffer(s, (char *) line, ll))
 	    break;
     }
@@ -398,22 +400,21 @@
 void
 historysearchforward(void)
 {
-    int histpos, histmpos, hl = histline;
+    int hl = histline;
     char *s;
 
-    for (histpos = histmpos = 0; histpos < ll && !iblank(line[histpos]);
-	histpos++, histmpos++)
-	if(imeta(line[histpos]))
-	    histmpos++;
+    if (histline == curhist || ll < histpos || mark != 0) {
+	for (histpos = 0; histpos < ll && !iblank(line[histpos]); histpos++) ;
+	if (histpos < ll)
+	    histpos++;
+    }
     for (;;) {
 	hl++;
 	if (!(s = zle_get_event(hl))) {
 	    feep();
 	    return;
 	}
-	if (metadiffer(s, (char *) line, histpos) < (histline == curhist) &&
-	    (!s[histmpos] ||
-	     iblank(s[histmpos] == Meta ? s[histmpos+1]^32 : s[histmpos])) &&
+	if (metadiffer(s, (char *) line, histpos) < (hl == curhist) &&
 	    metadiffer(s, (char *) line, ll))
 	    break;
     }
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---



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