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

Re: Another ${(z)param} buglet



On Dec 12, 10:45pm, Peter Stephenson wrote:
}
} > Here it is implemented and tested, so you can tell me it's not good
} > enough.
} 
} As there were no further comments (funny, that...) I've committed it.

I'd already made my suggestion about (Z:...:) as an alternative, so it
didn't seem necessary to repeat myself.  You've now done the difficult
bits, so ...

Here's a patch that leaves (z+...+) and the rest of PWS's excellent
bufferwords tricks, but adds (Z:...:) where ":" can be an arbitrary
character or matching braces as with (s:...:) et al.

I'm thinking future possible enhancments for (Z) include locally altering
the value of $histchars (which is why one might want a delimiter other
than "+"), and performing history substitutions on the string.  None of
that has been done here, yet; also I made only a minimal change to the
test script to prove it works, and haven't done doc yet either.

What say?  This could also easily be tweaked to make (z) and (z:...:),
with the :...: having become optional, but we don't have any other cases
where the delimited arg string is completely optional [although (l) and
(r) have optional sub-parts].

Index: Src/subst.c
--- zsh-forge/current/Src/subst.c	2010-12-12 16:22:56.000000000 -0800
+++ Src/subst.c	2010-12-12 16:50:38.000000000 -0800
@@ -1938,10 +1938,16 @@
 
 		case 'z':
 		    shsplit = 1;
-		    if (s[1] == '+') {
-			s += 2;
-			while (*s && *s != '+' && *s != ')' && *s != Outpar) {
-			    switch (*s++) {
+		    if (s[1] != '+')
+			break;
+
+		case 'Z':
+		    t = get_strarg(++s, &arglen);
+		    if (*t) {
+			sav = *t;
+			*t = 0;
+			while (*++s) {
+			    switch (*s) {
 			    case 'c':
 				/* Parse and keep comments */
 				shsplit = 2;
@@ -1956,9 +1962,10 @@
 				goto flagerr;
 			    }
 			}
-			if (*s != '+')
-			    goto flagerr;
-		    }
+			*t = sav;
+			s = t + arglen - 1;
+		    } else
+			goto flagerr;
 		    break;
 
 		case 'u':
--- zsh-forge/current/Test/D04parameter.ztst	2010-12-12 16:22:56.000000000 -0800
+++ Test/D04parameter.ztst	2010-12-12 16:50:37.000000000 -0800
@@ -423,7 +423,7 @@
   print "*** Kept ***"
   print -l ${(z+c+)line}
   print "*** Removed ***"
-  print -l ${(z+C+)line}
+  print -l ${(Z+C+)line}
 0:Comments with (z)
 >*** Normal ***
 >A



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