zsh-users
 help / color / mirror / code / Atom feed
* declare -p and -H (hideval)
@ 2017-05-12 16:21 Sebastian Gniazdowski
  2017-05-12 22:03 ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Sebastian Gniazdowski @ 2017-05-12 16:21 UTC (permalink / raw)
  To: zsh-users

Hello,
written small plugin to fullscreen flash all interactive-created parameters https://github.com/zdharma/zbrowse.

I use "declare -p" there, when user selects a parameter. No value is being shown for -H parameters. Is this correct? Manual says:

Hide value: specifies that tt(typeset) will not display the value of the
parameter when listing parameters; the display for such parameters is
always as if the `tt(PLUS())' flag had been given.  Use of the parameter is
in other respects normal, and the option does not apply if the parameter is
specified by name, or by pattern with the tt(-m) option.

The ", and ..." at the end would suggest that if "declare -p NAME" or "declare -pm NAME" will be used, the value will be shown, but this doesn't happen.

Any way to avoid -H effects with typeset -p?

--
Sebastian Gniazdowski
psprint /at/ zdharma.org


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

* Re: declare -p and -H (hideval)
  2017-05-12 16:21 declare -p and -H (hideval) Sebastian Gniazdowski
@ 2017-05-12 22:03 ` Bart Schaefer
  2017-05-14  1:04   ` Daniel Shahaf
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2017-05-12 22:03 UTC (permalink / raw)
  To: zsh-users

On May 12,  6:21pm, Sebastian Gniazdowski wrote:
}
} I use "declare -p" there, when user selects a parameter. No value is
} being shown for -H parameters. Is this correct?

Yes.  Manual for -p option says:

      If the -p option is given, parameters and values are printed
      in the form of a typeset command with an assignment,
      regardless of other flags and options.  Note that the -H flag
      on parameters is respected; no value will be shown for these
      parameters.

This takes precedence over the -m flag, etc.

} Any way to avoid -H effects with typeset -p?

It would appear not.


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

* Re: declare -p and -H (hideval)
  2017-05-12 22:03 ` Bart Schaefer
@ 2017-05-14  1:04   ` Daniel Shahaf
  2017-05-14 17:22     ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Shahaf @ 2017-05-14  1:04 UTC (permalink / raw)
  To: zsh-users

Bart Schaefer wrote on Fri, May 12, 2017 at 15:03:02 -0700:
> On May 12,  6:21pm, Sebastian Gniazdowski wrote:
> }
> } I use "declare -p" there, when user selects a parameter. No value is
> } being shown for -H parameters. Is this correct?
> 
> Yes.  Manual for -p option says:
> 
>       If the -p option is given, parameters and values are printed
>       in the form of a typeset command with an assignment,
>       regardless of other flags and options.  Note that the -H flag
>       on parameters is respected; no value will be shown for these
>       parameters.
> 
> This takes precedence over the -m flag, etc.

The fact remains that the "does not apply" clause that Sebastian quoted
does not match the implementation.  The question is just which of them
should be fixed to match the other.  (Code archeology may answer this,
but I'm not going to do it tonight.)

> } Any way to avoid -H effects with typeset -p?
> 
> It would appear not.


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

* Re: declare -p and -H (hideval)
  2017-05-14  1:04   ` Daniel Shahaf
@ 2017-05-14 17:22     ` Bart Schaefer
  2017-05-15 13:36       ` Daniel Shahaf
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2017-05-14 17:22 UTC (permalink / raw)
  To: zsh-users

On May 14,  1:04am, Daniel Shahaf wrote:
}
} The fact remains that the "does not apply" clause that Sebastian quoted
} does not match the implementation.  The question is just which of them
} should be fixed to match the other.  (Code archeology may answer this,
} but I'm not going to do it tonight.)

Based on git history, -p has always taken precendence here.

It'd be quite simple to make -pm behave differently with respect to the
value.  However, I also note that PM_HIDEVAL is not one of the "type
flags" that is output by "typeset -p" -- it only emits flags for things
like array, integer, padding/alignment, etc.  So that would presumably
also need to change, which begins to get more involved.


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

* Re: declare -p and -H (hideval)
  2017-05-14 17:22     ` Bart Schaefer
@ 2017-05-15 13:36       ` Daniel Shahaf
  2017-05-15 20:03         ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Shahaf @ 2017-05-15 13:36 UTC (permalink / raw)
  To: zsh-users

Bart Schaefer wrote on Sun, May 14, 2017 at 10:22:07 -0700:
> On May 14,  1:04am, Daniel Shahaf wrote:
> }
> } The fact remains that the "does not apply" clause that Sebastian quoted
> } does not match the implementation.  The question is just which of them
> } should be fixed to match the other.  (Code archeology may answer this,
> } but I'm not going to do it tonight.)
> 
> Based on git history, -p has always taken precendence here.

Ah, I see: 'typeset k' ignores -H but 'typeset -p k' does not.

> It'd be quite simple to make -pm behave differently with respect to the
> value.  However, I also note that PM_HIDEVAL is not one of the "type
> flags" that is output by "typeset -p" -- it only emits flags for things
> like array, integer, padding/alignment, etc.  So that would presumably
> also need to change, which begins to get more involved.

I went down the rabbit hole, and it seems pretty sane so far:

[[[
% Z -c 'typeset -H k=v; typeset | grep -w k; typeset + | grep -w k; typeset -p | grep -w k' | grep -v ZSH_EXECUTION_STRING
hidden value k
hidden value k
typeset -H k
% Z -c 'typeset -H k=v; typeset k; typeset -p k; typeset -m k; typeset -pm k' 
k=v
typeset -H k=v
k=v
typeset -H k=v
]]]

[[[
diff --git a/Src/builtin.c b/Src/builtin.c
index 86c79bb..a762987 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -2617,6 +2617,7 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
 	printflags |= PRINT_TYPESET;
     hasargs = *argv != NULL || (assigns && firstnode(assigns));
     if (!hasargs) {
+	printflags |= PRINT_ALL;
 	if (!OPT_ISSET(ops,'p')) {
 	    if (!(on|roff))
 		printflags |= PRINT_TYPE;
diff --git a/Src/params.c b/Src/params.c
index 3e423cd..2c3c2bd 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -5483,7 +5483,9 @@ static const struct paramtypes pmtypes[] = {
     { PM_UPPER, "uppercase", 'u', 0},
     { PM_READONLY, "readonly", 'r', 0},
     { PM_TAGGED, "tagged", 't', 0},
-    { PM_EXPORTED, "exported", 'x', 0}
+    { PM_EXPORTED, "exported", 'x', 0},
+    { PM_HIDE, "hiding", 'h', 0},
+    { PM_HIDEVAL, "hidden value", 'H', 0}
 };
 
 #define PMTYPES_SIZE ((int)(sizeof(pmtypes)/sizeof(struct paramtypes)))
@@ -5648,7 +5650,8 @@ printparamnode(HashNode hn, int printflags)
     }
 
     if ((printflags & PRINT_NAMEONLY) ||
-	((p->node.flags & PM_HIDEVAL) && !(printflags & PRINT_INCLUDEVALUE))) {
+	((p->node.flags & PM_HIDEVAL) && !(printflags & PRINT_INCLUDEVALUE) &&
+	 (printflags & PRINT_ALL))) {
 	zputs(p->node.nam, stdout);
 	putchar('\n');
     } else {
diff --git a/Src/zsh.h b/Src/zsh.h
index f77204e..93d515f 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -2077,7 +2077,8 @@ typedef groupset *Groupset;
 #define PRINT_LIST		(1<<2)
 #define PRINT_KV_PAIR		(1<<3)
 #define PRINT_INCLUDEVALUE	(1<<4)
-#define PRINT_TYPESET		(1<<5)
+#define PRINT_TYPESET		(1<<5)   /* typeset -p */
+#define PRINT_ALL		(1<<11)  /* printing all parameters, not just named ones nor -m */
 
 /* flags for printing for the whence builtin */
 #define PRINT_WHENCE_CSH	(1<<6)
]]]

Whether to commit this is another question: it'd break an explicitly
documented property of the -p flag, which people might conceivably rely
on: currently,
.
    % typeset -H foo=1 bar=2
    % store=`typeset -p foo bar`
    ⋮
    % eval $store > /dev/null
.
wouldn't change $foo's value.

Thoughts?

Daniel

P.S. Haven't updated test expectations yet.


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

* Re: declare -p and -H (hideval)
  2017-05-15 13:36       ` Daniel Shahaf
@ 2017-05-15 20:03         ` Bart Schaefer
  0 siblings, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 2017-05-15 20:03 UTC (permalink / raw)
  To: zsh-users

On May 15,  1:36pm, Daniel Shahaf wrote:
}
} Bart Schaefer wrote on Sun, May 14, 2017 at 10:22:07 -0700:
} > It'd be quite simple to make -pm behave differently
} 
} I went down the rabbit hole, and it seems pretty sane so far:

This (changing the default behavior of -p) isn't where I'd have gone
with this.  I'd have e.g. added PRINT_INCLUDEVALUE to the flags in
the case of -m and -p used together.  Even in your patch, I don't
see any purpose to PRINT_ALL that isn't covered by _INCLUDEVALUE.

} +    { PM_EXPORTED, "exported", 'x', 0},
} +    { PM_HIDE, "hiding", 'h', 0},
} +    { PM_HIDEVAL, "hidden value", 'H', 0}

I don't think it's quite that easy.  For one thing PM_HIDE can be
attached to a top-level variable, but has no effect there, so it's
not clear whether to include it in the typeset output or if instead
it needs special handling ala PM_EXPORTED.

Follow-ups to zsh-workers.


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

end of thread, other threads:[~2017-05-15 20:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-12 16:21 declare -p and -H (hideval) Sebastian Gniazdowski
2017-05-12 22:03 ` Bart Schaefer
2017-05-14  1:04   ` Daniel Shahaf
2017-05-14 17:22     ` Bart Schaefer
2017-05-15 13:36       ` Daniel Shahaf
2017-05-15 20:03         ` 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).