Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: declare -p and -H (hideval)



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.



Messages sorted by: Reverse Date, Date, Thread, Author