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

PATCH: compadd: prefer first options



One of the problems with the approximate completion stuff is that it
uses extra options for `compadd' and `compgen'. Previously all the
completion builtins (including `compctl') used the last use of an
option if it appeared more than once. E.g., with `compgen -X foo -X bar'
you got the explanation string `bar'. For `compgen' the correction
code could use this to append the extra options it inserted to the
list given by the completion function (correcting completion uses
temporarily defined functions with the names `compadd' and `compgen'
to insert it's own options in the argument list and to turn
`PREFIX/SUFFIX' into a pattern). But for `compadd' this didn't work
because there the last arguments are the words to add and finding the
last *option* in such an argument list can be very hard.

The patch below makes `compadd' prefer the *first* occurrence of an
option, allowing the correcting completion code to get the things
right.

This means that `compadd' differs in this respect from `compgen' and
`compctl', which is a bit ugly. I would like to change the code for
them, too, but that would make it incompatible with previous versions.
This is no problem for `compgen', but probably for `compctl', although 
this was never documented and using an option more than once probably
shows a thinko anyway. So my question is: should I change it for
`compgen' and `compctl', too? And then probably even document it?

Bye
 Sven

diff -u os/Zle/compctl.c Src/Zle/compctl.c
--- os/Zle/compctl.c	Thu Apr  1 15:09:22 1999
+++ Src/Zle/compctl.c	Wed Apr  7 21:10:05 1999
@@ -1799,15 +1799,13 @@
 		return 1;
 	    }
 	    if (sp) {
-		if (*sp) {
-		    zerrnam(name, "doubled option: -%c", NULL, *p);
-		    return 1;
-		}
 		if (p[1]) {
-		    *sp = p + 1;
+		    if (!*sp)
+			*sp = p + 1;
 		    p = "" - 1;
 		} else if (argv[1]) {
-		    *sp = *++argv;
+		    if (!*sp)
+			*sp = *++argv;
 		    p = "" - 1;
 		} else {
 		    zerrnam(name, e, NULL, *p);

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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