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

PATCH: LASTSEARCH new ZLE parameter



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
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 "";
 }


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