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

Re: Completion in braces limitation



Oliver Kiddle wrote:

> Completion in braces doesn't seem to work in combination with variables:
> 
> zsh -f
> less $PWD/<tab>  - beep and lists files
> less $PWD/{<tab> - just beeps

This was intentional, the completion gave up as soon as it found the `$'.
The patch below makes it try a little harder by looking at what comes
after the `$'. If there is a complete parameter expansion and the
opening brace from the brace expansion comes after it, this should
work now.
I would be thankful if someone (you?) could test this more thoroughly, 
though.

> Another feature which would be useful is if completion of variables was
> extended to
> properly handle associative arrays. So for example, if I have an
> associative array named 'test',
> cd $test[<tab>
> would complete from the list of keys in $test.

Well, the new style completion can do this, of course...

And: I /think/ I already mentioned this some time ago (I knew someone
would say that he would like to have it). I don't remember exactly,
but I think I foresaw some problem there (mainly due to the code, I
think, not in what the user sees). There might be some ugly
interaction with normal subscripts...

So, no patch for this now. Sorry.

Bye
 Sven

diff -u os/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- os/Zle/zle_tricky.c	Tue Apr 27 13:06:22 1999
+++ Src/Zle/zle_tricky.c	Tue Apr 27 15:29:04 1999
@@ -1515,12 +1515,46 @@
 	     */
 	    for (i = 0, p = s; *p; p++, i++) {
 		/* careful, ${... is not a brace expansion...
-		 * in fact, if it's got a substitution in it's too
-		 * hard for us anyway.  sorry.
+		 * we try to get braces after a parameter expansion right,
+		 * but this may fail sometimes. sorry.
 		 */
 		if (*p == String || *p == Qstring) {
-		    tt = NULL;
-		    break;
+		    if (p[1] == Inbrace) {
+			char *tp = p + 1;
+			if (skipparens(Inbrace, Outbrace, &tp)) {
+			    tt = NULL;
+			    break;
+			}
+			i += tp - p;
+			p = tp;
+		    } else {
+			char *tp = p + 1;
+
+			if (*tp == Quest || *tp == Star || *tp == String ||
+			    *tp == Qstring || *tp == '?' || *tp == '*' ||
+			    *tp == '$' || *tp == '-' || *tp == '!' ||
+			    *tp == '@')
+			    p++, i++;
+			else {
+			    if (idigit(*tp))
+				while (idigit(*tp))
+				    tp++;
+			    else if (iident(*tp))
+				while (iident(*tp))
+				    tp++;
+			    else {
+				tt = NULL;
+				break;
+			    }
+			    if (*tp == Inbrace) {
+				tt = NULL;
+				break;
+			    }
+			    tp--;
+			    i += tp - p;
+			    p = tp;
+			}
+		    }
 		} else if (*p == Inbrace) {
 		    if (tt) {
 			/* too many inbraces */

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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