From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29827 invoked by alias); 5 Oct 2012 22:24:25 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 30718 Received: (qmail 6799 invoked from network); 5 Oct 2012 22:24:21 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 Received-SPF: neutral (ns1.primenet.com.au: 74.125.82.171 is neither permitted nor denied by SPF record at ntlworld.com) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-proxyuser-ip:date:from:to:subject:message-id:in-reply-to :references:x-mailer:mime-version:content-type :content-transfer-encoding:x-gm-message-state; bh=YnuZHV7+CKCqwkS2XFwWfjZmgAKwEHgRarEjfnLPVrI=; b=KDiEj8zOdWiAd1IBOjPTQgg07jmM+xvw7r4QYf0zBF3wy8cbfCV+psZhonQ9oCcmJn V6/jd6bKervrcIb0xGOWiJSaaCuSZsUXQzs6zWzSXZQhuRD8B86+tc2+HKGi24oDQ82q G59JmOrMK33Q2y/3xBrXdOiw+9F/5HM1nvjTWUCz9Z1O0j3O/JgpUK1tTaESl9cXKv/6 I6IF/mk3h0UnH6Jg1RY7SoyFNofrvQCVlDiyLKdbRzBKRwg2xmgZhJBektNjiM0Nzzye LKLenJVs9miUay+jmtqZBoBddqKxv7br6wGOP7OcyFqZ4AAFjtPB3JxVwtn1J6F5yiEO y2eQ== X-ProxyUser-IP: 82.8.55.192 Date: Fri, 5 Oct 2012 23:24:10 +0100 From: Peter Stephenson To: Zsh workers Subject: Re: autoload -X inside an anonymous function Message-ID: <20121005232410.1dec5bca@pws-pc.ntlworld.com> In-Reply-To: <20121005223228.408a7b2f@pws-pc.ntlworld.com> References: <13194.1347934322@thecus.kiddle.eu> <120918095827.ZM23535@torch.brasslantern.com> <1348021726.8764.YahooMailNeo@web29706.mail.ird.yahoo.com> <120919075811.ZM24917@torch.brasslantern.com> <20120920203537.29bb1d18@pws-pc.ntlworld.com> <120924115023.ZM22732@torch.brasslantern.com> <20121005223228.408a7b2f@pws-pc.ntlworld.com> X-Mailer: Claws Mail 3.8.0 (GTK+ 2.24.7; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQm8/hTgt26zYbpsZ8Y15vR9Dpw0efO9eFi3JI5sZdurMP27OqeslPzZtujtDn09vbutMV5c On Fri, 5 Oct 2012 22:32:28 +0100 Peter Stephenson wrote: > On the whole I'd be inclined to reverse my decision not to propagate > stickiness to autoloads, and to document that -z only affects the > autoload style and that > > emulate zsh -c 'autoload -Uz ...' > > is the way to ensure functions are loaded with appropriate options. This would be the corresponding patch, but I'll wait for reaction. One slight subtlety is that I only changed the use of sticky emulation at the point where the function is marked for autoload; this causes the sticky emulation to be in effect during the autoload itself, and it remains in effect while the function is being defined so propagates to the new function definition which retains the same sticky emulation for execution. If you don't believe me, believe the test... Index: README =================================================================== RCS file: /cvsroot/zsh/zsh/README,v retrieving revision 1.77 diff -p -u -r1.77 README --- README 15 Jun 2012 21:23:42 -0000 1.77 +++ README 5 Oct 2012 22:18:58 -0000 @@ -30,8 +30,38 @@ Zsh is a shell with lots of features. F file FEATURES, and for the latest changes see NEWS. For more details, see the documentation. -Possible incompatibilities ---------------------------- +Incompatibilities between 5.0.0 and 5.0.1 +----------------------------------------- + +In 5.0.0, the new "sticky" emulation feature was applied to functions +explicitly declared within an expression following `emulate ... -c', but +did not apply to functions marked for autoload in that expression. This +was not documented and experience suggests it was inconvenient, so in +5.0.1 autoloads also have the sticky property. + +In other words, + + emulate zsh -c 'func() { ... }' + +behaves the same way in 5.0.0 and 5.0.1, with the function func always being +run in native zsh emulation regardless of the current option settings. +However, + + emulate zsh -c 'autoload -Uz func' + +behaves differently: in 5.0.0, func was loaded with the options in +effect at the point where it was first run, and subsequently run with +whatever options were in effect at that point; in 5.0.1, func is loaded +with native zsh emulation options and run with those same options. This +is now the recommended way of ensuring a function is loaded and run with +a consistent set of options. + +Note that the `autoload -z' has never affected the options applied when +the function is loaded or run, only the effect of the KSH_AUTOLOAD +option at the point the function is loaded. + +Possible incompatibilities between 4.2 and 5.0 +---------------------------------------------- Here are some incompatibilities in the shell since the 4.2 series of releases. It is hoped most users will not be adversely affected by these. Index: Doc/Zsh/builtins.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/builtins.yo,v retrieving revision 1.143 diff -p -u -r1.143 builtins.yo --- Doc/Zsh/builtins.yo 21 Sep 2012 19:08:36 -0000 1.143 +++ Doc/Zsh/builtins.yo 5 Oct 2012 22:18:58 -0000 @@ -137,10 +137,19 @@ With the tt(-w) flag, the var(name)s are with the tt(zcompile) builtin, and all functions defined in them are marked for autoloading. -The flags tt(-z) and tt(-k) mark the function to be autoloaded in -native or ksh emulation, as if the option tt(KSH_AUTOLOAD) were -unset or were set, respectively. The flags override the setting of -the option at the time the function is loaded. +The flags tt(-z) and tt(-k) mark the function to be autoloaded using the +zsh or ksh style, as if the option tt(KSH_AUTOLOAD) were unset or were +set, respectively. The flags override the setting of the option at the +time the function is loaded. + +Note that the tt(autoload) command makes no attempt to ensure the +shell options set during the loading or execution of the file have +any particular value. For this, the tt(emulate) command can be used: + +example(emulate zsh -c 'autoload -Uz var(func)') + +arranges that when var(func) is loaded the shell is in native tt(zsh) +emulation, and this emulation is also applied when var(func) is run. ) findex(bg) cindex(jobs, backgrounding) @@ -393,6 +402,7 @@ ifnzman(noderef(Invocation))\ ifzman(the section INVOCATION in zmanref(zsh)), except that `tt(-o EMACS)' and `tt(-o VI)' may not be used. Flags such as `tt(+r)'/`tt(+o RESTRICTED)' may be prohibited in some circumstances. + If tt(-c) var(arg) appears in var(flags), var(arg) is evaluated while the requested emulation is temporarily in effect. In this case the emulation mode and all options are restored to their previous values before @@ -409,7 +419,10 @@ If the function is called when the stick effect, either within an `tt(emulate) var(shell) tt(-c)' expression or within another function with the same sticky emulation, entry and exit from the function do not cause options to be altered (except due to -standard processing such as the tt(LOCAL_OPTIONS) option). +standard processing such as the tt(LOCAL_OPTIONS) option). This also +applies to functions marked for autoload within the sticky emulation; +the appropriate set of options will be applied at the point the +function is loaded as well as when it is run. For example: Index: Src/builtin.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v retrieving revision 1.263 diff -p -u -r1.263 builtin.c --- Src/builtin.c 21 Sep 2012 19:08:36 -0000 1.263 +++ Src/builtin.c 5 Oct 2012 22:18:58 -0000 @@ -2944,8 +2944,7 @@ bin_functions(char *name, char **argv, O shf = (Shfunc) zshcalloc(sizeof *shf); shf->node.flags = on; shf->funcdef = mkautofn(shf); - /* No sticky emulation for autoloaded functions */ - shf->emulation = 0; + shf->emulation = sticky_emulation; shfunctab->addnode(shfunctab, ztrdup(*argv), shf); if (signum != -1) { Index: Test/C04funcdef.ztst =================================================================== RCS file: /cvsroot/zsh/zsh/Test/C04funcdef.ztst,v retrieving revision 1.10 diff -p -u -r1.10 C04funcdef.ztst --- Test/C04funcdef.ztst 3 Aug 2011 18:45:19 -0000 1.10 +++ Test/C04funcdef.ztst 5 Oct 2012 22:18:58 -0000 @@ -251,6 +251,23 @@ >foo1 >bar2 + ( + setopt ignorebraces + fpath=(.) + print "{ echo OK }\n[[ -o ignorebraces ]] || print 'ignorebraces is off'" \ + >emufunctest + (autoload -z emufunctest; emufunctest) 2>&1 + emulate zsh -c 'autoload -Uz emufunctest' + emufunctest + [[ -o ignorebraces ]] && print 'ignorebraces is still on here' + ) +0:sticky emulation applies to autoloads and autoloaded function execution +>emufunctest:3: parse error near `\n' +>OK +>ignorebraces is off +>ignorebraces is still on here + + %clean rm -f file.in file.out -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/