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 10535 invoked from network); 15 Apr 2021 21:36:13 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 15 Apr 2021 21:36:13 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1618522573; b=lPkuvoTDFT+AJZrdCqEklbUdfkNmKidxJDk3SztWheHRALAbDiInwwF0L+kB4lHd4wQAScDrcM 0UNM7tL6/JidodAg5iE39HtwxnbKFxQ80hgXERN1eRm9SFftJLQuM/mGD5M1EswxL06b6nY4s2 fNPSkl/J6Y20BqpS9bBhCqT1E5xAPi/c26HEY39kNRTwGWnqTzX/vzc/Pqf5yIeRY93NhqzCwj 6XTDI0JFhNrme8DlAKCjMJzIZZunY6rVSIcKmPnLHejHZ/mJe2KMeoamG0lLB2P+rg1L0PdpLo RSeRwtQF59zLCWqdg5NE+HbMWK2Ds9Lz0TyNms2ftgCtag==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (out3-smtp.messagingengine.com) smtp.remote-ip=66.111.4.27; dkim=pass header.d=daniel.shahaf.name header.s=fm3 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm2 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=1618522573; bh=DqK/Ypk+1+kHd9etkftFWxcnHNFj6brG5Hsg9dlhka4=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:DKIM-Signature: DKIM-Signature:DKIM-Signature; b=E2bL3rLnDU0by3m22nqORwuL35KyiUHZOqKYWyfdQ4yY86J4SQb+RliruHcJd4ejLHAYcy1eCW QLS3nguB6Yv0BU7jJU9j4ovRi3kyupcPNz4L+0Kn79DXGRcdYyFOSq2PlXzNEjhYDT7ACSltHG aO+R765BU/9wJRvwVuAFZXmDU9Rxu8N6ziIjEQzLpaMhKKbpNcxldcgKIMbHOhetE/+vb4L84y Zn4y3hX3B+rTm4Yrf7RU+P8xF9k2/rANbCGBqzRTF48t/yc5mfZJJYCSHjzqh1H2IuKPibNHOv 3tgalLSJrPp3m1vfgYYkIAMgF6Zx6ngDp/EZb6BlHPaIpw==; 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:In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References: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=1Dqjg4m/sWOYm4/4kNfbSu+FWTms1ys5GH3DOgF+nyM=; b=QbUfoFpwrfO2MGPDLMQ/eInlh9 WsPU72aLA5t6faUsvRSr0AdwgvoadEKSEjtTgUy3fNxh/FKvdI/8ci+Gywzb6aJopbhR2lltcxyUd 0B/0diDNvFiuZaGytiSmgz5tG4Qtay+LhHcCPbSlxnwz5DVhfLJQtQakV1YrnudopmS6KKHYj99ZA QgjmJCsfi/naTt6fTMn6mIktMtnEFSjA3vJfzhVkqlIOABcrQPlUblrK4TGjTfN6QFvl2s9INMb83 0GxjGXzsFT8cGIy2Ii8PBlvJygSzLnOqVzl/c/6dJ30oAGEzCsF/opBeo3qm1qH09WoHZOUDQLclj ShopMHJg==; Received: from authenticated user by zero.zsh.org with local id 1lX9ej-00028G-VN; Thu, 15 Apr 2021 21:36:10 +0000 Authentication-Results: zsh.org; iprev=pass (out3-smtp.messagingengine.com) smtp.remote-ip=66.111.4.27; dkim=pass header.d=daniel.shahaf.name header.s=fm3 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm2 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none Received: from out3-smtp.messagingengine.com ([66.111.4.27]:58955) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1lX9dc-0001SE-UN; Thu, 15 Apr 2021 21:35:02 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 550D85C0153; Thu, 15 Apr 2021 17:34:59 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 15 Apr 2021 17:34:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=date:from:to:cc:subject:message-id :references:mime-version:content-type:content-transfer-encoding :in-reply-to; s=fm3; bh=1Dqjg4m/sWOYm4/4kNfbSu+FWTms1ys5GH3DOgF+ nyM=; b=Ya21v5UCYHj9znewAgBh+2g/5HM60RlxcA+z7rm/JLe/AWAHQNiYOsY4 awrb61gQc9OsSRCwEUb7cwecjBNzx9p+aL32agogGGPqEShppgnCrK/FFHHP9Xyp zfk5dop+KYdSy1jZx6+8B28IiWIEul91pkOC4unn+mwMDC10J33+63U8QYDUh92i I2FA40K6m7nChNIxmTt+j2tEuwXSgRSAAkH0vRAmb2bMFv3mbPZW+qCmBCRZVlo0 SgtOz6apglRTj16gICXhSDLAdn4S12zspV9+fvWfxzeN5TRzY/KOQADmJTWI7pql 6BJxsRViR1LDsbQAPKe2hACON/T8yQ== 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=fm2; bh=1Dqjg4m/sWOYm4/4kNfbSu+FWTms1ys5GH3DOgF+n yM=; b=og+QBubgnqq1pGhlODdgPPKDZKQ9Xax0vXSqSkIs5kcgFsgEy7Qs1IJ/d ZkKHUL8jtojLG0z75WaFcescquv9/FTsILbLvoCL6cYS3fokC/Plx8uB2dDyizbw O1N78Jvwtj0Mm2B00kuTJ1RsoNdOFZeItQfh6smO8zGACKw07CIgONinqRNg45m3 yIFKvpqhJzzXGe54pTsLhAR2W/8V/ZyIESKkFCmgiRZIS0gSk/C4yIn6Oa4VlX6S scXyuUQ+ugdYtCEu9MiKctbhZRddUeQ3xb59ctFYSFOg+Sx39MpJBLF5agZU70M2 cS42PMc6BsRnxw1oN5tfGo63IMigA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudelgecutefuodetggdotefrodftvfcurf hrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtugfgjggfsehtkedttd dtreejnecuhfhrohhmpeffrghnihgvlhcuufhhrghhrghfuceougdrshesuggrnhhivghl rdhshhgrhhgrfhdrnhgrmhgvqeenucggtffrrghtthgvrhhnpefgkefgfeejgfdvvdfgud dtleelkedvfeetiedtudfhveevveduhfdvveeffedvueenucfkphepuddtledrieeirdei fedrvdeftdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpegurdhssegurghnihgvlhdrshhhrghhrghfrdhnrghmvg X-ME-Proxy: Received: from tarpaulin.shahaf.local2 (bzq-109-66-63-230.red.bezeqint.net [109.66.63.230]) by mail.messagingengine.com (Postfix) with ESMTPA id D8776240054; Thu, 15 Apr 2021 17:34:58 -0400 (EDT) Received: by tarpaulin.shahaf.local2 (Postfix, from userid 1005) id 4FLt0c42s4z3dR; Thu, 15 Apr 2021 21:34:56 +0000 (UTC) Date: Thu, 15 Apr 2021 21:34:56 +0000 From: Daniel Shahaf To: Marlon Cc: Zsh hackers list Subject: Re: [RFC][PATCH] Reset ZLE hooks when changing prompt themes (was Re: [RFC][PATCH] `newuser` prompt theme) Message-ID: <20210415213456.GE6669@tarpaulin.shahaf.local2> References: <7E71FA83-356E-448B-9726-02DF3FF5BD14@gmail.com> <873D08A9-F321-474A-8440-CCE7DCCBA529@gmail.com> <20210414120551.GA3882@tarpaulin.shahaf.local2> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Seq: 48595 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: Marlon wrote on Thu, Apr 15, 2021 at 21:54:48 +0300: > Patch attached, but not yet including Daniel’s suggested change below (since I still have questions about it). It includes an update to the docs, but note that I am not able to build those myself. I would much appreciate it f someone else could do that to test whether I did it correctly. > > On 14 Apr 2021, at 15:05, Daniel Shahaf wrote: > >> +++ b/Functions/Prompts/promptinit > >> @@ -178,8 +177,13 @@ Use prompt -h for help on specific themes.' > >> > >> # Reset some commonly altered bits to the default > >> local hook > >> - for hook in chpwd precmd preexec periodic zshaddhistory zshexit; do > >> - add-zsh-hook -D "${hook}" "prompt_*_${hook}" > >> + for hook in chpwd precmd preexec periodic zshaddhistory zshexit \ > >> + zsh_directory_name; do > >> + add-zsh-hook -D "$hook" "prompt_*_$hook" > >> + done > >> + for hook in isearch-exit isearch-update line-pre-redraw line-init \ > >> + line-finish history-line-set keymap-select; do > >> + add-zle-hook-widget -D "$hook" "prompt_*_$hook" > > > > All these should be documented, like prompt_${foo}_preview is. > > > > Recommend to name these prompt_${foo}_bar-{isearch-exit,isearch-update,…,keymap-select} > > for some fixed value of «bar» to avoid namespace issues (i.e., name > > collisions between existing prompts and future hooks). > > Wouldn’t that be a breaking change in the API, though? No, it wouldn't, because those are add-zle-hook-widget hooks and the current API only deals with add-zsh-hook hooks. We could even recommend that add-zsh-hook hooks be named prompt_${foo}_baz_{chpwd,…} for some fixed value of baz. We don't even have to change the code to support this (because the asterisk will match «${foo}_baz» just fine); we just need to document the recommendation and deprecate the previous recommended naming pattern. > I mean, there are already 3rd party prompt themes that use the current prompt_${foo}_{isearch-exit,isearch-update,…,keymap-select} naming scheme. And you're arguing that avoiding breaking code of third parties that relied on a patch that (presumably) hadn't even been posted to -workers@, never mind merged to master and released in a stable release, trumps preventing namespace collisions for future users? > Also, isn’t the prefix prompt_${foo}_ already a namespace of sorts? Why change this? What if the foo theme declares a function called prompt_foo_lorem (or even prompt_foo_ipsum_lorem) that _isn't_ an «add-*-hook lorem» hook function, and later we start to to auto-register functions matching the name pattern? Or if we were to make «add-zsh-hook bar lorem» and «add-zle-hook-widget bar ipsum» both valid, for a single value of bar, and a prompt theme wanted to install both hooks _and_ name the functions «lorem» and «ipsum» conventionally? Or if someone wanted to quickly grep for add-zle-hook-widget callbacks? > From b60bfd135ae2631a3b28aaf81074594d0ec1f967 Mon Sep 17 00:00:00 2001 > From: Marlon Richert > Date: Thu, 15 Apr 2021 21:50:36 +0300 > Subject: [PATCH] Reset ZLE hooks when changing prompt themes > Your mail didn't trigger workers/48587 (that's good). I wonder why. Probably because your MUA quoted-printable-escaped the first byte of the From_ line. > +++ b/Doc/Zsh/contrib.yo > @@ -2032,10 +2032,10 @@ setopts (tt(promptbang), etc.) are turned on, all other prompt-related > options are turned off. The tt(prompt_opts) array preserves setopts even > beyond the scope of tt(localoptions), should your function need that. > ) > -item(Modify precmd and preexec)( > -Use of tt(add-zsh-hook) is recommended. The tt(precmd) and tt(preexec) > -hooks are automatically adjusted if the prompt theme changes or is > -disabled. > +item(Modify hooks)( > +Use of tt(add-zsh-hook) and tt(add-zle-hook-widget) is recommended. All hooks > +that follow the naming pattern tt(prompt__) are automatically This should be tt(prompt_)var(theme)tt(_)var(hook). > +removed when the prompt theme changes or is disabled. Add a pointer to the relevant section? Something like . ifzman(… Manipulating Hook Functions … above)ifnzman(noderef(Manipulating Hook Functions)) . plus appropriate markup in the first branch. > +++ Functions/Prompts/promptinit > @@ -14,6 +14,8 @@ prompt_themes=() > promptinit () { > emulate -L zsh > setopt extendedglob > + autoload -Uz add-zsh-hook add-zle-hook-widget > + > local ppath='' name theme > local -a match mbegin mend > > @@ -32,9 +34,6 @@ promptinit () { > fi > done > > - # To manipulate precmd and preexec hooks... > - autoload -Uz add-zsh-hook > - > # Variables common to all prompt styles > prompt_newline=$'\n%{\r%}' > } > @@ -178,8 +177,13 @@ Use prompt -h for help on specific themes.' > > # Reset some commonly altered bits to the default > local hook > - for hook in chpwd precmd preexec periodic zshaddhistory zshexit; do > - add-zsh-hook -D "${hook}" "prompt_*_${hook}" > + for hook in chpwd precmd preexec periodic zshaddhistory zshexit \ > + zsh_directory_name; do > + add-zsh-hook -D "$hook" "prompt_*_$hook" > + done > + for hook in isearch-exit isearch-update line-pre-redraw line-init \ > + line-finish history-line-set keymap-select; do > + add-zle-hook-widget -D "$hook" "prompt_*_$hook" > done > typeset -ga zle_highlight=( ${zle_highlight:#default:*} ) > (( ${#zle_highlight} )) || unset zle_highlight Hmm. I'm not at all sure that this is sufficient. There's a bunch of reference to precmd and preexec in promptinit; it's possible that some of these should also handle chpwd,periodic,zshaddhistory,zshexit (a preëxisting issue) and the add-zle-hook-widget hook classes (an issue this patch might be introducing). Cheers, Daniel