Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: 3.1.5 - (Wayne) History search more like 3.0.5
- X-seq: zsh-workers 4476
- From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxxx
- Subject: PATCH: 3.1.5 - (Wayne) History search more like 3.0.5
- Date: Sat, 31 Oct 1998 02:17:44 -0800
Wayne's patch from zsh-workers/4078, updated for 3.1.5.
I'm pretty sure Zefram omitted this one on purpose, but I like it. It's
so much more intuitive this way.
Index: Src/Zle/zle_hist.c
===================================================================
diff -u -r1.1.1.2 -r1.3
--- zle_hist.c 1998/10/30 15:57:13 1.1.1.2
+++ zle_hist.c 1998/06/13 04:24:15 1.3
@@ -291,73 +291,86 @@
feep();
}
+static int histpos, srch_hl, srch_cs = -1;
+static char *srch_str;
+
/**/
void
historysearchbackward(void)
{
- int histpos, histmpos, hl = histline;
+ int hl = histline;
int n = zmult;
char *s;
- if (!n)
- return;
- if (n < 0) {
+ if (zmult < 0) {
zmult = -n;
historysearchforward();
zmult = n;
return;
}
- for (histpos = histmpos = 0; histpos < ll && !iblank(line[histpos]);
- histpos++, histmpos++)
- if(imeta(line[histpos]))
- histmpos++;
+ if (hl == curhist || hl != srch_hl || cs != srch_cs || mark != 0
+ || memcmp(srch_str, line, histpos) != 0) {
+ zfree(srch_str, histpos);
+ for (histpos = 0; histpos < ll && !iblank(line[histpos]); histpos++) ;
+ if (histpos < ll)
+ histpos++;
+ srch_str = zalloc(histpos);
+ memcpy(srch_str, line, histpos);
+ }
for (;;) {
hl--;
if (!(s = zle_get_event(hl))) {
feep();
return;
}
- if (metadiffer(s, (char *) line, histpos) < 0 &&
- iblank(s[histmpos] == Meta ? s[histmpos+1]^32 : s[histmpos]) &&
- metadiffer(s, (char *) line, ll) && !--n)
- break;
+ if (metadiffer(s, srch_str, histpos) < 0 &&
+ metadiffer(s, srch_str, ll)) {
+ if (--n <= 0)
+ break;
+ }
}
zle_goto_hist(hl);
+ srch_hl = hl;
+ srch_cs = cs;
}
/**/
void
historysearchforward(void)
{
- int histpos, histmpos, hl = histline;
+ int hl = histline;
int n = zmult;
char *s;
- if (!n)
- return;
- if (n < 0) {
+ if (zmult < 0) {
zmult = -n;
historysearchbackward();
zmult = n;
return;
}
- for (histpos = histmpos = 0; histpos < ll && !iblank(line[histpos]);
- histpos++, histmpos++)
- if(imeta(line[histpos]))
- histmpos++;
+ if (hl == curhist || hl != srch_hl || cs != srch_cs || mark != 0
+ || memcmp(srch_str, line, histpos) != 0) {
+ zfree(srch_str, histpos);
+ for (histpos = 0; histpos < ll && !iblank(line[histpos]); histpos++) ;
+ if (histpos < ll)
+ histpos++;
+ srch_str = zalloc(histpos);
+ memcpy(srch_str, line, 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])) &&
- metadiffer(s, (char *) line, ll) && !--n)
- break;
+ if (metadiffer(s, srch_str, histpos) < (hl == curhist) &&
+ metadiffer(s, srch_str, ll))
+ if (--n <= 0)
+ break;
}
zle_goto_hist(hl);
+ srch_hl = hl;
+ srch_cs = cs;
}
/**/
@@ -1030,9 +1043,7 @@
feep();
return;
}
- if (!n)
- return;
- if (n < 0) {
+ if (zmult < 0) {
n = -n;
visrchsense = -visrchsense;
}
@@ -1078,9 +1089,7 @@
int n = zmult;
char *s;
- if (!n)
- return;
- if (n < 0) {
+ if (zmult < 0) {
zmult = -n;
historybeginningsearchforward();
zmult = n;
@@ -1114,9 +1123,7 @@
int n = zmult;
char *s;
- if (!n)
- return;
- if (n < 0) {
+ if (zmult < 0) {
zmult = -n;
historybeginningsearchbackward();
zmult = n;
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Messages sorted by:
Reverse Date,
Date,
Thread,
Author