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 --- Doc/Zsh/contrib.yo | 8 ++++---- Functions/Prompts/promptinit | 14 +++++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo index 3c4fdded0..01809c0c4 100644 --- a/Doc/Zsh/contrib.yo +++ 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 +removed when the prompt theme changes or is disabled. ) item(Declare cleanup)( If your function makes any other changes that should be undone when the diff --git a/Functions/Prompts/promptinit b/Functions/Prompts/promptinit index 37d69f100..b9d833c4b 100644 --- a/Functions/Prompts/promptinit +++ b/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 -- 2.31.1