about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
Diffstat (limited to 'Src')
-rw-r--r--Src/Zle/compcore.c33
-rw-r--r--Src/Zle/compctl.c3
2 files changed, 29 insertions, 7 deletions
diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c
index eeea42a4d..542c5eebc 100644
--- a/Src/Zle/compcore.c
+++ b/Src/Zle/compcore.c
@@ -152,6 +152,11 @@ mod_export int nmatches;
 /**/
 mod_export int smatches;
 
+/* != 0 if more than one match and at least two different matches */
+
+/**/
+mod_export int diffmatches;
+
 /* The number of messages. */
 
 /**/
@@ -388,10 +393,10 @@ do_completion(Hookdef dummy, Compldat dat)
 	    invalidatelist();
     } else if (useline) {
 	/* We have matches. */
-	if (nmatches > 1) {
+	if (nmatches > 1 && diffmatches) {
 	    /* There is more than one match. */
 	    ret = do_ambiguous();
-	} else if (nmatches == 1) {
+	} else if (nmatches == 1 || !diffmatches) {
 	    /* Only one match. */
 	    Cmgroup m = amatches;
 
@@ -423,7 +428,8 @@ do_completion(Hookdef dummy, Compldat dat)
 	cs = origcs;
     }
     /* Print the explanation strings if needed. */
-    if (!showinglist && validlist && usemenu != 2 && nmatches != 1 &&
+    if (!showinglist && validlist && usemenu != 2 && 
+	(nmatches != 1 || diffmatches) &&
 	useline != 2 && (!oldlist || !listshown)) {
 	onlyexpl = 1;
 	showinglist = -2;
@@ -870,7 +876,7 @@ makecomplist(char *s, int incmd, int lst)
 
     if (compfunc) {
 	char *os = s;
-	int onm = nmatches, osi = movefd(0);
+	int onm = nmatches, odm = diffmatches, osi = movefd(0);
 
 	bmatchers = NULL;
 	mstack = NULL;
@@ -905,6 +911,7 @@ makecomplist(char *s, int incmd, int lst)
 
 	if (oldlist) {
 	    nmatches = onm;
+	    diffmatches = odm;
 	    validlist = 1;
 	    amatches = lastmatches;
 	    lmatches = lastlmatches;
@@ -2635,7 +2642,7 @@ permmatches(int last)
 
     opm = pmatches;
     pmatches = lmatches = NULL;
-    nmatches = smatches = 0;
+    nmatches = smatches = diffmatches = 0;
 
     if (!ainfo->count) {
 	if (last)
@@ -2667,6 +2674,9 @@ permmatches(int last)
 	    nmatches += g->mcount;
 	    smatches += g->lcount;
 
+	    if (g->mcount > 1)
+		diffmatches = 1;
+
 	    n = (Cmgroup) zcalloc(sizeof(struct cmgroup));
 
 	    if (g->perm) {
@@ -2721,18 +2731,29 @@ permmatches(int last)
 
 	    nmatches += g->mcount;
 	    smatches += g->lcount;
+
+	    if (g->mcount > 1)
+		diffmatches = 1;
+
 	    g->num = gn++;
 	}
 	g->new = 0;
 	g = g->next;
     }
-    for (g = pmatches; g; g = g->next) {
+    for (g = pmatches, p = NULL; g; g = g->next) {
 	g->nbrbeg = nbrbeg;
 	g->nbrend = nbrend;
 	for (rn = 1, q = g->matches; *q; q++) {
 	    (*q)->rnum = rn++;
 	    (*q)->gnum = mn++;
 	}
+	if (!diffmatches && *g->matches) {
+	    if (p) {
+		if (!matcheq(*g->matches, *p))
+		    diffmatches = 1;
+	    } else
+		p = g->matches;
+	}
     }
     hasperm = 1;
     permmnum = mn - 1;
diff --git a/Src/Zle/compctl.c b/Src/Zle/compctl.c
index accd97c93..b443b7da5 100644
--- a/Src/Zle/compctl.c
+++ b/Src/Zle/compctl.c
@@ -1762,7 +1762,7 @@ ccmakehookfn(Hookdef dummy, struct ccmakedat *dat)
     struct cmlist ms;
     Cmlist m;
     char *os = s;
-    int onm = nmatches, osi = movefd(0);
+    int onm = nmatches, odm = diffmatches, osi = movefd(0);
     LinkNode n;
 
     /* We build a copy of the list of matchers to use to make sure that this
@@ -1843,6 +1843,7 @@ ccmakehookfn(Hookdef dummy, struct ccmakedat *dat)
 
 	if (oldlist) {
 	    nmatches = onm;
+	    diffmatches = odm;
 	    validlist = 1;
 	    amatches = lastmatches;
 	    lmatches = lastlmatches;