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

PATCH: indent in code output (was Re: preventing the leading space ...)



On Thu, 11 Sep 2008 15:54:16 +0100
Peter Stephenson <pws@xxxxxxx> wrote:
> I note that $ZSH_DEBUG_CMD has strange (overlarge) indentation for the
> elements of (...)  after the opening parenthesis.  I think that needs
> revisiting.  I don't quite understand why the default indentation is 1
> instead of 0; obviously that's right for outputting the bodies of
> functions, but the code has many other uses.

I think it's simply never been right for uses other than outputting
functions for the reason that usually in other case the indentation doesn't
show up.  I can't believe

% (trap '(echo foo); echo bar' DEBUG; trap) 
foo
bar
trap -- '(
		echo foo
	)
	echo bar' DEBUG

was ever the intention.  (It's certainly not the case that the code is
indented to match the code before the opening quote, that's not taken into
account.)  This makes the output code

trap -- '(
	echo foo
)
echo bar' DEBUG

and fixes other pieces of code (including $ZSH_DEBUG_CMD) similarly.

Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.204
diff -u -r1.204 builtin.c
--- Src/builtin.c	3 Sep 2008 09:08:22 -0000	1.204
+++ Src/builtin.c	11 Sep 2008 17:05:32 -0000
@@ -5725,7 +5725,7 @@
 		if (!siglists[sig])
 		    printf("trap -- '' %s\n", name);
 		else {
-		    s = getpermtext(siglists[sig], NULL);
+		    s = getpermtext(siglists[sig], NULL, 0);
 		    printf("trap -- ");
 		    quotedzputs(s, stdout);
 		    printf(" %s\n", name);
Index: Src/exec.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/exec.c,v
retrieving revision 1.150
diff -u -r1.150 exec.c
--- Src/exec.c	11 Sep 2008 14:47:33 -0000	1.150
+++ Src/exec.c	11 Sep 2008 17:05:32 -0000
@@ -1084,7 +1084,7 @@
 	    noerrexit = 1;
 	    if (ltype & Z_SIMPLE) /* skip the line number */
 		pc2++;
-	    pm = setsparam("ZSH_DEBUG_CMD", getpermtext(state->prog, pc2));
+	    pm = setsparam("ZSH_DEBUG_CMD", getpermtext(state->prog, pc2, 0));
 
 	    exiting = donetrap;
 	    ret = lastval;
Index: Src/hashtable.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/hashtable.c,v
retrieving revision 1.28
diff -u -r1.28 hashtable.c
--- Src/hashtable.c	11 Aug 2008 19:22:54 -0000	1.28
+++ Src/hashtable.c	11 Sep 2008 17:05:32 -0000
@@ -887,7 +887,7 @@
 	if (f->node.flags & PM_UNDEFINED)
 	    printf("%c undefined\n\t", hashchar);
 	else
-	    t = getpermtext(f->funcdef, NULL);
+	    t = getpermtext(f->funcdef, NULL, 1);
 	if (f->node.flags & PM_TAGGED)
 	    printf("%c traced\n\t", hashchar);
 	if (!t) {
Index: Src/init.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/init.c,v
retrieving revision 1.95
diff -u -r1.95 init.c
--- Src/init.c	3 Sep 2008 09:08:22 -0000	1.95
+++ Src/init.c	11 Sep 2008 17:05:32 -0000
@@ -168,7 +168,7 @@
 		else
 		    addlinknode(args, "");
 		addlinknode(args, dupstring(getjobtext(prog, NULL)));
-		addlinknode(args, cmdstr = getpermtext(prog, NULL));
+		addlinknode(args, cmdstr = getpermtext(prog, NULL, 0));
 
 		callhookfunc("preexec", args, 1, NULL);
 
Index: Src/text.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/text.c,v
retrieving revision 1.23
diff -u -r1.23 text.c
--- Src/text.c	5 Sep 2008 09:05:23 -0000	1.23
+++ Src/text.c	11 Sep 2008 17:05:32 -0000
@@ -118,7 +118,7 @@
 
 /**/
 mod_export char *
-getpermtext(Eprog prog, Wordcode c)
+getpermtext(Eprog prog, Wordcode c, int start_indent)
 {
     struct estate s;
 
@@ -131,6 +131,7 @@
     s.pc = c;
     s.strs = prog->strs;
 
+    tindent = start_indent;
     tnewlins = 1;
     tbuf = (char *)zalloc(tsiz = 32);
     tptr = tbuf;
@@ -162,6 +163,7 @@
     s.pc = c;
     s.strs = prog->strs;
 
+    tindent = 0;
     tnewlins = 0;
     tbuf = NULL;
     tptr = jbuf;
@@ -245,16 +247,6 @@
     int stack = 0;
     wordcode code;
 
-    /*
-     * Hack for parsing "simple" format of function definitions.
-     * In this case there is no surrounding context so the initial
-     * indent should be zero.
-     */
-    if (wc_code(*state->pc) == WC_FUNCDEF)
-	tindent = 0;
-    else
-	tindent = 1;
-
     while (1) {
 	if (stack) {
 	    if (!(s = tstack))
Index: Src/Modules/parameter.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Modules/parameter.c,v
retrieving revision 1.48
diff -u -r1.48 parameter.c
--- Src/Modules/parameter.c	3 Sep 2008 09:08:22 -0000	1.48
+++ Src/Modules/parameter.c	11 Sep 2008 17:05:32 -0000
@@ -390,7 +390,7 @@
 				((shf->node.flags & PM_TAGGED) ? "Ut" : "U") :
 				((shf->node.flags & PM_TAGGED) ? "t" : "")));
 	} else {
-	    char *t = getpermtext(shf->funcdef, NULL), *n, *h;
+	    char *t = getpermtext(shf->funcdef, NULL, 1), *n, *h;
 
 	    if (shf->funcdef->flags & EF_RUN) {
 		n = nicedupstring(name);
@@ -455,7 +455,8 @@
 				    ((shf->node.flags & PM_TAGGED) ? "Ut" : "U") :
 				    ((shf->node.flags & PM_TAGGED) ? "t" : "")));
 		    } else {
-			char *t = getpermtext(((Shfunc) hn)->funcdef, NULL), *n;
+			char *t = getpermtext(((Shfunc) hn)->funcdef, NULL, 1);
+			char *n;
 
 			if (((Shfunc) hn)->funcdef->flags & EF_RUN) {
 			    n = nicedupstring(hn->nam);

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



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