zsh-workers
 help / color / mirror / code / Atom feed
From: Wayne Davison <wayne@tenor.clarinet.com>
To: hzoli@unicorn.sch.bme.hu
Cc: Zsh hacking and development <zsh-workers@math.gatech.edu>
Subject: Re: history-beginning-search fixes
Date: Mon, 13 May 1996 11:35:41 -0700	[thread overview]
Message-ID: <199605131835.LAA05254@tenor.clari.net> (raw)
In-Reply-To: hzoli's message of Sun, 12 May 1996 05:02:20 +0200. <199605120302.FAA05347@hzoli.ppp.cs.elte.hu>

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---



      reply	other threads:[~1996-05-13 18:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-05-12  3:02 Zoltan Hidvegi
1996-05-13 18:35 ` Wayne Davison [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199605131835.LAA05254@tenor.clari.net \
    --to=wayne@tenor.clarinet.com \
    --cc=hzoli@unicorn.sch.bme.hu \
    --cc=zsh-workers@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).