zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <Peter.Stephenson@csr.com>
To: "Zsh Hackers' List" <zsh-workers@zsh.org>
Subject: Re: emulate & xtrace
Date: Wed, 29 Feb 2012 15:52:57 +0000	[thread overview]
Message-ID: <20120229155257.204ea6fd@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <120223084529.ZM11820@torch.brasslantern.com>

On Thu, 23 Feb 2012 08:45:29 -0800
Bart Schaefer <schaefer@brasslantern.com> 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@csr.com>            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


      reply	other threads:[~2012-02-29 16:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-23 11:01 Peter Stephenson
2012-02-23 16:45 ` Bart Schaefer
2012-02-29 15:52   ` Peter Stephenson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120229155257.204ea6fd@pwslap01u.europe.root.pri \
    --to=peter.stephenson@csr.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).