zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk (Zsh hackers list)
Subject: Re: PATCH: $' completion, the story so far
Date: Fri, 8 Dec 2006 18:48:20 +0000	[thread overview]
Message-ID: <20061208184820.0758614e.pws@csr.com> (raw)
In-Reply-To: <200612032100.kB3L0gl2023398@pwslaptop.csr.com>

Peter Stephenson <p.w.stephenson@ntlworld.com> 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


      reply	other threads:[~2006-12-08 18:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-03 21:00 Peter Stephenson
2006-12-08 18:48 ` Peter Stephenson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20061208184820.0758614e.pws@csr.com \
    --to=pws@csr.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).