diff options
author | Tanaka Akira <akr@users.sourceforge.net> | 1999-12-06 11:39:12 +0000 |
---|---|---|
committer | Tanaka Akira <akr@users.sourceforge.net> | 1999-12-06 11:39:12 +0000 |
commit | bb93d135ba484cd423ae71b1686c63ac2c1c654f (patch) | |
tree | ea3a27c4f3a5855eb3c176ad322c2d9e225e9d9d /Src | |
parent | fb5a1bc4dce28016a61eb11033bfb9a23ea74b5e (diff) | |
download | zsh-bb93d135ba484cd423ae71b1686c63ac2c1c654f.tar.gz zsh-bb93d135ba484cd423ae71b1686c63ac2c1c654f.tar.xz zsh-bb93d135ba484cd423ae71b1686c63ac2c1c654f.zip |
zsh-workers/8911
Diffstat (limited to 'Src')
-rw-r--r-- | Src/Zle/comp.h | 60 | ||||
-rw-r--r-- | Src/Zle/compcore.c | 66 | ||||
-rw-r--r-- | Src/Zle/complete.c | 7 | ||||
-rw-r--r-- | Src/Zle/compresult.c | 39 |
4 files changed, 109 insertions, 63 deletions
diff --git a/Src/Zle/comp.h b/Src/Zle/comp.h index 6f3b2cd16..a177be614 100644 --- a/Src/Zle/comp.h +++ b/Src/Zle/comp.h @@ -81,6 +81,8 @@ struct cmgroup { #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 */ +#define CGF_PACKED 32 /* LIST_PACKED for this group */ +#define CGF_ROWS 64 /* LIST_ROWS_FIRST for this group */ /* This is the struct used to hold matches. */ @@ -107,15 +109,17 @@ struct cmatch { int gnum; /* global number */ }; -#define CMF_FILE 1 /* this is a file */ -#define CMF_REMOVE 2 /* remove the suffix */ -#define CMF_ISPAR 4 /* is paramter expansion */ -#define CMF_PARBR 8 /* paramter expansion with a brace */ -#define CMF_PARNEST 16 /* nested paramter expansion */ -#define CMF_NOLIST 32 /* should not be listed */ -#define CMF_DISPLINE 64 /* display strings one per line */ -#define CMF_HIDE 128 /* temporarily hide this one */ -#define CMF_NOSPACE 256 /* don't add a space */ +#define CMF_FILE (1<< 0) /* this is a file */ +#define CMF_REMOVE (1<< 1) /* remove the suffix */ +#define CMF_ISPAR (1<< 2) /* is paramter expansion */ +#define CMF_PARBR (1<< 3) /* paramter expansion with a brace */ +#define CMF_PARNEST (1<< 4) /* nested paramter expansion */ +#define CMF_NOLIST (1<< 5) /* should not be listed */ +#define CMF_DISPLINE (1<< 6) /* display strings one per line */ +#define CMF_HIDE (1<< 7) /* temporarily hide this one */ +#define CMF_NOSPACE (1<< 8) /* don't add a space */ +#define CMF_PACKED (1<< 9) /* prefer LIST_PACKED */ +#define CMF_ROWS (1<<10) /* prefer LIST_ROWS_FIRST */ /* Stuff for completion matcher control. */ @@ -322,43 +326,41 @@ typedef void (*CLPrintFunc)(Cmgroup, Cmatch *, int, int, int, int, #define CP_RESTORE (1 << CPN_RESTORE) #define CPN_LIST 10 #define CP_LIST (1 << CPN_LIST) -#define CPN_FORCELIST 11 -#define CP_FORCELIST (1 << CPN_FORCELIST) -#define CPN_INSERT 12 +#define CPN_INSERT 11 #define CP_INSERT (1 << CPN_INSERT) -#define CPN_EXACT 13 +#define CPN_EXACT 12 #define CP_EXACT (1 << CPN_EXACT) -#define CPN_EXACTSTR 14 +#define CPN_EXACTSTR 13 #define CP_EXACTSTR (1 << CPN_EXACTSTR) -#define CPN_PATMATCH 15 +#define CPN_PATMATCH 14 #define CP_PATMATCH (1 << CPN_PATMATCH) -#define CPN_PATINSERT 16 +#define CPN_PATINSERT 15 #define CP_PATINSERT (1 << CPN_PATINSERT) -#define CPN_UNAMBIG 17 +#define CPN_UNAMBIG 16 #define CP_UNAMBIG (1 << CPN_UNAMBIG) -#define CPN_UNAMBIGC 18 +#define CPN_UNAMBIGC 17 #define CP_UNAMBIGC (1 << CPN_UNAMBIGC) -#define CPN_LISTMAX 19 +#define CPN_LISTMAX 18 #define CP_LISTMAX (1 << CPN_LISTMAX) -#define CPN_LASTPROMPT 20 +#define CPN_LASTPROMPT 19 #define CP_LASTPROMPT (1 << CPN_LASTPROMPT) -#define CPN_TOEND 21 +#define CPN_TOEND 20 #define CP_TOEND (1 << CPN_TOEND) -#define CPN_OLDLIST 22 +#define CPN_OLDLIST 21 #define CP_OLDLIST (1 << CPN_OLDLIST) -#define CPN_OLDINS 23 +#define CPN_OLDINS 22 #define CP_OLDINS (1 << CPN_OLDINS) -#define CPN_VARED 24 +#define CPN_VARED 23 #define CP_VARED (1 << CPN_VARED) -#define CPN_ANMATCHES 25 +#define CPN_ANMATCHES 24 #define CP_ANMATCHES (1 << CPN_ANMATCHES) -#define CPN_LISTLINES 26 +#define CPN_LISTLINES 25 #define CP_LISTLINES (1 << CPN_LISTLINES) -#define CPN_QUOTES 27 +#define CPN_QUOTES 26 #define CP_QUOTES (1 << CPN_QUOTES) -#define CP_KEYPARAMS 28 -#define CP_ALLKEYS ((unsigned int) 0xfffffff) +#define CP_KEYPARAMS 27 +#define CP_ALLKEYS ((unsigned int) 0x7ffffff) /* Hooks. */ diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c index 1bc1fd86f..d6f21f46d 100644 --- a/Src/Zle/compcore.c +++ b/Src/Zle/compcore.c @@ -37,7 +37,12 @@ static Widget lastcompwidget; /* Flags saying what we have to do with the result. */ /**/ -int useexact, useline, uselist; +int useexact, useline, uselist, forcelist, startauto; + +/* Non-zero if we should go back to the last prompt. */ + +/**/ +int dolastprompt; /* Non-zero if we should keep an old list. */ @@ -276,6 +281,8 @@ do_completion(Hookdef dummy, Compldat dat) hasunqu = 0; useline = (lst != COMP_LIST_COMPLETE); useexact = isset(RECEXACT); + zsfree(compexactstr); + compexactstr = ztrdup(""); uselist = (useline ? ((isset(AUTOLIST) && !isset(BASHAUTOLIST)) ? (isset(LISTAMBIGUOUS) ? 3 : 2) : 0) : 1); @@ -283,14 +290,19 @@ do_completion(Hookdef dummy, Compldat dat) opm = comppatmatch = ztrdup(useglob ? "*" : ""); zsfree(comppatinsert); comppatinsert = ztrdup("menu"); - zsfree(compforcelist); - compforcelist = ztrdup(""); + forcelist = 0; haspattern = 0; complistmax = getiparam("LISTMAX"); zsfree(complastprompt); - complastprompt = ztrdup(((isset(ALWAYSLASTPROMPT) && zmult == 1) || - (unset(ALWAYSLASTPROMPT) && zmult != 1)) ? + complastprompt = ztrdup((dolastprompt = + ((isset(ALWAYSLASTPROMPT) && zmult == 1) || + (unset(ALWAYSLASTPROMPT) && zmult != 1))) ? "yes" : ""); + zsfree(complist); + complist = ztrdup(isset(LISTROWSFIRST) ? + (isset(LISTPACKED) ? "packed rows" : "rows") : + (isset(LISTPACKED) ? "packed" : "")); + startauto = isset(AUTOMENU); movetoend = ((cs == we || isset(ALWAYSTOEND)) ? 2 : 1); showinglist = 0; hasmatched = 0; @@ -360,7 +372,7 @@ do_completion(Hookdef dummy, Compldat dat) menucmp = 0; minfo.cur = NULL; - if (compforcelist && *compforcelist && uselist) + if (forcelist) showinglist = -2; else invalidatelist(); @@ -378,7 +390,7 @@ do_completion(Hookdef dummy, Compldat dat) minfo.cur = NULL; minfo.asked = 0; do_single(m->matches[0]); - if (compforcelist && *compforcelist) { + if (forcelist) { if (uselist) showinglist = -2; else @@ -388,7 +400,7 @@ do_completion(Hookdef dummy, Compldat dat) } } else { invalidatelist(); - if (compforcelist && *compforcelist) + if (forcelist) clearlist = 1; cs = 0; foredel(ll); @@ -450,7 +462,7 @@ before_complete(Hookdef dummy, int *lst) /* Check if we have to start a menu-completion (via automenu). */ - if (isset(AUTOMENU) && lastambig && + if (startauto && lastambig && (!isset(BASHAUTOLIST) || lastambig == 2)) usemenu = 2; @@ -495,7 +507,7 @@ callcompfunc(char *s, char *fn) rset = CP_ALLREALS; kset = CP_ALLKEYS & ~(CP_PARAMETER | CP_REDIRECT | CP_QUOTE | CP_QUOTING | - CP_EXACTSTR | CP_FORCELIST | CP_OLDLIST | CP_OLDINS | + CP_EXACTSTR | CP_OLDLIST | CP_OLDINS | (useglob ? 0 : CP_PATMATCH)); zsfree(compvared); if (varedarg) { @@ -641,11 +653,20 @@ callcompfunc(char *s, char *fn) case 2: complist = "autolist"; break; case 3: complist = "ambiguous"; break; } + if (isset(LISTPACKED)) + complist = dyncat(complist, " packed"); + if (isset(LISTROWSFIRST)) + complist = dyncat(complist, " rows"); + complist = ztrdup(complist); zsfree(compinsert); if (useline) { switch (usemenu) { - case 0: compinsert = "unambiguous"; break; + case 0: + compinsert = (isset(AUTOMENU) ? + "automenu-unambiguous" : + "unambiguous"); + break; case 1: compinsert = "menu"; break; case 2: compinsert = "automenu"; break; } @@ -722,13 +743,14 @@ callcompfunc(char *s, char *fn) uselist = 3; else uselist = 0; - + forcelist = (complist && strstr(complist, "force")); onlyexpl = (complist && strstr(complist, "expl")); if (!compinsert) useline = 0; else if (!strcmp(compinsert, "unambig") || - !strcmp(compinsert, "unambiguous")) + !strcmp(compinsert, "unambiguous") || + !strcmp(compinsert, "automenu-unambiguous")) useline = 1, usemenu = 0; else if (!strcmp(compinsert, "menu")) useline = 1, usemenu = 1; @@ -749,6 +771,8 @@ callcompfunc(char *s, char *fn) insspace = (compinsert[strlen(compinsert) - 1] == ' '); } else useline = usemenu = 0; + startauto = (compinsert && + !strcmp(compinsert, "automenu-unambiguous")); useexact = (compexact && !strcmp(compexact, "accept")); if (!comptoend || !*comptoend) @@ -1545,6 +1569,8 @@ addmatches(Cadata dat, char **argv) qipre = ztrdup(compqiprefix ? compqiprefix : ""); qisuf = ztrdup(compqisuffix ? compqisuffix : ""); + useexact = (compexact && !strcmp(compexact, "accept")); + /* Switch back to the heap that was used when the completion widget * was invoked. */ SWITCHHEAPS(compheap) { @@ -2075,7 +2101,11 @@ add_match_data(int alt, char *str, Cline line, cm->isuf = (isuf && *isuf ? isuf : NULL); cm->pre = pre; cm->suf = suf; - cm->flags = flags; + cm->flags = (flags | + (complist ? + ((strstr(complist, "packed") ? CMF_PACKED : 0) | + (strstr(complist, "rows") ? CMF_ROWS : 0)) : 0)); + if ((*compqstack == '\\' && compqstack[1]) || (autoq && *compqstack && compqstack[1] == '\\')) cm->flags |= CMF_NOSPACE; @@ -2117,6 +2147,8 @@ add_match_data(int alt, char *str, Cline line, newmatches = 1; + if (!complastprompt || !*complastprompt) + dolastprompt = 0; /* One more match for this explanation. */ if (curexpl) { if (alt) @@ -2140,8 +2172,8 @@ add_match_data(int alt, char *str, Cline line, /* Do we have an exact match? More than one? */ if (exact) { if (!ai->exact) { - ai->exact = 1; - if (incompfunc) { + ai->exact = useexact; + if (incompfunc && (!compexactstr || !*compexactstr)) { /* If a completion widget is active, we make the exact * string available in `compstate'. */ @@ -2160,7 +2192,7 @@ add_match_data(int alt, char *str, Cline line, comp_setunset(0, 0, CP_EXACTSTR, 0); } ai->exactm = cm; - } else { + } else if (useexact) { ai->exact = 2; ai->exactm = NULL; if (incompfunc) diff --git a/Src/Zle/complete.c b/Src/Zle/complete.c index 416ebfff7..a78a12058 100644 --- a/Src/Zle/complete.c +++ b/Src/Zle/complete.c @@ -66,7 +66,6 @@ char *compiprefix, *compquoting, *comprestore, *complist, - *compforcelist, *compinsert, *compexact, *compexactstr, @@ -948,7 +947,6 @@ static struct compparam compkparams[] = { { "quoting", PM_SCALAR | PM_READONLY, VAL(compquoting), NULL, NULL }, { "restore", PM_SCALAR, VAL(comprestore), NULL, NULL }, { "list", PM_SCALAR, NULL, VAL(set_complist), VAL(get_complist) }, - { "force_list", PM_SCALAR, VAL(compforcelist), NULL, NULL }, { "insert", PM_SCALAR, VAL(compinsert), NULL, NULL }, { "exact", PM_SCALAR, VAL(compexact), NULL, NULL }, { "exact_string", PM_SCALAR, VAL(compexactstr), NULL, NULL }, @@ -1363,8 +1361,8 @@ setup_complete(Module m) compcontext = compparameter = compredirect = compquote = compquoting = comprestore = complist = compinsert = compexact = compexactstr = comppatmatch = comppatinsert = - compforcelist = complastprompt = comptoend = - compoldlist = compoldins = compvared = compqstack = NULL; + complastprompt = comptoend = compoldlist = compoldins = + compvared = compqstack = NULL; hascompmod = 1; @@ -1431,7 +1429,6 @@ finish_complete(Module m) zsfree(compquoting); zsfree(comprestore); zsfree(complist); - zsfree(compforcelist); zsfree(compinsert); zsfree(compexact); zsfree(compexactstr); diff --git a/Src/Zle/compresult.c b/Src/Zle/compresult.c index bdafa3059..4aa171ea1 100644 --- a/Src/Zle/compresult.c +++ b/Src/Zle/compresult.c @@ -586,7 +586,7 @@ do_ambiguous(void) /* If we have to insert the first match, call do_single(). This is * * how REC_EXACT takes effect. We effectively turn the ambiguous * * completion into an unambiguous one. */ - if (ainfo && ainfo->exact == 1 && useexact && !(fromcomp & FC_LINE)) { + if (ainfo && ainfo->exact == 1 && !(fromcomp & FC_LINE)) { minfo.cur = NULL; do_single(ainfo->exactm); invalidatelist(); @@ -669,7 +669,7 @@ do_ambiguous(void) if (uselist && (usemenu != 2 || (!listshown && !oldlist)) && ((!showinglist && (!listshown || !oldlist)) || (usemenu == 3 && !oldlist)) && - (smatches >= 2 || (compforcelist && *compforcelist))) + (smatches >= 2 || forcelist)) showinglist = -2; return ret; @@ -1151,6 +1151,8 @@ calclist(void) char **pp = g->ylist; int nl = 0, l, glong = 1, gshort = columns, ndisp = 0, totl = 0; + g->flags |= CGF_PACKED | CGF_ROWS; + if (!onlyexpl && pp) { /* We have an ylist, lets see, if it contains newlines. */ hidden = 1; @@ -1211,6 +1213,10 @@ calclist(void) mlens[m->gnum] = l; } nlist++; + if (!(m->flags & CMF_PACKED)) + g->flags &= ~CGF_PACKED; + if (!(m->flags & CMF_ROWS)) + g->flags &= ~CGF_ROWS; } else if (!(m->flags & CMF_NOLIST)) { l = niceztrlen(m->str); ndisp++; @@ -1221,6 +1227,10 @@ calclist(void) totl += l; mlens[m->gnum] = l; nlist++; + if (!(m->flags & CMF_PACKED)) + g->flags &= ~CGF_PACKED; + if (!(m->flags & CMF_ROWS)) + g->flags &= ~CGF_ROWS; } else hidden = 1; } @@ -1289,11 +1299,14 @@ calclist(void) nlines += glines; } } - if (!onlyexpl && isset(LISTPACKED)) { + if (!onlyexpl) { char **pp; int *ws, tlines, tline, tcols, maxlen, nth, width; for (g = amatches; g; g = g->next) { + if (!(g->flags & CGF_PACKED)) + continue; + ws = g->widths = (int *) zalloc(columns * sizeof(int)); memset(ws, 0, columns * sizeof(int)); tlines = g->lins; @@ -1308,7 +1321,7 @@ calclist(void) for (i = 0; *pp; i++, pp++) ylens[i] = strlen(*pp) + add; - if (isset(LISTROWSFIRST)) { + if (g->flags & CGF_ROWS) { int count, tcol, first, maxlines = 0, llines; for (tcols = columns / g->shortest; tcols > g->cols; @@ -1366,7 +1379,7 @@ calclist(void) } } } else if (g->width) { - if (isset(LISTROWSFIRST)) { + if (g->flags & CGF_ROWS) { int addlen, count, tcol, maxlines = 0, llines, i; Cmatch *first; @@ -1477,12 +1490,12 @@ int asklist(void) trashzle(); showinglist = listshown = 0; - clearflag = (isset(USEZLE) && !termflags && - complastprompt && *complastprompt); + clearflag = (isset(USEZLE) && !termflags && dolastprompt); /* Maybe we have to ask if the user wants to see the list. */ if ((!minfo.cur || !minfo.asked) && - ((complistmax && listdat.nlist > complistmax) || + ((complistmax > 0 && listdat.nlist >= complistmax) || + (complistmax < 0 && listdat.nlines <= -complistmax) || (!complistmax && listdat.nlines >= lines))) { int qup; zsetterm(); @@ -1599,7 +1612,7 @@ printlist(int over, CLPrintFunc printm) while (a--) putc(' ', shout); } - pq += (isset(LISTROWSFIRST) ? 1 : nc); + pq += ((g->flags & CGF_ROWS) ? 1 : nc); mc++; n--; } @@ -1612,7 +1625,7 @@ printlist(int over, CLPrintFunc printm) tcout(TCCLEAREOD); } } - pp += (isset(LISTROWSFIRST) ? g->cols : 1); + pp += ((g->flags & CGF_ROWS) ? g->cols : 1); } } } else if (!listdat.onlyexpl && g->lcount) { @@ -1678,7 +1691,8 @@ printlist(int over, CLPrintFunc printm) printed++; if (--n) - for (j = (isset(LISTROWSFIRST) ? 1 : nc); j && *q; j--) + for (j = ((g->flags & CGF_ROWS) ? 1 : nc); + j && *q; j--) q = skipnolist(q + 1); mc++; } @@ -1696,7 +1710,8 @@ printlist(int over, CLPrintFunc printm) tcout(TCCLEAREOD); } if (nl) - for (j = (isset(LISTROWSFIRST) ? g->cols : 1); j && *p; j--) + for (j = ((g->flags & CGF_ROWS) ? g->cols : 1); + j && *p; j--) p = skipnolist(p + 1); } } |