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=-2.2 required=5.0 tests=DKIM_ADSP_ALL,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 21951 invoked from network); 25 Jan 2021 15:14:15 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 25 Jan 2021 15:14:15 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1611587655; b=RoOVJ4Eo+HTTierPZknDLEadVdkRyKVqH2t828qRVnqVyUZsJO9UaAKtthFlAmU5lJurqRpDjs qZtoEtZUNaq37I/db/bjehq7P3hwJ9CBakPxses0ZXm3SqQ5uGmnAUU2tJkEDqeKdayQR9kqsu l9/0rzVhiKFnQDPjsXYXBMUtlYOx9bURB9P5QFoHIn9jjTvafcuzlPAOWOQudbyqdTIu2lvqBY AHwz5RqURBITGEBdOTzP5j7vHE74MA/AKCocVtPyH1eeUf8KcyRvLSUXP8arRjab2ij/t/KG1J opU2MU1ASmurXke9kj6frfpSO2TXNmUCco0954Pm7G8PVw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail.cs.msu.ru) smtp.remote-ip=188.44.42.39; dkim=pass header.d=cs.msu.ru header.s=dkim header.a=rsa-sha256; dmarc=pass header.from=cs.msu.ru; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1611587655; bh=0Eg3vzreSmkn4zzTqFLUFeaP7bg+SdhyhVZYtlnZdr4=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Subject:In-Reply-To:Content-Type:MIME-Version:References: Message-ID:To:From:Date:DKIM-Signature:DKIM-Signature; b=CeocwNe5/wHTWfQaXEIJGBu+uzAtYoYHkX6vvNPvV/nRDbJR5S8RYXrMjcZrKBczSmCCbFY8XM H82vmO1SAGDIHg143gLxMdYPVveCL7QIbvd2gBMzA0/PKuK38Ipijbq2yxBEHHwvAWCrmr4pN2 OPGFznIuJk1GWlG6fmToX2EA4rlM1b+op6pISc52FKoPfnAsgJzMRGt/WukRj8W7987c1P0Dvv MLH19m3GSULc/kcmrF/e5FMd+vqhSuLn9Riz9gPMbGg6pobKJoFPK6utEFPfoEeY648ap8QAnJ wrCe66eirWAeFhTEbbgijoF1N6WLpq3c6cuugZILm0Fecg==; 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:Subject:In-Reply-To:Content-Type: MIME-Version:References:Message-ID: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=Qm5j4rAyipmiLuR2LfPGPmMJl4bu0L3rhW1atYpuUaw=; b=DsudYgAzYmG4UV1sWsEZPgLe5D 7PKww0kvU+XoX5ZVBuBdxiH/PfQLq/JGPOScNfwNIwCVq5x1/UXGI/05alAIPmRXgUUNCEkrvojqU 710AdZBb6ksdxsnrQbhWGQGZ76Gvqot7TMfAqC/DozzbQpotA/siptg9bKDtdLrjXnsjQQ2pfRJ38 u4yThc1/KdEJl7JmoIbn8eLKEu7QdbdDH9AGSUG640tlAoWLICMuZms6iIQmYo3iERbvYDvVlBHJr JH4TgrutMcrYb2IAWkOuNMDuY4g0hzz6N9Lso0cNbOmwspySYoAryXtauha/ii+NbzzBB2p1A3IP9 ZsX+1HtA==; Received: from authenticated user by zero.zsh.org with local id 1l43ZG-000Huu-9e; Mon, 25 Jan 2021 15:14:14 +0000 Authentication-Results: zsh.org; iprev=pass (mail.cs.msu.ru) smtp.remote-ip=188.44.42.39; dkim=pass header.d=cs.msu.ru header.s=dkim header.a=rsa-sha256; dmarc=pass header.from=cs.msu.ru; arc=none Received: from mail.cs.msu.ru ([188.44.42.39]:46654) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1l43Z4-000HmB-BK; Mon, 25 Jan 2021 15:14:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=cs.msu.ru; s=dkim; h=Subject:In-Reply-To:Content-Type:MIME-Version:References:Message-ID :To:From:Date:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Qm5j4rAyipmiLuR2LfPGPmMJl4bu0L3rhW1atYpuUaw=; b=Z1tGWACLR6BjfMaZ/ezExzhLEh kgQfjHMZd/jUyL/rmV9DUm8lEsg0vRdZm+6ZbnwotOHD2gW5M6B2CReGx+H/vNxoisM2D2jqFLqOD fgF4VNZZ/ON/5N1ce+C6XUsSBAOjcbivpgpjZfcMTq3rWVnXGvf3vATKvTlzKUoYoYj76Ftm5sL6V wemgcZ2r9z7LDVR09bw2afCD/2gzLm6/p6B2DgGlV2Copa+C0NFhd740blLPGUndlPjlDICpVykM+ 7gIHNOKHA1g0HZiCqsw/PpiR/dVsjq8kW3e5N+rKJNemJaQzGwbFeZSN3cEoWV4CDI/RnHWPeO62L XZeYH5cA==; Received: from [37.204.119.143] (port=55310 helo=cello) by mail.cs.msu.ru with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94 (FreeBSD)) (envelope-from ) id 1l43Z3-0002yk-Db for zsh-workers@zsh.org; Mon, 25 Jan 2021 18:14:01 +0300 Date: Mon, 25 Jan 2021 18:14:00 +0300 From: Arseny Maslennikov To: Zsh hackers list Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="ZPxKtbGfJ9CvW+cr" Content-Disposition: inline In-Reply-To: OpenPGP: url=http://grep.cs.msu.ru/~ar/pgp-key.asc X-SA-Exim-Connect-IP: 37.204.119.143 X-SA-Exim-Mail-From: ar@cs.msu.ru Subject: Re: PATCH: Invoke prompt cleanup hooks when changing prompt X-SA-Exim-Version: 4.2.1 X-SA-Exim-Scanned: Yes (on mail.cs.msu.ru) X-Seq: 47874 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: Archived-At: --ZPxKtbGfJ9CvW+cr Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Jan 25, 2021 at 03:41:42PM +0300, Arseny Maslennikov wrote: > On Tue, Jul 07, 2020 at 01:50:04PM +0200, Roman Perepelitsa wrote: > > The documentation for promptinit states that themes can install > > cleanup hooks via prompt_cleanup. > >=20 > > > If your function makes any other changes that should > > > be undone when the theme is disabled, your setup function > > > may call > > > > > > prompt_cleanup command > > > > > > where command should be suitably quoted. If your theme > > > is ever disabled or replaced by another, command is > > > executed with eval. > >=20 > > The documentation also states that: > >=20 > > > The precmd and preexec hooks are automatically > > > adjusted if the prompt theme changes or is disabled. >=20 > I understood that in terms of workers/30087: the theme "foo" may define > prompt_foo_precmd and prompt_foo_preexec, which are removed from the > respective arrays if the prompt theme is deactivated. >=20 > It would probably make sense to do something like >=20 > (( $+functions[prompt_$name_precmd] )) && > [[ -n ${precmd_functions[(r)prompt_$name_precmd]} ]] && Sorry, not "-n", but "-z" to invert the meaning. > precmd_functions+=3D(prompt_$name_precmd) >=20 > automatically on theme activation, though =E2=80=94 to match the above. >=20 > >=20 > > If I understand it correctly, this implies that the following script > > should print "cleanup" and shouldn't print "hook". > >=20 > > autoload -Uz promptinit > > promptinit > > prompt_foo_setup() { > > prompt_cleanup 'print cleanup' > > precmd_functions+=3D(hook) > > } > > prompt_themes+=3D(foo) > > prompt foo >=20 > Consider the following right here: >=20 > precmd_functions+=3D(func1 func2) > > prompt off > > print -r -- $precmd_functions > >=20 > > It doesn't print "cleanup" and does print "hook". >=20 > As per what you suggest, user-supplied precmd functions, which > were set after prompt theme activation =E2=80=94 in that example func1 and > func2 =E2=80=94 will be unhooked as well. I doubt this is what users want. >=20 > >=20 > > I'm attaching a patch that does what I believe the documentation > > describes. I'm not very confident that I understood the documentation > > or that my patch is correct. > >=20 > > Roman. >=20 > > diff --git a/Functions/Prompts/promptinit b/Functions/Prompts/promptinit > > index e27b8779a..a9850d35c 100644 > > --- a/Functions/Prompts/promptinit > > +++ b/Functions/Prompts/promptinit > > @@ -200,33 +200,37 @@ prompt_cleanup () { > > prompt () { > > local -a prompt_opts theme_active > > =20 > > - zstyle -g theme_active :prompt-theme cleanup || { > > - # This is done here rather than in set_prompt so that it > > - # is safe and sane for set_prompt to setopt localoptions, > > - # which will be cleared before we arrive back here again. > > - # This is also why we pass around the prompt_opts array. > > - [[ -o promptbang ]] && prompt_opts+=3D(bang) > > - [[ -o promptcr ]] && prompt_opts+=3D(cr) > > - [[ -o promptpercent ]] && prompt_opts+=3D(percent) > > - [[ -o promptsp ]] && prompt_opts+=3D(sp) > > - [[ -o promptsubst ]] && prompt_opts+=3D(subst) > > - zstyle -e :prompt-theme cleanup \ > > - 'zstyle -d :prompt-theme cleanup;' \ > > - 'prompt_default_setup;' \ > > - ${PS1+PS1=3D"${(q)PS1}"} \ > > - ${PS2+PS2=3D"${(q)PS2}"} \ > > - ${PS3+PS3=3D"${(q)PS3}"} \ > > - ${PS4+PS4=3D"${(q)PS4}"} \ > > - ${RPS1+RPS1=3D"${(q)RPS1}"} \ > > - ${RPS2+RPS2=3D"${(q)RPS2}"} \ > > - ${RPROMPT+RPROMPT=3D"${(q)RPROMPT}"} \ > > - ${RPROMPT2+RPROMPT2=3D"${(q)RPROMPT2}"} \ > > - ${PSVAR+PSVAR=3D"${(q)PSVAR}"} \ > > - "precmd_functions=3D(${(q)precmd_functions[@]})" \ > > - "preexec_functions=3D(${(q)preexec_functions[@]})" \ > > - "prompt_opts=3D( ${prompt_opts[*]} )" \ > > - 'reply=3D(yes)' > > + zstyle -g theme_active :prompt-theme cleanup && { > > + local -a reply > > + eval "$theme_active" >=20 > Nit: `prompt restore' opts to call `zstyle -t :prompt-theme cleanup' to > do this. >=20 > > } > > + > > + # This is done here rather than in set_prompt so that it > > + # is safe and sane for set_prompt to setopt localoptions, > > + # which will be cleared before we arrive back here again. > > + # This is also why we pass around the prompt_opts array. > > + [[ -o promptbang ]] && prompt_opts+=3D(bang) > > + [[ -o promptcr ]] && prompt_opts+=3D(cr) > > + [[ -o promptpercent ]] && prompt_opts+=3D(percent) > > + [[ -o promptsp ]] && prompt_opts+=3D(sp) > > + [[ -o promptsubst ]] && prompt_opts+=3D(subst) > > + zstyle -e :prompt-theme cleanup \ > > + 'zstyle -d :prompt-theme cleanup;' \ > > + 'prompt_default_setup;' \ > > + ${PS1+PS1=3D"${(q)PS1}"} \ > > + ${PS2+PS2=3D"${(q)PS2}"} \ > > + ${PS3+PS3=3D"${(q)PS3}"} \ > > + ${PS4+PS4=3D"${(q)PS4}"} \ > > + ${RPS1+RPS1=3D"${(q)RPS1}"} \ > > + ${RPS2+RPS2=3D"${(q)RPS2}"} \ > > + ${RPROMPT+RPROMPT=3D"${(q)RPROMPT}"} \ > > + ${RPROMPT2+RPROMPT2=3D"${(q)RPROMPT2}"} \ > > + ${PSVAR+PSVAR=3D"${(q)PSVAR}"} \ > > + "precmd_functions=3D(${(q)precmd_functions[@]})" \ > > + "preexec_functions=3D(${(q)preexec_functions[@]})" \ > > + "prompt_opts=3D( ${prompt_opts[*]} )" \ > > + 'reply=3D(yes)' > > + > > set_prompt "$@" > > =20 > > (( ${#prompt_opts} )) && >=20 --ZPxKtbGfJ9CvW+cr Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEE56JD3UKTLEu/ddrm9dQjyAYL01AFAmAO4C0ACgkQ9dQjyAYL 01B16g/+Ne+mv82aDzjOtJOCqUnNeqkwPDxiJ+aXcp8oqCDqbBiJIG4aVNIxqdyF EbB0TcVY0k2VhvDCqr1lunVSk9VgijdTuBYdtX5J1Q6a0aNwX/Jln8dYq0mFAhBQ FA/e2l8NepTs2+UkAVnbPaEAdN1+UfTaD8ZzmEkd8xtDHPIg6f2C3J5ZVScjH0N7 fVsmFlMjdi9PBzsWLGE9WRHfzgaJIi9v63aLHxXgTV0bblSr9dcZzmi9drhpOC48 Q+Ry0yVM3lDEe8qSKQu4oe/1lG4Qv5nhm2n3lP3eLgEIbKOyJcHHjAa3uGCVAbaa L9DUgz+T/XnPpKIwFUosIx1eSeEtdwLszDPweY4jVWsBAGxO2dTC1HwhNWMhn6uf Ci+HBM6se0O3ishfyBIh86CQx4LwThM+DZLNPo+EEQlOwhB7FqWxz/40rfOJ+fMu uIIyaHJhVvL95Kca7zq4+8gdKN+lijMYfWMNQS/q6wXD4VFPW0A7DNfk3/x17wp9 ckPbyQKUk/jH9SLraqIMT0hHKieU30aB1kDk5Xf12lexAsspgfY1eZHGCJqkxCVI SuyJ8ttAR3KqJcRF8lp6JtTbjFbP5nPho6GFhPHVhscJ4RKlKNdRe18Kd86602+Z 6IoGeTK0FINTp7+rtuNgSyqfDLmFIWmA8KUI3euLR55F+7Gm+Ow= =NCa/ -----END PGP SIGNATURE----- --ZPxKtbGfJ9CvW+cr--