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

Re: PATCH: some minor fixes for zle_hist.c (3.1.4)



"Bart Schaefer" writes:
> I would have expected zmult to indicate how many previous occurrences
> of the first word on the current line to search through. However,
> historysearchbackward() ignores zmult entirely

I had meant to comment on this and ask why this was.  I think its
weird for zmult to be ignored like this, but it appears to be
consistently ignored throughout the various search functions (e.g.
history-beginning-search-* ignores it too, and history-incremental-
search-* uses it to determine if case is to be ignored in the
search).

If the code is not meant to work this way, the following patch will
make zmult now affect these commands:

	{vi-,}history-search-{for,back}ward
	history-beginning-search-{for,back}ward
	{vi-,}{up,down}-line-or-history
	vi-{rev-,}repeat-search

There's also one unrelated bug-fix in this patch in the function
historybeginningsearchforward():  the command would not go forward
to the last line in the history because of the "if" comparing
"histline" instead of the current value of "hl".  My previous
changes to history-search-forward had fixed this there (though I
don't think I mentioned it), but I hadn't noticed that it was also
broken elsewhere.

This patch assumes you've applied my prior changes for history-
search-{for,back}ward.

..wayne..

---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
--- old/zle_hist.c	Wed Jun 10 03:31:06 1998
+++ zle_hist.c	Fri Jun 12 10:06:27 1998
@@ -299,8 +299,15 @@
 historysearchbackward(void)
 {
     int hl = histline;
+    int n = zmult;
     char *s;
 
+    if (zmult < 0) {
+	zmult = -n;
+	historysearchforward();
+	zmult = n;
+	return;
+    }
     if (hl == curhist || hl != srch_hl || cs != srch_cs || mark != 0
      || memcmp(srch_str, line, histpos) != 0) {
 	zfree(srch_str, histpos);
@@ -317,8 +324,10 @@
 	    return;
 	}
 	if (metadiffer(s, srch_str, histpos) < 0 &&
-	    metadiffer(s, srch_str, ll))
-	    break;
+	    metadiffer(s, srch_str, ll)) {
+	    if (--n <= 0)
+		break;
+	}
     }
     zle_goto_hist(hl);
     srch_hl = hl;
@@ -330,8 +339,15 @@
 historysearchforward(void)
 {
     int hl = histline;
+    int n = zmult;
     char *s;
 
+    if (zmult < 0) {
+	zmult = -n;
+	historysearchbackward();
+	zmult = n;
+	return;
+    }
     if (hl == curhist || hl != srch_hl || cs != srch_cs || mark != 0
      || memcmp(srch_str, line, histpos) != 0) {
 	zfree(srch_str, histpos);
@@ -349,7 +365,8 @@
 	}
 	if (metadiffer(s, srch_str, histpos) < (hl == curhist) &&
 	    metadiffer(s, srch_str, ll))
-	    break;
+	    if (--n <= 0)
+		break;
     }
     zle_goto_hist(hl);
     srch_hl = hl;
@@ -1019,12 +1036,17 @@
 virepeatsearch(void)
 {
     int hl = histline, t0;
+    int n = zmult;
     char *s;
 
     if (!visrchstr) {
 	feep();
 	return;
     }
+    if (zmult < 0) {
+	n = -n;
+	visrchsense = -visrchsense;
+    }
     t0 = strlen(visrchstr);
     for (;;) {
 	hl += visrchsense;
@@ -1035,9 +1057,11 @@
 	if (!metadiffer(s, (char *) line, ll))
 	    continue;
 	if (*visrchstr == '^') {
-	    if (!strncmp(s, visrchstr + 1, t0 - 1))
-		break;
-	} else if (hstrnstr(s, 0, visrchstr, t0, 1, 1))
+	    if (strncmp(s, visrchstr + 1, t0 - 1) != 0)
+		continue;
+	} else if (!hstrnstr(s, 0, visrchstr, t0, 1, 1))
+	    continue;
+	if (--n <= 0)
 	    break;
     }
     zle_goto_hist(hl);
@@ -1062,8 +1086,15 @@
 {
     int cpos = cs;		/* save cursor position */
     int hl = histline;
+    int n = zmult;
     char *s;
 
+    if (zmult < 0) {
+	zmult = -n;
+	historybeginningsearchforward();
+	zmult = n;
+	return;
+    }
     for (;;) {
 	hl--;
 	if (!(s = zle_get_event(hl))) {
@@ -1072,7 +1103,8 @@
 	}
 	if (metadiffer(s, (char *)line, cs) < 0 &&
 	    metadiffer(s, (char *)line, ll))
-	    break;
+	    if (--n <= 0)
+		break;
     }
 
     zle_goto_hist(hl);
@@ -1088,17 +1120,25 @@
 {
     int cpos = cs;		/* save cursor position */
     int hl = histline;
+    int n = zmult;
     char *s;
 
+    if (zmult < 0) {
+	zmult = -n;
+	historybeginningsearchbackward();
+	zmult = n;
+	return;
+    }
     for (;;) {
 	hl++;
 	if (!(s = zle_get_event(hl))) {
 	    feep();
 	    return;
 	}
-	if (metadiffer(s, (char *)line, cs) < (histline == curhist) &&
+	if (metadiffer(s, (char *)line, cs) < (hl == curhist) &&
 	    metadiffer(s, (char *)line, ll))
-	    break;
+	    if (--n <= 0)
+		break;
     }
 
     zle_goto_hist(hl);
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---



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