From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from euclid.skiles.gatech.edu (list@euclid.skiles.gatech.edu [130.207.146.50]) by melb.werple.net.au (8.7.5/8.7.3) with ESMTP id LAA16121 for ; Thu, 16 May 1996 11:22:11 +1000 (EST) Received: (from list@localhost) by euclid.skiles.gatech.edu (8.7.3/8.7.3) id UAA18112; Wed, 15 May 1996 20:57:39 -0400 (EDT) Resent-Date: Wed, 15 May 1996 20:57:39 -0400 (EDT) Message-Id: <199605160056.RAA00758@tenor.clarinet.com> To: Zsh hacking and development Subject: Adding recall of previous search to isearch Date: Wed, 15 May 1996 17:56:14 -0700 From: Wayne Davison Resent-Message-ID: <"bNfup3.0.tQ4.2sdcn"@euclid> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/1084 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu 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---