zsh-workers
 help / color / mirror / code / Atom feed
From: "Christian Höltje" <docwhat@gerf.org>
To: zsh-workers@zsh.org
Subject: Re: Teardown for prompts [patch - remove all hooks]
Date: Thu, 5 Jan 2012 13:44:31 -0500	[thread overview]
Message-ID: <78D2AAEB600F453B8ED374A29B7642F7@gmail.com> (raw)
In-Reply-To: <B3BC4505B3444C2EAEEF95F8B334D14F@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2228 bytes --]

This patch will remove all prompt hooks when changing prompts, using the prompt system.

The current code only catches the precmd and preexec hooks, but all the hooks should be checked.

diff --git a/Functions/Prompts/promptinit b/Functions/Prompts/promptinit
index b07eabb..66e73a7 100644
--- a/Functions/Prompts/promptinit
+++ b/Functions/Prompts/promptinit
@@ -155,8 +155,10 @@ Use prompt -h <theme> for help on specific themes.'
        fi
  
        # Reset some commonly altered bits to the default
-       add-zsh-hook -D precmd "prompt_*_precmd"
-       add-zsh-hook -D preexec "prompt_*_preexec"
+       local hook
+       for hook in chpwd precmd preexec periodic zshaddhistory zshexit; do
+         add-zsh-hook -D "${hook}" "prompt_*_${hook}"
+       done
        set -A zle_highlight ${zle_highlight:#default:*}
        (( ${#zle_highlight} )) || unset zle_highlight
  


--  
Christian Höltje
docwhat@gerf.org
http://docwhat.org/


On Thursday, January 5, 2012 at 11:23 AM, Christian Höltje wrote:

> I have some suggestions for the promptinit stuff....  
>  
> 1) Remove other prompt related hooks.  Currently, it removes preexec and precmd, but it doesn't remove chpwd, periodic, zshexit, nor zshaddhistory.
>       e.g.
> for hook in preexec precmd chpwd periodic zshexit zshaddhistory; do
>           add-zsh-hook -D "${hook}" "prompt_*_${hook}"
>         done
>  
>      Bonus points for getting the list of hooks from add-zsh-hook itself.
>  
>  2) Add a teardown function.  This could be used to unset things, etc. if the prompt changes.  If prompt is switching from the prompt 'adam2', it would look for prompt_adam2_teardown and run it if it exists before switch to the new prompt.
>  
>  3) On switching away from a prompt, look for any and all variables and functions with pattern "prompt_${current_prompt_name}_*" and unset/unfunction them.
>  
> I discovered this when I wrote a prompt that used the chpwd hook to try to minimize certain VCS checks (an optimization) and that function was still being called when I switched to a new prompt.  
>  
> --  
> Christian Höltje
> docwhat@gerf.org (mailto:docwhat@gerf.org)
> http://docwhat.org/
>  


  reply	other threads:[~2012-01-05 18:44 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-05 16:23 Teardown for prompts Christian Höltje
2012-01-05 18:44 ` Christian Höltje [this message]
2012-01-06 15:47   ` Teardown for prompts [patch - remove all hooks] Bart Schaefer
2012-01-06 16:22 ` Teardown for prompts 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=78D2AAEB600F453B8ED374A29B7642F7@gmail.com \
    --to=docwhat@gerf.org \
    --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).