From: Arseny Maslennikov <ar@cs.msu.ru>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: "zsh-workers@zsh.org" <zsh-workers@zsh.org>
Subject: Re: [PATCH 2/2] promptinit: Fix prompt cleanups
Date: Tue, 23 Feb 2021 01:24:27 +0300 [thread overview]
Message-ID: <YDQvG2hUq2455fQb@cello> (raw)
In-Reply-To: <CAH+w=7Zq_bfhb-eR8oSZ+EpGnu+y6sQsNs3nVsw3dY3WpLQHww@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3649 bytes --]
On Mon, Feb 22, 2021 at 10:29:52AM -0800, Bart Schaefer wrote:
> On Mon, Jan 25, 2021 at 12:17 AM Arseny Maslennikov <ar@cs.msu.ru> wrote:
> >
> > The promptinit framework fails to apply cleanup commands of the current
> > theme on any theme change other than "prompt restore", as well as when
> > invoking setup functions of a certain $theme as an implementation detail
> > of `prompt -[hp] $theme'.
>
> Thanks, I did have a chance to look at this.
>
> > We fix it in the following way, hopefully without breaking compatibility:
> > * Rename zstyle `cleanup' on the context `:prompt-theme' to `restore'
> > everywhere but in prompt_cleanup(). It is only used as a restore
> > mechanism now.
> > * Ensure prompt_cleanup() continues to store its command list in the
> > `cleanup' style.
> > * Clean up before theme switch at the end of set_prompt().
>
> These all seem fine, conceptually.
>
> > * Prepend every use of prompt_*_setup (which might modify the shell
> > state in ways that require cleanup) with a cleanup run.
>
> Have you confirmed that this is a no-op when there has not been a
> previous installation of a theme?
I double-checked right now; in that case, with the patch applied as
posted, it is a no-op when the command 'prompt -p' is invoked, but not
when 'prompt -h' is — the trap does not run. Thanks for the good catch!
The following diff on top of my patch fixes it:
--->8---
diff --git a/Functions/Prompts/promptinit b/Functions/Prompts/promptinit
index ab2b50857..5c7dcc5a1 100644
--- a/Functions/Prompts/promptinit
+++ b/Functions/Prompts/promptinit
@@ -105,9 +105,11 @@ Use prompt -h <theme> for help on specific themes.'
local +h PS1=$PS1 PS2=$PS2 PS3=$PS3 PS4=$PS4 RPS1=$RPS1 RPS2=$RPS2
local +h PROMPT=$PROMPT RPROMPT=$RPROMPT RPROMPT2=$RPROMPT2 PSVAR=$PSVAR
local -a precmd_functions preexec_functions
+ local theme_reset=''
else
- trap 'zstyle -t :prompt-theme cleanup; prompt_${prompt_theme[1]}_setup "${(@)prompt_theme[2,-1]}"' 0
+ local theme_reset='prompt_${prompt_theme[1]}_setup "${(@)prompt_theme[2,-1]}"'
fi
+ trap 'zstyle -t :prompt-theme cleanup;'"${theme_reset:+ $theme_reset}" 0
;;
esac
case "$opt" in
--------
>
> > * Adjust `prompt restore' to do both parts of the newly split restore
> > mechanism, cleanup first.
>
> Also fine. Just a couple of nit-picky things about the diff itself:
>
> > diff --git a/Functions/Prompts/promptinit b/Functions/Prompts/promptinit
> > index 5e42ebdd3..1c6d27ad7 100644
> > --- a/Functions/Prompts/promptinit
> > +++ b/Functions/Prompts/promptinit
> > @@ -123,6 +125,7 @@ Use prompt -h <theme> for help on specific themes.'
> > # The next line is a bit ugly. It (perhaps unnecessarily)
> > # runs the prompt theme setup function to ensure that if
> > # the theme has a _help function that it's been autoloaded.
> > + zstyle -t :prompt-theme cleanup
> > prompt_$2_setup
> > fi
> > if functions prompt_$2_help >/dev/null; then
>
> Placement of the added zstyle call makes the comment incorrect, move
> it above the comment?
Will do.
>
> > @@ -179,28 +182,41 @@ Use prompt -h <theme> for help on specific themes.'
> > + # Will add the hook this time.
> > + prompt_cleanup "$@"
>
> This is logically correct, but I don't think it adds much in terms of
> maintainability to make this a recursive call; there are only 2
> commands executed in that event.
Ok; I'll have to refactor this again. :)
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2021-02-22 22:25 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-25 8:16 [PATCH 1/2] promptinit: typo: RPOMPT -> RPROMPT Arseny Maslennikov
2021-01-25 8:16 ` [PATCH 2/2] promptinit: Fix prompt cleanups Arseny Maslennikov
2021-01-25 8:23 ` Roman Perepelitsa
2021-01-25 12:50 ` Arseny Maslennikov
2021-02-18 13:03 ` (ping) " Arseny Maslennikov
2021-02-20 0:50 ` dana
2021-02-20 19:01 ` Bart Schaefer
2021-02-22 18:29 ` Bart Schaefer
2021-02-22 22:24 ` Arseny Maslennikov [this message]
2021-02-22 22:28 ` [PATCH v2] " Arseny Maslennikov
2021-02-22 23:50 ` Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YDQvG2hUq2455fQb@cello \
--to=ar@cs.msu.ru \
--cc=schaefer@brasslantern.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).