From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14706 invoked from network); 4 Dec 2002 21:10:51 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 4 Dec 2002 21:10:51 -0000 Received: (qmail 23933 invoked by alias); 4 Dec 2002 21:07:17 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 17983 Received: (qmail 23573 invoked from network); 4 Dec 2002 21:06:43 -0000 Message-ID: <20021204210639.14869.qmail@web10407.mail.yahoo.com> Date: Wed, 4 Dec 2002 13:06:39 -0800 (PST) From: Felix Rosencrantz Subject: PATCH: LASTSEARCH new ZLE parameter To: zsh-workers@sunsite.dk MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="0-2071024256-1039035999=:14165" --0-2071024256-1039035999=:14165 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Here is a patch that adds a new LASTSEARCH zle parameter that provides read-only access to the last string used in a zle incremental search command. Before there was no way to access this value directly; and indirectly only via the vi-repeat-find widgets. This could be used to implement some sort of history for incremental search. I use incremental search a lot. I repeatedly use a set of search strings during a session to get previous commands. I made this into a ZLE parameter (e.g. HISTNO, LASTWIDGET) rather than a global parameter (e.g. widgets & keymaps), since LASTSEARCH was like ZLE parameters. Though it seemed to me that LASTWIDGET, along with other ZLE parameters could potentially be useful globally. If I don't hear complaints, I'll check this in tomorrow. -FR. __________________________________________________ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com --0-2071024256-1039035999=:14165 Content-Type: text/plain; name="LASTSEARCH_diff.txt" Content-Description: LASTSEARCH_diff.txt Content-Disposition: inline; filename="LASTSEARCH_diff.txt" Index: Doc/Zsh/zle.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/zle.yo,v retrieving revision 1.26 diff -u -r1.26 zle.yo --- Doc/Zsh/zle.yo 5 Aug 2002 12:33:28 -0000 1.26 +++ Doc/Zsh/zle.yo 3 Dec 2002 19:41:30 -0000 @@ -627,6 +627,11 @@ any extra are ignored. If fewer than eight elements are given, the remaining elements of the kill ring will be treated as undefined. ) + +vindex(LASTSEARCH) +item(tt(LASTSEARCH) (scalar))( +The last search string used by an interactive search ; read-only. +) vindex(LASTWIDGET) item(tt(LASTWIDGET) (scalar))( The name of the last widget that was executed; read-only. Index: Src/Zle/zle_hist.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_hist.c,v retrieving revision 1.8 diff -u -r1.8 zle_hist.c --- Src/Zle/zle_hist.c 24 Jun 2002 18:21:20 -0000 1.8 +++ Src/Zle/zle_hist.c 3 Dec 2002 19:41:35 -0000 @@ -41,6 +41,14 @@ /**/ int histline; +/* Previous search string use in an incremental search */ + +/**/ +char *previous_search = NULL; + +/**/ +int previous_search_len = 0; + #define ZLETEXT(X) ((X)->zle_text ? (X)->zle_text : (X)->text) /**/ @@ -757,8 +765,6 @@ int hl = histline, savekeys = -1, feep = 0; Thingy cmd; char *okeymap; - static char *previous_search = NULL; - static int previous_search_len = 0; Histent he; if (!(he = quietgethist(hl))) Index: Src/Zle/zle_params.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_params.c,v retrieving revision 1.6 diff -u -r1.6 zle_params.c --- Src/Zle/zle_params.c 4 Jul 2002 10:13:38 -0000 1.6 +++ Src/Zle/zle_params.c 3 Dec 2002 19:41:37 -0000 @@ -89,6 +89,8 @@ zleunsetfn, NULL }, { "POSTDISPLAY", PM_SCALAR, FN(set_postdisplay), FN(get_postdisplay), zleunsetfn, NULL }, + { "LASTSEARCH", PM_SCALAR | PM_READONLY, NULL, FN(get_lsearch), + zleunsetfn, NULL }, { NULL, 0, NULL, NULL, NULL, NULL } }; @@ -525,4 +527,14 @@ set_prepost(&predisplay, &predisplaylen, NULL); if (postdisplaylen) set_prepost(&postdisplay, &postdisplaylen, NULL); +} + +/**/ +static char * +get_lsearch(Param pm) +{ + if (previous_search_len) + return metafy(previous_search, previous_search_len, META_HEAPDUP); + else + return ""; } --0-2071024256-1039035999=:14165--