zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: Zsh Hackers' List <zsh-workers@zsh.org>
Subject: PATCH: evaluation depth in prompts
Date: Tue, 26 Aug 2014 18:10:55 +0100	[thread overview]
Message-ID: <20140826181055.59c99bdc@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <20140826174029.6478ee3a@pwslap01u.europe.root.pri>

On Tue, 26 Aug 2014 17:40:29 +0100
Peter Stephenson <p.stephenson@samsung.com> wrote:
> A better solution might be for a prompt escape that tracks the
> nesting level (which is trivial apart from picking a new letter).

%e for evaluation depth (%E is taken but %e isn't).

I won't commit this until the release now.  Probably Thursday is my next
chance for that while leaving enough time for people to moan.

diff --git a/Doc/Zsh/prompt.yo b/Doc/Zsh/prompt.yo
index 0ed52b5..183a93a 100644
--- a/Doc/Zsh/prompt.yo
+++ b/Doc/Zsh/prompt.yo
@@ -108,6 +108,12 @@ the full path;
 ifzman(see em(Dynamic) and em(Static named directories) in zmanref(zshexpn))\
 ifnzman(noderef(Filename Expansion)).
 )
+item(tt(%e))(
+Evaluation depth of the current sourced file, shell function, or tt(eval).
+This is incremented or decremented every time the value of tt(%N) is
+set or reverted to a previous value, respectively.  This is most useful
+for debugging as part of tt($PS4).
+)
 xitem(tt(%h))
 item(tt(%!))(
 Current history event number.
diff --git a/Src/prompt.c b/Src/prompt.c
index 328ae3c..4762535 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -786,6 +786,19 @@ putpromptchar(int doprint, int endchar, unsigned int *txtchangep)
 		if(bv->Rstring)
 		    stradd(bv->Rstring);
 		break;
+	    case 'e':
+	    {
+		int depth = 0;
+		Funcstack fsptr = funcstack;
+		while (fsptr) {
+		    depth++;
+		    fsptr = fsptr->prev;
+		}
+		addbufspc(DIGBUFSIZE);
+		sprintf(bv->bp, "%d", depth);
+		bv->bp += strlen(bv->bp);
+		break;
+	    }
 	    case 'I':
 		if (funcstack && funcstack->tp != FS_SOURCE &&
 		    !IN_EVAL_TRAP()) {


pws


  reply	other threads:[~2014-08-26 17:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-26 16:40 Function for examining structure of calls in debug output Peter Stephenson
2014-08-26 17:10 ` Peter Stephenson [this message]
2014-08-29 16:16   ` PATCH: evaluation depth in prompts Peter Stephenson
2014-09-01 21:02     ` Bart Schaefer
2014-09-02  8:38       ` Peter Stephenson
2014-09-02 23:53       ` Oliver Kiddle
2014-09-03  1:38         ` Bart Schaefer
2014-08-30 20:35   ` Bart Schaefer
2014-08-30 19:38 ` Function for examining structure of calls in debug output Bart Schaefer

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=20140826181055.59c99bdc@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.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).