zsh-workers
 help / color / mirror / code / Atom feed
From: Wayne Davison <wayne@clari.net>
To: Zsh hacking and development <zsh-workers@math.gatech.edu>
Subject: Adding recall of previous search to isearch
Date: Wed, 15 May 1996 17:56:14 -0700	[thread overview]
Message-ID: <199605160056.RAA00758@tenor.clarinet.com> (raw)

Here's a patch that adds the recall of the last isearch if you press
fwd/bck-isearch with an empty isearch started (i.e. the usual emacs
behaviour).

It also fixes one pretty rare bug in the backing-up line refresh.  You
can see it if you start an isearch in one direction until it fails,
switch directions and find that string on some other line, and then hit
backspace.

..wayne..
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
Index: zle_hist.c
@@ -666,6 +666,8 @@
     int sbptr = 0, cmd, top_spot = 0, pos, sibuf = 80;
     int nomatch = 0, skip_line = 0, skip_pos = 0;
     int odir = dir, *obindtab = bindtab;
+    static char *previous_search = NULL;
+    static int previous_search_len = 0;
 
     strcpy(ibuf, ISEARCH_PROMPT);
     memcpy(ibuf + NORM_PROMPT_POS, (dir == 1) ? "fwd" : "bck", 3);
@@ -770,7 +772,7 @@
 		skip_pos = 1;
 	    }
 	    s = zle_get_event(histline);
-	    if (!sbptr || (sbptr == 1 && sbuf[0] == '^')) {
+	    if (nomatch || !sbptr || (sbptr == 1 && sbuf[0] == '^')) {
 		int i = cs;
 		setline(s);
 		cs = i;
@@ -813,6 +815,14 @@
 	    dir = odir;
 	    skip_pos = 1;
 	rpt:
+	    if (!sbptr && previous_search_len) {
+		if (previous_search_len > sibuf - FIRST_SEARCH_CHAR - 2) {
+		    ibuf = hrealloc(ibuf, sibuf, sibuf + previous_search_len);
+		    sbuf = ibuf + FIRST_SEARCH_CHAR;
+		    sibuf += previous_search_len;
+		}
+		memcpy(sbuf, previous_search, sbptr = previous_search_len);
+	    }
 	    memcpy(ibuf + NORM_PROMPT_POS, (dir == 1) ? "fwd" : "bck", 3);
 	    continue;
 	case z_sendstring:
@@ -839,6 +849,8 @@
 		    ungetkey(c);
 		else
 		    feep();
+		if (cmd == z_sendbreak)
+		    sbptr = 0;
 		goto brk;
 	    }
 	ins:
@@ -856,6 +868,11 @@
 	}
     }
   brk:
+    if (sbptr) {
+	zsfree(previous_search);
+	previous_search = zalloc(sbptr);
+	memcpy(previous_search, sbuf, previous_search_len = sbptr);
+    }
     statusline = NULL;
     bindtab = obindtab;
 }
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---



                 reply	other threads:[~1996-05-16  1:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=199605160056.RAA00758@tenor.clarinet.com \
    --to=wayne@clari.net \
    --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).