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 31606 invoked from network); 22 Dec 2021 22:09:34 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 22 Dec 2021 22:09:34 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1640210974; b=Zg2bJNya/MAL6/sBqnTsjakF8LxwQwpTlL2IdQQiukrPhVoiQdcSkNHsUmb1vcWyjUw+gcanxo kqduJpQsOMfBh/C8yUXKmf35CZYFV0ZNq9bsPr2iWF4LkQRIxbpDbBBH8D/3XMDdsXvJWifW6g BnQgEj0KrWBmxqhEGlK1TvLhPyvQS+oCaxS4H/Tdm8HGXdMFX421KNHVrb4EVQiw0+DJeepRj4 pkAFmfzMiavz9Lua76Wr9mglXH7EjxWO0XKpZWzQdKptouS2gJeYo2Gci9N1JgAGIgICL+n+VW 3OyO7EUdnnD1OU6k1HinRtNWIfUO9Tg+9bV9kHLR+eQWTQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (out4-smtp.messagingengine.com) smtp.remote-ip=66.111.4.28; dkim=pass header.d=daniel.shahaf.name header.s=fm2 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm1 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-20210803; t=1640210974; bh=XKksfK2ml7lYbm18t0Q94qC34jlCUjKykh+Tb5Rc1Ls=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:Subject:To:From:Date: References:In-Reply-To:Message-ID:MIME-Version:DKIM-Signature: DKIM-Signature:DKIM-Signature; b=jTjnBJgg+FkuQtxDWicULZIK8mrJBYot4xt+mtZptkelvc5G+AjJaSNDug+YayMicTT1F0s2bX rLwbtBbv2ZJkPsvx3Yja8TLlDDxs/nYqpCpNhfsmNzQq20O8klJ5X/OWQLroR+wtcYKDHQKg/0 NjMNMbma/xsluCCuo7/A+oheEcdxs6on5BK+hJjDxVs9FpAJ2VUcmxgJcJZKfacw27byqMdw23 bHJKIRSkSSrU5yyl0AwJpS0hpD0kqrW6ZHK5G2vqf9/egDwy52IiPEPwXDxdrlULlsgGtMWV0K xKPHrZLQM05dlJkooP624T13Md+eVFVKrZDGmJhe8W97Zg==; 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:Content-Transfer-Encoding: Content-Type:Subject:To:From:Date:References:In-Reply-To:Message-Id: Mime-Version:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=WaPXPJuGyMdGUFjAZyPUS3AWiiE6rcc7Dycag5Ra7qQ=; b=IjWH/d9lWPOv8TDbwyZuH2/iP8 D2C22LsF7sOqbqj/N7eUhf3lgXpJD8DBr81k9w8hqWNLwavsBxrv6zNpMEZTI2J/HO0f/eK7gSAuS VTe78MkGguNzuMVH1K9LCvABwbt6kU1Z+Ror5u/zvslb3Teup2+0tP1gWnvPvBZdFbGuTXQNl7f6G UWXDiin2pldtNup3qR6mkD2T220kFEFUdSKZ+/+4CapqJGi0E/fn8FEGs/A+rYZ3YBiLCDfsguIk4 KXNG6FfKGYA1y1v4BFP1Iz2gJwuCu3nLL+FsG0fKSQjBf1ImXErJ9sDmn1nar+z2KVtV0VFSQTuMu E8tPyDxA==; Received: from authenticated user by zero.zsh.org with local id 1n09ni-000Nj4-5V; Wed, 22 Dec 2021 22:09:34 +0000 Authentication-Results: zsh.org; iprev=pass (out4-smtp.messagingengine.com) smtp.remote-ip=66.111.4.28; dkim=pass header.d=daniel.shahaf.name header.s=fm2 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm1 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none Received: from out4-smtp.messagingengine.com ([66.111.4.28]:35505) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1n09mi-000N24-RC; Wed, 22 Dec 2021 22:08:34 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 6B0C05C0199; Wed, 22 Dec 2021 17:08:31 -0500 (EST) Received: from imap46 ([10.202.2.96]) by compute5.internal (MEProxy); Wed, 22 Dec 2021 17:08:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=mime-version:message-id:in-reply-to :references:date:from:to:subject:content-type :content-transfer-encoding; s=fm2; bh=WaPXPJuGyMdGUFjAZyPUS3AWii E6rcc7Dycag5Ra7qQ=; b=ARiiX8c3YuZVuPrLgBL1cNmkIHxFEbfkJ0/tjrXqOQ KGdOv9kbcmtMV6OmhDnCAYjPimPysVi7cJmEiRyOJeD1+p/l9cJbkNVm+Yr0gz3I pmz2KGt5oP9k8S9uxXz3mOKKOqQFPZLcsKEKbp5ay5ZwuqzCftM+e4j+RQVcB+CW 1+X8qDJnhu+d1L95r73OhVHDVgsFUV/jN34OcGnsexLIQg+nccUWtfVvZFADWhQ/ sTpvrsZoCWoRx7zgcT314S11Y0jOJy/r+NuwoCY2JD6mAjPyUIdUCL0W4c9Noe3B jQ96vC2VotVAq9Mp/kO+IyIneLmTdyHvQOiaz+XBd/AQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=fm1; bh=WaPXPJuGyMdGUFjAZyPUS3AWiiE6rcc7Dycag5Ra7 qQ=; b=AEGQ6WHX3Llwa7NhxrTVuxX6FyorWNaktNG/6rg5BLUCzMCLOBJv/Sc/k cWs6XhYxnM2ul/4VTO9NLE7uOaOf4m7r+zCDRK+lkMDqz9vN/wfOGL1pS6zWp4O6 5lOkT2U8m4EjnIsqk9dwWqURhtGLKWVzFs1sVnBYZvM9zmUD/Xe41wzvL9JKLso/ mFpvgPTuatL95R5XCQxGEn8WEORuDo5Zn47CErMa7OIsF2FIizlLfzKIw9oZN32z F06OrmDB5Llo4pDHdT5GhVpFEk+X4Vhj86GOrBt5AmJG8fH6ojThFVHQ4NeDzpsw cOu9PI0i2pnFan4D7030i3buRhcfQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddruddtiedgudehudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepfdff rghnihgvlhcuufhhrghhrghffdcuoegurdhssegurghnihgvlhdrshhhrghhrghfrdhnrg hmvgeqnecuggftrfgrthhtvghrnhepfefhkeefveeileelheeiffdtkedujeelvdfhtdej tdeggedvuefffeelhefhvdfgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepugdrshesuggrnhhivghlrdhshhgrhhgrfhdrnhgrmhgv X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 0ED661EE007B; Wed, 22 Dec 2021 17:08:30 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-4525-g8883000b21-fm-20211221.001-g8883000b Mime-Version: 1.0 Message-Id: <6e3644fd-07ad-4251-9310-b6899c41a233@www.fastmail.com> In-Reply-To: <2495135b4cf73e7add73e3fcd5fd6165a76b3cfa.camel@gmail.com> References: <2495135b4cf73e7add73e3fcd5fd6165a76b3cfa.camel@gmail.com> Date: Wed, 22 Dec 2021 22:08:10 +0000 From: "Daniel Shahaf" To: "Daniel Parks" , zsh-users@zsh.org Subject: Re: Strange behavior when calling select-a-shell-word multiple times from the same user-defined widget Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Seq: 27436 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: [ -workers@: see at the end ] Daniel Parks wrote on Wed, 22 Dec 2021 21:20 +00:00: > I'm trying to write a function that selects the nth argument in the > buffer. I would use it like `3gva` to select the 3rd argument. > > Here's the widget I have so far: > > function select-n-shell-word { > if [[ -z "$NUMERIC" ]]; then NUMERIC=3D1; fi > zle vi-beginning-of-line > zle visual-mode > zle select-a-shell-word > for ((i =3D 1; i < $NUMERIC; i =3D i + 1)); do > zle deactivate-region > zle vi-forward-char -n 2 > zle visual-mode > zle select-a-shell-word > done > } > zle -N select-n-shell-word > bindkey -M vicmd "gva" select-n-shell-word > Adding =C2=AB-N=C2=BB to both select-a-shell-word calls does the trick. While here, you can simplify the function a bit. For one, you could use a =C2=ABrepeat=C2=BB loop =E2=80=94 its repeat count is a math expressio= n, so you can actually do =C2=ABrepeat "NUMERIC - 1"; do =E2=80=A6; done=C2=BB =E2=80=94= but I'm not sure why you select-a-shell-word more than once. Why not just this: select-n-shell-word() { CURSOR=3D0 repeat "${NUMERIC:-1} - 1" zle vi-forward-word zle visual-mode zle select-a-shell-word -N } =C2=ABCURSOR=3D0=C2=BB is not equivalent to =C2=ABzle vi-beginning-of-li= ne=C2=BB when there's a literal newline in $BUFFER. Pick what you prefer. Using =C2=ABrepeat=C2=BB rather than =C2=ABzle =E2=80=A6 -n=C2=BB to han= dle the case (( NUMERIC =3D=3D 1 )) correctly. > Aside: =C2=ABrepeat 'foo+1'=C2=BB works, but =C2=ABrepeat '$foo+1'=C2=BB= (with single quotes) errors: . zsh: bad math expression: operator expected at `foo + 1' . So, apparently, the repeat count word does not undergo parameter interpolation before being parsed as a math expression, the way =C2=AB$((=E2=80=A6))=C2=BB expansions do. [To see the last bit, try =C2= =ABs=3D'1+1'; echo $((s*2)) $(($s*2))=C2=BB.]