Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Adding recall of previous search to isearch



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




Messages sorted by: Reverse Date, Date, Thread, Author