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.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 16968 invoked from network); 2 Jun 2022 10:43:29 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 2 Jun 2022 10:43:29 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1654166609; b=FLwOsRD3WjHu4n5uOT4wFgNcW0UPatoH/kuMb75YccX82FstShGjAKJflYTecX8pLeRI1WDkmI LTARljOPRFSxbsogR3tjnc9MCBnbKzK7aGRltl+Sx1PB9ksDA4r46eG1kb0T1yz1EfgyNZGpv9 fjcZ3X4sC3DFM2qQxU2PNPbKVsOd0jbZp+59uO6M9lbPuJP0F2h+0R30bVtEwDlRCdsYI2tGjr QPOKZ6gJg9kN4BVbpyGnLN4jd5x4whnNKYEswASe2feAQc3zY9U4T6bmGbNPpWVAnUAJkpUGRk oK+zzeJ961CLqMCYaKgVNUn+P4lMojsjUhFxBGOyoz8J/A==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (wout2-smtp.messagingengine.com) smtp.remote-ip=64.147.123.25; dkim=pass header.d=daniel.shahaf.name header.s=fm3 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=1654166609; bh=En+9tyQCRGOpMQJLPoz16DWJWogQnJNz00aFOyyxjaQ=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:To:From:Date:DKIM-Signature:DKIM-Signature:DKIM-Signature; b=nhCN9TfpWJpUg8v6i4ZE9JENqZD3YTIkSlOqXwuzkcAdvU24fto/DHba++AZZ70gdHuAIbXkqH d/1JgPVzwHNZUaVMu4jJo3Kxmd3BhbcOdF7xFiMbqCuAksCXvgROUHjmSJGAsseAv2fSaMHB6w xkw92keRxvaUA8dnGn4y5rByiAuucDfzMMPAhNLl8zBeYk10zYOrjm8Ghv/8ypMBoRRduMv1hR VMSzyAUzhyhLPvCqFqXj8cHnqI+FxAOCW3HlatKE6m6V2ylpT76KjH1gufgjgpxH5OvBj5g8jt v4RuzBpbF/p0zKRVwi1PLvw/gOiyIH7zzmTE02KOchcEYQ==; 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:In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:To:From:Date:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=pxbpL1wdyLeziIMi65IjmVWfT+euHyyemInJUY8e4cA=; b=FESEVqv8bvU3uVXJd8lOzD8ouQ u5BAsvoZr1IOwUOYU5zfFnZ8U7g961XDVzLMGu45z+cTH0cMSDc2QBAZ2ioJOyDp5oZ2rhFUC8f5E RnpC0YUGya4smii98V9L3WakHkHoY523SF6bZYjxKhwtKDuTKAXMeKGDaimfj9m8pvrl+KbAEuESC uvMpVbE9W+LmG4VZWX478GYilSnmL+SKx5V3kLnf7s5tIkvChAlo1RNG91tA0QxSzgRjE5DJ6425G S7okP8Sb9vfoSfeomT0n/3gpp+iW/cCI8cZq3Z6yP2uMqYPOq6EBIPBXpULOQ40c2/dr14yMQ6TtV OvjmBtkQ==; Received: from authenticated user by zero.zsh.org with local id 1nwiIa-000DyP-80; Thu, 02 Jun 2022 10:43:28 +0000 Authentication-Results: zsh.org; iprev=pass (wout2-smtp.messagingengine.com) smtp.remote-ip=64.147.123.25; dkim=pass header.d=daniel.shahaf.name header.s=fm3 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 wout2-smtp.messagingengine.com ([64.147.123.25]:44425) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1nwhv2-000CA9-Rr; Thu, 02 Jun 2022 10:19:09 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 435173200970; Thu, 2 Jun 2022 06:19:07 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Thu, 02 Jun 2022 06:19:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=cc:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1654165146; x= 1654251546; bh=pxbpL1wdyLeziIMi65IjmVWfT+euHyyemInJUY8e4cA=; b=I rH6ezv2yGISyo+fMmAWaZJgknVa5S5zldfCIwr49lOPc4qDGFH1gvm9+8WIQPfNo hSP18s1bCbSM0xTaMRXgvjzyUsqij/TQ+s4MqzHlxKsmBxIZpLpg4eX5LUdfEuTz W8ch4ofBliWDY+522Tiwy+eyX+yCrqVmytBymYL3KcjwxwFvlIR6/vqoG2NfbOhz miVQUWOWdtmb3pidMKKNiaSvC7JhYmuk4bNbvseYo2qxBYacZCy7e+zwVFZwee68 gvxxWTYQeU8kG2RVwdOlTsKXZPKhRgdHoxs8B1FKe1ksa8CoApzP+E2cxeSZxbiR aL1VwOJ9VvhF9+sGtQ0FQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1654165146; x=1654251546; bh=pxbpL1wdyLeziIMi65IjmVWfT+eu HyyemInJUY8e4cA=; b=HBm/DMSBodR2ajO16zW41ZZrI3iw+wxQ3hjEwnK88b4N W5OjGCOyV1Q+42HL+Pq3H0ghJAux2EFVqekjgwe5JNrACejmikRGlI/wHko4Xojm dON66kNi13vIwqw1yRc3ubQOoy9yjJZf/azw9U2togOYWeUPnSQ+hJ2o45lv0fkX gAwkvL14o4l40bjkv4GLQuEiPv932hUsqHq9xgYv6gKsDfTcdVWr35WJdbZJ4DV3 Q6ZY1MIyM9JNJ1k8l5twaVb/hbnVHNg5F4ceFVOYQbHbISYVlOwMdop0hmuZ0U/X jHc8CUWyo8uxQi5iSpsSTihfB5fmlM1I8KOSLie5gA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrledvgddvgecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjfgesthdttd dttdervdenucfhrhhomhepffgrnhhivghlucfuhhgrhhgrfhcuoegurdhssegurghnihgv lhdrshhhrghhrghfrdhnrghmvgeqnecuggftrfgrthhtvghrnhepueevkeefffeufeehfe fhgefffedviedthedtgeeljeelvdeihfevjeefteegvdeknecuvehluhhsthgvrhfuihii vgeptdenucfrrghrrghmpehmrghilhhfrhhomhepugdrshesuggrnhhivghlrdhshhgrhh grfhdrnhgrmhgv X-ME-Proxy: Feedback-ID: i425e4195:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 2 Jun 2022 06:19:06 -0400 (EDT) Received: by tarpaulin.shahaf.local2 (Postfix, from userid 1000) id 4LDMS91R4Bz222; Thu, 2 Jun 2022 10:19:05 +0000 (UTC) Date: Thu, 2 Jun 2022 10:19:05 +0000 From: Daniel Shahaf To: zsh-users@zsh.org Subject: Re: prevent some lines directly coming from the history from being executed Message-ID: <20220602101905.GE28173@tarpaulin.shahaf.local2> References: <20220526143602.GA1236826@zira.vinc17.org> <20220526155329.GF19001@tarpaulin.shahaf.local2> <1936193667.415066.1653581604546@mail2.virginmedia.com> <20220528000720.GB1236826@zira.vinc17.org> <20220528100639.GB29128@tarpaulin.shahaf.local2> <41f13468-b9b9-4b64-845a-aadbcc3b8472@www.fastmail.com> <1388910908.482590.1653901645100@mail2.virginmedia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1388910908.482590.1653901645100@mail2.virginmedia.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Seq: 27833 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: v3. This should incorporate all feedback up to this point. Cheers, Daniel diff --git a/Doc/Zsh/zle.yo b/Doc/Zsh/zle.yo index 2d033a0a1..7266aa80a 100644 --- a/Doc/Zsh/zle.yo +++ b/Doc/Zsh/zle.yo @@ -746,16 +746,67 @@ ifnzman(noderef(Standard Widgets)). Other built-in widgets can be defined by other modules (see ifzman(zmanref(zshmodules))\ ifnzman(noderef(Zsh Modules))\ -). Each built-in widget has two names: its normal canonical name, and the -same name preceded by a `tt(.)'. The `tt(.)' name is special: it can't be -rebound to a different widget. This makes the widget available even when -its usual name has been redefined. +). User-defined widgets are defined using `tt(zle -N)', and implemented as shell functions. When the widget is executed, the corresponding shell function is executed, and can perform editing (or other) actions. -It is recommended that user-defined widgets should not have names -starting with `tt(.)'. + +cindex(widgets, shadowing standard) +cindex(widgets, overriding standard) +cindex(shadowing standard widgets) +cindex(overriding standard widgets) +User-defined widgets may shadow (override) standard widgets: for instance, +after `tt(zle -N self-insert) var(myfunc)', any invocation of the standard +tt(self-insert) widget (including every keypress that appends an alphanumeric +or space character to the command line) would invoke the user-defined +function var(myfunc) rather than the standard implementation of that widget. + +In order for the standard implementations to be available to be called by +user-defined widgets or bound to keypresses even when shadowed, +each standard widget `var(foo)' is also available under the +name `tt(.)var(foo)'. +These names are reserved and cannot be created as user-defined widgets, +so for compatibility with possible future revisions of the shell, +it is recommended that users avoid naming widgets with a leading `tt(.)'. + +Continuing the example, var(myfunc) would typically invoke the built-in widget +it is replacing using the dot-prefix syntax. For instance: + +em(Example #1) + +example(self-insert-vowels-twice+LPAR()+RPAR() { + [[ $KEYS == [aeiou] ]] && zle .self-insert -- "$@" + zle .self-insert -- "$@" +} +zle -N self-insert self-insert-vowels-twice) + +This example causes vowels to be inserted twice. For instance, typing +`tt(hello)' would insert `tt(heelloo)'. + +Note the use of the dot-prefix syntax. If the tt(self-insert) widget had been +invoked without the dot DASH()- that is, as `tt(zle self-insert -- "$@")' DASH()- +then tt(self-insert-vowels-twice) would have been called again, effecting +a bottomless recursion. + +em(Example #2) + +In a similar way, to perform a final action on all lines returned from Zle, +the tt(accept-line) widget can be rebound to a function that performs an action +on the current line, then calls the tt(.accept-line) widget to return the line +to the shell. For example, to change the default behaviour that pressing +tt() on an empty line redraws the prompt (and runs tt(precmd) hooks, +if any are configured), one may override accept-line as follows: + +example(accept-non-empty-lines+LPAR()+RPAR() { + [[ -z $PREBUFFER && -z $BUFFER ]] || zle .accept-line -- "$@" +} +zle -N accept-line accept-non-empty-lines) + +The special parameters used by these examples DASH()- tt($KEYS), +tt($PREBUFFER), and tt($BUFFER) DASH()- are documented in the next +section. + texinode(User-Defined Widgets)(Standard Widgets)(Zle Widgets)(Zsh Line Editor) sect(User-Defined Widgets)