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

Re: Quickhack that seems to fix issues with the menuselect keymap



On Mon, 25 Aug 2008 01:52:38 +0200
"xRaich[o]²x" <raichoo@xxxxxxxxxxxxxx> wrote:
> I had some issues with Zsh (http://www.zsh.org/mla/users/2008/msg00772.html). 
> I did a quickhack which seems to fix the behavior mentioned there, but i 
> don't know if this makes any sense at all.
> 
> i changed line 2315 of the complist.c file from
> selectlocalmap(mskeymap);
> into
> selectkeymap("menuselect",1);
> 
> This is a "lets-see-what-happens" hack, so it might be complete rubbish. 
> Comments and pointers are very welcome since I'm totally new to Zsh

I think I've worked out what this breaks (though there's a fuller patch
to do the same thing attached, which I won't commit).  From the
documentation:

  Any key that is not bound in the listscroll keymap or that is bound to
  undefined-key is looked up in the keymap currently selected.

So, for example, if you type "^F" without the patch it moves you forward
through the list, while with the patch it doesn't because that's not
bound in the main keymap.  One reason why it's hard to do this without
local key maps is that the main key map may be either vi or emacs mode,
which have different bindings for this.  So this may be a can of worms
better left unopened.

I'll leave this hanging until I get back again.

I tickled at least two further oddities with menu completion looking at
this.  I think at least one is a bug, though it may still depend on the
styles I have set: if the menu is too large for the screen, then hitting
"return" accepts the completion (but not the line) but the line is
hidden.  (If it wasn't too long for the screen, it accepts the whole
line, so this is a bit inconsistent anyway.)  The other is that
file-list is behaving unexpectedly with the argument "list=10".  Neither
problem is affected by this patch.

Index: Src/Zle/complist.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/complist.c,v
retrieving revision 1.118
diff -u -r1.118 complist.c
--- Src/Zle/complist.c	6 Aug 2008 02:21:03 -0000	1.118
+++ Src/Zle/complist.c	25 Aug 2008 17:47:43 -0000
@@ -948,12 +948,13 @@
 {
     Thingy cmd;
     int i, ret = 0;
+    char *okeymap = ztrdup(curkeymapname);
 
     compprintfmt(NULL, 1, 1, 1, ml, NULL);
 
     fflush(shout);
     zsetterm();
-    selectlocalmap(lskeymap);
+    selectkeymap("listscroll", 1);
     if (!(cmd = getkeycmd()) || cmd == Th(z_sendbreak))
 	ret = 1;
     else if (cmd == Th(z_acceptline) ||
@@ -978,7 +979,8 @@
 	ungetkeycmd();
 	ret = 1;
     }
-    selectlocalmap(NULL);
+    selectkeymap(okeymap, 1);
+    zsfree(okeymap);
     settyinfo(&shttyinfo);
     putc('\r', shout);
     for (i = columns - 1; i-- > 0; )
@@ -2337,7 +2339,7 @@
     int space, lbeg = 0, step = 1, wrap, pl = nlnct, broken = 0, first = 1;
     int nolist = 0, mode = 0, modecs, modell, modelen, wasmeta;
     char *s;
-    char status[MAX_STATUS], *modeline = NULL;
+    char status[MAX_STATUS], *modeline = NULL, *okeymap;
 
     msearchstack = NULL;
     msearchstr = "";
@@ -2407,7 +2409,8 @@
     unqueue_signals();
     mhasstat = (mstatus && *mstatus);
     fdat = dat;
-    selectlocalmap(mskeymap);
+    okeymap = ztrdup(curkeymapname);
+    selectkeymap("menuselect", 1);
     noselect = 1;
     while ((menuacc &&
 	    !hasbrpsfx(*(minfo.cur), minfo.prebr, minfo.postbr)) ||
@@ -3282,7 +3285,8 @@
 	    if (u->lastmatches != lastmatches)
 		freematches(u->lastmatches, 0);
 
-    selectlocalmap(NULL);
+    selectkeymap(okeymap, 1);
+    zsfree(okeymap);
     mselect = mlastcols = mlastlines = -1;
     mstatus = NULL;
     inselect = mhasstat = 0;
Index: Src/Zle/zle_keymap.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_keymap.c,v
retrieving revision 1.29
diff -u -r1.29 zle_keymap.c
--- Src/Zle/zle_keymap.c	3 Apr 2008 15:20:24 -0000	1.29
+++ Src/Zle/zle_keymap.c	25 Aug 2008 17:47:44 -0000
@@ -108,7 +108,7 @@
 /* currently selected keymap, and its name */
 
 /**/
-Keymap curkeymap, localkeymap;
+Keymap curkeymap;
 /**/
 char *curkeymapname;
 
@@ -423,15 +423,6 @@
     return 0;
 }
 
-/* Select a local key map. */
-
-/**/
-mod_export void
-selectlocalmap(Keymap m)
-{
-    localkeymap = m;
-}
-
 /* Reopen the currently selected keymap, in case it got deleted.  This *
  * should be called after doing anything that might have run an        *
  * arbitrary user-specified command.                                   */
@@ -1310,15 +1301,9 @@
     while(getkeybuf(!!lastlen) != EOF) {
 	char *s;
 	Thingy f;
-	int loc = !!localkeymap;
 	int ispfx = 0;
 
-	if (loc) {
-	    loc = ((f = keybind(localkeymap, keybuf, &s)) != t_undefinedkey);
-	    ispfx = keyisprefix(localkeymap, keybuf);
-	}
-	if (!loc)
-	    f = keybind(km, keybuf, &s);
+	f = keybind(km, keybuf, &s);
 	ispfx |= keyisprefix(km, keybuf);
 
 	if (f != t_undefinedkey) {
Index: Src/Zle/zle_main.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_main.c,v
retrieving revision 1.114
diff -u -r1.114 zle_main.c
--- Src/Zle/zle_main.c	31 Jul 2008 08:44:21 -0000	1.114
+++ Src/Zle/zle_main.c	25 Aug 2008 17:47:44 -0000
@@ -1025,7 +1025,6 @@
 	statusline = NULL;
 	vilinerange = 0;
 	reselectkeymap();
-	selectlocalmap(NULL);
 	bindk = getkeycmd();
 	if (bindk) {
 	    if (!zlell && isfirstln && !(zlereadflags & ZLRF_IGNOREEOF) &&
@@ -1163,7 +1162,6 @@
     viinsbegin = 0;
     statusline = NULL;
     selectkeymap("main", 1);
-    selectlocalmap(NULL);
     fixsuffix();
     if ((s = getlinknode(bufstack))) {
 	setline(s, ZSL_TOEND);


-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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