Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: emulate & xtrace
On Thu, 23 Feb 2012 08:45:29 -0800
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Feb 23, 11:01am, Peter Stephenson wrote:
> } I'm thinking (post 4.3.17) of trying to make the "emulate" command leave
> } on the "xtrace" option if running inside a function and the nearest
> } enclosing function has "functions -t" set. Before I look at this, can
> } anybody see if this is a bad idea? (Obviously "unsetopt xtrace" still
> } does what you expect).
>
> I'd almost be inclined to leave xtrace alone regardess of functions -t
> but I don't see any harm in doing it the way you've described.
This is easy, but I'm in two minds about whether to trace back through
the shell's execution stack to find the nearest enclosing function, or
to decree that if you have "source", ".", or "eval" inside the function
then an "emulate" in those won't have this behaviour. I've done the
latter because it was slightly simpler to implement, but I could be
convinced otherwise: after all, the emulate is not local to those other
commands so it's other effects propagate back.
Index: Doc/Zsh/builtins.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/builtins.yo,v
retrieving revision 1.136
diff -p -u -r1.136 builtins.yo
--- Doc/Zsh/builtins.yo 3 Jun 2011 19:54:44 -0000 1.136
+++ Doc/Zsh/builtins.yo 29 Feb 2012 15:47:14 -0000
@@ -366,6 +366,13 @@ noderef(Compatibility)
)\
.
+If the tt(emulate) command occurs inside a function that has been
+marked for execution tracing with tt(functions -t) then the tt(xtrace)
+option will be turned on regardless of emulation mode or other options.
+Note that code executed inside the function by the tt(.), tt(source), or
+tt(eval) commands is not considered to be running directly from the
+function, hence does not provoke this behaviour.
+
If the tt(-R) option is given, all options
are reset to their default value corresponding to the specified emulation
mode, except for certain options describing the interactive
Index: Src/options.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/options.c,v
retrieving revision 1.59
diff -p -u -r1.59 options.c
--- Src/options.c 8 Jan 2012 16:02:55 -0000 1.59
+++ Src/options.c 29 Feb 2012 15:47:14 -0000
@@ -523,6 +523,20 @@ emulate(const char *zsh_name, int fully)
if (fully)
emulation |= EMULATE_FULLY;
installemulation();
+
+ if (funcstack && funcstack->tp == FS_FUNC) {
+ /*
+ * We are inside a function. Decide if it's traced.
+ * Pedantic note: the function in the function table isn't
+ * guaranteed to be what we're executing, but it's
+ * close enough.
+ */
+ Shfunc shf = (Shfunc)shfunctab->getnode(shfunctab, funcstack->name);
+ if (shf && (shf->node.flags & PM_TAGGED)) {
+ /* Tracing is on, so set xtrace */
+ opts[XTRACE] = 1;
+ }
+ }
}
/* setopt, unsetopt */
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK
Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog
Messages sorted by:
Reverse Date,
Date,
Thread,
Author