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

Re: PATCH: $' completion, the story so far



Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> wrote:
> Here's my attempt so far to make $' quoting work a little better in
> completion.
>...
> If you want to see what's still wrong, try
> 
> su -c "ls $'<file>
> 
> and you'll get a whole load of unnecessary backslashes when a word is
> inserted (for some reason listing alone works OK).

This fixes two real problems and a cosmetic one, the latter being that the
$ in the double quotes was quoted by the internal equivalent of
${(qqq)...}.  This is harmless because the backslash is stripped, but I
think leaving it without is preferable --- quotestring() usually only adds
backslashes when they're necessary.

There's still a problem with multiple uses of $'...':

su -c "ls $'onefile' $'...

doesn't complete properly.

Index: Src/utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/utils.c,v
retrieving revision 1.146
diff -u -r1.146 utils.c
--- Src/utils.c	3 Dec 2006 21:07:18 -0000	1.146
+++ Src/utils.c	8 Dec 2006 18:32:40 -0000
@@ -4292,9 +4292,17 @@
 		if (!*u)
 		    u--;
 		continue;
-	    }
-	    else if ((*u == String || *u == Qstring) &&
-		     (u[1] == Inpar || u[1] == Inbrack || u[1] == Inbrace)) {
+	    } else if ((*u == Qstring || *u == '$') && u[1] == '\'' &&
+		       instring == QT_DOUBLE) {
+		/*
+		 * We don't need to quote $'...' inside a double-quoted
+		 * string.  This is largely cosmetic; it looks neater
+		 * if we don't but it doesn't do any harm since the
+		 * \ is stripped.
+		 */
+		*v++ = *u++;
+	    } else if ((*u == String || *u == Qstring) &&
+		       (u[1] == Inpar || u[1] == Inbrack || u[1] == Inbrace)) {
 		char c = (u[1] == Inpar ? Outpar : (u[1] == Inbrace ?
 						    Outbrace : Outbrack));
 		char beg = *u;
Index: Src/Zle/compcore.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compcore.c,v
retrieving revision 1.87
diff -u -r1.87 compcore.c
--- Src/Zle/compcore.c	3 Dec 2006 21:07:18 -0000	1.87
+++ Src/Zle/compcore.c	8 Dec 2006 18:32:42 -0000
@@ -1653,6 +1653,7 @@
 	    instring = QT_DOLLARS;
 	    nsptr++;
 	    tsptr++;
+	    swb++;
 	    break;
 	}
 
Index: Src/Zle/zle_tricky.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_tricky.c,v
retrieving revision 1.80
diff -u -r1.80 zle_tricky.c
--- Src/Zle/zle_tricky.c	3 Dec 2006 21:07:18 -0000	1.80
+++ Src/Zle/zle_tricky.c	8 Dec 2006 18:32:42 -0000
@@ -1032,6 +1032,16 @@
 has_real_token(const char *s)
 {
     while (*s) {
+	/*
+	 * Special action required for $' strings, which
+	 * need to be treated like nulls.
+	 */
+	if ((*s == Qstring && s[1] == '\'') ||
+	    (*s == String && s[1] == Snull))
+	{
+	    s += 2;
+	    continue;
+	}
 	if (itok(*s) && !inull(*s))
 	    return 1;
 	s++;


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php



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