Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: customisable menu selection keymap



Hi,

I wanted to use a custom keymap for certain menu selections (in
particular with cd - , to choose a directory from the stack and change
to it by pressing enter once rather than twice).

These two patches seem to do the trick:

Index: Src/Zle/complist.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/complist.c,v
retrieving revision 1.102
diff -d -u -w -r1.102 complist.c
--- Src/Zle/complist.c  2 Apr 2007 13:58:19 -0000       1.102
+++ Src/Zle/complist.c  7 Apr 2007 23:12:56 -0000
@@ -2222,6 +2222,8 @@
    int nolist = 0, mode = 0, modecs, modell, modelen, wasmeta;
    char *s;
    char status[MAX_STATUS], *modeline = NULL;
+    char *user_mskeymapname;
+    Keymap user_mskeymap;

    msearchstack = NULL;
    msearchstr = "";
@@ -2291,6 +2293,10 @@
    unqueue_signals();
    mhasstat = (mstatus && *mstatus);
    fdat = dat;
+    if ((user_mskeymapname = getsparam("MENUKEYMAP")) &&
+        (user_mskeymap = openkeymap(user_mskeymapname)))
+      selectlocalmap(user_mskeymap);
+    else
    selectlocalmap(mskeymap);
    noselect = 1;
    while ((menuacc &&


Index: Completion/Base/Core/_main_complete
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Core/_main_complete,v
retrieving revision 1.10
diff -d -u -w -r1.10 _main_complete
--- Completion/Base/Core/_main_complete 1 Oct 2004 10:29:21 -0000       1.10
+++ Completion/Base/Core/_main_complete 7 Apr 2007 23:12:26 -0000
@@ -292,6 +292,17 @@
      else
        unset MENUMODE
      fi
+
+      keymap=( "${(@M)_menu_style:#keymap*}" )
+
+      if (( $#keymap )); then
+        for i in "$keymap[@]"; do
+          if [[ "$i" = *\=* ]]; then
+            MENUKEYMAP="${i#*\=}"
+            break
+          fi
+        done
+      fi
    fi
  fi
elif [[ nm -lt 1 && -n "$_comp_mesg" ]]; then

That then lets me use my special keymap only for directory completion:

bindkey -N pete_menuselect
bindkey -M pete_menuselect '^M' .accept-line

# Use menu selection on directory stack completion
zstyle ":completion:*:directory-stack" menu yes 'select=0'
'keymap=pete_menuselect'

Is this likely to be useful to anyone else?

Thanks,
Pete



Messages sorted by: Reverse Date, Date, Thread, Author