From 9acc1dd713d95c0e894b4eee86f524888753f8a3 Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Wed, 22 Sep 1999 22:29:54 +0000 Subject: zsh-workers/8001 --- Completion/Core/_description | 4 +- Doc/Zsh/compctl.yo | 14 +++- Doc/Zsh/compsys.yo | 6 +- Doc/Zsh/compwid.yo | 14 +++- Src/Zle/comp.h | 12 +++- Src/Zle/compctl.c | 22 +++++- Src/Zle/zle_tricky.c | 160 ++++++++++++++++++++++++------------------- 7 files changed, 151 insertions(+), 81 deletions(-) diff --git a/Completion/Core/_description b/Completion/Core/_description index 874ba8a96..a19a8373c 100644 --- a/Completion/Core/_description +++ b/Completion/Core/_description @@ -2,8 +2,8 @@ local gropt=-J -if [[ "$1" = -V ]]; then - gropt=-V +if [[ "$1" = -[VJ]* ]]; then + gropt="$1" shift fi diff --git a/Doc/Zsh/compctl.yo b/Doc/Zsh/compctl.yo index eaf257660..5ac0a910d 100644 --- a/Doc/Zsh/compctl.yo +++ b/Doc/Zsh/compctl.yo @@ -137,7 +137,7 @@ matching specifications, as described below in noderef(Matching Control). texinode(Option Flags)(Alternative Completion)(Command Flags)(Programmable Completion Using compctl) sect(Option Flags) startlist() -list([ tt(-fcFBdeaRGovNAIOPZEnbjrzu/) ]) +list([ tt(-fcFBdeaRGovNAIOPZEnbjrzu/12) ]) list([ tt(-k) var(array) ] [ tt(-g) var(globstring) ] \ [ tt(-s) var(subststring) ]) list([ tt(-K) var(function) ] [ tt(-i) var(function) ]) @@ -516,6 +516,18 @@ nor in menucompletion. These unsorted groups are in a different name space from the sorted ones, so groups defined as tt(-J files) and tt(-V files) are distinct. ) +item(tt(-1))( +If given together with the tt(-J) option, makes duplicate matches in +the group be kept. If given together with the tt(-V) option, makes +only consecutive duplicates in the group be removed. Note that groups +with and without this flag are in different name spaces. +) +item(tt(-2))( +If given together with the tt(-J) option, behaves the same as +tt(-J). If given together with the tt(-V) option, keep all duplicate +matches. Again, groups with and without this flag are in different +name spaces. +) item(tt(-M) var(match-spec))( This defines additional matching control specifications that should be used only when testing words for the list of flags this flag appears in. The format diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index 913bc95ea..524ea6ee0 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -566,8 +566,10 @@ above the matches added. These options also will make sure that the matches are placed in a separate group (the second argument is used as the name of the group) if the configuration key tt(group_matches) is set to a non-empty string. Normally a sorted group will be used for this -(with the `tt(-J)' option), but if the option `tt(-V)' is given, a -unsorted group will be used instead. +(with the `tt(-J)' option), but if a option starting with `tt(-V)' or +`tt(-J)' is given, that option will be included in the array, so that +it is possible to make the group unsorted by given the option +`tt(-V)', `tt(-V1)', or `tt(-V2)'. In most cases, this function will be used like this: diff --git a/Doc/Zsh/compwid.yo b/Doc/Zsh/compwid.yo index d4b9dd797..c8abf7959 100644 --- a/Doc/Zsh/compwid.yo +++ b/Doc/Zsh/compwid.yo @@ -369,7 +369,7 @@ otherwise. ) findex(compadd) cindex(completion widgets, adding specified matches) -xitem(tt(compadd) [ tt(-qQfenUaml) ] [ tt(-F) var(array) ]) +xitem(tt(compadd) [ tt(-qQfenUaml12) ] [ tt(-F) var(array) ]) xitem([ tt(-P) var(prefix) ] [ tt(-S) var(suffix) ]) xitem([ tt(-p) var(hidden-prefix) ] [ tt(-s) var(hidden-suffix) ]) xitem([ tt(-i) var(ignored-prefix) ] [ tt(-I) var(ignored-suffix) ]) @@ -463,6 +463,18 @@ of matches the words should be stored in. item(tt(-V) var(name))( Like tt(-J) but naming a unsorted group. ) +item(tt(-1))( +If given together with the tt(-J) option, makes duplicate matches in +the group be kept. If given together with the tt(-V) option, makes +only consecutive duplicates in the group be removed. Note that groups +with and without this flag are in different name spaces. +) +item(tt(-2))( +If given together with the tt(-J) option, behaves the same as +tt(-J). If given together with the tt(-V) option, keep all duplicate +matches. Again, groups with and without this flag are in different +name spaces. +) item(tt(-X) var(explanation))( As for tt(compctl) and tt(compgen), the var(explanation) string will be printed with the list of matches. diff --git a/Src/Zle/comp.h b/Src/Zle/comp.h index d7178a73a..e32a969f3 100644 --- a/Src/Zle/comp.h +++ b/Src/Zle/comp.h @@ -161,6 +161,8 @@ struct compctl { #define CC_CCCONT (1<<2) #define CC_PATCONT (1<<3) #define CC_DEFCONT (1<<4) +#define CC_UNIQCON (1<<5) +#define CC_UNIQALL (1<<6) typedef struct cexpl *Cexpl; typedef struct cmgroup *Cmgroup; @@ -206,9 +208,11 @@ struct cmgroup { }; -#define CGF_NOSORT 1 /* don't sort this group */ -#define CGF_LINES 2 /* these are to be printed on different lines */ -#define CGF_HASDL 4 /* has disply strings printed on sseparate lines */ +#define CGF_NOSORT 1 /* don't sort this group */ +#define CGF_LINES 2 /* these are to be printed on different lines */ +#define CGF_HASDL 4 /* has display strings printed on separate lines */ +#define CGF_UNIQALL 8 /* remove all duplicates */ +#define CGF_UNIQCON 16 /* remove consecutive duplicates */ /* This is the struct used to hold matches. */ @@ -301,6 +305,8 @@ struct menuinfo { #define CAF_NOSORT 2 #define CAF_ALT 4 #define CAF_MATCH 8 +#define CAF_UNIQCON 16 +#define CAF_UNIQALL 32 /* Data for compadd and addmatches() */ diff --git a/Src/Zle/compctl.c b/Src/Zle/compctl.c index 50cdadf26..0f42372f0 100644 --- a/Src/Zle/compctl.c +++ b/Src/Zle/compctl.c @@ -750,6 +750,14 @@ get_compctl(char *name, char ***av, Compctl cc, int first, int isdef, int cl) } cct.mask2 |= CC_NOSORT; break; + case '1': + cct.mask2 |= CC_UNIQALL; + cct.mask2 &= ~CC_UNIQCON; + break; + case '2': + cct.mask2 |= CC_UNIQCON; + cct.mask2 &= ~CC_UNIQALL; + break; case 'M': if (cclist & COMP_LIST) { cclist |= COMP_LISTMATCH; @@ -1439,7 +1447,7 @@ printcompctl(char *s, Compctl cc, int printflags, int ispat) } /* loop through flags w/o args that are set, printing them if so */ - if (flags & t) { + if ((flags & t) || (flags2 & (CC_UNIQALL | CC_UNIQCON))) { printf(" -"); if ((flags & (CC_ALREG | CC_ALGLOB)) == (CC_ALREG | CC_ALGLOB)) putchar('a'), flags &= ~(CC_ALREG | CC_ALGLOB); @@ -1450,6 +1458,10 @@ printcompctl(char *s, Compctl cc, int printflags, int ispat) flags >>= 1; t >>= 1; } + if (flags2 & CC_UNIQALL) + putchar('1'); + else if (flags2 & CC_UNIQCON) + putchar('2'); } if (flags2 & (CC_XORCONT | CC_PATCONT | CC_DEFCONT)) { printf(" -t"); @@ -1788,6 +1800,14 @@ bin_compadd(char *name, char **argv, char *ops, int func) sp = &(dat.group); e = "group name expected after -%c"; break; + case '1': + if (!(dat.aflags & CAF_UNIQCON)) + dat.aflags |= CAF_UNIQALL; + break; + case '2': + if (!(dat.aflags & CAF_UNIQALL)) + dat.aflags |= CAF_UNIQCON; + break; case 'y': sp = &(dat.ylist); e = "string expected after -%c"; diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c index 0183bea3b..2984b836f 100644 --- a/Src/Zle/zle_tricky.c +++ b/Src/Zle/zle_tricky.c @@ -3963,7 +3963,7 @@ addmatches(Cadata dat, char **argv) char **aign = NULL, **dparr = NULL, oaq = autoq, *oppre = dat->ppre; char *oqp = qipre, *oqs = qisuf, qc, **disp = NULL; int lpl, lsl, pl, sl, bpl, bsl, bppl = -1, bssl = -1; - int llpl = 0, llsl = 0, nm = mnum; + int llpl = 0, llsl = 0, nm = mnum, gflags; int oisalt = 0, isalt, isexact, doadd, ois = instring, oib = inbackt; Cline lc = NULL; Cmatch cm; @@ -4145,20 +4145,19 @@ addmatches(Cadata dat, char **argv) } else dat->prpre = dupstring(dat->prpre); /* Select the group in which to store the matches. */ + gflags = (((dat->aflags & CAF_NOSORT ) ? CGF_NOSORT : 0) | + ((dat->aflags & CAF_UNIQALL) ? CGF_UNIQALL : 0) | + ((dat->aflags & CAF_UNIQCON) ? CGF_UNIQCON : 0)); if (dat->group) { endcmgroup(NULL); - begcmgroup(dat->group, (dat->aflags & CAF_NOSORT)); - if (dat->aflags & CAF_NOSORT) - mgroup->flags |= CGF_NOSORT; + begcmgroup(dat->group, gflags); } else { endcmgroup(NULL); begcmgroup("default", 0); } if (dat->ylist) { endcmgroup(NULL); - begcmgroup(NULL, (dat->aflags & CAF_NOSORT)); - if (dat->aflags & CAF_NOSORT) - mgroup->flags |= CGF_NOSORT; + begcmgroup(NULL, gflags); } /* Select the set of matches. */ oisalt = (dat->aflags & CAF_ALT); @@ -4247,7 +4246,7 @@ addmatches(Cadata dat, char **argv) if (dat->ylist) { if (dat->group) { endcmgroup(get_user_var(dat->ylist)); - begcmgroup(dat->group, (dat->aflags & CAF_NOSORT)); + begcmgroup(dat->group, gflags); if (dat->exp) addexpl(); } else { @@ -6164,7 +6163,7 @@ findnode(LinkList list, void *dat) static void makecomplistflags(Compctl cc, char *s, int incmd, int compadd) { - int t, sf1, sf2, ooffs, um = usemenu, delit, oaw; + int t, sf1, sf2, ooffs, um = usemenu, delit, oaw, gflags; char *p, *sd = NULL, *tt, *s1, *s2, *os = dupstring(s); struct cmlist ms; @@ -6199,18 +6198,19 @@ makecomplistflags(Compctl cc, char *s, int incmd, int compadd) curcc = cc; mflags = 0; + gflags = (((cc->mask2 & CC_NOSORT ) ? CGF_NOSORT : 0) | + ((cc->mask2 & CC_UNIQALL) ? CGF_UNIQALL : 0) | + ((cc->mask2 & CC_UNIQCON) ? CGF_UNIQCON : 0)); if (cc->gname) { endcmgroup(NULL); - begcmgroup(cc->gname, cc->mask2 & CC_NOSORT); + begcmgroup(cc->gname, gflags); } if (cc->ylist) { endcmgroup(NULL); - begcmgroup(NULL, cc->mask2 & CC_NOSORT); + begcmgroup(NULL, gflags); } if (cc->mask & CC_REMOVE) mflags |= CMF_REMOVE; - if (cc->mask2 & CC_NOSORT) - mgroup->flags |= CGF_NOSORT; if (cc->explain) { expl = (Cexpl) zhalloc(sizeof(struct cexpl)); expl->count = expl->fcount = 0; @@ -7006,7 +7006,7 @@ makecomplistflags(Compctl cc, char *s, int incmd, int compadd) expl->str = tt; if (cc->gname) { endcmgroup(yaptr); - begcmgroup(cc->gname, cc->mask2 & CC_NOSORT); + begcmgroup(cc->gname, gflags); addexpl(); } else { addexpl(); @@ -7227,7 +7227,7 @@ matcheq(Cmatch a, Cmatch b) /**/ static Cmatch * -makearray(LinkList l, int s, int u, int *np, int *nlp, int *llp) +makearray(LinkList l, int type, int flags, int *np, int *nlp, int *llp) { Cmatch *ap, *bp, *cp, *rp; LinkNode nod; @@ -7242,57 +7242,75 @@ makearray(LinkList l, int s, int u, int *np, int *nlp, int *llp) *ap++ = (Cmatch) getdata(nod); *ap = NULL; - if (s == 1) { - char **ap, **bp, **cp; - - /* Now sort the array (it contains strings). */ - qsort((void *) rp, n, sizeof(char *), - (int (*) _((const void *, const void *)))strbpcmp); - - /* And delete the ones that occur more than once. */ - for (ap = cp = (char **) rp; *ap; ap++) { - *cp++ = *ap; - for (bp = ap; bp[1] && !strcmp(*ap, bp[1]); bp++, n--); - ap = bp; - } - *cp = NULL; - } else if (s) { - /* Now sort the array (it contains matches). */ - qsort((void *) rp, n, sizeof(Cmatch), - (int (*) _((const void *, const void *)))matchcmp); - - /* And delete the ones that occur more than once. */ - for (ap = cp = rp; *ap; ap++) { - *cp++ = *ap; - for (bp = ap; bp[1] && matcheq(*ap, bp[1]); bp++, n--); - ap = bp; - /* Mark those, that would show the same string in the list. */ - for (; bp[1] && !(*ap)->disp && !(bp[1])->disp && - !strcmp((*ap)->str, (bp[1])->str); bp++) - (bp[1])->flags |= CMF_NOLIST; - } - for (ap = rp; *ap; ap++) { - if ((*ap)->disp && ((*ap)->flags & CMF_DISPLINE)) - ll++; - if ((*ap)->flags & CMF_NOLIST) - nl++; - } - *cp = NULL; - } else if (u) { - for (ap = rp; *ap; ap++) { - for (bp = cp = ap + 1; *bp; bp++) { - if (!matcheq(*ap, *bp)) - *cp++ = *bp; - else - n--; + if (!type) { + if (flags) { + char **ap, **bp, **cp; + + /* Now sort the array (it contains strings). */ + qsort((void *) rp, n, sizeof(char *), + (int (*) _((const void *, const void *)))strbpcmp); + + /* And delete the ones that occur more than once. */ + for (ap = cp = (char **) rp; *ap; ap++) { + *cp++ = *ap; + for (bp = ap; bp[1] && !strcmp(*ap, bp[1]); bp++, n--); + ap = bp; } *cp = NULL; } - for (ap = rp; *ap; ap++) { - if ((*ap)->disp && ((*ap)->flags & CMF_DISPLINE)) - ll++; - if ((*ap)->flags & CMF_NOLIST) - nl++; + } else { + if (!(flags & CGF_NOSORT)) { + /* Now sort the array (it contains matches). */ + qsort((void *) rp, n, sizeof(Cmatch), + (int (*) _((const void *, const void *)))matchcmp); + + if (!(flags & (CGF_UNIQALL | CGF_UNIQCON))) { + /* And delete the ones that occur more than once. */ + for (ap = cp = rp; *ap; ap++) { + *cp++ = *ap; + for (bp = ap; bp[1] && matcheq(*ap, bp[1]); bp++, n--); + ap = bp; + /* Mark those, that would show the same string in the list. */ + for (; bp[1] && !(*ap)->disp && !(bp[1])->disp && + !strcmp((*ap)->str, (bp[1])->str); bp++) + (bp[1])->flags |= CMF_NOLIST; + } + *cp = NULL; + } + for (ap = rp; *ap; ap++) { + if ((*ap)->disp && ((*ap)->flags & CMF_DISPLINE)) + ll++; + if ((*ap)->flags & CMF_NOLIST) + nl++; + } + } else { + if (!(flags & CGF_UNIQALL) && !(flags & CGF_UNIQCON)) { + for (ap = rp; *ap; ap++) { + for (bp = cp = ap + 1; *bp; bp++) { + if (!matcheq(*ap, *bp)) + *cp++ = *bp; + else + n--; + } + *cp = NULL; + } + } else if (!(flags & CGF_UNIQCON)) { + for (ap = cp = rp; *ap; ap++) { + *cp++ = *ap; + for (bp = ap; bp[1] && matcheq(*ap, bp[1]); bp++, n--); + ap = bp; + for (; bp[1] && !(*ap)->disp && !(bp[1])->disp && + !strcmp((*ap)->str, (bp[1])->str); bp++) + (bp[1])->flags |= CMF_NOLIST; + } + *cp = NULL; + } + for (ap = rp; *ap; ap++) { + if ((*ap)->disp && ((*ap)->flags & CMF_DISPLINE)) + ll++; + if ((*ap)->flags & CMF_NOLIST) + nl++; + } } } if (np) @@ -7308,13 +7326,14 @@ makearray(LinkList l, int s, int u, int *np, int *nlp, int *llp) /**/ static void -begcmgroup(char *n, int nu) +begcmgroup(char *n, int flags) { if (n) { Cmgroup p = amatches; while (p) { - if (p->name && ((nu && !p->lallccs) || (!nu && p->lallccs)) && + if (p->name && + flags == (p->flags & (CGF_NOSORT|CGF_UNIQALL|CGF_UNIQCON)) && !strcmp(n, p->name)) { mgroup = p; @@ -7330,7 +7349,8 @@ begcmgroup(char *n, int nu) } mgroup = (Cmgroup) zhalloc(sizeof(struct cmgroup)); mgroup->name = dupstring(n); - mgroup->flags = mgroup->lcount = mgroup->llcount = mgroup->mcount = 0; + mgroup->lcount = mgroup->llcount = mgroup->mcount = 0; + mgroup->flags = flags; mgroup->matches = NULL; mgroup->ylist = NULL; mgroup->expls = NULL; @@ -7339,7 +7359,7 @@ begcmgroup(char *n, int nu) mgroup->lmatches = matches = newlinklist(); mgroup->lfmatches = fmatches = newlinklist(); - mgroup->lallccs = allccs = (nu ? NULL : newlinklist()); + mgroup->lallccs = allccs = ((flags & CGF_NOSORT) ? NULL : newlinklist()); mgroup->next = amatches; amatches = mgroup; @@ -7435,9 +7455,7 @@ permmatches(void) /* We have no matches, try ignoring fignore. */ g->lmatches = g->lfmatches; - g->matches = makearray(g->lmatches, - ((g->flags & CGF_NOSORT) ? 0 : 2), 1, - &nn, &nl, &ll); + g->matches = makearray(g->lmatches, 1, g->flags, &nn, &nl, &ll); g->mcount = nn; if ((g->lcount = nn - nl) < 0) g->lcount = 0; @@ -9172,7 +9190,7 @@ listlist(LinkList l) smatches = 1; validlist = 1; memset(&dg, 0, sizeof(struct cmgroup)); - dg.ylist = (char **) makearray(l, 1, 0, &(dg.lcount), NULL, NULL); + dg.ylist = (char **) makearray(l, 0, 1, &(dg.lcount), NULL, NULL); amatches = &dg; ilistmatches(NULL, NULL); amatches = am; -- cgit 1.4.1