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

Re: help with _match, globcomplete etc.



Oliver Kiddle wrote:

> ...
>
> so that ^X$ wouldn't also glob complete but it comes back with any glob
> characters quoted. It seems that expand-word always does this when
> noglob is set. Surely this isn't right? In the process, I also noticed
> that the quoting can go slightly wrong if there are opened but not
> closed braces: $code[ai]/{a,b<Ctrl-X,*> comes back with a quoted '[' in
> the middle.

Hm. It's the call to quotename() in zle_tricky.c:1649. I'm pretty sure 
this is intended to make things work when the words resulting from
parameter expansion or globbing contains characters that need to be
quoted.

Trying to fix that would be very hard... we would have to find out
which part comes from the expansion and which doesn't or maybe being
more careful with (un)tokenization()... so, no patch for this.

However, it also removed parts of the string in cases like the example --
brace expansions. That's due to the in-brace completion stuff. The
patch fixes this in the simplest way I could thnik of: keep a
unaltered copy of the word an let expansion work on that.

I couldn't reproduce your `[' problem, unless that was a typo and you
meant a quoted `{'. In this case it's the same as for the quoted
globbing characters.

Bye
 Sven

P.S.:   The difference between the not-fixed and the fixed part is
        that I didn't write the former and hence don't really feel
        responsible ;-)

P.P.S.: Yes, there are parts of zle_tricky.c I didn't write.

diff -ru ../z.old/Src/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- ../z.old/Src/Zle/zle_tricky.c	Tue Feb 15 13:21:40 2000
+++ Src/Zle/zle_tricky.c	Tue Feb 15 16:55:11 2000
@@ -108,6 +108,10 @@
 
 static char *qword;
 
+/* This holds the word we are working on without braces removed. */
+
+static char *origword;
+
 /* The quoted prefix/suffix and a flag saying if we want to add the
  * closing quote. */
 
@@ -685,17 +689,17 @@
 	    inwhat = IN_CMD;
 
 	if (lst == COMP_SPELL) {
-	    char *x, *q, *ox;
+	    char *w = dupstring(origword), *x, *q, *ox;
 
-	    for (q = s; *q; q++)
+	    for (q = w; *q; q++)
 		if (INULL(*q))
 		    *q = Nularg;
 	    cs = wb;
 	    foredel(we - wb);
 	    HEAPALLOC {
-		untokenize(x = ox = dupstring(s));
-		if (*s == Tilde || *s == Equals || *s == String)
-		    *x = *s;
+		untokenize(x = ox = dupstring(w));
+		if (*w == Tilde || *w == Equals || *w == String)
+		    *x = *w;
 		spckword(&x, 0, lincmd, 0);
 		ret = !strcmp(x, ox);
 	    } LASTALLOC;
@@ -708,7 +712,7 @@
 	    int ocs = cs, ne = noerrs;
 
 	    noerrs = 1;
-	    ret = doexpansion(s, lst, olst, lincmd);
+	    ret = doexpansion(origword, lst, olst, lincmd);
 	    lastambig = 0;
 	    noerrs = ne;
 
@@ -1329,6 +1333,9 @@
 		chuck(p--);
 	    }
 
+	zsfree(origword);
+	origword = ztrdup(s);
+
 	if (!isset(IGNOREBRACES)) {
 	    /* Try and deal with foo{xxx etc. */
 	    char *curs = s + (isset(COMPLETEINWORD) ? offs : strlen(s));
@@ -1353,8 +1360,8 @@
 			    break;
 			}
 			i += tp - p;
-			p = tp;
 			dp += tp - p;
+			p = tp;
 		    } else {
 			char *tp = p + 1;
 
@@ -1385,8 +1392,8 @@
 			    }
 			    tp--;
 			    i += tp - p;
-			    p = tp;
 			    dp += tp - p;
+			    p = tp;
 			}
 		    }
 		} else if (p < curs) {

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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