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 3018 invoked from network); 25 Jan 2021 08:17:17 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 25 Jan 2021 08:17:17 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1611562637; b=Jo+CuNXhiN7wmkLliPzXQSpy5DXeXQxNNE5iN0EOkklM7Z1zMxb515xhVOpf6do1VKIBlD5Est Iyn6MIn1oJsAnqrCGq2rmkaEE/kpBRvDlDBIcvU5m3/v1BQS9p1vLFbAQBq4tsz7vJkiMbPuhT IAUuY8kLntYJWWlzY5eOzqcOgpISFcoEt/qH0dw5+6yBPxNvvNfo4ObZYLpzAdDNIzPzGGXTkl K3TaUaO1VyvuxUXtx4LnTPG4zMRktIZRy0zGwrY9GnJ8GcdV+x53XB0FX7V6z34YQaXPJCipcw 6KQmjKq9nu06rai1F9ZrcI26rL1azB1BK8w5DrUI7so12A==; 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=1611562637; bh=3PG4DJnb5q8vv9w+4YXzdWVCcs5Sxvm7mgTr+kV3JyI=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Subject:Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Cc:To:From:DKIM-Signature:DKIM-Signature; b=y9ZEOOxbCcJGoDsrxSi+2VdsliDMvgeJEDtWIPf4zAMcda3mGGR+Tafyr+lI9SDoJ2gSW8ngux x+9/YRT2hZ5xAzMm0RZVEoZbTv8+KJ73h5zCiIcQ1SKvTgwaNecKgYyDLE8pJHt6NsAYjTbicX MtOokIkyrvfxeZw/YL3XrK+QpsMVrUS7dwHeKRHwgPNL+zfM05zlZmx1av6SYd+N6y5Rnlwaay D6NCUIc9b3tJx1BsnVdPqItlNf+eKcL3pFpqh+vgZUKBaBAB8YyYhkXNR2iNwf70dNj+VKXfme 2xjzuu6tn/BD49/ZATWZsbLlATjElkhqBVQX2Y1Y3NJI6Q==; 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:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Cc:To:From:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=tPBjbhWjKcydz7+R7JkioPx0AYlFsnLpelqLpxRscFY=; b=I1jC2rPOubPu0nND3P/F1iRP4Z TkZxTYmu5FPSW2lfMfVyB6EOeNo0+Y2ScW6v6hO9/uCvNOxwWrB2pknxwdXH7bk8hV7iBozQXH1p7 CIQcwR/cHi8uDOBmgzrjB+grmbaeBfxegJdPz5uL7Kb2jihdOG9R/q11xMJZ/crBDWP4Nc+e42MzD 1fUYyTfwVvVKNcXWYTdDo6O7NMwlZhaMlZYtJ5OXN+7vBSmaoXYQ99/T1I6z1yX5B1+/Ql8yBRdBI WE1+uC5nAWfoxphuI+gOq0skmGZ3Y8EqqrY1BeVsTqDKqKYreyFjuzfgTww4/bROOZD2BkBoX2h+A DsnGp9dw==; Received: from authenticated user by zero.zsh.org with local id 1l3x3i-0004c2-MA; Mon, 25 Jan 2021 08:17:14 +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]:33518) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1l3x3C-0004CN-1p; Mon, 25 Jan 2021 08:16:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=cs.msu.ru; s=dkim; h=Subject:Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Cc:To:From:Sender:Reply-To:Content-Type: 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=tPBjbhWjKcydz7+R7JkioPx0AYlFsnLpelqLpxRscFY=; b=R/x36FXvEYiEy/ihnT8XDKZ5Cy nY9/+QHsQ/tFum4wmG1WwWU4R6mKkwAEMbQBrbkKHANt/NA1/dP1labnfbZb8NUzERlz5MV4sm3d6 9u1qL4hoPgiUNiq9CxAM4YXL0LNQ5m1lBOv51/t3hblBvJbyp37KGfxAgxofuHwSOykI1TdRLfNC7 gIgkc4JcXHT1CL3HQk/6jc55ILPonJNCvoE6JGTEbwcercjQjPyBLsNW3vFZ6ziuO/eNDhU9w9F4f yHx//mZIXd8mRkI9bf/kGBpnY1bFjrZ/EdqIZBihAB5A34JR46nFmDQ2ERQD+yDdcXBXtdNARMift oOP7WL/g==; Received: from [37.204.119.143] (port=47660 helo=localhost.localdomain) by mail.cs.msu.ru with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94 (FreeBSD)) (envelope-from ) id 1l3x3A-00030z-4X; Mon, 25 Jan 2021 11:16:40 +0300 From: Arseny Maslennikov To: zsh-workers@zsh.org Cc: Arseny Maslennikov Date: Mon, 25 Jan 2021 11:16:25 +0300 Message-Id: <20210125081625.3193714-2-ar@cs.msu.ru> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210125081625.3193714-1-ar@cs.msu.ru> References: <20210125081625.3193714-1-ar@cs.msu.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 37.204.119.143 X-SA-Exim-Mail-From: ar@cs.msu.ru Subject: [PATCH 2/2] promptinit: Fix prompt cleanups X-SA-Exim-Version: 4.2.1 X-SA-Exim-Scanned: Yes (on mail.cs.msu.ru) X-Seq: 47868 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: The Zsh documentation at Doc/Zsh/contrib, paragraph 26.6.4 "Writing Themes", says: Declare 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. You may declare more than one such cleanup hook. 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'. This problem was previously brought up in zsh-users/23314, to no avail. 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(). * Prepend every use of prompt_*_setup (which might modify the shell state in ways that require cleanup) with a cleanup run. * Adjust `prompt restore' to do both parts of the newly split restore mechanism, cleanup first. --- Functions/Prompts/prompt_restore_setup | 1 + Functions/Prompts/promptinit | 43 ++++++++++++++++++-------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/Functions/Prompts/prompt_restore_setup b/Functions/Prompts/prompt_restore_setup index 54c4adbf9..b77dbe815 100644 --- a/Functions/Prompts/prompt_restore_setup +++ b/Functions/Prompts/prompt_restore_setup @@ -1,2 +1,3 @@ # Damn that was easy zstyle -t :prompt-theme cleanup +zstyle -t :prompt-theme restore diff --git a/Functions/Prompts/promptinit b/Functions/Prompts/promptinit index 5e42ebdd3..1c6d27ad7 100644 --- a/Functions/Prompts/promptinit +++ b/Functions/Prompts/promptinit @@ -47,17 +47,19 @@ prompt_preview_safely() { return fi - # This handles all the stuff from the default :prompt-theme cleanup + # This handles all the stuff from the default :prompt-theme restore 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 prompt_preview_cleanup + local -a precmd_functions preexec_functions prompt_preview_restore local -aLl +h zle_highlight { # Save and clear current restore-point if any - zstyle -g prompt_preview_cleanup :prompt-theme cleanup + zstyle -g prompt_preview_restore :prompt-theme restore { - zstyle -d :prompt-theme cleanup + zstyle -d :prompt-theme restore + # Execute current cleanup sequence, if any. + zstyle -t :prompt-theme cleanup # The next line is a bit ugly. It (perhaps unnecessarily) # runs the prompt theme setup function to ensure that if @@ -74,8 +76,8 @@ prompt_preview_safely() { zstyle -t :prompt-theme cleanup } } always { - (( $#prompt_preview_cleanup )) && - zstyle -e :prompt-theme cleanup "${prompt_preview_cleanup[@]}" + (( $#prompt_preview_restore )) && + zstyle -e :prompt-theme restore "${prompt_preview_restore[@]}" } } @@ -104,7 +106,7 @@ Use prompt -h for help on specific themes.' local +h PROMPT=$PROMPT RPROMPT=$RPROMPT RPROMPT2=$RPROMPT2 PSVAR=$PSVAR local -a precmd_functions preexec_functions else - trap 'prompt_${prompt_theme[1]}_setup "${(@)prompt_theme[2,-1]}"' 0 + trap 'zstyle -t :prompt-theme cleanup; prompt_${prompt_theme[1]}_setup "${(@)prompt_theme[2,-1]}"' 0 fi ;; esac @@ -123,6 +125,7 @@ Use prompt -h 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 @@ -179,28 +182,41 @@ Use prompt -h for help on specific themes.' typeset -ga zle_highlight=( ${zle_highlight:#default:*} ) (( ${#zle_highlight} )) || unset zle_highlight + zstyle -t :prompt-theme cleanup prompt_$1_setup "$@[2,-1]" && prompt_theme=( "$@" ) ;; esac } prompt_cleanup () { - local -a cleanup_hooks + local -a cleanup_hooks theme_active if zstyle -g cleanup_hooks :prompt-theme cleanup then cleanup_hooks+=(';' "$@") zstyle -e :prompt-theme cleanup "${cleanup_hooks[@]}" - elif (( $+prompt_preview_cleanup == 0 )) + return 0 + fi + + (( $+prompt_preview_restore == 0 )) && + if ! zstyle -g theme_active :prompt-theme restore then print -u2 "prompt_cleanup: no prompt theme active" return 1 fi + + # Set the cleanup sequence up. + zstyle -e :prompt-theme cleanup \ + 'zstyle -d :prompt-theme cleanup;' \ + 'reply=(yes)' + + # Will add the hook this time. + prompt_cleanup "$@" } prompt () { local -a prompt_opts theme_active - zstyle -g theme_active :prompt-theme cleanup || { + zstyle -g theme_active :prompt-theme restore || { # 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. @@ -210,8 +226,8 @@ prompt () { [[ -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;' \ + zstyle -e :prompt-theme restore \ + 'zstyle -d :prompt-theme restore;' \ 'prompt_default_setup;' \ ${PS1+PS1="${(q)PS1}"} \ ${PS2+PS2="${(q)PS2}"} \ @@ -239,7 +255,7 @@ prompt_preview_theme () { emulate -L zsh # Check for proper state handling - (( $+prompt_preview_cleanup )) || { + (( $+prompt_preview_restore )) || { prompt_preview_safely "$@" return } @@ -249,6 +265,7 @@ prompt_preview_theme () { print -n "$1 theme" (( $#* > 1 )) && print -n " with parameters \`$*[2,-1]'" print ":" + zstyle -t :prompt-theme cleanup prompt_${1}_setup "$@[2,-1]" (( ${#prompt_opts} )) && setopt noprompt{bang,cr,percent,sp,subst} "prompt${^prompt_opts[@]}" -- 2.30.0