about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2012-10-07 17:50:18 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2012-10-07 17:50:18 +0000
commit321471891e259c7b406f3cfaf1c076b28ae16a5f (patch)
tree19d797c373bd51fe49437a7eb58933fbf1c81c09
parentfff9a871e469bf689f22ff47561e0de960d5d49b (diff)
downloadzsh-321471891e259c7b406f3cfaf1c076b28ae16a5f.tar.gz
zsh-321471891e259c7b406f3cfaf1c076b28ae16a5f.tar.xz
zsh-321471891e259c7b406f3cfaf1c076b28ae16a5f.zip
30718: emulate command evaluations should apply sticky emulation
to autoloads, too
-rw-r--r--ChangeLog8
-rw-r--r--Doc/Zsh/builtins.yo23
-rw-r--r--README34
-rw-r--r--Src/builtin.c3
-rw-r--r--Test/C04funcdef.ztst17
5 files changed, 75 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 37dce9bf9..31896e953 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2012-10-07  Peter Stephenson  <p.w.stephenson@ntlworld.com>
+
+	* 30718: README, Doc/Zsh/builtins.yo, Src/builtin.c,
+	Test/C04funcdef.ztst: emulate command evaluations should apply
+	sticky emulation to autoloads, too.
+
 2012-10-07  Oliver Kiddle <opk@zsh.org>
 
 	* unposted: Completion/Unix/Command/_webbrowser,
@@ -233,5 +239,5 @@
 
 *****************************************************
 * This is used by the shell to define $ZSH_PATCHLEVEL
-* $Revision: 1.5737 $
+* $Revision: 1.5738 $
 *****************************************************
diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo
index 75745028f..f7924a072 100644
--- a/Doc/Zsh/builtins.yo
+++ b/Doc/Zsh/builtins.yo
@@ -137,10 +137,19 @@ With the tt(-w) flag, the var(name)s are taken as names of files compiled
 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 sticky emulation is already in
 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:
 
diff --git a/README b/README
index c5c18a90d..7542f8d35 100644
--- a/README
+++ b/README
@@ -30,8 +30,38 @@ Zsh is a shell with lots of features.  For a list of some of these, see the
 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.
diff --git a/Src/builtin.c b/Src/builtin.c
index 51ddce18c..e9ad8f3de 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -2944,8 +2944,7 @@ bin_functions(char *name, char **argv, Options ops, int func)
 	    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) {
diff --git a/Test/C04funcdef.ztst b/Test/C04funcdef.ztst
index 90f01e397..706aa28c2 100644
--- a/Test/C04funcdef.ztst
+++ b/Test/C04funcdef.ztst
@@ -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