Workaround incompatibilities with the keyboard setup of some vendors
authorFrank Terbeck <ft@grml.org>
Fri, 7 Sep 2012 15:59:35 +0000 (17:59 +0200)
committerFrank Terbeck <ft@grml.org>
Fri, 7 Sep 2012 16:09:54 +0000 (18:09 +0200)
Some vendors, like Debian (and therefore Ubuntu), enable smkx terminal
mode in the zle-line-init widget and turn it back off in
zle-line-finish.

While that is the right thing to do, because it makes sure the values
from $terminfo are valid. However, we are currently incompatible with
that. And it is a lot of work to get it right for every binding we have,
because we do have some, that are not available in the vast majority of
terminfo entries (like <Ctrl>-<CursorKey>).

Signed-off-by: Frank Terbeck <ft@grml.org>
etc/zsh/zshrc

index 4f0da7e..4e7ef09 100644 (file)
@@ -585,6 +585,22 @@ watch=(notme root)
 # automatically remove duplicates from these arrays
 typeset -U path cdpath fpath manpath
 
+# Remove zle-line-{init,finish} if it looks like it turns smkx. This would be
+# better fixed by working with those modes too, but we use way too many
+# hardcoded bindings for now.
+function remove_widget () {
+    local name=$1
+    local cap=$2
+    if (( ${+functions[$name]} )) && [[ ${functions[$name]} == *${cap}* ]]; then
+        local w=${widgets[$name]}
+        zle -D $name
+        [[ $w == user:* ]] && unfunction ${w#*:}
+    fi
+}
+remove_widget zle-line-init smkx
+remove_widget zle-line-finish rmkx
+unfunction remove_widget
+
 # keybindings
 if [[ "$TERM" != emacs ]] ; then
     [[ -z "$terminfo[kdch1]" ]] || bindkey -M emacs "$terminfo[kdch1]" delete-char