Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: history-beginning-search fixes
- X-seq: zsh-workers 1063
- From: Wayne Davison <wayne@xxxxxxxxxxxxxxxxxx>
- To: hzoli@xxxxxxxxxxxxxxxxxx
- Subject: Re: history-beginning-search fixes
- Date: Mon, 13 May 1996 11:35:41 -0700
- Cc: Zsh hacking and development <zsh-workers@xxxxxxxxxxxxxxx>
- In-reply-to: hzoli's message of Sun, 12 May 1996 05:02:20 +0200. <199605120302.FAA05347@xxxxxxxxxxxxxxxxxxxx>
Zoltan Hidvegi writes:
> history-beginning-search-* stopped working after Zefram latest patch if the
> cursor was at the end of the line. Here is the fix.
There's a problem with these functions (and the history-search-* ones)
that they are comparing the unmetafied line against metafied history
lines.
The folowing patch fixes that and switches the functions back to using
str[n]cmp() (since they are comparing metafied lines).
I also optimized the second strcmp() call to skip the N characters that
we just compared and found to be equal.
Finally, I changed the history-search-forward function to have a similar
fix that Zephram added to history-beginning-search-forward that allows it
to find the last line in the history. It's not really the correct fix in
either case (we should probably add a global to store the starting line
of a sequence of ZLE_HISTSEARCH commands), but it handles most of the
search cases people will run into.
..wayne..
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
Index: zle_hist.c
@@ -373,17 +373,18 @@
historysearchbackward(void)
{
int t0, ohistline = histline;
- char *s;
+ char *s, *mline;
remember_edits();
+ mline = qgetevent(histline);
if (lastcmd & ZLE_HISTSEARCH)
t0 = histpos;
else {
for (t0 = 0; t0 < ll && !iblank(line[t0]); t0++);
if (t0 < ll)
t0++;
+ t0 = histpos = metalen(mline, t0);
}
- histpos = t0;
for (;;) {
histline--;
if (!(s = qgetevent(histline))) {
@@ -391,8 +392,8 @@
histline = ohistline;
return;
}
- if (strlen(UTOSCP(s)) > t0
- && !strncmp(s, UTOSCP(line), t0) && strcmp(s, UTOSCP(line)))
+ if (strlen(s) > t0 &&
+ !strncmp(s, mline, t0) && strcmp(s + t0, mline + t0))
break;
}
setline(s);
@@ -403,17 +404,18 @@
historysearchforward(void)
{
int t0, ohistline = histline;
- char *s;
+ char *s, *mline;
remember_edits();
+ mline = qgetevent(histline);
if (lastcmd & ZLE_HISTSEARCH)
t0 = histpos;
else {
for (t0 = 0; t0 < ll && !iblank(line[t0]); t0++);
if (t0 < ll)
t0++;
+ t0 = histpos = metalen(mline, t0);
}
- histpos = t0;
for (;;) {
histline++;
if (!(s = qgetevent(histline))) {
@@ -421,8 +423,8 @@
histline = ohistline;
return;
}
- if (strlen(UTOSCP(s)) > t0
- && !strncmp(s, UTOSCP(line), t0) && strcmp(s, UTOSCP(line)))
+ if ((histline == curhist || strlen(s) > t0) &&
+ !strncmp(s, mline, t0) && strcmp(s + t0, mline + t0))
break;
}
setline(s);
@@ -1103,11 +1105,13 @@
void
historybeginningsearchbackward(void)
{
- int cpos = cs; /* save cursor position */
+ int pos, cpos = cs; /* save cursor position */
int ohistline = histline;
- char *s;
+ char *s, *mline;
remember_edits();
+ mline = qgetevent(histline);
+ pos = metalen(mline, cs);
for (;;) {
histline--;
if (!(s = qgetevent(histline))) {
@@ -1115,9 +1119,8 @@
histline = ohistline;
return;
}
- if (strlen((char *)s) > cs &&
- !memcmp(s, (char *)line, cs) &&
- (strlen((char *)s) > ll || memcmp(s, (char *)line, ll)))
+ if (strlen(s) > pos &&
+ !strncmp(s, mline, pos) && strcmp(s + pos, mline + pos))
break;
}
@@ -1132,11 +1135,13 @@
void
historybeginningsearchforward(void)
{
- int cpos = cs; /* save cursor position */
+ int pos, cpos = cs; /* save cursor position */
int ohistline = histline;
- char *s;
+ char *s, *mline;
remember_edits();
+ mline = qgetevent(histline);
+ pos = metalen(mline, cs);
for (;;) {
histline++;
if (!(s = qgetevent(histline))) {
@@ -1144,9 +1149,8 @@
histline = ohistline;
return;
}
- if ((histline == curhist || strlen((char *)s) > cs) &&
- !memcmp(s, (char *)line, cs) &&
- (strlen((char *)s) > ll || memcmp(s, (char *)line, ll)))
+ if ((histline == curhist || strlen(s) > pos) &&
+ !strncmp(s, mline, pos) && strcmp(s + pos, mline + pos))
break;
}
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
Messages sorted by:
Reverse Date,
Date,
Thread,
Author