Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Evaluating parameters in general-purpose widgets
- X-seq: zsh-users 23095
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Evaluating parameters in general-purpose widgets
- Date: Fri, 19 Jan 2018 00:21:54 +0000
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=D198KwZxPTfxPMJiGfrl6ibJBf/Kd J2uAf3vAHt4rcQ=; b=QrVjqSbFijpSvQTYmVAPrjz46+o1WBLPTv3PgBenFu3Oa QWas3Il4h5pn/COlTVjdEmeEztATf2IbLUnjgFXz95zmRFEyWxfR4xMWT4E2njY4 513FHNIivACRYegg3ftHrOrlInO650KwQdvzKJR2u5fjOJ64Lb69zv1frr9p1RWf 9TRjI7eyLYhps8Z7Qes7Sc8rV1sasqEqJzl8vP7fJJTyE32v72YMA6zET3ylqD3h 7J9H6td2PvEb+TKng6Vn2K8HKYbge7M8BpalhiLLbYpNqQ+sEWYQ0+T5NjcBQpJu YWeOOOCxBW3kOe6vy/DpJbzc0zkmw/jVci8SsnDsw==
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=D198KwZxPTfxPMJiGfrl6ibJBf/Kd J2uAf3vAHt4rcQ=; b=AEQy7qbGsfvBbNThMf2AmX/nNJsK1ADsTFgKgMo3AfDvM rij0GpxV+sLHOJv8FicsYxT5G4TKA74+jcqO8qHc8t2VCCI5FnBotthjEogogFNX ILRWLBXlYscZ/2V2GSq8q4iQHsqnnytNGw4Xgz8CDSXuTnI5bOso43sXRX++kWh+ vWhxOEPVraZakjdv1ezYRVvGNfZpavmQgQnSIFfgTTjqc/fe8JmsucTLFUXIOZ1r LSRBBQ3qZkw+pfNxBB53HPM0fQ7bSMvB1f3g6/6VoN6mqQOV/Xuook0XHutuJ0DB o/J6TZSaJqY0gE7ZBQmjJfsfNq+JUbqF6d3W/uNZA==
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
zsh-syntax-highlighting is designed to run as a zle-line-pre-redraw widget.
Is it safe for zsh-syntax-highlighting to evaluate parameter expansions
in the input?
Things like «${:-`foo`}» and «${foo:=bar}» clearly may have side effects
and are not evaluated by z-sy-h under any circumstances. However, what
about simple expressions such as «${foo}»? Even those can have side
effects when $foo is provided by a module:
[[[
diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c
index 10c47d214..789d262fe 100644
--- a/Src/Modules/parameter.c
+++ b/Src/Modules/parameter.c
@@ -1821,6 +1821,24 @@ setpmdissaliases(Param pm, HashTable ht)
setaliases(sufaliastab, pm, ht, ALIAS_SUFFIX|DISABLED);
}
+/* autoincrement */
+
+static zlong autoincrement = 0;
+
+/**/
+static zlong
+autoincrementgetfn(UNUSED(Param pm))
+{
+ return ++autoincrement;
+}
+
+/**/
+static void
+autoincrementsetfn(UNUSED(Param pm), zlong value)
+{
+ autoincrement = value;
+}
+
static const struct gsu_scalar pmralias_gsu =
{ strgetfn, setpmralias, unsetpmalias };
static const struct gsu_scalar pmgalias_gsu =
@@ -2168,6 +2186,8 @@ static const struct gsu_hash pmdisgaliases_gsu =
{ hashgetfn, setpmdisgaliases, stdunsetfn };
static const struct gsu_hash pmdissaliases_gsu =
{ hashgetfn, setpmdissaliases, stdunsetfn };
+static const struct gsu_integer pmautoincrement_gsu =
+{ autoincrementgetfn, autoincrementsetfn, stdunsetfn };
static const struct gsu_array funcstack_gsu =
{ funcstackgetfn, arrsetfn, stdunsetfn };
@@ -2254,7 +2274,9 @@ static struct paramdef partab[] = {
SPECIALPMDEF("userdirs", PM_READONLY,
NULL, getpmuserdir, scanpmuserdirs),
SPECIALPMDEF("usergroups", PM_READONLY,
- NULL, getpmusergroups, scanpmusergroups)
+ NULL, getpmusergroups, scanpmusergroups),
+ SPECIALPMDEF("autoincrement", PM_INTEGER,
+ &pmautoincrement_gsu, NULL, NULL)
};
static struct features module_features = {
%
% zmodload zsh/parameter
% print $autoincrement $autoincrement
1 2
%
]]]
So...
1. Suppose [[ $BUFFER == 'echo $foobar' ]], is it safe for a
general-purpose widget (= z-sy-h) to evaluate $foobar?
2. Likewise, after checking that «[[ ${parameters[foobar]} != *special* ]]»?
Cheers,
Daniel
P.S. Currently, the only case in which z-sy-h expands parameters is when
they appear at command position, in order to know what the effective
command word (after expansions) is.
P.P.S. I wasn't going to commit the above, and it has some quirks (for
example, evaluating ${+autoincrement} increments the parameter), but if
there's interest let me know.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author