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

Re: one time in 20 error



Bart wrote:
> I'm not attached to them causing chaos, but I'm not sure discarding
> them unacknowledged is the right thing either.  Roman's binding does
> produce some unexpected behavior if you actually type escape bracket
> (which might occur in vi modes, if unlikely in emacs?).  Some kind of
> feep or "zle -M"-style warning, or is that also chaos?

Returning 1 from the widget function as I did in the C implementation
does result in a feep.

Allowing for KEYTIMEOUT resolves unexpected behaviour if you actually
type escape [.

Roman wrote:
> Is there an advantage to implementing this widget in C rather than zsh?

If implemented in shell code, every user that wants to make use of it
needs to setup the function and bind it for every keymap. That includes
local keymaps given that it is near certain to be a prefix of other
key bindings. What advantage do you see to implementing it in shell
code?

I wrote:
> After testing this, I'm inclined to think it would be better to special
> case the CSI sequence in getkeymapcmd() instead.

The new patch below takes this approach. This is able to be even
stricter on the definition of a CSI sequence. This has the advantage of
working even where the key sequence doesn't start with a CSI sequence.
So if Ctrl-X is a prefix, you can press Ctrl-X followed by Delete and
it'll wait for the full CSI sequence from the Delete key. Similarly for
cases like Alt-Delete generating a sequence like '^[^[[3~'.

If you examine keys with describe-key-briefly, it will now give,
e.g "^[[12~" is undefined-key for F2 where before I got "^[" is
vi-cmd-suffix-retain and [12~ inserted.

undefined-key is implemented as just return 1 so this results in a feep
but with mouse events enabled, that's all that happens. You still don't
want to enable mouse events if you've not arranged for them to be
handled.

Oliver

diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c
index d90838f03..2fe48796c 100644
--- a/Src/Zle/zle_keymap.c
+++ b/Src/Zle/zle_keymap.c
@@ -1586,7 +1586,7 @@ getkeymapcmd(Keymap km, Thingy *funcp, char **strp)
     Thingy func = t_undefinedkey;
     char *str = NULL;
     int lastlen = 0, lastc = lastchar;
-    int timeout = 0;
+    int timeout = 0, csi = 0, startcsi;
 
     keybuflen = 0;
     keybuf[0] = 0;
@@ -1636,7 +1636,26 @@ getkeymapcmd(Keymap km, Thingy *funcp, char **strp)
 	    }
 #endif
 	}
-	if (!ispfx)
+
+	/* CSI key sequences have a well defined structure so if we currently
+	 * have an incomplete one, loop so the rest of it will be included in
+	 * the key sequence if that arrives within the timeout. */
+	if (keybuflen >= 3 && !csi) {
+	    startcsi = keybuflen - 3;
+	    csi = keybuf[startcsi] == '\033' && keybuf[keybuflen - 2] == '[';
+	}
+	if (csi) {
+	    csi = keybuf[keybuflen - 2] != Meta && keybuf[keybuflen - 1] >= 0x20
+		&& keybuf[keybuflen - 1] <= 0x3f;
+	    if (!csi && keybuf[keybuflen - 1] >= 0x40 &&
+		    keybuf[keybuflen - 1] <= 0x7e && lastlen > startcsi &&
+		    lastlen != keybuflen) {
+		func = t_undefinedkey;
+		lastlen = keybuflen;
+	    }
+	}
+
+	if (!ispfx && !csi)
 	    break;
     }
     if(!lastlen && keybuflen)




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