about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--Doc/Zsh/zle.yo17
-rw-r--r--Src/Zle/zle_keymap.c18
3 files changed, 37 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 2d175ad00..90ac948a0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2006-01-28  Peter Stephenson  <p.w.stephenson@ntlworld.com>
+
+	* 22169: Doc/Zsh/zle.yo, Src/Zle/zle_keymap.c: hook function
+	zle-keymap-select called when $KEYMAP changes.
+
 2006-01-21  Clint Adams  <clint@zsh.org>
 
 	* 22168: Completion/Debian/Command/_bts: add options and
diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo
index 40bc24988..f0808314a 100644
--- a/Doc/Zsh/zle.yo
+++ b/Doc/Zsh/zle.yo
@@ -763,8 +763,8 @@ enditem()
 
 subsect(Special Widget)
 
-There is one user-defined widget which is special to the shell.
-If it does not exist, no special action is taken.  The environment
+There are a few user-defined widgets which are special to the shell.
+If they do not exist, no special action is taken.  The environment
 provided is identical to that for any other editing widget.
 
 startitem()
@@ -780,6 +780,19 @@ zle -N zle-line-init)
 (The command inside the function sets the keymap directly; it is
 equivalent to tt(zle vi-cmd-mode).)
 )
+tindex(zle-keymap-select)
+item(tt(zle-keymap-select))(
+Executed every time the keymap changes, i.e. the special parameter
+tt(KEYMAP) is set to a different value, while the line editor is active.
+Initialising the keymap when the line editor starts does not cause the
+widget to be called.
+
+The value tt($KEYMAP) within the function reflects the new keymap.  The
+old keymap is passed as the sole argument.
+
+This can been used for detecting switches between the vi command
+(tt(vicmd)) and insert (usually tt(main)) keymaps.
+)
 enditem()
 
 sect(Standard Widgets)
diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c
index 7cd3b2365..7b1f9e1ad 100644
--- a/Src/Zle/zle_keymap.c
+++ b/Src/Zle/zle_keymap.c
@@ -400,8 +400,24 @@ selectkeymap(char *name, int fb)
 	km = openkeymap(name = ".safe");
     }
     if(name != curkeymapname) {
-	zsfree(curkeymapname);
+	char *oname = curkeymapname;
+	Thingy chgthingy;
+
 	curkeymapname = ztrdup(name);
+
+	if (oname && zleactive && strcmp(oname, curkeymapname) &&
+	    (chgthingy = rthingy_nocreate("zle-keymap-select"))) {
+	    char *args[2];
+	    int saverrflag = errflag, savretflag = retflag;
+	    args[0] = oname;
+	    args[1] = NULL;
+	    errflag = retflag = 0;
+	    execzlefunc(chgthingy, args);
+	    unrefthingy(chgthingy);
+	    errflag = saverrflag;
+	    retflag = savretflag;
+	}
+	zsfree(oname);
     }
     curkeymap = km;
     return 0;