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

typeset -p with assoc array (was Re: Typeset with array)



On Jun 23, 10:24pm, Mikael Magnusson wrote:
} 
} > If I were going to "fix" it for no reason other than the consistency,
} > I'd simply add MORE spaces rather than try to squash that one.
} 
} This would also be consistent with xtrace output, so I agree :).

This is not difficult, and doesn't conflict with the typeset-array
branch as far as I can see, so ... patch below.

However, it does point out that the typeset-array branch could update
printparamnode() to emit

    typeset -a a=( b )

instead of the historic two-line format.  (Urk, it'd be kind of ugly
to make that depend on whether the reserved word was enabled.)


diff --git a/Src/params.c b/Src/params.c
index 3b75735..f8d039a 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -5091,8 +5091,10 @@ printparamvalue(Param p, int printflags)
 	break;
     case PM_ARRAY:
 	/* array */
-	if (!(printflags & PRINT_KV_PAIR))
+	if (!(printflags & PRINT_KV_PAIR)) {
 	    putchar('(');
+	    putchar(' ');
+	}
 	u = p->gsu.a->getfn(p);
 	if(*u) {
 	    quotedzputs(*u++, stdout);
@@ -5101,13 +5103,17 @@ printparamvalue(Param p, int printflags)
 		quotedzputs(*u++, stdout);
 	    }
 	}
-	if (!(printflags & PRINT_KV_PAIR))
+	if (!(printflags & PRINT_KV_PAIR)) {
+	    putchar(' ');
 	    putchar(')');
+	}
 	break;
     case PM_HASHED:
 	/* association */
-	if (!(printflags & PRINT_KV_PAIR))
+	if (!(printflags & PRINT_KV_PAIR)) {
 	    putchar('(');
+	    putchar(' ');
+	}
 	{
             HashTable ht = p->gsu.h->getfn(p);
             if (ht)



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