From: Roman Perepelitsa <roman.perepelitsa@gmail.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: PATCH: Invoke prompt cleanup hooks when changing prompt
Date: Tue, 7 Jul 2020 13:50:04 +0200 [thread overview]
Message-ID: <CAN=4vMrUPU695MfPDZ_6c-HPWFW_Q7UYwP+FFGjcHfq5FhuwtA@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1088 bytes --]
The documentation for promptinit states that themes can install
cleanup hooks via prompt_cleanup.
> 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.
The documentation also states that:
> The precmd and preexec hooks are automatically
> adjusted if the prompt theme changes or is disabled.
If I understand it correctly, this implies that the following script
should print "cleanup" and shouldn't print "hook".
autoload -Uz promptinit
promptinit
prompt_foo_setup() {
prompt_cleanup 'print cleanup'
precmd_functions+=(hook)
}
prompt_themes+=(foo)
prompt foo
prompt off
print -r -- $precmd_functions
It doesn't print "hello" and does print "hook".
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.
Roman.
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 2710 bytes --]
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
- 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+=(bang)
- [[ -o promptcr ]] && prompt_opts+=(cr)
- [[ -o promptpercent ]] && prompt_opts+=(percent)
- [[ -o promptsp ]] && prompt_opts+=(sp)
- [[ -o promptsubst ]] && prompt_opts+=(subst)
- zstyle -e :prompt-theme cleanup \
- 'zstyle -d :prompt-theme cleanup;' \
- 'prompt_default_setup;' \
- ${PS1+PS1="${(q)PS1}"} \
- ${PS2+PS2="${(q)PS2}"} \
- ${PS3+PS3="${(q)PS3}"} \
- ${PS4+PS4="${(q)PS4}"} \
- ${RPS1+RPS1="${(q)RPS1}"} \
- ${RPS2+RPS2="${(q)RPS2}"} \
- ${RPROMPT+RPROMPT="${(q)RPROMPT}"} \
- ${RPROMPT2+RPROMPT2="${(q)RPROMPT2}"} \
- ${PSVAR+PSVAR="${(q)PSVAR}"} \
- "precmd_functions=(${(q)precmd_functions[@]})" \
- "preexec_functions=(${(q)preexec_functions[@]})" \
- "prompt_opts=( ${prompt_opts[*]} )" \
- 'reply=(yes)'
+ zstyle -g theme_active :prompt-theme cleanup && {
+ local -a reply
+ eval "$theme_active"
}
+
+ # 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+=(bang)
+ [[ -o promptcr ]] && prompt_opts+=(cr)
+ [[ -o promptpercent ]] && prompt_opts+=(percent)
+ [[ -o promptsp ]] && prompt_opts+=(sp)
+ [[ -o promptsubst ]] && prompt_opts+=(subst)
+ zstyle -e :prompt-theme cleanup \
+ 'zstyle -d :prompt-theme cleanup;' \
+ 'prompt_default_setup;' \
+ ${PS1+PS1="${(q)PS1}"} \
+ ${PS2+PS2="${(q)PS2}"} \
+ ${PS3+PS3="${(q)PS3}"} \
+ ${PS4+PS4="${(q)PS4}"} \
+ ${RPS1+RPS1="${(q)RPS1}"} \
+ ${RPS2+RPS2="${(q)RPS2}"} \
+ ${RPROMPT+RPROMPT="${(q)RPROMPT}"} \
+ ${RPROMPT2+RPROMPT2="${(q)RPROMPT2}"} \
+ ${PSVAR+PSVAR="${(q)PSVAR}"} \
+ "precmd_functions=(${(q)precmd_functions[@]})" \
+ "preexec_functions=(${(q)preexec_functions[@]})" \
+ "prompt_opts=( ${prompt_opts[*]} )" \
+ 'reply=(yes)'
+
set_prompt "$@"
(( ${#prompt_opts} )) &&
next reply other threads:[~2020-07-07 11:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-07 11:50 Roman Perepelitsa [this message]
2021-01-25 12:41 ` Arseny Maslennikov
2021-01-25 15:14 ` Arseny Maslennikov
2021-03-27 17:01 ` Lawrence Velázquez
2021-03-28 8:01 ` Roman Perepelitsa
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='CAN=4vMrUPU695MfPDZ_6c-HPWFW_Q7UYwP+FFGjcHfq5FhuwtA@mail.gmail.com' \
--to=roman.perepelitsa@gmail.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).