From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10977 invoked by alias); 19 Jan 2018 00:22:14 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 23095 Received: (qmail 3439 invoked by uid 1010); 19 Jan 2018 00:22:14 -0000 X-Qmail-Scanner-Diagnostics: from out1-smtp.messagingengine.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(66.111.4.25):SA:0(-1.9/5.0):. Processed in 11.049346 secs); 19 Jan 2018 00:22:14 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | 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== X-ME-Sender: Date: Fri, 19 Jan 2018 00:21:54 +0000 From: Daniel Shahaf To: zsh-users@zsh.org Subject: Evaluating parameters in general-purpose widgets Message-ID: <20180119002154.ssgbaowmrjvehme5@tarpaulin.shahaf.local2> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: NeoMutt/20170113 (1.7.2) 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.