diff options
author | Bart Schaefer <barts@users.sourceforge.net> | 2006-07-31 06:33:48 +0000 |
---|---|---|
committer | Bart Schaefer <barts@users.sourceforge.net> | 2006-07-31 06:33:48 +0000 |
commit | e7944e7606442684578fb2d31f8e811ece0b1403 (patch) | |
tree | 3548def4a5926d95ec7ade1d075e2b67d87ebb77 | |
parent | f5bbc619bd76fe871ecd241ca3a2d698fa509398 (diff) | |
download | zsh-e7944e7606442684578fb2d31f8e811ece0b1403.tar.gz zsh-e7944e7606442684578fb2d31f8e811ece0b1403.tar.xz zsh-e7944e7606442684578fb2d31f8e811ece0b1403.zip |
unposted: a technique for overriding ZLE widgets within a selected keymap
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | Functions/Zle/keymap+widget | 76 |
2 files changed, 84 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog index 94ff508ea..62e3bf2b0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-07-30 Barton E. Schaefer <schaefer@zsh.org> + + * unposted (see users/10559): Functions/Zle/keymap+widget: a + technique for overriding ZLE widgets only within a selected + keymap. + 2006-07-30 Peter Stephenson <p.w.stephenson@ntlworld.com> * 22565: Src/compcore.c: Fix bug with menu completion after failed @@ -6,7 +12,7 @@ * 22562: Src/glob.c, Test/D07multibyte.ztst: make ${...#...} etc. understand multibyte characters. -2006-07-29 Barton E. Schaefer <schaefer@brasslantern.com> +2006-07-29 Barton E. Schaefer <schaefer@zsh.org> * 22561: Functions/Zle/incremental-complete-word: fix display bug introduced roughly five years ago when _main_complete was changed @@ -159,7 +165,7 @@ * 22501: configure.ac: reduce default maximum function depth to 1000. -2006-06-17 Barton E. Schaefer <schaefer@brasslantern.com> +2006-06-17 Barton E. Schaefer <schaefer@zsh.org> * 22492: Functions/Zle/url-quote-magic: properly detect when a new word (in the zsh syntax sense) has been started, and thus avoid diff --git a/Functions/Zle/keymap+widget b/Functions/Zle/keymap+widget new file mode 100644 index 000000000..2a437c234 --- /dev/null +++ b/Functions/Zle/keymap+widget @@ -0,0 +1,76 @@ +#autoload + +## +# self-insert-by-keymap originally appeared in zsh-users/10559 (July 2006). +# Changes have been made to the widget naming scheme, based on feedback on +# the mailing list thread. +## + +emulate -L zsh +zmodload -i zsh/zleparameter || return 1 + +# Rebind the most common widgets to override in multiple keymaps. Ideally +# complete-word would also be in this list, but so many other things +# already rebind complete-word that doing so here is a waste of effort. + +local -a m +local w='' k='' +for w in self-insert accept-line forward-char backward-char \ + up-{,line-or-}history down-{,line-or-}history \ + magic-space backward-delete-char delete-char-or-list +do + + # If this is run early enough that all the widgets are still builtins, + # no explicit remapping is needed. If they've already been rebound, + # it's not safe to assume we can do so again. + + if [[ $widgets[$w] != (builtin|user:$w-by-keymap) ]] + then + m+="Cannot rebind $w: $widgets[$w]" + continue + fi + + function $w-by-keymap { + if (( $+widgets[$KEYMAP+$WIDGET] == 1 )) + then zle $KEYMAP+$WIDGET "$@" + else zle .$WIDGET "$@" + fi + } + + zle -N $w $w-by-keymap + +done + +[[ -n $m ]] && { zle && zle -M "${(F)m}" || print -l -u2 -R $m } + +return 0 + +# With this in place, you should rarely need "zle -N self-insert frob" +# again. Instead you do this: +# +# bindkey -N frobber main +# zle -N frobber+self-insert frob +# +# Then, whenever you wish to replace self-insert with frob, change +# keymaps: +# +# zle recursive-edit -K frobber + +# Here's a simple example, which improves upon the caps-lock example in +# the zsh manual entry for recursive-edit: +# +# ucase+self-insert() { +# LBUFFER+=${(U)KEYS[-1]} +# } +# zle -N ucase+self-insert +# caps-lock() { +# bindkey -N ucase $KEYMAP +# bindkey -M ucase "$KEYS" .accept-line +# zle recursive-edit -K ucase || zle send-break +# } +# zle -N caps-lock +# +# To turn this on, pick a key sequence (I've chosen ctrl-x shift-L) and +# bind the caps-lock widget to it: +# +# bindkey -M main '^XL' caps-lock |