From 4b3cdcdb696840c6af4a77cd37fed62df1f3a3e8 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Sat, 28 Jan 2006 15:02:25 +0000 Subject: 22169: hook function zle-keymap-select called when $KEYMAP changes --- ChangeLog | 5 +++++ Doc/Zsh/zle.yo | 17 +++++++++++++++-- Src/Zle/zle_keymap.c | 18 +++++++++++++++++- 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 + + * 22169: Doc/Zsh/zle.yo, Src/Zle/zle_keymap.c: hook function + zle-keymap-select called when $KEYMAP changes. + 2006-01-21 Clint Adams * 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; -- cgit 1.4.1