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

Re: completion problem with matching control.



Tanaka Akira wrote:

> I found a problem about completion with matching control.
> 
> Z:akr@is27e1u11% zsh-3.1.6-test-1 -f
> is27e1u11% autoload -U compinit
> is27e1u11% compinit -D
> is27e1u11% _tst () { compadd -P b A; compadd -P c A }
> is27e1u11% compdef -a _tst tst
> is27e1u11% compctl -M m:\{a-z\}\=\{A-Z\}
> is27e1u11% tst a<TAB>
> 
> Then, "a" is deleted.

The problem is in the different -P prefixes, not in the matching. The
completion code stuffed all prefixes and all suffixes together and adds 
them to the string itself, so that things still work even if for one
match a string-part is in one prefix and for another match the same
string is in a different prefix. However, -P is slightly different
since it doesn't `come from the line'. So this patch tries to keep the 
old behavior if possible and otherwise adds the prefixes one by one.

Bye
 Sven

diff -u os/Zle/zle_tricky.c Src/Zle/zle_tricky.c
--- os/Zle/zle_tricky.c	Thu Jul 15 16:01:50 1999
+++ Src/Zle/zle_tricky.c	Mon Jul 19 15:38:54 1999
@@ -3527,7 +3527,9 @@
 		p->next = qsl;
 	}
     }
-    /* And the same for the prefix. */
+    /* The prefix is handled differently because the completion code
+     * is much more eager to insert the -P prefix than it is to insert
+     * the -S suffix. */
     if (qipre)
 	palen = (qipl = strlen(qipre));
     if (ipre)
@@ -3537,7 +3539,49 @@
     if (ppre)
 	palen += (ppl = strlen(ppre));
 
-    if (palen) {
+    if (pl) {
+	if (ppl) {
+	    Cline lp, p = bld_parts(ppre, ppl, ppl, &lp);
+
+	    if (lp->prefix && !(line->flags & (CLF_SUF | CLF_MID))) {
+		lp->prefix->next = line->prefix;
+		line->prefix = lp->prefix;
+		lp->prefix = NULL;
+
+		free_cline(lp);
+
+		if (p != lp) {
+		    Cline q;
+
+		    for (q = p; q->next != lp; q = q->next);
+
+		    q->next = line;
+		    line = p;
+		}
+	    } else {
+		lp->next = line;
+		line = p;
+	    }
+	}
+	if (pl) {
+	    Cline lp, p = bld_parts(pre, pl, pl, &lp);
+
+	    lp->next = line;
+	    line = p;
+	}
+	if (ipl) {
+	    Cline lp, p = bld_parts(ipre, ipl, ipl, &lp);
+
+	    lp->next = line;
+	    line = p;
+	}
+	if (qipl) {
+	    Cline lp, p = bld_parts(qipre, qipl, qipl, &lp);
+
+	    lp->next = line;
+	    line = p;
+	}
+    } else if (palen) {
 	char *apre = (char *) zhalloc(palen);
 	Cline p, lp;
 

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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