Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: evaluation depth in prompts

On Tue, 26 Aug 2014 17:40:29 +0100
Peter Stephenson <p.stephenson@xxxxxxxxxxx> 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)).
+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).
 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)
+	    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()) {


Messages sorted by: Reverse Date, Date, Thread, Author