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,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 20856 invoked from network); 23 Sep 2020 11:30:18 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 23 Sep 2020 11:30:18 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1600860618; b=kyctyNTUnYEpW4UBEqag29Tk06CnesyvYIX49LP9pB8NyHHC5w7F6ks/Gie2jzkBJSUz+OwZcK /FtVHWACAbZk2Ks/JxFxry3NgmnoZKLSXg5c1CZQsUhuzTSewivUN7C1U2PBLkYLGAY3iPWysb rrTRSk2rZCEAQT5dmvVTDyL4fe8KfSmQpOVqf9+cMduUVJsUBlKEr8Ioc0TXDHFxmQvsWxMgh6 0e6vpZVrj28bLCcRiOk8vEDvROr+M0PgE61ppuO/YcftM/uMNjsGEXqkUTxm94FOiOsFQlCx39 3LyJ0TET6/7ipnmP1BysZ/ndiiC80yB7Rbb9ivhuwEAMaQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (out5-smtp.messagingengine.com) smtp.remote-ip=66.111.4.29; dkim=pass header.d=daniel.shahaf.name header.s=fm1 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm3 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1600860618; bh=YBMBDdMJICp/YLRswyR2cafGpuT3C2ENKp0mrQ99TEo=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:MIME-Version: References:In-Reply-To:Message-ID:Subject:Cc:To:From:Date:DKIM-Signature: DKIM-Signature:DKIM-Signature; b=c6CCVEXYu4UVtzqzLRQX26eZTbt100DAG7vV/2ZbWYBGfS8y88TuUzhjfs41WsobKEzVuAi9I2 1KkJ2hqHlpHYQDYZflzX71Jc3aQCOhLbdrpwDerX6rnCQlXT1Z0kHQ8BiHhqzHdC0mIH9hlI+R BtTqq0hriRQfXta2ZpZ5fHh7vi54ADmGp4VCkS3Fy34EpAvhBsqL4gXAhSc4H4hAsVOCSUm59e oKXFtNuQKV+mcdmc99xbSfPdDP8GunhKDTtw92Y+dPhNMEebe+v/dMnd0Rh90cH/jjD3wUcKPx 6IgRFSnMVk/+NrMefF6are4S/mlXSRXkcGMOIe+fyN96dA==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Subject:Cc:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=KT1Ipe98AJP7CjBw97Jqm6V2Kn0Ljzt7QG0VBrOalP4=; b=zt65YN2ZYKjF9dZdkNtwpwBrH7 ZinQDgvAeRMMI9UeQRLT3jluda098v8tKg6BdEIdla8ySIWng9EyGi/2uj0kUrfGdP0GLgkCdnyWU Qx0PSrKhsRZUkirRg0/km9R0GhaLVyOw9BBEroGRq2hSqtc6+iHjEPBs8CxS2JGqkTicC/YF4goLw QuRSFwILh0BRuBXsoWdWRsg9SloRbQRjd3alj1AvcY8G32NJX+yrqnXYuqRCneBqraEfowFp/9rEZ wPTVeaMJUz+ZHu1rJe7d3CEbBO8j2WRO+6QW9umR/UWarZh0PQRW2GwPqcph53YUCLJo2duEEOi08 fn2y0vRw==; Received: from authenticated user by zero.zsh.org with local id 1kL2yU-000DaI-01; Wed, 23 Sep 2020 11:30:14 +0000 Authentication-Results: zsh.org; iprev=pass (out5-smtp.messagingengine.com) smtp.remote-ip=66.111.4.29; dkim=pass header.d=daniel.shahaf.name header.s=fm1 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm3 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none Received: from out5-smtp.messagingengine.com ([66.111.4.29]:58065) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1kL2y7-000DCz-6x; Wed, 23 Sep 2020 11:29:52 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 857355C0246; Wed, 23 Sep 2020 07:29:50 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 23 Sep 2020 07:29:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=date:from:to:cc:subject:message-id :in-reply-to:references:mime-version:content-type :content-transfer-encoding; s=fm1; bh=KT1Ipe98AJP7CjBw97Jqm6V2Kn 0Ljzt7QG0VBrOalP4=; b=SJwEIKsEcOWUO67YKiA+n0sBD9iKrFUjgwhM3aKD64 FvC53tPpOM2SHMisJGMCXFmfXNgeIZD5bMwjcaB50dbTO/mxkUbI8Gxd633wWC7v 4wO0LLr/La4ab4riHNXeKH0up2gqKAQ17oSSEVNdHRkw0MwzyGhe2dXO/Z2Dk78f RziCnL23LQs+WMo3kA3PpqhQfSCgTD11pxsGOLSQSY+pP7YBOUyB6Coy+ZWyL4Ob et86N/UGGlWn99irJn1xF/z4Oe86eC0b2wor6pT42KuiaL41vdY3BxWV2lOykfHQ QLzmhplLZT9h+mP17/vIg6SiYWYf6B24czqJ93bVWf9w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=KT1Ipe98AJP7CjBw97Jqm6V2Kn0Ljzt7QG0VBrOal P4=; b=a5af0Bjzcv6DBTDO/0cORGASijRpCEulJvSYlSvF1oJJ2cZLzfmxyCbnA d0YXE5Kklnf4wE6gEVPROYAi3REHCdUI1MmAkXcrYEQ4k8Hv8vVqqhctuEuBAj5u 5/w5ywFqcMDusLuUsPKlQbgigIxnPDnWwCOIu4ZNdgGqOA/zpQep7DIzp9Qax0q/ 5Qvfd59H6g6XzFrJE8RBmbis6NHeoKCYC36mII1O41ckLWgS0YunZWxEx0HgzwLe fy2sHFHH1pMXKedPhU1op8AuC182UG93fs17fyTZNeOw/tspyZm8pcCN75oB0QI0 6ANscuptlzeGzFKDOn5dDdYls+2ow== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudeigdegudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvuffkjghfofggtgfgsehtqhdttdertdejnecuhfhrohhmpeffrghnihgv lhcuufhhrghhrghfuceougdrshesuggrnhhivghlrdhshhgrhhgrfhdrnhgrmhgvqeenuc ggtffrrghtthgvrhhnpefhtdetfeehveeutdehuddtieefgeettedtjedtffehudeiieej leetteekudetheenucfkphepuddtledrieehrdefvddrudekfeenucevlhhushhtvghruf hiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegurdhssegurghnihgvlhdrshhh rghhrghfrdhnrghmvg X-ME-Proxy: Received: from tarpaulin.shahaf.local2 (bzq-109-65-32-183.red.bezeqint.net [109.65.32.183]) by mail.messagingengine.com (Postfix) with ESMTPA id 1F0E9328005E; Wed, 23 Sep 2020 07:29:50 -0400 (EDT) Received: from tarpaulin.shahaf.local2 (localhost [IPv6:::1]) by tarpaulin.shahaf.local2 (Postfix) with ESMTP id 4BxGDW37xbzsL; Wed, 23 Sep 2020 11:29:47 +0000 (UTC) Date: Wed, 23 Sep 2020 11:29:45 +0000 From: Daniel Shahaf To: Peter =?UTF-8?B?U2zDrcW+aWs=?= Cc: zsh-users@zsh.org Subject: Re: How to avoid infinite recursion in ZLE widgets Message-ID: <20200923112945.578227b9@tarpaulin.shahaf.local2> In-Reply-To: References: X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Seq: 26076 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: Peter Sl=C3=AD=C5=BEik wrote on Wed, 23 Sep 2020 10:34 +0200: > Hello, >=20 > I'd like to replicate the functionality found in some text editors - name= ly > that if you press a single or double quote, the editor inserts two of them > and places the cursor inside the pair. >=20 > With some necessary checks for word boundaries, etc. left out, the soluti= on > looks rather trivial: >=20 > function insert-single-quotes() { > zle self-insert "''" # that's "_'_'_" > zle backward-char > } =20 >=20 > zle -N insert-single-quotes > bindkey "'" insert-single-quotes # that's "_'_" >=20 > However, this solution creates infinite recursion (a single quote bound to > insert a single quote). No, it doesn't. I tried in =C2=ABzsh -f=C2=BB and it inserts a single quote without moving the cursor. It inserts _one_ quote, rather than two, because self-insert ignores its positional arguments and the widget was bound to =C2=AB'=C2=BB. > 1. How to prevent the recursion? Always open a new shell for testing. > Is self-insert the right widget for this task? You could also use =C2=ABzle .self-insert=C2=BB, or even modify $LBUFFER and $RBUFFER directly (=C2=ABLBUFFER+=3D\'; RBUFFER=3D\'$RBUFFER=C2=BB). (Incidentally, I guess you may also want to check whether ${RBUFFER} starts with a single quote, but that's no longer a zsh question but a business logic question.) > 2. I played with zle -U. What are the use cases for zle self-insert and z= le > -U? =C2=ABzle -U foo=C2=BB subjects the =C2=ABf=C2=BB, =C2=ABo=C2=BB, and =C2= =ABo=C2=BB to bindkey mappings. For instance, =C2=ABbindkey -s x y=C2=BB followed by =C2=ABzle -U x=C2=BB would= insert =C2=ABy=C2=BB. =C2=ABself-insert=C2=BB appends one character to the buffer. > 3. I tried to avoid the recursion by using "zle -K .safe -U text", but it > ended with "too many arguments for -K". How is zle -K expected to be used? As =C2=ABzle -K foo=C2=BB without further arguments. You can do something = like this: { readonly save_KEYMAP=3D$KEYMAP zle -K .safe =E2=8B=AE } always { zle -K $save_KEYMAP } But see above about $LBUFFER. Cheers, Daniel