zsh-workers
 help / color / mirror / code / Atom feed
* history search bug{,fix}
@ 1997-01-04 19:51 Zefram
  1997-01-04 23:34 ` Wayne Davison
  0 siblings, 1 reply; 3+ messages in thread
From: Zefram @ 1997-01-04 19:51 UTC (permalink / raw)
  To: Z Shell workers mailing list

-----BEGIN PGP SIGNED MESSAGE-----

There is a bug is history-search-{for,back}ward.  If the previous
command executed was one of history-beginning-serach-{for,back}ward or
{up,down}-line-or-search, it assumes that it already knows the extent of
the word it is supposed to search for, which it doesn't.  The solution is
to ignore the previous command, and look at the actual first word anyway.
As this was the only thing the ZLE_HISTSEACH flag was used for, that
can be removed.

 -zefram


      *** Src/Zle/zle.h	1997/01/03 07:23:25	1.8
      --- Src/Zle/zle.h	1997/01/04 08:39:45
      ***************
      *** 62,68 ****
        #define ZLE_LINEMOVE	(1<<4)
        #define ZLE_ARG		(1<<5)
        #define ZLE_KILL	(1<<6)
      - #define ZLE_HISTSEARCH	(1<<7)
        #define ZLE_NEGARG	(1<<8)
        #define ZLE_INSERT	(1<<9)
        #define ZLE_DELETE	(1<<10)
      --- 62,67 ----
      *** Src/Zle/zle_bindings.c	1997/01/03 07:23:25	1.4
      --- Src/Zle/zle_bindings.c	1997/01/04 08:43:38
      ***************
      *** 72,78 ****
            C("down-case-word", downcaseword, 0)
            C("down-history", downhistory, 0)
            C("down-line-or-history", downlineorhistory, ZLE_MOVEMENT | ZLE_LINEMOVE)
      !     C("down-line-or-search", downlineorsearch, ZLE_MOVEMENT | ZLE_LINEMOVE | ZLE_HISTSEARCH)
            C("emacs-backward-word", emacsbackwardword, ZLE_MOVEMENT)
            C("emacs-forward-word", emacsforwardword, ZLE_MOVEMENT)
            C("end-of-buffer-or-history", endofbufferorhistory, ZLE_MOVEMENT)
      --- 72,78 ----
            C("down-case-word", downcaseword, 0)
            C("down-history", downhistory, 0)
            C("down-line-or-history", downlineorhistory, ZLE_MOVEMENT | ZLE_LINEMOVE)
      !     C("down-line-or-search", downlineorsearch, ZLE_MOVEMENT | ZLE_LINEMOVE)
            C("emacs-backward-word", emacsbackwardword, ZLE_MOVEMENT)
            C("emacs-forward-word", emacsforwardword, ZLE_MOVEMENT)
            C("end-of-buffer-or-history", endofbufferorhistory, ZLE_MOVEMENT)
      ***************
      *** 91,102 ****
            C("forward-word", forwardword, ZLE_MOVEMENT)
            C("get-line", getline, 0)
            C("gosmacs-transpose-chars", gosmacstransposechars, 0)
      !     C("history-beginning-search-backward", historybeginningsearchbackward, ZLE_HISTSEARCH)
      !     C("history-beginning-search-forward", historybeginningsearchforward, ZLE_HISTSEARCH)
            C("history-incremental-search-backward", historyincrementalsearchbackward, 0)
            C("history-incremental-search-forward", historyincrementalsearchforward, 0)
      !     C("history-search-backward", historysearchbackward, ZLE_HISTSEARCH)
      !     C("history-search-forward", historysearchforward, ZLE_HISTSEARCH)
            C("infer-next-history", infernexthistory, 0)
            C("insert-last-word", insertlastword, ZLE_INSERT)
            C("kill-buffer", killbuffer, ZLE_KILL)
      --- 91,102 ----
            C("forward-word", forwardword, ZLE_MOVEMENT)
            C("get-line", getline, 0)
            C("gosmacs-transpose-chars", gosmacstransposechars, 0)
      !     C("history-beginning-search-backward", historybeginningsearchbackward, 0)
      !     C("history-beginning-search-forward", historybeginningsearchforward, 0)
            C("history-incremental-search-backward", historyincrementalsearchbackward, 0)
            C("history-incremental-search-forward", historyincrementalsearchforward, 0)
      !     C("history-search-backward", historysearchbackward, 0)
      !     C("history-search-forward", historysearchforward, 0)
            C("infer-next-history", infernexthistory, 0)
            C("insert-last-word", insertlastword, ZLE_INSERT)
            C("kill-buffer", killbuffer, ZLE_KILL)
      ***************
      *** 134,140 ****
            C("up-case-word", upcaseword, 0)
            C("up-history", uphistory, 0)
            C("up-line-or-history", uplineorhistory, ZLE_LINEMOVE | ZLE_MOVEMENT)
      !     C("up-line-or-search", uplineorsearch, ZLE_MOVEMENT | ZLE_LINEMOVE | ZLE_HISTSEARCH)
            C("vi-add-eol", viaddeol, 0)
            C("vi-add-next", viaddnext, 0)
            C("vi-backward-blank-word", vibackwardblankword, ZLE_MOVEMENT)
      --- 134,140 ----
            C("up-case-word", upcaseword, 0)
            C("up-history", uphistory, 0)
            C("up-line-or-history", uplineorhistory, ZLE_LINEMOVE | ZLE_MOVEMENT)
      !     C("up-line-or-search", uplineorsearch, ZLE_MOVEMENT | ZLE_LINEMOVE)
            C("vi-add-eol", viaddeol, 0)
            C("vi-add-next", viaddnext, 0)
            C("vi-backward-blank-word", vibackwardblankword, ZLE_MOVEMENT)
      *** Src/Zle/zle_hist.c	1997/01/03 07:23:26	1.4
      --- Src/Zle/zle_hist.c	1997/01/04 09:03:18
      ***************
      *** 340,363 ****
            setline(s);
        }
        
      - static int histpos;
      - 
        /**/
        void
        historysearchbackward(void)
        {
      !     int t0, ohistline = histline;
            char *s;
        
            remember_edits();
      !     if (lastcmd & ZLE_HISTSEARCH)
      ! 	t0 = histpos;
      !     else {
      ! 	for (t0 = 0; t0 < ll && !iblank(line[t0]); t0++);
      ! 	if (t0 < ll)
      ! 	    t0++;
      ! 	histpos = t0;
      !     }
            for (;;) {
        	histline--;
        	if (!(s = zle_get_event(histline))) {
      --- 340,356 ----
            setline(s);
        }
        
        /**/
        void
        historysearchbackward(void)
        {
      !     int histpos, ohistline = histline;
            char *s;
        
            remember_edits();
      !     for (histpos = 0; histpos < ll && !iblank(line[histpos]); histpos++);
      !     if (histpos < ll)
      ! 	histpos++;
            for (;;) {
        	histline--;
        	if (!(s = zle_get_event(histline))) {
      ***************
      *** 365,371 ****
        	    histline = ohistline;
        	    return;
        	}
      ! 	if (metadiffer(s, (char *) line, t0) < 0 &&
        	    metadiffer(s, (char *) line, ll))
        	    break;
            }
      --- 358,364 ----
        	    histline = ohistline;
        	    return;
        	}
      ! 	if (metadiffer(s, (char *) line, histpos) < 0 &&
        	    metadiffer(s, (char *) line, ll))
        	    break;
            }
      ***************
      *** 376,393 ****
        void
        historysearchforward(void)
        {
      !     int t0, ohistline = histline;
            char *s;
        
            remember_edits();
      !     if (lastcmd & ZLE_HISTSEARCH)
      ! 	t0 = histpos;
      !     else {
      ! 	for (t0 = 0; t0 < ll && !iblank(line[t0]); t0++);
      ! 	if (t0 < ll)
      ! 	    t0++;
      ! 	histpos = t0;
      !     }
            for (;;) {
        	histline++;
        	if (!(s = zle_get_event(histline))) {
      --- 369,381 ----
        void
        historysearchforward(void)
        {
      !     int histpos, ohistline = histline;
            char *s;
        
            remember_edits();
      !     for (histpos = 0; histpos < ll && !iblank(line[histpos]); histpos++);
      !     if (histpos < ll)
      ! 	histpos++;
            for (;;) {
        	histline++;
        	if (!(s = zle_get_event(histline))) {
      ***************
      *** 395,401 ****
        	    histline = ohistline;
        	    return;
        	}
      ! 	if (metadiffer(s, (char *) line, t0) < (histline == curhist) &&
        	    metadiffer(s, (char *) line, ll))
        	    break;
            }
      --- 383,389 ----
        	    histline = ohistline;
        	    return;
        	}
      ! 	if (metadiffer(s, (char *) line, histpos) < (histline == curhist) &&
        	    metadiffer(s, (char *) line, ll))
        	    break;
            }

-----BEGIN PGP SIGNATURE-----
Version: 2.6.2

iQCVAwUBMs4fCHD/+HJTpU/hAQH3UQP+JHvA3F5SmV16Y4wWqpv1WBgRsAf3G2qf
x2nOC9+uqEtE8iMtSisuV4AZH08UjCp01NqGVtE5iwS+6CW7l6/yxA23FyN/VrBv
3E1xs0i9yI+kLqPL9e631RhskAI40rEyZsXcVQEeFirccz59FsPhN46SBdHAbwEY
rYuo/ngsREo=
=tFCb
-----END PGP SIGNATURE-----


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: history search bug{,fix}
  1997-01-04 19:51 history search bug{,fix} Zefram
@ 1997-01-04 23:34 ` Wayne Davison
  1997-01-04 23:47   ` Zefram
  0 siblings, 1 reply; 3+ messages in thread
From: Wayne Davison @ 1997-01-04 23:34 UTC (permalink / raw)
  To: Zefram; +Cc: Z Shell workers mailing list

Zefram writes:
> The solution is to ignore the previous command, and look at the
> actual first word anyway.  As this was the only thing the
> ZLE_HISTSEACH flag was used for, that can be removed.

Unfortunately this changes the way searching works in some cases.
For instance, if you type an 's' and then use history-search-backward
it will find a command that starts with the letter 's' (as before).
However, if you type the command again it searches for a command
that matches the current command instead of continuing to look for
commands that start with the letter 's'.  The only time the new
behavior matches the old is when the initial search is for a full
word (i.e. it was terminated by a space).

A better fix is to remove ZLE_HISTSEARCH from just history-beginning-
serach-{for,back}ward (which haven't used histpos for quite some time
now) and to fix {up,down}-line-or-search so that they indicate if
they did a search or not.  I chose to have them set histpos to -1
when it is not valid.  You'll have to back out your changes before
applying the appended patch.

..wayne..
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
Index: Src/Zle/zle_bindings.c
@@ -80,8 +80,8 @@
     {"forward-word", forwardword, ZLE_MOVEMENT},
     {"get-line", getline, 0},
     {"gosmacs-transpose-chars", gosmacstransposechars, 0},
-    {"history-beginning-search-backward", historybeginningsearchbackward, ZLE_HISTSEARCH},
-    {"history-beginning-search-forward", historybeginningsearchforward, ZLE_HISTSEARCH},
+    {"history-beginning-search-backward", historybeginningsearchbackward, 0},
+    {"history-beginning-search-forward", historybeginningsearchforward, 0},
     {"history-incremental-search-backward", historyincrementalsearchbackward, 0},
     {"history-incremental-search-forward", historyincrementalsearchforward, 0},
     {"history-search-backward", historysearchbackward, ZLE_HISTSEARCH},
Index: Src/Zle/zle_hist.c
@@ -153,6 +153,7 @@
     lastcol = cs - findbol();
 }
 
+static int histpos;
 
 /**/
 void
@@ -179,6 +180,7 @@
 	cs = ocs;
 	if (virangeflag || in_vared) {
 	    feep();
+	    histpos = -1;
 	    return;
 	}
 	historysearchbackward();
@@ -190,6 +192,7 @@
 	    if (cs && bindtab == altbindtab)
 		cs--;
 	}
+	histpos = -1;
     }
 }
 
@@ -218,6 +221,7 @@
 	cs = ocs;
 	if (virangeflag || in_vared) {
 	    feep();
+	    histpos = -1;
 	    return;
 	}
 	downhistory();
@@ -229,6 +233,7 @@
 	    if (cs > findbol() && bindtab == altbindtab)
 		cs--;
 	}
+	histpos = -1;
     }
 }
 
@@ -339,8 +344,6 @@
     setline(s);
 }
 
-static int histpos;
-
 /**/
 void
 historysearchbackward(void)
@@ -349,7 +352,7 @@
     char *s;
 
     remember_edits();
-    if (lastcmd & ZLE_HISTSEARCH)
+    if ((lastcmd & ZLE_HISTSEARCH) && histpos >= 0)
 	t0 = histpos;
     else {
 	for (t0 = 0; t0 < ll && !iblank(line[t0]); t0++);
@@ -379,7 +382,7 @@
     char *s;
 
     remember_edits();
-    if (lastcmd & ZLE_HISTSEARCH)
+    if ((lastcmd & ZLE_HISTSEARCH) && histpos >= 0)
 	t0 = histpos;
     else {
 	for (t0 = 0; t0 < ll && !iblank(line[t0]); t0++);
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: history search bug{,fix}
  1997-01-04 23:34 ` Wayne Davison
@ 1997-01-04 23:47   ` Zefram
  0 siblings, 0 replies; 3+ messages in thread
From: Zefram @ 1997-01-04 23:47 UTC (permalink / raw)
  To: Wayne Davison; +Cc: zefram, zsh-workers

Wayne Davison wrote:
>Unfortunately this changes the way searching works in some cases.
>For instance, if you type an 's' and then use history-search-backward
>it will find a command that starts with the letter 's' (as before).
>However, if you type the command again it searches for a command
>that matches the current command instead of continuing to look for
>commands that start with the letter 's'.  The only time the new
>behavior matches the old is when the initial search is for a full
>word (i.e. it was terminated by a space).

That's odd.  It looks like history-search-{for,back}ward only behaved
as documented if the word ended in a space, otherwise acting like
history-beginning-search-{for,back}ward.  Wouldn't it be better to make
them actually behave as documented -- only look for complete words
matching the current one?

-zefram


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1997-01-04 23:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-01-04 19:51 history search bug{,fix} Zefram
1997-01-04 23:34 ` Wayne Davison
1997-01-04 23:47   ` Zefram

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