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

Re: PATCH: completion for perl



Adam Spiers wrote:

> Sven Wischnowsky (wischnow@xxxxxxxxxxxxxxxxxxxxxxx) wrote:
> > 
> > Adam Spiers wrote:
> > 
> > > Whilst struggling with the mess which is _perl_config_vars below, it
> > > struck me how an equivalent of compset -P which matched the /whole/ of
> > > PREFIX rather than just the beginning would have come in handy. 
> > 
> > Err... `compset -P "*"' does that, but it leaves you with an empty
> > $PREFIX, of course, which is probably not what one wants.
> 
> Sorry; I didn't explain myself clearly at all.  I would like to be
> able to do a compset -P type of operation using a pattern which is
> anchored to both the start /and/ end of PREFIX, rather than just the
> start, which is what currently always happens.  Then again, I suppose
> this can be implemented easily manually, e.g.:
> 
>   if [[ "$PREFIX" == *: ]]; then
>     IPREFIX="$IPREFIX$PREFIX"
>     PREFIX=''
>   fi

Yep.

> ...
> > 
> > The problem is that we check the quoting stuff at the very beginning
> > of the completion code -- and detect only quotes at the beginning of
> > the word. So what we could get to work is completion of
> > 
> >   $ perl '-V:<TAB>
> > 
> > but not with the quote after the colon. That's done with first calling 
> > `compset -q', then the `compset -P'. Getting quotes in words to work
> > is to hard to make me try it (all kinds of nasty interactions with the 
> > lexer). But maybe calling first `compset -P' and then `compset -q'
> > should have the same effect as the other way round... I currently
> > don't remember why it behaves the way it does.
> 
> So is there currently no solution?  I tried using things like
> 
>   compset -P '*"'
> 
> but they never matched, presumably because of the lexer interactions
> you mention.

Yes, the completion code doesn't see the in-word quotes (well, only
get_comp_string() sees the tokens for them, but we decided some time
ago that the completion code only keeps quotes at the beginning/end of 
the word, generating some kind of `normalised' quoting).

But at least we should make `compset -q' work on the current value of
$PREFIX/$SUFFIX, keeping $IPREFIX/$ISUFFIX ignored (that's what I
meant in my last mail). The patch below does that.

Bye
 Sven

diff -ru ../z.old/Src/Zle/compcore.c Src/Zle/compcore.c
--- ../z.old/Src/Zle/compcore.c	Tue Mar 14 09:06:21 2000
+++ Src/Zle/compcore.c	Tue Mar 14 09:11:36 2000
@@ -1148,11 +1148,11 @@
     LinkNode n;
     int owe = we, owb = wb, ocs = cs, swb, swe, scs, soffs, ne = noerrs;
     int tl, got = 0, i = 0, cur = -1, oll = ll, sl, remq;
-    int ois = instring, oib = inbackt, noffs = lip + lp;
+    int ois = instring, oib = inbackt, noffs = lp;
     char *tmp, *p, *ns, *ol = (char *) line, sav, *qp, *qs, *ts, qc = '\0';
 
-    if (compisuffix)
-	s = dyncat(s, compisuffix);
+    s += lip;
+    wb += lip;
     untokenize(s);
 
     swb = swe = soffs = 0;
@@ -1343,16 +1343,16 @@
 	    untokenize(ss);
 	    compsuffix = ztrdup(ss);
 	}
-	zsfree(compiprefix);
-	compiprefix = ztrdup("");
-	zsfree(compisuffix);
-	compisuffix = ztrdup("");
-	tmp = tricat(compqiprefix, "", multiquote(qp, 1));
+	tmp = tricat(compqiprefix, compiprefix, multiquote(qp, 1));
 	zsfree(compqiprefix);
 	compqiprefix = tmp;
-	tmp = tricat(multiquote(qs, 1), "", compqisuffix);
+	tmp = tricat(multiquote(qs, 1), compisuffix, compqisuffix);
 	zsfree(compqisuffix);
 	compqisuffix = tmp;
+	zsfree(compiprefix);
+	compiprefix = ztrdup("");
+	zsfree(compisuffix);
+	compisuffix = ztrdup("");
 	freearray(compwords);
 	i = countlinknodes(foo);
 	compwords = (char **) zalloc((i + 1) * sizeof(char *));

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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