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 2636 invoked from network); 25 Jan 2021 12:42:03 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 25 Jan 2021 12:42:03 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1611578523; b=pzPsZfL+xeeamamd9zgF8dZ6NoXMkKAn10yLO9MRQ4Ome4vIOQ6zU3/T5ju9NYKN7mttPrVefK CyQMFyP8IX+uYky1VesFfFveVBZXF9HU/WPwSlZJhIu/Ufkvb/7CJXxILT803dm4xhPZgRieLb +Wejdoeb8vFZlw0TktAV3xyRzSxj9mfJ8Lw/vKz9mC1sMxsgyQQx6mOt7jfvw+awjtDAR4L2oh IyuRG4zCfj0PHIE5vURttB8HGBqUrUK09JcFrKCf/6uheWoG0yaGGOlZ4hUHRRjMbOO//CQjq3 n5qNcZNSHBxJ/lVZ9qtYAtJrsfM268644CanugEwJYNVVA==; 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=1611578523; bh=uH+6e7fBuSYTZiDGkCgexz9GQs9Bz0wZt4BoQSezhAw=; 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=icSWkhT99FVBuGmTbBmTL4OxiKxKmAWvV5PDcz4PNRZ9XsHEvhc2FoojZKhFCnZI2BeAXR8sEO khTKKl/k6XRlWXkQHSAMYDNOr6EaJMBA4dkwlRaGB4INgFN16yNwXnsOM/fwSktixtQ3FiiGVs zsW7f7d6Pt90F13ss81ou/yFtYV4kVQf12EkR93o6GZmXyQRivYRieprTzErbnv0vdkvVu8pO8 rop4CsuykMnuCJPNa4tdGW60ioslETXE76Qx2mlWvg6bDO/8VJST+OEvfmArtqoG+WpSFa4KoO g+HKyDpZH0MV0fkM4CD8B3Kcp/b76W6kgJABlG0Q95zTdw==; 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=prUj9D3RKFtE4dun3JEOR6hV4+NkjfuXDuvdQAxuehk=; b=c/8+LZbv+ChUp0mJe3yKHnXQWF +T4s6Lcw+2NFr37UQGugzE5X0KVGb310OsGt9Woz0gVTVp395LUd8OUtSZryvXWZycBCO2M0WK9qC XR4KU4lfb74e1vLkDzTKJSQQZIQ4r6oT0mxnB96+Dy04nrFebL9YNAaRqSKU6YRYtORPLcP/aoO7V AMSrq252YhWSUu1MuakpLav9ZO4V1EomMsBwJxX6IiKcVJlx3Q3QPyLmRT0TsoVXs0Sdgriblde8m VYDOqBxwuC1NYY2epArSgEiRQlThzq55itHG0oWteZoa5Sr+qqAvlZ4Ezmr/f5h1O13Wox90iJYVU hKwXBpyw==; Received: from authenticated user by zero.zsh.org with local id 1l41Bx-000Cdw-Qg; Mon, 25 Jan 2021 12:42:01 +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]:57036) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1l41Bm-000CVV-8y; Mon, 25 Jan 2021 12:41:51 +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=prUj9D3RKFtE4dun3JEOR6hV4+NkjfuXDuvdQAxuehk=; b=x0hFp1M/362fSMPWp4Unhgwed+ p1K+iC0G1KCY0muHqBAtlFq/EA+84xv5m1sBPlf9NlVZndKAy+ARjEBSnHP48R+ZJsOWjlbb31nem DLhTrCc41iQpoHxzLn8ficDjw8XEYM4dxyNtlfa6hiQNyTcMUjSJHFGY9euLyelsefjQimXV3o0rN MTIa3Q3e72kT6xUGHbwcw52M+qh9DMYduNBaDEolT+YJfcztjCorww54zShmQkx7xxbRBpF2e3PKU +CtaCeTKTEcGGxOId/agnJEOApF34LgPa3MGHEHjUFvFltuzSY1gTCD/EDSuVjRuc50jZ6PuwdqDl S2ffWjXg==; Received: from [37.204.119.143] (port=52174 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 1l41Bl-000ORJ-8i for zsh-workers@zsh.org; Mon, 25 Jan 2021 15:41:49 +0300 Date: Mon, 25 Jan 2021 15:41:42 +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="/pU07X3mxmOd6l12" 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: 47870 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: --/pU07X3mxmOd6l12 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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. 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. It would probably make sense to do something like (( $+functions[prompt_$name_precmd] )) && [[ -n ${precmd_functions[(r)prompt_$name_precmd]} ]] && precmd_functions+=3D(prompt_$name_precmd) automatically on theme activation, though =E2=80=94 to match the above. >=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 Consider the following right here: precmd_functions+=3D(func1 func2) > prompt off > print -r -- $precmd_functions >=20 > It doesn't print "cleanup" and does print "hook". 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 > 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. > 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" Nit: `prompt restore' opts to call `zstyle -t :prompt-theme cleanup' to do this. > } > + > + # 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} )) && --/pU07X3mxmOd6l12 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEE56JD3UKTLEu/ddrm9dQjyAYL01AFAmAOvHcACgkQ9dQjyAYL 01B8XA/+MZlbMzMoFaT1LBONP+YEH40flilHmbeLk7S/4t2E66fGx93ETd6GXksu Fanl6CBaYlUK/2zsrfEavicCmmwK0xmkG1w8voP8pHpy+8RW7XW/anPOfKkSaauw PnFtbZXC4jt2C75ha0/1TrZYZH6ncslh+00akBVIBALeWZ6DHaNnNCAySQzQntxc Skz6WPvFQRYIfF/qb7qeP2150PxCFZS/4c6/5msHl1x+c7v/robZwFBBOs+kDcIQ QFg4QQ/zvUq3tC4Y+KPqgM9owLE9C/N1AOhjiFYr+qyy5SJ/InY5AQudOv593eoW hWg3LQhnjj5QL5w7bjLn1KX6VMPA2Ob3vQvk4ZZL3kreR6KOfS+qIoAipQz0p+ju hjhisea3R8cJuRhMRhkR64Gb5mGHTSQS8dxmmAIyp7ENP061Yvs8Y0czYREMvxJ5 npcorkZlhEnhx9zji3mVrdNglSofjVjFNOoUL7tYL0sYkHcCIamEyZvHVZNTC4Gi OBX7CWEK9jgvpCRxpJsFH+3Gg030zXzeIbFSdmjmNU/CjCSi7sAlpEKfs5AfyuM3 R7LTtEgSHcmV7bn1RbO53u4YUh9rWgUCp/DdL9IIj3Sxl1p2ymNGferxzhBcL+/Q 5RUIlC1//+3ChM1jz7JIs1MjztL6x6NCyy5CiiPsjClU1Nr6CME= =yLrG -----END PGP SIGNATURE----- --/pU07X3mxmOd6l12--