From 4414e16a6a958c39209f37f7f7a6fae6b1b78864 Mon Sep 17 00:00:00 2001 From: Sven Wischnowsky Date: Thu, 4 May 2000 07:44:21 +0000 Subject: don't list when all matches look the same; force-list style to give users control over this (11140) --- ChangeLog | 7 +++++++ Completion/Builtins/_zstyle | 1 + Completion/Core/_main_complete | 7 +++++++ Doc/Zsh/compsys.yo | 12 ++++++++++++ Src/Zle/compcore.c | 33 +++++++++++++++++++++++++++------ Src/Zle/compctl.c | 3 ++- 6 files changed, 56 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 66f25ccc4..9896bf9fb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2000-05-04 Sven Wischnowsky + + * 11140: Completion/Builtins/_zstyle, Completion/Core/_main_complete, + Doc/Zsh/compsys.yo, Src/Zle/compcore.c, Src/Zle/compctl.c: don't + list when all matches look the same; force-list style to give + users control over this + 2000-05-03 Tanaka Akira * 11137: Test/07cond.ztst: detect block device file using find. diff --git a/Completion/Builtins/_zstyle b/Completion/Builtins/_zstyle index a2a19320d..1edd0987f 100644 --- a/Completion/Builtins/_zstyle +++ b/Completion/Builtins/_zstyle @@ -25,6 +25,7 @@ styles=( expand c: file-patterns c:filepat file-sort c:fsort + force-list c format c: glob c: group-name c: diff --git a/Completion/Core/_main_complete b/Completion/Core/_main_complete index 7c1135959..cf2cbb808 100644 --- a/Completion/Core/_main_complete +++ b/Completion/Core/_main_complete @@ -200,6 +200,13 @@ elif [[ nm -eq 0 && fi fi +if zstyle -s ":completion:${curcontext}:" force-list tmp && + [[ "$compstate[list]" = *list* && + ( "$tmp" = always || + ( "$tmp" = [0-9]## && nm -ge tmp ) ) ]]; then + compstate[list]="$compstate[list] force" +fi + # Now call the post-functions. funcs=( "$comppostfuncs[@]" ) diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index b3402d664..0c5d02f08 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -1033,6 +1033,18 @@ time. Any other value (or not setting this style at all) makes them be sorted alphabetically by name. If the value contains the string `tt(reverse)', sorting is done in decreasing order. ) +kindex(force-list, completion style) +item(tt(force-list))( +If the completion code would show a list of completions at all, this +style controls whether the list is shown even in cases when it would +normally not do that. For example, normally the list is only shown if +there are at least to different matches. By setting this style to +`tt(always)', the list will always even be shown, even if there is +only a single match which is immediately accepted. The style may also +be set to a number. In this case the list will be shown if there are +at least that many matches, even if they would all insert the same +string. +) kindex(format, completion style) item(tt(format))( If this is set for the tt(descriptions) tag, its value is used as a 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; -- cgit 1.4.1