From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: zsh-users@zsh.org
Subject: Re: declare -p and -H (hideval)
Date: Mon, 15 May 2017 13:36:10 +0000 [thread overview]
Message-ID: <20170515133610.GA21381@fujitsu.shahaf.local2> (raw)
In-Reply-To: <170514102207.ZM15414@torch.brasslantern.com>
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.
next prev parent reply other threads:[~2017-05-15 13:36 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-12 16:21 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 [this message]
2017-05-15 20:03 ` 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=20170515133610.GA21381@fujitsu.shahaf.local2 \
--to=d.s@daniel.shahaf.name \
--cc=zsh-users@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).