summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndrew Main <zefram@users.sourceforge.net>2001-09-03 01:39:19 +0000
committerAndrew Main <zefram@users.sourceforge.net>2001-09-03 01:39:19 +0000
commitb73d71105eaca6ae001a3e836ab08406ef188789 (patch)
tree691753f67199df3b7c9cfdaec6b5dd88cb14bf18
parente8f8c3abee5763d58cfcb8eb89e50ec40dbcfde2 (diff)
downloadzsh-b73d71105eaca6ae001a3e836ab08406ef188789.tar.gz
zsh-b73d71105eaca6ae001a3e836ab08406ef188789.tar.xz
zsh-b73d71105eaca6ae001a3e836ab08406ef188789.zip
15734: zle -K option to select a keymap, and zle KEYMAP parameter to
examine the current selection.
-rw-r--r--ChangeLog7
-rw-r--r--Doc/Zsh/zle.yo13
-rw-r--r--Src/Zle/zle_hist.c6
-rw-r--r--Src/Zle/zle_keymap.c5
-rw-r--r--Src/Zle/zle_main.c2
-rw-r--r--Src/Zle/zle_misc.c4
-rw-r--r--Src/Zle/zle_params.c9
-rw-r--r--Src/Zle/zle_thingy.c12
8 files changed, 53 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 95b1d59da..5ba72df31 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2001-09-03  Andrew Main (Zefram)  <zefram@zsh.org>
+
+	* 15734: Doc/Zsh/zle.yo, Src/Zle/zle_hist.c, Src/Zle/zle_keymap.c,
+	Src/Zle/zle_main.c, Src/Zle/zle_misc.c, Src/Zle/zle_params.c,
+	Src/Zle/zle_thingy.c: zle -K option to select a keymap, and zle
+	KEYMAP parameter to examine the current selection.
+
 2001-08-28  Peter Stephenson  <pws@pwstephenson.fsnet.co.uk>
 
 	* 15722: Completion/Unix/Command/_sh: handle zsh options.
diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo
index d39c610f4..4e5a4dc1d 100644
--- a/Doc/Zsh/zle.yo
+++ b/Doc/Zsh/zle.yo
@@ -305,6 +305,7 @@ xitem(tt(zle) tt(-C) var(widget) var(completion-widget) var(function))
 xitem(tt(zle) tt(-R) [ tt(-c) ] [ var(display-string) ] [ var(string) ... ])
 xitem(tt(zle) tt(-M) var(string))
 xitem(tt(zle) tt(-U) var(string))
+xitem(tt(zle) tt(-K) var(keymap))
 xitem(tt(zle) tt(-I))
 xitem(tt(zle) var(widget) tt([ -n) var(num) tt(]) tt([ -N ]) var(args) ...)
 item(tt(zle))(
@@ -394,6 +395,14 @@ the last string pushed onto the stack will be processed first.  However,
 the characters in each var(string) will be processed in the order in which
 they appear in the string.
 )
+item(tt(-K) var(keymap))(
+Selects the keymap named var(keymap).  An error message will be displayed if
+there is no such keymap.
+
+This keymap selection affects the interpretation of following keystrokes
+within this invocation of ZLE.  Any following invocation (e.g., the next
+command line) will start as usual with the `tt(main)' keymap selected.
+)
 item(tt(-I))(
 Unusually, this option is only useful em(outside) ordinary widget functions.
 It invalidates the current zle display in preparation for output; usually
@@ -519,6 +528,10 @@ vindex(HISTNO)
 item(tt(HISTNO) (integer))(
 The current history number.
 )
+vindex(KEYMAP)
+item(tt(KEYMAP) (scalar))(
+The name of the currently selected keymap.
+)
 vindex(KEYS)
 item(tt(KEYS) (scalar))(
 The keys typed to invoke this widget, as a literal string.
diff --git a/Src/Zle/zle_hist.c b/Src/Zle/zle_hist.c
index 9719e5418..d7223316c 100644
--- a/Src/Zle/zle_hist.c
+++ b/Src/Zle/zle_hist.c
@@ -660,7 +660,7 @@ doisearch(char **args, int dir)
     int odir = dir, sens = zmult == 1 ? 3 : 1;
     int hl = histline, savekeys = -1, feep = 0;
     Thingy cmd;
-    char *okeymap = curkeymapname;
+    char *okeymap = ztrdup(curkeymapname);
     static char *previous_search = NULL;
     static int previous_search_len = 0;
     Histent he;
@@ -883,6 +883,7 @@ doisearch(char **args, int dir)
     }
     statusline = NULL;
     selectkeymap(okeymap, 1);
+    zsfree(okeymap);
     /*
      * Don't allow unused characters provided as a string to the
      * widget to overflow and be used as separated commands.
@@ -960,7 +961,7 @@ getvisrchstr(void)
     char *sbuf = zhalloc(80);
     int sptr = 1, ret = 0, ssbuf = 80, feep = 0;
     Thingy cmd;
-    char *okeymap = curkeymapname;
+    char *okeymap = ztrdup(curkeymapname);
 
     if (vipenultsrchstr) {
 	zsfree(vipenultsrchstr);
@@ -1044,6 +1045,7 @@ getvisrchstr(void)
     }
     statusline = NULL;
     selectkeymap(okeymap, 1);
+    zsfree(okeymap);
     return ret;
 }
 
diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c
index f820a758f..9fd5a9197 100644
--- a/Src/Zle/zle_keymap.c
+++ b/Src/Zle/zle_keymap.c
@@ -388,7 +388,10 @@ selectkeymap(char *name, int fb)
 	    return 1;
 	km = openkeymap(name = ".safe");
     }
-    curkeymapname = name;
+    if(name != curkeymapname) {
+	zsfree(curkeymapname);
+	curkeymapname = ztrdup(name);
+    }
     curkeymap = km;
     return 0;
 }
diff --git a/Src/Zle/zle_main.c b/Src/Zle/zle_main.c
index d46d3b537..cec6c1b4e 100644
--- a/Src/Zle/zle_main.c
+++ b/Src/Zle/zle_main.c
@@ -1100,7 +1100,7 @@ zleaftertrap(Hookdef dummy, void *dat)
 static struct builtin bintab[] = {
     BUILTIN("bindkey", 0, bin_bindkey, 0, -1, 0, "evaMldDANmrsLRp", NULL),
     BUILTIN("vared",   0, bin_vared,   1,  7, 0, NULL,             NULL),
-    BUILTIN("zle",     0, bin_zle,     0, -1, 0, "lDANCLmMgGcRaUI", NULL),
+    BUILTIN("zle",     0, bin_zle,     0, -1, 0, "lDANCLmMgGcRaUKI", NULL),
 };
 
 /* The order of the entries in this table has to match the *HOOK
diff --git a/Src/Zle/zle_misc.c b/Src/Zle/zle_misc.c
index e24d0c08b..592a590b5 100644
--- a/Src/Zle/zle_misc.c
+++ b/Src/Zle/zle_misc.c
@@ -669,7 +669,7 @@ executenamedcommand(char *prmt)
     int len, l = strlen(prmt), feep = 0, listed = 0, curlist = 0;
     int ols = (listshown && validlist), olll = lastlistlen;
     char *ptr;
-    char *okeymap = curkeymapname;
+    char *okeymap = ztrdup(curkeymapname);
 
     clearlist = 1;
     cmdbuf = zhalloc(l + NAMLEN + 2);
@@ -685,6 +685,7 @@ executenamedcommand(char *prmt)
 	if (!(cmd = getkeycmd()) || cmd == Th(z_sendbreak)) {
 	    statusline = NULL;
 	    selectkeymap(okeymap, 1);
+	    zsfree(okeymap);
 	    if ((listshown = ols)) {
 		showinglist = -2;
 		lastlistlen = olll;
@@ -752,6 +753,7 @@ executenamedcommand(char *prmt)
 		    unrefthingy(r);
 		    statusline = NULL;
 		    selectkeymap(okeymap, 1);
+		    zsfree(okeymap);
 		    if ((listshown = ols)) {
 			showinglist = -2;
 			lastlistlen = olll;
diff --git a/Src/Zle/zle_params.c b/Src/Zle/zle_params.c
index 7db5d6698..dfdc0dcd7 100644
--- a/Src/Zle/zle_params.c
+++ b/Src/Zle/zle_params.c
@@ -69,6 +69,8 @@ static struct zleparam {
         zleunsetfn, NULL },
     { "LASTWIDGET", PM_SCALAR | PM_READONLY, NULL, FN(get_lwidget),
         zleunsetfn, NULL },
+    { "KEYMAP", PM_SCALAR | PM_READONLY, NULL, FN(get_keymap),
+        zleunsetfn, NULL },
     { "KEYS", PM_SCALAR | PM_READONLY, NULL, FN(get_keys),
         zleunsetfn, NULL },
     { "NUMERIC", PM_INTEGER | PM_UNSET, FN(set_numeric), FN(get_numeric),
@@ -273,6 +275,13 @@ get_lwidget(Param pm)
 
 /**/
 static char *
+get_keymap(Param pm)
+{
+    return dupstring(curkeymapname);
+}
+
+/**/
+static char *
 get_keys(Param pm)
 {
     return keybuf;
diff --git a/Src/Zle/zle_thingy.c b/Src/Zle/zle_thingy.c
index f5acb73b4..dd2aea40d 100644
--- a/Src/Zle/zle_thingy.c
+++ b/Src/Zle/zle_thingy.c
@@ -339,6 +339,7 @@ bin_zle(char *name, char **args, char *ops, int func)
 	{ 'R', bin_zle_refresh, 0, -1 },
 	{ 'M', bin_zle_mesg, 1, 1 },
 	{ 'U', bin_zle_unget, 1, 1 },
+	{ 'K', bin_zle_keymap, 1, 1 },
 	{ 'I', bin_zle_invalidate, 0, 0 },
 	{ 0,   bin_zle_call, 0, -1 },
     };
@@ -465,6 +466,17 @@ bin_zle_unget(char *name, char **args, char *ops, char func)
 }
 
 /**/
+static int
+bin_zle_keymap(char *name, char **args, char *ops, char func)
+{
+    if (!zleactive) {
+	zwarnnam(name, "can only be called from widget function", NULL, 0);
+	return 1;
+    }
+    return selectkeymap(*args, 0);
+}
+
+/**/
 static void
 scanlistwidgets(HashNode hn, int list)
 {