* history-beginning-search fixes
@ 1996-05-12 3:02 Zoltan Hidvegi
1996-05-13 18:35 ` Wayne Davison
0 siblings, 1 reply; 2+ messages in thread
From: Zoltan Hidvegi @ 1996-05-12 3:02 UTC (permalink / raw)
To: Zsh hacking and development
[-- Attachment #1: Type: application/pgp, Size: 1503 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: history-beginning-search fixes
1996-05-12 3:02 history-beginning-search fixes Zoltan Hidvegi
@ 1996-05-13 18:35 ` Wayne Davison
0 siblings, 0 replies; 2+ messages in thread
From: Wayne Davison @ 1996-05-13 18:35 UTC (permalink / raw)
To: hzoli; +Cc: Zsh hacking and development
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---
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1996-05-13 18:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-05-12 3:02 history-beginning-search fixes Zoltan Hidvegi
1996-05-13 18:35 ` Wayne Davison
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).