zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: Re: Option completion after "nono"
@ 2000-10-09 12:48 Sven Wischnowsky
  2000-10-09 14:59 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Sven Wischnowsky @ 2000-10-09 12:48 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

> On Oct 6,  2:53pm, Sven Wischnowsky wrote:
> }
> } We use nonomatch not because of globbing, but because of ~... and
> } =... expansion.
> 
> Speaking of using nonomatch, have you tried to complete it?
> 
> zagzig% setopt nonom<TAB>
> nonomagicequalsubst   nonomarkdirs          nonomultios
> nonomailwarn          nonomenucomplete      
> nonomailwarning       nonomonitor           
> 
> Hmm, where is it?
>
> ...
> 
> There has to be some kind of matcher-magic to insert into _options (and
> into the example in the "Matching Control" doc) that means to accept
> matches both with _and without_ the leading "no" deleted, but I can't
> work out what it is.

Hm, I think it should do the right thing without using match-spec
hacks.

The patch below does that by preferring exact character matches over
using match specs. I know I once had a reason for doing it
differently, but I can't remember which. The completion matching tests
work and the only ones that might be in danger are ones with partial
word matching (as far as I can see). And the recusive code for that
has been improved several times since I made it prefer match specs
over exact character matches.

So I've left a comment in there and we'll see if it breaks anything.

If it doesn't, fine, that would make matching quite a bit faster...

Bye
 Sven

Index: Src/Zle/compmatch.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compmatch.c,v
retrieving revision 1.23
diff -u -r1.23 compmatch.c
--- Src/Zle/compmatch.c	2000/07/19 14:04:57	1.23
+++ Src/Zle/compmatch.c	2000/10/09 12:47:39
@@ -485,10 +485,19 @@
 	 * recursive calls. At least, it /seems/ to work.
 	 *
 	 * Let's try.
+	 *
+	 * Update: this once tested `test && ...' to check for exact
+	 * character matches only in recursive calls.  But then one
+	 * can't complete `nom<TAB>' to `nomatch' with a match spec
+	 * of `B:[nN][oO]=' because that will eat the `no'. I'm almost
+	 * certain that this will break something, but I don't know what
+	 * or if it really is a problem (or has been fixed by other
+	 * changes in the code handling partial word matching). And the
+	 * completion matching tests work.
 	 */
 
 	bslash = 0;
-	if (test && !sfx && lw &&
+	if (!sfx && lw &&
 	    (l[ind] == w[ind] ||
 	     (bslash = (lw > 1 && w[ind] == '\\' &&
 			(ind ? (w[0] == l[0]) : (w[1] == l[0])))))) {

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


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

* Re: PATCH: Re: Option completion after "nono"
  2000-10-09 12:48 PATCH: Re: Option completion after "nono" Sven Wischnowsky
@ 2000-10-09 14:59 ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2000-10-09 14:59 UTC (permalink / raw)
  To: zsh-workers

On Oct 9,  2:48pm, Sven Wischnowsky wrote:
} 
} Bart Schaefer wrote:
} 
} > Speaking of using nonomatch, have you tried to complete it?
} 
} Hm, I think it should do the right thing without using match-spec
} hacks.
} 
} The patch below does that by preferring exact character matches over
} using match specs.

One can now complete "nomatch" and "notify" but still not "nonomatch"
and "nonotify".

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

* Re: PATCH: Re: Option completion after "nono"
@ 2000-10-10 13:34 Sven Wischnowsky
  0 siblings, 0 replies; 4+ messages in thread
From: Sven Wischnowsky @ 2000-10-10 13:34 UTC (permalink / raw)
  To: zsh-workers


Slightly misplaced. Sorry.

Bye
 Sven

Index: Src/Zle/compmatch.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compmatch.c,v
retrieving revision 1.25
diff -u -r1.25 compmatch.c
--- Src/Zle/compmatch.c	2000/10/10 08:36:34	1.25
+++ Src/Zle/compmatch.c	2000/10/10 13:34:14
@@ -843,6 +843,9 @@
 	    he = 0;
 	} else {
 
+	    if (!lw)
+		break;
+
 	    if (exact) {
 		/* If we just accepted some characters directly (at the
 		 * beginning of the loop) and now can't match any further,
@@ -858,9 +861,6 @@
 
 		goto retry;
 	    }
-
-	    if (!lw)
-		break;
 	    /* No matcher and different characters: l does not match w. */
 	    if (test)
 		return 0;

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


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

* Re: PATCH: Re: Option completion after "nono"
@ 2000-10-10  8:31 Sven Wischnowsky
  0 siblings, 0 replies; 4+ messages in thread
From: Sven Wischnowsky @ 2000-10-10  8:31 UTC (permalink / raw)
  To: zsh-workers


Bart Schaefer wrote:

> On Oct 9,  2:48pm, Sven Wischnowsky wrote:
> } 
> } Bart Schaefer wrote:
> } 
> } > Speaking of using nonomatch, have you tried to complete it?
> } 
> } Hm, I think it should do the right thing without using match-spec
> } hacks.
> } 
> } The patch below does that by preferring exact character matches over
> } using match specs.
> 
> One can now complete "nomatch" and "notify" but still not "nonomatch"
> and "nonotify".

Ouch, of course. No good writing such patches between two exams.

Well, this patch makes match_str() go back when it just accepted some
exact character matches but can't match any further. It goes back to
before those character and then tries again, using the match specs.

I.e. it now tries both styles we had before.

Bye
 Sven

Index: Src/Zle/compmatch.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/compmatch.c,v
retrieving revision 1.24
diff -u -r1.24 compmatch.c
--- Src/Zle/compmatch.c	2000/10/09 12:50:21	1.24
+++ Src/Zle/compmatch.c	2000/10/10 08:30:50
@@ -440,7 +440,7 @@
 match_str(char *l, char *w, Brinfo *bpp, int bc, int *rwlp,
 	  int sfx, int test, int part)
 {
-    int ll = strlen(l), lw = strlen(w), oll = ll, olw = lw;
+    int ll = strlen(l), lw = strlen(w), oll = ll, olw = lw, exact = 0, wexact = 0;
     int il = 0, iw = 0, t, ind, add, he = 0, bpc, obc = bc, bslash;
     VARARR(unsigned char, ea, (ll > lw ? ll : lw) + 1);
     char *ow;
@@ -489,11 +489,12 @@
 	 * Update: this once tested `test && ...' to check for exact
 	 * character matches only in recursive calls.  But then one
 	 * can't complete `nom<TAB>' to `nomatch' with a match spec
-	 * of `B:[nN][oO]=' because that will eat the `no'. I'm almost
-	 * certain that this will break something, but I don't know what
-	 * or if it really is a problem (or has been fixed by other
-	 * changes in the code handling partial word matching). And the
-	 * completion matching tests work.
+	 * of `B:[nN][oO]=' because that will eat the `no'.
+	 * But that would break completion of strings like `nonomatch'
+	 * because the `B:[nN][oO]=' doesn't match the second `no'.
+	 * For this we added the code below that can remove already
+	 * accepted exact characters and try again, preferring match
+	 * specs.
 	 */
 
 	bslash = 0;
@@ -503,10 +504,12 @@
 			(ind ? (w[0] == l[0]) : (w[1] == l[0])))))) {
 	    /* No matcher could be used, but the strings have the same
 	     * character here, skip over it. */
-	    l += add; w += (bslash ? (add + add ) : add);
+	    l += add; w += (bslash ? (add + add) : add);
 	    il++; iw += 1 + bslash;
 	    ll--; lw -= 1 + bslash;
 	    bc++;
+	    exact++;
+	    wexact += 1 + bslash;
 	    if (!test)
 		while (bp && bc >= (useqbr ? bp->qpos : bp->pos)) {
 		    bp->curpos = matchbufadded + (sfx ? (ow - w) : (w - ow)) + obc;
@@ -517,6 +520,7 @@
 
 	    continue;
 	}
+    retry:
 	/* First try the matchers. Err... see above. */
 	for (mp = NULL, ms = mstack; !mp && ms; ms = ms->next) {
 	    for (mp = ms->matcher; mp; mp = mp->next) {
@@ -687,6 +691,7 @@
 		    ll -= llen; il += llen;
 		    lw -= alen; iw += alen;
 		    bc += llen;
+		    exact = 0;
 
 		    if (!test)
 			while (bp &&
@@ -798,6 +803,7 @@
 		    il += mp->llen; iw += mp->wlen;
 		    ll -= mp->llen; lw -= mp->wlen;
 		    bc += mp->llen;
+		    exact = 0;
 
 		    if (!test)
 			while (bp &&
@@ -836,6 +842,23 @@
 	    lm = NULL;
 	    he = 0;
 	} else {
+
+	    if (exact) {
+		/* If we just accepted some characters directly (at the
+		 * beginning of the loop) and now can't match any further,
+		 * we go back to before those characters and try again,
+		 * preferring match specs this time. */
+
+		il -= exact; iw -= wexact;
+		ll += exact; lw += wexact;
+		bc -= exact;
+		l -= add * exact; w -= add * wexact;
+
+		exact = wexact = 0;
+
+		goto retry;
+	    }
+
 	    if (!lw)
 		break;
 	    /* No matcher and different characters: l does not match w. */

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


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

end of thread, other threads:[~2000-10-10 13:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-10-09 12:48 PATCH: Re: Option completion after "nono" Sven Wischnowsky
2000-10-09 14:59 ` Bart Schaefer
2000-10-10  8:31 Sven Wischnowsky
2000-10-10 13:34 Sven Wischnowsky

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).