zsh-workers
 help / color / mirror / code / Atom feed
From: Wayne Davison <wayne@clari.net>
To: Zefram <zefram@dcs.warwick.ac.uk>
Cc: zsh-workers@math.gatech.edu (Z Shell workers mailing list)
Subject: Re: history search bug{,fix}
Date: Sat, 04 Jan 1997 15:34:40 -0800	[thread overview]
Message-ID: <199701042334.PAA19601@bebop.clari.net> (raw)
In-Reply-To: zefram's message of Sat, 04 Jan 1997 19:51:48 +0000. <3851.199701041951@stone.dcs.warwick.ac.uk>

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


  reply	other threads:[~1997-01-04 23:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-01-04 19:51 Zefram
1997-01-04 23:34 ` Wayne Davison [this message]
1997-01-04 23:47   ` Zefram

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=199701042334.PAA19601@bebop.clari.net \
    --to=wayne@clari.net \
    --cc=zefram@dcs.warwick.ac.uk \
    --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).