zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] _complete_debug: do not clobber PS4/PROMPT4
@ 2022-07-03  2:43 Eric Cook
  2022-07-04  4:32 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Cook @ 2022-07-03  2:43 UTC (permalink / raw)
  To: Zsh hackers list

If you invoke _complete_debug (^X?) after it, you will notice that PS4 is set to empty string.

Which led me to line 22 of _complete_debug:

local PROMPT4 PS4="${(j::)debug_indent}+%N:%i> "

Within the scope of the function this seems to work(?) the output of the xtrace uses PS4's new value.
% (f() typeset -p PS4 PROMPT4; f;() { local PROMPT4 PS4=bar;typeset -p PROMPT4 PS4; }; f)
typeset -g PS4='+%N:%i> '
typeset -g PROMPT4='+%N:%i> '
typeset PROMPT4=bar
typeset PS4=bar
typeset -g PS4=''
typeset -g PROMPT4=''

I noticed that if you only local one of these two tied parameters, PS4/PROMPT4 outside of _complete_debug isn't
changed. regardless of which one is chosen while within the function scope, both are updated.
% (f() typeset -p PS4 PROMPT4; f;() { local PS4=bar;typeset -p PROMPT4 PS4; }; f)
typeset -g PS4='+%N:%i> '
typeset -g PROMPT4='+%N:%i> '
typeset -g PROMPT4=bar
typeset PS4=bar
typeset -g PS4='+%N:%i> '
typeset -g PROMPT4='+%N:%i> '

Seems to be long standing behavior and the oldest version of zsh i have available to me at the moment 4.3.12
have the same behavior.

Strangely enough the problem doesn't seem to be related PROMPT4 not being given a value during the local call.
(f() typeset -p PS4 PROMPT4; f;() { local PROMPT4=bar PS4=bar;typeset -p PROMPT4 PS4; }; f)
typeset -g PS4='+%N:%i> '
typeset -g PROMPT4='+%N:%i> '
typeset PROMPT4=bar
typeset PS4=bar
typeset -g PS4=bar
typeset -g PROMPT4=bar

So unless there is a reason that I am missing, the following patch should stop _complete_debug from overwriting
PS4/PROMPT4

diff --git a/Completion/Base/Widget/_complete_debug b/Completion/Base/Widget/_complete_debug
index 94fd4accd..f3a809f42 100644
--- a/Completion/Base/Widget/_complete_debug
+++ b/Completion/Base/Widget/_complete_debug
@@ -19,7 +19,7 @@ integer debug_fd=-1
      setopt localoptions no_ignorebraces
      debug_indent=( '%'{3..20}'(e. .)' )
    }
-  local PROMPT4 PS4="${(j::)debug_indent}+%N:%i> "
+  local PS4="${(j::)debug_indent}+%N:%i> "
    setopt xtrace
    : $ZSH_NAME $ZSH_VERSION
    ${1:-_main_complete}




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] _complete_debug: do not clobber PS4/PROMPT4
  2022-07-03  2:43 [PATCH] _complete_debug: do not clobber PS4/PROMPT4 Eric Cook
@ 2022-07-04  4:32 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2022-07-04  4:32 UTC (permalink / raw)
  To: Eric Cook; +Cc: Zsh hackers list

On Sat, Jul 2, 2022 at 7:44 PM Eric Cook <llua@gmx.com> wrote:
>
> So unless there is a reason that I am missing, the following patch should stop _complete_debug from overwriting
> PS4/PROMPT4

All of these paired variables -- PROMPT/PS1, PROMPT2/PS2, etc. -- are
implemented the same way, by pointers to the same internal C string.
Even if one is local and the other is not, they can't have different
values (which can be its own strange effect).  Due to the way local
variables are implemented, this means that when the local scope ends
the previous values of all the locals are restored in what amounts to
random order ... so you may or may not see the behavior you described.

> -  local PROMPT4 PS4="${(j::)debug_indent}+%N:%i> "
> +  local PS4="${(j::)debug_indent}+%N:%i> "

Although I can't imagine why a completion function would change
PROMPT4, I still think it's odd for one of the pair to be local and
the other not.  I suggest instead:

local PROMPT4="$PROMPT4" PS4="${(j::)debug_indent}+%N:%i> "

This will force the up-scope value of both variables to be restored
properly regardless of the order in which they're unwound, and
correctly identifies PROMPT4 as local to called scopes.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-07-04  4:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-03  2:43 [PATCH] _complete_debug: do not clobber PS4/PROMPT4 Eric Cook
2022-07-04  4:32 ` Bart Schaefer

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).