Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Feature Patch: Use completion to view parameter values
- X-seq: zsh-workers 48332
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Cc: Marlon Richert <marlon.richert@xxxxxxxxx>
- Subject: Re: Feature Patch: Use completion to view parameter values
- Date: Mon, 29 Mar 2021 18:14:52 +0000
- Archived-at: <https://zsh.org/workers/48332>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-workers/2021-03/20210329181452.GB6044%40tarpaulin.shahaf.local2>
- In-reply-to: <CAH+w=7bD9bA-AKV4NoQ9YZVM_VpSMgX8GcLjSVhgP06KYokM_A@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAHLkEDtf6JqSn86duXjEuQFXGKJn8COcxnEypoOUV=V63SsdPQ@mail.gmail.com> <20210329073913.GP18178@tarpaulin.shahaf.local2> <CAHLkEDuHjvRhXhcX4iqZ0mJuAabcpSnRikunLeK9Y2Ucjhf0oQ@mail.gmail.com> <20210329171120.GA6044@tarpaulin.shahaf.local2> <CAH+w=7bD9bA-AKV4NoQ9YZVM_VpSMgX8GcLjSVhgP06KYokM_A@mail.gmail.com>
Bart Schaefer wrote on Mon, Mar 29, 2021 at 10:20:08 -0700:
> On Mon, Mar 29, 2021 at 10:11 AM Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
> >
> > I think that's right. -workers@: Is it possible for a non-PM_SPECIAL
> > parameter have a custom getfn?
>
> Only with the zsh/param/private module, I think, and in that case the
> getfn is just a wrapper around the default and doesn't add any
> side-effects.
Thanks, Bart.
And as to $AUTOINCREMENT, this isn't the first time I mentioned it as
a hypothetical, so I'm going to go ahead and post it here. I suspect
people from the future will use this for something-or-other.
Works as you'd expect:
.
% echo $AUTOINCREMENT $AUTOINCREMENT
0 1
%
And in Marlon's patch with the ${(t)…*special*} exclusion bypassed:
.
% zstyle \* extra-verbose yes
% AUTOFOO=42
% echo $AUTO<TAB><TAB>
AUTOFOO -- 42 AUTOINCREMENT -- 2
AUTOFOO -- 42 AUTOINCREMENT -- 4
Yes, it does actually increment the variable twice, probably because the
_parameters patch uses both ${(t)${(P)}} and then ${(P)}, and the former
does an increment too:
.
% echo $AUTOINCREMENT ${(tP)AUTOINCREMENT} $AUTOINCREMENT
0 array-special 2
%
I'm not proposing to commit $AUTOINCREMENT.
Cheers,
Daniel
P.S. Another similar example is Perl's magic flip-flop variable:
«perl -E 'say --$| for (1..10)'»
diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c
index ef9148d7b..179ac068e 100644
--- a/Src/Modules/parameter.c
+++ b/Src/Modules/parameter.c
@@ -2136,6 +2136,24 @@ scanpmusergroups(UNUSED(HashTable ht), ScanFunc func, int flags)
}
+/* Functions for the AUTOINCREMENT special parameter. */
+
+static zlong autoincrement = 0;
+
+static zlong
+autoincrementgetfn(UNUSED(Param pm))
+{
+ return autoincrement++;
+}
+
+static void
+autoincrementsetfn(UNUSED(Param pm), zlong value)
+{
+ autoincrement = value;
+}
+
+
+
/* Table for defined parameters. */
struct pardef {
@@ -2192,8 +2210,13 @@ static const struct gsu_array dirs_gsu =
static const struct gsu_array historywords_gsu =
{ histwgetfn, arrsetfn, stdunsetfn };
+static const struct gsu_integer autoincrement_gsu =
+{ autoincrementgetfn, autoincrementsetfn, stdunsetfn };
+
/* Make sure to update autofeatures in parameter.mdd if necessary */
static struct paramdef partab[] = {
+ SPECIALPMDEF("AUTOINCREMENT", PM_SPECIAL | PM_INTEGER,
+ &autoincrement_gsu, NULL, NULL),
SPECIALPMDEF("aliases", 0,
&pmraliases_gsu, getpmralias, scanpmraliases),
SPECIALPMDEF("builtins", PM_READONLY_SPECIAL, NULL, getpmbuiltin, scanpmbuiltins),
diff --git a/Src/Modules/parameter.mdd b/Src/Modules/parameter.mdd
index f71c17a72..b8fb93d54 100644
--- a/Src/Modules/parameter.mdd
+++ b/Src/Modules/parameter.mdd
@@ -2,6 +2,6 @@ name=zsh/parameter
link=either
load=yes
-autofeatures="p:parameters p:commands p:functions p:dis_functions p:functions_source p:dis_functions_source p:funcfiletrace p:funcsourcetrace p:funcstack p:functrace p:builtins p:dis_builtins p:reswords p:dis_reswords p:patchars p:dis_patchars p:options p:modules p:dirstack p:history p:historywords p:jobtexts p:jobdirs p:jobstates p:nameddirs p:userdirs p:usergroups p:aliases p:dis_aliases p:galiases p:dis_galiases p:saliases p:dis_saliases"
+autofeatures="p:parameters p:commands p:functions p:dis_functions p:functions_source p:dis_functions_source p:funcfiletrace p:funcsourcetrace p:funcstack p:functrace p:builtins p:dis_builtins p:reswords p:dis_reswords p:patchars p:dis_patchars p:options p:modules p:dirstack p:history p:historywords p:jobtexts p:jobdirs p:jobstates p:nameddirs p:userdirs p:usergroups p:aliases p:dis_aliases p:galiases p:dis_galiases p:saliases p:dis_saliases p:AUTOINCREMENT"
objects="parameter.o"
Messages sorted by:
Reverse Date,
Date,
Thread,
Author