From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 5445 invoked from network); 10 Dec 2022 01:04:41 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 10 Dec 2022 01:04:41 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Message-ID:Date:Content-ID: Content-Type:MIME-Version:Subject:To:References:From:In-reply-to:cc:Reply-To: Content-Transfer-Encoding:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=vzTMm4GZh32J91wQ9o/w5nqqwvLL0lDqZ8jM83H2UP8=; b=aDaTWS3yZYw2cExyLztbVO65G1 6VMaXUwvn4/OMJh51pS4F2QcdXR66F9tmoBHdSLNASo2HU9g6Z0Q51zmfqP7terNAgIiXcIY/9z+c LHdwCstWxd9OrTFlOjLcldvuTY0dIKU/FfEVZX9XN9j57zdGhQjqVkIkCKPDFgfmvcYaaUuEuTr1T UWKLuAvnKa0tun7WuH8rq463vfX3m49fJzd7Y35kOdaw8QNypyiWVMM2Y6R9HPY2XVkdqBt3J/Ohb VTJ+OWo9Er3o+U7G/K5N5fTi9KcSMWKFFguyTJMSNBAMFAoHNa3p6mK6J6RlvsimDCr8mYXnRnTHe QbVIN6CA==; Received: by zero.zsh.org with local id 1p3oIC-0001Xb-3W; Sat, 10 Dec 2022 01:04:40 +0000 Received: by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1p3oHe-0001Dw-18; Sat, 10 Dec 2022 01:04:06 +0000 Received: from [192.168.178.21] (helo=hydra) by mail.kiddle.eu with esmtp(Exim 4.95) (envelope-from ) id 1p3oHd-0002w3-0u; Sat, 10 Dec 2022 02:04:05 +0100 cc: Zsh Workers In-reply-to: From: Oliver Kiddle References: <45486-1670284091.713245@QrNT.Ugrc.e_6U> To: Roman Perepelitsa Subject: Re: one time in 20 error MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <11285.1670634245.1@hydra> Date: Sat, 10 Dec 2022 02:04:05 +0100 Message-ID: <11286-1670634245.024361@Cn3a.dvUs.EJET> X-Seq: 51160 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: 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)