zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: Re: Don't understand compadd -p (or -P) any more
@ 1999-03-01 17:10 Sven Wischnowsky
  1999-03-01 17:18 ` Something wrong with dependencies (RE: PATCH: Re: Don't understand compadd -p (or -P) any more) Andrej Borsenkow
  0 siblings, 1 reply; 4+ messages in thread
From: Sven Wischnowsky @ 1999-03-01 17:10 UTC (permalink / raw)
  To: zsh-workers


Peter Stephenson wrote:

> I thought I'd got this worked out, so maybe it's a bug.
> 
> % _foo() { compadd -p pref/ bar rod; }
> % compdef _foo foo
> % foo pref/<TAB>                      # nothing
> % foo <TAB>
> bar rod
> 
> and the choices on the line do have the correct prefix.  In other words, if
> there's a pre-existing prefix there, it doesn't recognise it.  Now it seems
> -P is doing the same thing.  Has the behaviour changed in some way I don't
> understand?

I had played with this the weekend before the last one and wanted to
make the code automatically insert the `-p'-prefix. At that time I had 
a function where it worked, but I don't remember it anymore.
The patch below implements the other thing I tried at the time. With
this, the prefix/suffix given with `-p' and `-s'  have to be present
on the line if matching is done. I think this makes sense (and the
older stuff had some other problems anyway).

The problem with the `-P' prefix was that the prefix on the line
wasn't ignored.

Bye
 Sven

--- os/Zle/zle_tricky.c	Mon Mar  1 16:42:13 1999
+++ Src/Zle/zle_tricky.c	Mon Mar  1 18:08:15 1999
@@ -3984,6 +3984,7 @@
 	   int flags, int aflags, Cmatcher match, char *exp, char **argv)
 {
     char *s, *t, *e, *me, *ms, *lipre = NULL, *lpre, *lsuf, **aign = NULL;
+    char *tlsuf;
     int lpl, lsl, i, pl, sl, test, bpl, bsl, llpl, llsl;
     Aminfo ai;
     Cline lc = NULL;
@@ -4030,6 +4031,14 @@
 		lsuf = dupstring(compsuffix);
 		llpl = strlen(lpre);
 		llsl = strlen(lsuf);
+		/* Test if there is an existing -P prefix. */
+		if (pre && *pre) {
+		    pl = strlen(pre);
+		    if (pl <= llpl && !strncmp(lpre, pre, pl)) {
+			llpl -= pl;
+			lpre += pl;
+		    }
+		}
 		if (isset(GLOBCOMPLETE)) {
 		    char *tmp = (char *) zhalloc(2 + llpl + llsl);
 
@@ -4061,47 +4070,56 @@
 		lsl = strlen(psuf);
 	    } else
 		lsl = 0;
-	    if (pre)
-		pre = dupstring(pre);
-	    if (suf)
-		suf = dupstring(suf);
-	    if (!prpre && (prpre = ppre)) {
-		singsub(&prpre);
-		untokenize(prpre);
-	    } else
-		prpre = dupstring(prpre);
-	    /* Select the group in which to store the matches. */
-	    if (group) {
-		endcmgroup(NULL);
-		begcmgroup(group, (aflags & CAF_NOSORT));
-		if (aflags & CAF_NOSORT)
-		    mgroup->flags |= CGF_NOSORT;
-	    } else {
-		endcmgroup(NULL);
-		begcmgroup("default", 0);
-	    }
-	    /* Select the set of matches. */
-	    if (aflags & CAF_ALT) {
-		l = fmatches;
-		ai = fainfo;
-	    } else {
-		l = matches;
-		ai = ainfo;
-	    }
-	    if (remf) {
-		remf = dupstring(remf);
-		rems = NULL;
-	    } else if (rems)
-		rems = dupstring(rems);
-	    /* Build the common -P prefix. */
-    	    if (ai->pprefix) {
+	    if ((aflags & CAF_MATCH) &&
+		((lpl && (llpl < lpl || strncmp(lpre, ppre, lpl))) ||
+		 (lsl && (llsl < lsl || strncmp(lsuf + llsl - lsl, psuf, lsl)))))
+		*argv = NULL;
+	    else {
+		if (aflags & CAF_MATCH) {
+		    tlsuf = dupstring(lsuf);
+		    tlsuf[llsl - lsl] = '\0';
+		}
 		if (pre)
-		    ai->pprefix[pfxlen(ai->pprefix, pre)] = '\0';
-		else
-		    ai->pprefix[0] = '\0';
-	    } else
-		ai->pprefix = dupstring(pre ? pre : "");
-
+		    pre = dupstring(pre);
+		if (suf)
+		    suf = dupstring(suf);
+		if (!prpre && (prpre = ppre)) {
+		    singsub(&prpre);
+		    untokenize(prpre);
+		} else
+		    prpre = dupstring(prpre);
+		/* Select the group in which to store the matches. */
+		if (group) {
+		    endcmgroup(NULL);
+		    begcmgroup(group, (aflags & CAF_NOSORT));
+		    if (aflags & CAF_NOSORT)
+			mgroup->flags |= CGF_NOSORT;
+		} else {
+		    endcmgroup(NULL);
+		    begcmgroup("default", 0);
+		}
+		/* Select the set of matches. */
+		if (aflags & CAF_ALT) {
+		    l = fmatches;
+		    ai = fainfo;
+		} else {
+		    l = matches;
+		    ai = ainfo;
+		}
+		if (remf) {
+		    remf = dupstring(remf);
+		    rems = NULL;
+		} else if (rems)
+		    rems = dupstring(rems);
+		/* Build the common -P prefix. */
+		if (ai->pprefix) {
+		    if (pre)
+			ai->pprefix[pfxlen(ai->pprefix, pre)] = '\0';
+		    else
+			ai->pprefix[0] = '\0';
+		} else
+		    ai->pprefix = dupstring(pre ? pre : "");
+	    }
 	    /* Walk through the matches given. */
 	    for (; (s = dupstring(*argv)); argv++) {
 		sl = strlen(s);
@@ -4136,19 +4154,19 @@
 			else
 			    continue;
 		    } else {
-			test = (sl >= llpl + llsl &&
-				strpfx(lpre, s) && strsfx(lsuf, s));
+			test = (sl >= llpl + llsl - lpl - lsl &&
+				strpfx(lpre + lpl, s) && strsfx(tlsuf, s));
 			if (!test && mstack &&
-			    (ms = comp_match(lpre, lsuf, s,
+			    (ms = comp_match(lpre + lpl, tlsuf, s,
 					     &lc, (aflags & CAF_QUOTE),
 					     &bpl, &bsl)))
 			    test = 1;
 
 			if (!test)
 			    continue;
-			pl = sl - llsl;
-			me = s + sl - llsl;
-			e = s + llpl;
+			pl = sl - (llsl - lsl);
+			me = s + sl - (llsl - lsl);
+			e = s + (llpl - lpl);
 		    }
 		} else {
 		    e = s;
@@ -4175,7 +4193,7 @@
 		if (ppre)
 		    t = dyncat(ppre, t);
 		if (!cp && !ms && mstack) {
-		    int bl = ((aflags & CAF_MATCH) ? llpl : 0);
+		    int bl = ((aflags & CAF_MATCH) ? (llpl - lpl) : 0);
 		    Cline *clp = &lc, tlc;
 		    char *ss = dupstring(s), *ee = me + (ss - s);
 

--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Something wrong with dependencies (RE: PATCH: Re: Don't understand compadd -p (or -P) any more)
  1999-03-01 17:10 PATCH: Re: Don't understand compadd -p (or -P) any more Sven Wischnowsky
@ 1999-03-01 17:18 ` Andrej Borsenkow
  0 siblings, 0 replies; 4+ messages in thread
From: Andrej Borsenkow @ 1999-03-01 17:18 UTC (permalink / raw)
  To: Sven Wischnowsky, zsh-workers


I just finished with build when this arrived :-) I applied the patch, did
make - and Src/Zle/zle_tricky.c was not recompiled.

/andrej


^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: Something wrong with dependencies (RE: PATCH: Re: Don't understand compadd -p (or -P) any more)
@ 1999-03-01 18:19 Andrej Borsenkow
  0 siblings, 0 replies; 4+ messages in thread
From: Andrej Borsenkow @ 1999-03-01 18:19 UTC (permalink / raw)
  To: zsh-workers

I think, I guess why it happens. I did ``gmake; gmake distclean; gmake'' and
then applied patch. Unfortunately, the second make never makes any modules
(including zle).

Here is what is generated for distclean (and mostlyclean, realclean)
targets.

Src/Makefile:

Makemod modules.index prep: modules-bltin $(CONFIG_INCS)
	                      ^^^^^^^^^^^^^

distclean:   distclean-recursive   distclean-here
distclean-here: clean-here
clean-here: mostlyclean-here
mostlyclean-here:
        rm -f stamp-modobjs stamp-modobjs.tmp
clean-here:
	rm -f modules.index.tmp modules.stamp zsh ansi2knr.o ansi2knr
	rm -f libzsh-*.$(DL_EXT)
distclean-here:
	rm -f TAGS tags
	rm -f modules.index modules-bltin Makefile
distclean: distclean-modules
mostlyclean-modules clean-modules distclean-modules realclean-modules:
Makemod
        @$(MAKE) -f Makemod $(MAKEDEFS) `echo $@ | sed 's/-modules//'`

So, make first removes (among others) modules-bltin, _then_ excutes
distclean-modules, that depends on Makemod that depends on modules-bltin ...
that reruns our nice scripts and leaves some files around (because they
already are deleted from make's point of view :-). And for some reason, all
modules are omitted when these scripts are run, and obviously some files are
never recreated after that because they are already up to date.

That means, that after ``make distclean'' you better remove the whole tree
and start over again. But I just applied all post-pws-10 patches ...

What a mess really


> -----Original Message-----
> From: Andrej Borsenkow
> Sent: Monday, March 01, 1999 8:19 PM
> To: Sven Wischnowsky; zsh-workers@sunsite.auc.dk
> Subject: RE: Something wrong with dependencies (RE: PATCH: Re: Don't
> understand compadd -p (or -P) any more)
>
>
> I forgot to mention, it was with --enable-dynamic
>
> > I just finished with build when this arrived :-) I applied the
> > patch, did make - and Src/Zle/zle_tricky.c was not recompiled.
> >
> > /andrej


^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: Something wrong with dependencies (RE: PATCH: Re: Don't understand compadd -p (or -P) any more)
@ 1999-03-01 17:19 Andrej Borsenkow
  0 siblings, 0 replies; 4+ messages in thread
From: Andrej Borsenkow @ 1999-03-01 17:19 UTC (permalink / raw)
  To: Sven Wischnowsky, zsh-workers

I forgot to mention, it was with --enable-dynamic

> I just finished with build when this arrived :-) I applied the 
> patch, did make - and Src/Zle/zle_tricky.c was not recompiled.
> 
> /andrej


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1999-03-01 18:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-03-01 17:10 PATCH: Re: Don't understand compadd -p (or -P) any more Sven Wischnowsky
1999-03-01 17:18 ` Something wrong with dependencies (RE: PATCH: Re: Don't understand compadd -p (or -P) any more) Andrej Borsenkow
1999-03-01 17:19 Andrej Borsenkow
1999-03-01 18:19 Andrej Borsenkow

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).