diff options
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | Completion/Base/Completer/_complete | 2 | ||||
-rw-r--r-- | Completion/Base/Core/_description | 15 | ||||
-rw-r--r-- | Completion/Base/Core/_main_complete | 2 | ||||
-rw-r--r-- | Completion/Base/Core/_message | 13 | ||||
-rw-r--r-- | Completion/Base/Utility/_alternative | 4 | ||||
-rw-r--r-- | Completion/Base/Utility/_arguments | 2 | ||||
-rw-r--r-- | Completion/Base/Utility/_values | 2 | ||||
-rw-r--r-- | Completion/Unix/Command/_chown | 2 | ||||
-rw-r--r-- | Doc/Zsh/compsys.yo | 23 | ||||
-rw-r--r-- | Src/Zle/comp.h | 1 | ||||
-rw-r--r-- | Src/Zle/compcore.c | 62 | ||||
-rw-r--r-- | Src/Zle/compctl.c | 6 | ||||
-rw-r--r-- | Src/Zle/complist.c | 9 | ||||
-rw-r--r-- | Src/Zle/compresult.c | 15 |
15 files changed, 113 insertions, 59 deletions
diff --git a/ChangeLog b/ChangeLog index afa231754..c635f4c22 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2002-01-22 Sven Wischnowsky <wischnow@zsh.org> + + * 16483: Completion/Base/Completer/_complete, + Completion/Base/Core/_description, + Completion/Base/Core/_main_complete, + Completion/Base/Core/_message, + Completion/Base/Utility/_alternative, + Completion/Base/Utility/_arguments, + Completion/Base/Utility/_values, Completion/Unix/Command/_chown, + Doc/Zsh/compsys.yo, Src/Zle/comp.h, Src/Zle/compcore.c, + Src/Zle/compctl.c, Src/Zle/complist.c, Src/Zle/compresult.c: + add new generic fake style and changes to the C-code for that + (different implementation of compadd -x) + 2002-01-21 Sven Wischnowsky <wischnow@zsh.org> * 16472: Completion/Base/Completer/_complete, diff --git a/Completion/Base/Completer/_complete b/Completion/Base/Completer/_complete index 98d293175..16e0f5e9f 100644 --- a/Completion/Base/Completer/_complete +++ b/Completion/Base/Completer/_complete @@ -36,7 +36,7 @@ if [[ -n "$compcontext" ]]; then case "$action" in \ #) - _message "$descr";; + _message -e "$tag" "$descr";; \(\(*\)\)) eval ws\=\( "${action[3,-3]}" \) diff --git a/Completion/Base/Core/_description b/Completion/Base/Core/_description index 6b4cadfe8..30e6dfa9b 100644 --- a/Completion/Base/Core/_description +++ b/Completion/Base/Core/_description @@ -1,6 +1,6 @@ #autoload -local name gropt=-J format gname hidden hide match opts +local name gropt=-J format gname hidden hide match opts tag opts=() @@ -51,6 +51,8 @@ else _comp_ignore=() fi +tag="$1" + shift 2 if [[ -z "$1" && $# -eq 1 ]]; then format= @@ -72,4 +74,15 @@ else fi fi +if ! (( ${funcstack[2,-1][(I)_description]} )) && + zstyle -a ":completion:${curcontext}:$tag" fake match; then + + local descr + + descr=( "${(@M)match:#*[^\\]:*}" ) + + compadd "${(@P)name}" - "${(@)${(@)match:#*[^\\]:*}:s/\\:/:/}" + (( $#descr )) && _describe -t "$tag" '' descr "${(@P)name}" +fi + return 0 diff --git a/Completion/Base/Core/_main_complete b/Completion/Base/Core/_main_complete index 5960b2da7..f3ad720c9 100644 --- a/Completion/Base/Core/_main_complete +++ b/Completion/Base/Core/_main_complete @@ -268,7 +268,7 @@ if [[ $compstate[old_list] = keep || nm -gt 1 ]]; then fi fi fi -elif [[ nm -le 1 && -n "$_comp_mesg" ]]; then +elif [[ nm -lt 1 && -n "$_comp_mesg" ]]; then compstate[insert]='' compstate[list]='list force' elif [[ nm -eq 0 && -z "$_comp_mesg" && diff --git a/Completion/Base/Core/_message b/Completion/Base/Core/_message index cd08d5fb0..44512f648 100644 --- a/Completion/Base/Core/_message +++ b/Completion/Base/Core/_message @@ -2,6 +2,19 @@ local format raw +if [[ "$1" = -e ]]; then + local expl ret=1 + + _comp_mesg=yes + + _tags "$2" && while _next_label "$2" expl "$3"; do + compadd ${expl:/-X/-x} + ret=0 + done + + return ret +fi + _tags messages || return 1 if [[ "$1" = -r ]]; then diff --git a/Completion/Base/Utility/_alternative b/Completion/Base/Utility/_alternative index d6aef96b6..2f3e2dbc8 100644 --- a/Completion/Base/Utility/_alternative +++ b/Completion/Base/Utility/_alternative @@ -31,7 +31,7 @@ while _tags; do # An empty action means that we should just display a message. - mesgs=( "$mesgs[@]" "$descr") + mesgs=( "$mesgs[@]" "${def%%:*}:$descr") elif [[ "$action" = \(\(*\)\) ]]; then local ws @@ -76,7 +76,7 @@ while _tags; do done for descr in "$mesgs[@]"; do - _message "$descr" + _message -e "${descr%%:*}" "${desc#*:}" done return 1 diff --git a/Completion/Base/Utility/_arguments b/Completion/Base/Utility/_arguments index 0551afcf2..b4f3c599f 100644 --- a/Completion/Base/Utility/_arguments +++ b/Completion/Base/Utility/_arguments @@ -274,7 +274,7 @@ if (( $# )) && comparguments -i "$autod" "$singopt[@]" "$@"; then # An empty action means that we should just display a message. - _message "$descr" + _message -e "$subc" "$descr" mesg=yes tried=yes alwopt=${alwopt:-yes} diff --git a/Completion/Base/Utility/_values b/Completion/Base/Utility/_values index bb0337911..00249e05b 100644 --- a/Completion/Base/Utility/_values +++ b/Completion/Base/Utility/_values @@ -103,7 +103,7 @@ if compvalues -i "$@"; then # An empty action means that we should just display a message. - _message "$descr" + _message -e arguments "$descr" return 1 elif [[ "$action" = \(\(*\)\) ]]; then diff --git a/Completion/Unix/Command/_chown b/Completion/Unix/Command/_chown index 2e55209c5..599e09d14 100644 --- a/Completion/Unix/Command/_chown +++ b/Completion/Unix/Command/_chown @@ -5,7 +5,7 @@ local suf usr grp req expl line line=( "${(@)words[2,CURRENT-1]:#-*}" ) if [[ -prefix - ]]; then - _message option + _message -e options option elif [[ $#line -eq 0 ]]; then if [[ $service = chgrp ]] || compset -P '*[:.]'; then if (( EGID && $+commands[groups] )); then # except for root diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index e382c0601..d01fced77 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -1120,6 +1120,22 @@ generated this way, this will also cycle through the names of the files in pathname components after the first ambiguous one. ) +kindex(fake, completion style) +item(tt(fake))( +This style may be set for every completion context and is used to +specify additional strings to complete in that context. It's values +are either the strings to complete with every colon quoted by a +preceding backslash or strings of the form +`var(string)tt(:)var(description)'. In the latter case the var(string)s +will be shown together with the var(description)s in completion +listings. + +Note that you only really want to use this style for a narrow +enough context, so that the additional string won't show up in other +contexts. Also note the styles tt(fake-files) and tt(fake-parameters) +which give more control over additional strings to add when completing +files or parameters. +) kindex(fake-files, completion style) item(tt(fake-files))( This style is used when completing files and looked up @@ -3676,7 +3692,8 @@ tt(_guard)), only the message will be displayed and if the `tt(-n)' is followed by another character, only options are completed. ) findex(_message) -item(tt(_message) [ -r ] var(descr))( +xitem(tt(_message) [ tt(-r) ] var(descr)) +item(tt(_message -e) var(tag descr))( The var(descr) is used like the third argument to the tt(_description) function. However, the resulting string will always be shown whether or not matches were @@ -3691,6 +3708,10 @@ If the tt(-r) option is given, no style is used and the var(descr) is used literally as the string to display. This is only used in cases where that string is taken from some pre-processed argument list containing an expanded description. + +In the second form, the var(descr) is added like a description added +by tt(_description) under the given var(tag), but the var(descr) will +always be shown even if no matches are added for the var(tag). ) findex(_multi_parts) item(tt(_multi_parts) var(sep) var(array))( diff --git a/Src/Zle/comp.h b/Src/Zle/comp.h index c06e7aa7e..9d92b4a5c 100644 --- a/Src/Zle/comp.h +++ b/Src/Zle/comp.h @@ -38,6 +38,7 @@ typedef struct cmatch *Cmatch; /* This is for explantion strings. */ struct cexpl { + int always; /* display even without matches */ char *str; /* the string */ int count; /* the number of matches */ int fcount; /* number of matches with fignore ignored */ diff --git a/Src/Zle/compcore.c b/Src/Zle/compcore.c index 7db5ffd13..748a01f6c 100644 --- a/Src/Zle/compcore.c +++ b/Src/Zle/compcore.c @@ -1618,6 +1618,18 @@ addmatches(Cadata dat, char **argv) Brinfo bp, bpl = brbeg, obpl, bsl = brend, obsl; Heap oldheap; + SWITCHHEAPS(oldheap, compheap) { + if (dat->mesg || dat->exp) { + curexpl = (Cexpl) zhalloc(sizeof(struct cexpl)); + curexpl->always = !!dat->mesg; + curexpl->count = curexpl->fcount = 0; + curexpl->str = dupstring(dat->mesg ? dat->mesg : dat->exp); + if (dat->mesg) + addexpl(1); + } else + curexpl = NULL; + } SWITCHBACKHEAPS(oldheap); + if (!*argv && !dat->dummies && !(dat->aflags & CAF_ALL)) { SWITCHHEAPS(oldheap, compheap) { /* Select the group in which to store the matches. */ @@ -1631,8 +1643,6 @@ addmatches(Cadata dat, char **argv) endcmgroup(NULL); begcmgroup("default", 0); } - if (dat->mesg) - addmesg(dat->mesg); } SWITCHBACKHEAPS(oldheap); return 1; @@ -1689,13 +1699,6 @@ addmatches(Cadata dat, char **argv) dparr = NULL; dparl = newlinklist(); } - if (dat->exp) { - curexpl = (Cexpl) zhalloc(sizeof(struct cexpl)); - curexpl->count = curexpl->fcount = 0; - curexpl->str = dupstring(dat->exp); - } else - curexpl = NULL; - /* Store the matcher in our stack of matchers. */ if (dat->match) { mst.next = mstack; @@ -1889,8 +1892,6 @@ addmatches(Cadata dat, char **argv) endcmgroup(NULL); begcmgroup("default", 0); } - if (dat->mesg) - addmesg(dat->mesg); if (*argv) { if (dat->pre) dat->pre = dupstring(dat->pre); @@ -2057,7 +2058,7 @@ addmatches(Cadata dat, char **argv) if (dat->dpar) set_list_array(dat->dpar, dparl); if (dat->exp) - addexpl(); + addexpl(0); if (!hasallmatch && (dat->aflags & CAF_ALL)) { addmatch("<all>", dat->flags | CMF_ALL, &disp, 1); hasallmatch = 1; @@ -2496,45 +2497,31 @@ endcmgroup(char **ylist) /**/ mod_export void -addexpl(void) +addexpl(int always) { LinkNode n; Cexpl e; for (n = firstnode(expls); n; incnode(n)) { e = (Cexpl) getdata(n); - if (e->count >= 0 && !strcmp(curexpl->str, e->str)) { + if (!strcmp(curexpl->str, e->str)) { e->count += curexpl->count; e->fcount += curexpl->fcount; - + if (always) { + e->always = 1; + nmessages++; + newmatches = 1; + mgroup->new = 1; + } return; } } addlinknode(expls, curexpl); newmatches = 1; -} - -/* Add a message to the current group. Make sure it is shown. */ - -/**/ -mod_export void -addmesg(char *mesg) -{ - LinkNode n; - Cexpl e; - - for (n = firstnode(expls); n; incnode(n)) { - e = (Cexpl) getdata(n); - if (e->count < 0 && !strcmp(mesg, e->str)) - return; + if (always) { + mgroup->new = 1; + nmessages++; } - e = (Cexpl) zhalloc(sizeof(*e)); - e->count = e->fcount = -1; - e->str = dupstring(mesg); - addlinknode(expls, e); - newmatches = 1; - mgroup->new = 1; - nmessages++; } /* The comparison function for matches (used for sorting). */ @@ -2852,6 +2839,7 @@ permmatches(int last) for (eq = g->expls; (o = *eq); eq++, ep++) { *ep = e = (Cexpl) zcalloc(sizeof(struct cexpl)); e->count = (fi ? o->fcount : o->count); + e->always = o->always; e->fcount = 0; e->str = ztrdup(o->str); } diff --git a/Src/Zle/compctl.c b/Src/Zle/compctl.c index b4981a842..cc0aebf04 100644 --- a/Src/Zle/compctl.c +++ b/Src/Zle/compctl.c @@ -3808,9 +3808,9 @@ makecomplistflags(Compctl cc, char *s, int incmd, int compadd) if (cc->gname) { endcmgroup(yaptr); begcmgroup(cc->gname, gflags); - addexpl(); + addexpl(0); } else { - addexpl(); + addexpl(0); endcmgroup(yaptr); begcmgroup("default", 0); } @@ -3825,7 +3825,7 @@ makecomplistflags(Compctl cc, char *s, int incmd, int compadd) untokenize(tt); } curexpl->str = tt; - addexpl(); + addexpl(0); } if (cc->subcmd) { /* Handle -l sub-completion. */ diff --git a/Src/Zle/complist.c b/Src/Zle/complist.c index 14cb16d4c..e38ffe33b 100644 --- a/Src/Zle/complist.c +++ b/Src/Zle/complist.c @@ -1042,9 +1042,9 @@ compprintlist(int showall) lastused = 1; } while (*e) { - if ((*e)->count && + if (((*e)->count || (*e)->always) && (!listdat.onlyexpl || - (listdat.onlyexpl & ((*e)->count > 0 ? 1 : 2)))) { + (listdat.onlyexpl & ((*e)->always > 0 ? 2 : 1)))) { if (pnl) { if (dolistnl(ml) && compprintnl(ml)) goto end; @@ -1058,8 +1058,9 @@ compprintlist(int showall) } if (mlbeg < 0 && mfirstl < 0) mfirstl = ml; - l = compprintfmt((*e)->str, (*e)->count, dolist(ml), 1, - ml, &stop); + l = compprintfmt((*e)->str, + ((*e)->always ? -1 : (*e)->count), + dolist(ml), 1, ml, &stop); if (mselect >= 0) { int mm = (mcols * ml), i; diff --git a/Src/Zle/compresult.c b/Src/Zle/compresult.c index 13b9edd72..44a40f0fb 100644 --- a/Src/Zle/compresult.c +++ b/Src/Zle/compresult.c @@ -1494,10 +1494,12 @@ calclist(int showall) } if ((e = g->expls)) { while (*e) { - if ((*e)->count && + if (((*e)->count || (*e)->always) && (!onlyexpl || - (onlyexpl & ((*e)->count > 0 ? 1 : 2)))) - nlines += 1 + printfmt((*e)->str, (*e)->count, 0, 1); + (onlyexpl & ((*e)->always > 0 ? 2 : 1)))) + nlines += 1 + printfmt((*e)->str, + ((*e)->always ? -1 : (*e)->count), + 0, 1); e++; } } @@ -1840,9 +1842,9 @@ printlist(int over, CLPrintFunc printm, int showall) int l; while (*e) { - if ((*e)->count && + if (((*e)->count || (*e)->always) && (!listdat.onlyexpl || - (listdat.onlyexpl & ((*e)->count > 0 ? 1 : 2)))) { + (listdat.onlyexpl & ((*e)->always > 0 ? 2 : 1)))) { if (pnl) { putc('\n', shout); pnl = 0; @@ -1853,7 +1855,8 @@ printlist(int over, CLPrintFunc printm, int showall) tcout(TCCLEAREOD); } } - l = printfmt((*e)->str, (*e)->count, 1, 1); + l = printfmt((*e)->str, + ((*e)->always ? -1 : (*e)->count), 1, 1); ml += l; if (cl >= 0 && (cl -= l) <= 1) { cl = -1; |