diff options
author | Tanaka Akira <akr@users.sourceforge.net> | 1999-11-15 12:01:46 +0000 |
---|---|---|
committer | Tanaka Akira <akr@users.sourceforge.net> | 1999-11-15 12:01:46 +0000 |
commit | 35b2633ad941966f5fca07b625a594a5b68c0fdb (patch) | |
tree | b54740d014e594ba5d81931cdcdb3387bcf9dfca /Completion/Core | |
parent | bb98460a01ce1f6c1e71f7e401f782c81b71486b (diff) | |
download | zsh-35b2633ad941966f5fca07b625a594a5b68c0fdb.tar.gz zsh-35b2633ad941966f5fca07b625a594a5b68c0fdb.tar.xz zsh-35b2633ad941966f5fca07b625a594a5b68c0fdb.zip |
manual/8639
Diffstat (limited to 'Completion/Core')
28 files changed, 432 insertions, 344 deletions
diff --git a/Completion/Core/.distfiles b/Completion/Core/.distfiles index 63592dfaf..eeac55a97 100644 --- a/Completion/Core/.distfiles +++ b/Completion/Core/.distfiles @@ -3,6 +3,6 @@ DISTFILES_SRC=' _approximate _compalso _complete _correct _description _expand _files _list _main_complete _match _menu _multi_parts _message _normal _oldlist _options _parameters _path_files - _sep_parts _set_options _unset_options + _sep_parts _set_options _sort_tags _unset_options compdump compinit compinstall ' diff --git a/Completion/Core/_alternative b/Completion/Core/_alternative index f13fc9e5a..76a8380bc 100644 --- a/Completion/Core/_alternative +++ b/Completion/Core/_alternative @@ -1,22 +1,23 @@ #autoload local tags def expl descr action mesgs nm="$compstack[nmatches]" subopts +local opt curcontext="$curcontext" + +subopts=() +while getopts 'O:C:' opt; do + case "$opt" in + O) subopts=( "${(@P)OPTARG}" ) ;; + C) curcontext="${curontext}:$OPTARG" ;; + esac +done -if [[ "$1" = -O?* ]]; then - subopts=( "${(@P)1[3,-1]}" ) - shift -elif [[ "$1" = -O ]]; then - subopts=( "${(@P)2}" ) - shift 2 -else - subopts=() -fi +shift OPTIND-1 [[ "$1" = -(|-) ]] && shift mesgs=() -_tags "$1" "${(@)argv[2,-1]%%:*}" +_tags "${(@)argv%%:*}" while _tags; do for def; do diff --git a/Completion/Core/_approximate b/Completion/Core/_approximate index 235e324f7..910742fee 100644 --- a/Completion/Core/_approximate +++ b/Completion/Core/_approximate @@ -7,6 +7,7 @@ local _comp_correct _correct_prompt comax local cfgacc cfgorig cfgps cfgins +local curcontext="$curcontext" oldcontext # Only if all global matchers have been tried. @@ -16,20 +17,16 @@ local cfgacc cfgorig cfgps cfgins [[ "${#:-$PREFIX$SUFFIX}" -le 1 ]] && return 1 -# Get the configuration values, using either the prefix `correct' or -# `approximate'. +# Probably set initial context. -if [[ "$compstate[pattern_match]" = (|\**) ]]; then - cfgacc="${compconfig[approximate_accept]:-$compconfig[correct_accept]}" - cfgorig="${compconfig[approximate_original]:-$compconfig[correct_original]}" - cfgps="${compconfig[approximate_prompt]:-$compconfig[correct_prompt]}" - cfgins="${compconfig[approximate_insert]:-$compconfig[correct_insert]}" -else - cfgacc="$compconfig[correct_accept]" - cfgorig="$compconfig[correct_original]" - cfgps="$compconfig[correct_prompt]" - cfgins="$compconfig[correct_insert]" -fi +[[ -z "$curcontext" ]] && curcontext=':approximate' + +oldcontext="$curcontext" + +_style -s '' accept cfgacc +_style -s '' original cfgorig +_style -s '' prompt cfgps +_style -s '' insert cfgins # Get the number of errors to accept. @@ -86,16 +83,18 @@ _correct_prompt="${cfgps//\\%e/1}" [[ -z "$compstate[pattern_match]" ]] && compstate[pattern_match]='*' while [[ _comp_correct -le comax ]]; do + curcontext="${oldcontext}:$_comp_correct" + if _complete; then if [[ "$cfgins" = unambig* && "${#compstate[unambiguous]}" -ge "${#:-$PREFIX$SUFFIX}" ]]; then compstate[pattern_insert]=unambiguous elif [[ compstate[nmatches] -gt 1 || "$cfgorig" = *always* ]]; then - local expl + local expl format if [[ "$cfgorig" = *show* ]]; then - if [[ -n "$compconfig[description_format]" ]]; then - expl=(-X "${compconfig[description_format]//\\%d/original}") + if _style -s descriptions format format; then + expl=(-X "${format//\\%d/original}") else expl=() fi diff --git a/Completion/Core/_complete b/Completion/Core/_complete index f351c7349..235265326 100644 --- a/Completion/Core/_complete +++ b/Completion/Core/_complete @@ -2,16 +2,21 @@ # Generate all possible completions. Note that this is not intended as # a normal completion function, but as one possible value for the -# compconfig[completer] parameter. +# completer style. -local comp name _tag_context="$_tag_context" +local comp name curcontext="$curcontext" oldcontext -[[ "$compstate[context]" != command || CURRENT -eq 1 ]] && - _tag_context="-${compstate[context]:s/_/-/}-" +# Probably set initial context. + +[[ -z "$curcontext" ]] && curcontext=':complete' + +oldcontext="$curcontext" # If we have a user-supplied context name, use only that. if [[ -n "$compcontext" ]]; then + curcontext="${curcontext}:$compcontext" + comp="$_comps[$compcontext]" [[ -z "$comp" ]] || "$comp" @@ -22,6 +27,7 @@ fi comp="$_comps[-first-]" if [[ ! -z "$comp" ]]; then + curcontext="${curcontext}:-first-" "$comp" if [[ "$_compskip" = all ]]; then _compskip='' @@ -34,12 +40,17 @@ fi # For arguments and command names we use the `_normal' function. if [[ "$compstate[context]" = command ]]; then + curcontext="$oldcontext" _normal -s else # Let's see if we have a special completion definition for the other # possible contexts. - comp="$_comps[$_tag_context]" + local cname="-${compstate[context]:s/_/-/}-" + + curcontext="${oldcontext}:$cname" + + comp="$_comps[$cname]" # If not, we use default completion, if any. diff --git a/Completion/Core/_correct b/Completion/Core/_correct index c9c3d999c..abd70ddeb 100644 --- a/Completion/Core/_correct +++ b/Completion/Core/_correct @@ -8,7 +8,11 @@ # Supported configuration keys are the same as for `_approximate', only # starting with `correct'. -local ret=1 opm="$compstate[pattern_match]" +local ret=1 opm="$compstate[pattern_match]" curcontext="$curcontext" + +# Probably set initial context. + +[[ -z "$curcontext" ]] && curcontext=':correct' compstate[pattern_match]='-' diff --git a/Completion/Core/_description b/Completion/Core/_description index 107be5cd6..8cd9cc2fb 100644 --- a/Completion/Core/_description +++ b/Completion/Core/_description @@ -1,6 +1,6 @@ #autoload -local gropt=-J +local gropt=-J format if [[ "$1" = -[VJ]* ]]; then gropt="$1" @@ -9,16 +9,20 @@ fi _lastdescr=( "$_lastdescr[@]" "$2" ) -if [[ -n "$compconfig[group_matches]" ]]; then - if [[ -n "$compconfig[description_format]" ]]; then - eval "$1=($gropt ${(q)2} -X ${(q)compconfig[description_format]//\\%d/$2})" +_style -s descriptions format format + +if _style matches group; then + if [[ -n "$format" ]]; then + eval "$1=($gropt ${(q)2} -X ${(q)format//\\%d/$2})" else eval "$1=($gropt ${(q)2})" fi else - if [[ -n "$compconfig[description_format]" ]]; then - eval "$1=(-X ${(q)compconfig[description_format]//\\%d/$2})" + if [[ -n "$format" ]]; then + eval "$1=(-X ${(q)format//\\%d/$2})" else eval "$1=()" fi fi + +return 0 diff --git a/Completion/Core/_expand b/Completion/Core/_expand index df9e0b9ea..97728bd3b 100644 --- a/Completion/Core/_expand +++ b/Completion/Core/_expand @@ -7,12 +7,16 @@ # the expansions done produce no result or do not change the original # word from the line. -local exp word="$PREFIX$SUFFIX" group=-V expl expl2 disp +local exp word="$PREFIX$SUFFIX" group=-V expl expl2 disp orig menu prompt +local curcontext="$curcontext" expr descr + +# Probably set initial context. + +[[ -z "$curcontext" ]] && curcontext=':expand' # First, see if we should insert all *completions*. -if [[ -n "$compconfig[expand_completions]" && - "${(e):-\$[$compconfig[expand_substitute]]}" -eq 1 ]]; then +if _style -s '' completions expr && [[ "${(e):-\$[$expr]}" -eq 1 ]]; then compstate[insert]=all return 1 fi @@ -28,8 +32,7 @@ exp=("$word") # First try substitution. That weird thing spanning multiple lines # changes quoted spaces, tabs, and newlines into spaces. -[[ -z "$compconfig[expand_substitute]" || - "${(e):-\$[$compconfig[expand_substitute]]}" -eq 1 ]] && +_style -s '' substitute expr && [[ "${(e):-\$[$expr]}" -eq 1 ]] && exp=( "${(e)exp//\\[ ]/ }" ) @@ -39,8 +42,7 @@ exp=("$word") # Now try globbing. -[[ -z "$compconfig[expand_glob]" || - "${(e):-\$[$compconfig[expand_glob]]}" -eq 1 ]] && +_style -s '' glob expr && [[ "${(e):-\$[$expr]}" -eq 1 ]] && exp=( ${~exp}(N) ) # If we don't have any expansions or only one and that is the same @@ -51,9 +53,14 @@ exp=("$word") # Get the options for adding the original string and `all'-string. -if [[ "$compconfig[expand_original]" = *show* ]]; then - if [[ -n "$compconfig[description_format]" ]]; then - expl=(-X "${compconfig[description_format]//\\%d/original}") +_style -s '' original orig +_style -s '' menu menu +_style -s '' prompt prompt +_style -s descriptions format descr + +if [[ "$orig" = *show* ]]; then + if [[ -n "$descr" ]]; then + expl=(-X "${descr//\\%d/original}") else expl=() fi @@ -61,11 +68,9 @@ else expl=(-n) fi -if [[ -n "$compconfig[expand_menu]" && - "$compconfig[expand_menu]" != *only* && - "$compconfig[expand_menu]" = *showall* ]]; then - if [[ -n "$compconfig[description_format]" ]]; then - expl2=(-ld disp -X "${compconfig[description_format]//\\%d/all words}") +if [[ -n "$menu" && "$menu" != *only* && "$menu" = *showall* ]]; then + if [[ -n "$descr" ]]; then + expl2=(-ld disp -X "${descr//\\%d/all words}") else expl2=(-ld disp ) fi @@ -83,7 +88,7 @@ fi # We have expansions, should we menucomplete them? -if [[ -z "$compconfig[expand_menu]" ]]; then +if [[ -z "$menu" ]]; then # No, so if the user only wants a list, we add the strings # separately. Otherwise we add the whole array as one string, @@ -92,14 +97,12 @@ if [[ -z "$compconfig[expand_menu]" ]]; then if [[ -z "$compstate[insert]" ]]; then compadd -U -V _expand -Q - "$exp[@]" else - [[ -n "$compconfig[expand_original]" && - "$compconfig[expand_original]" != *last* ]] && + [[ -n "$orig" && "$orig" != *last* ]] && compadd "$expl[@]" -UQ -V _expand_original - "$word" compadd -UQ -V _expand - "$exp" - [[ -n "$compconfig[expand_original]" && - "$compconfig[expand_original]" = *last* ]] && + [[ -n "$orig" && "$orig" = *last* ]] && compadd "$expl[@]" -UQ -V _expand_original - "$word" compstate[insert]=menu @@ -107,31 +110,27 @@ if [[ -z "$compconfig[expand_menu]" ]]; then else # Sorting? We just use a different group type then. - [[ "$compconfig[expand_menu]" = *sort* ]] && group=-J + [[ "$menu" = *sort* ]] && group=-J # Now add the expansion string, probably also adding the original # and/or the string containing all expanded string. - [[ -n "$compconfig[expand_original]" && - "$compconfig[expand_original]" != *last* ]] && + [[ -n "$orig" && "$orig" != *last* ]] && compadd "$expl[@]" -UQ -V _expand_original - "$word" - [[ $#exp -ne 1 && "$compconfig[expand_menu]" = *last* && - "$compconfig[expand_menu]" != *only* ]] && + [[ $#exp -ne 1 && "$menu" = *last* && "$menu" != *only* ]] && compadd "$expl2[@]" -UQ -V _expand_all - "$exp" - if [[ -z "$compconfig[expand_prompt]" ]]; then + if [[ -z "$prompt" ]]; then compadd -UQ $group _expand - "$exp[@]" else - compadd -UQ -X "${compconfig[expand_prompt]//\\%o/$word}" \ + compadd -UQ -X "${prompt//\\%o/$word}" \ $group _expand - "$exp[@]" fi - [[ $#exp -ne 1 && "$compconfig[expand_menu]" != *last* && - "$compconfig[expand_menu]" != *only* ]] && + [[ $#exp -ne 1 && "$menu" != *last* && "$menu" != *only* ]] && compadd "$expl2[@]" -UQ -V _expand_all - "$exp" - [[ -n "$compconfig[expand_original]" && - "$compconfig[expand_original]" = *last* ]] && + [[ -n "$orig" && "$orig" = *last* ]] && compadd "$expl[@]" -UQ -V _expand_original - "$word" compstate[insert]=menu diff --git a/Completion/Core/_files b/Completion/Core/_files index 973eea69b..ba5445797 100644 --- a/Completion/Core/_files +++ b/Completion/Core/_files @@ -13,9 +13,9 @@ while getopts "P:S:qr:R:W:F:J:V:X:f/g:M:" opt; do done case "$type" in -file) _tags any all-files ;; -dir) _tags any directories all-files ;; -*) _tags any globbed-files directories all-files ;; +file) _tags all-files ;; +dir) _tags directories all-files ;; +*) _tags globbed-files directories all-files ;; esac while _tags; do diff --git a/Completion/Core/_list b/Completion/Core/_list index f0bdda08a..803da2f71 100644 --- a/Completion/Core/_list +++ b/Completion/Core/_list @@ -4,11 +4,15 @@ # insert possible completions only after the list has been shown at # least once. -local pre suf +local pre suf curcontext="$curcontext" expr + +# Probably set initial context. + +[[ -z "$curcontext" ]] && curcontext=':list' # Get the strings to compare. -if [[ -z "$compconfig[list_word]" ]]; then +if _style '' word; then pre="$HISTNO$LBUFFER" suf="$RBUFFER" else @@ -18,8 +22,8 @@ fi # Should we only show a list now? -if [[ ( -z "$compconfig[list_condition]" || - "${(e):-\$[$compconfig[list_condition]]}" -eq 1 ) && +_style -s '' condition expr +if [[ ( -z "$expr" || "${(e):-\$[$expr]}" -eq 1 ) && ( "$pre" != "$_list_prefix" || "$suf" != "$_list_suffix" ) ]]; then # Yes. Tell the completion code about it and save the new values diff --git a/Completion/Core/_main_complete b/Completion/Core/_main_complete index f9a8a19ad..ba31399b3 100644 --- a/Completion/Core/_main_complete +++ b/Completion/Core/_main_complete @@ -17,10 +17,9 @@ # state than the global one for which you are completing. -local comp post ret=1 _compskip _prio_num=1 _tag_context _cur_contexts -local context state line opt_args val_args +local comp post ret=1 _compskip _prio_num=1 _cur_context format +local context state line opt_args val_args curcontext typeset -U _offered_tags _tried_tags _failed_tags _used_tags _unused_tags -typeset -A _prio_names _prio_contexts _cur_tags _tag_contexts _offered_tags=() _tried_tags=() @@ -42,7 +41,12 @@ fi # Get the names of the completers to use in the positional parameters. -(( $# )) || set ${(s.:.)compconfig[completer]} +if (( ! $# )); then + local tmp + + _style -a '' completer tmp + set -- "$tmp[@]" +fi # And now just call the completer functions defined. @@ -66,9 +70,12 @@ done comppostfuncs=() _lastdescr=( "\`${(@)^_lastdescr:#}'" ) + +_style -s warnings format format + if [[ compstate[nmatches] -eq 0 && compstate[matcher] -eq compstate[total_matchers] && - -n "$compconfig[warning_format]" && $#_lastdescr -ne 0 ]]; then + -n "$format" && $#_lastdescr -ne 0 ]]; then local str compstate[list]=list @@ -81,10 +88,10 @@ if [[ compstate[nmatches] -eq 0 && *) str="${(j:, :)_lastdescr[1,-2]}, or $_lastdescr[-1]";; esac - compadd -UX "${compconfig[warning_format]//\\%d/$str}" -n '' + compadd -UX "${format//\\%d/$str}" -n '' fi -[[ "$compconfig[last_prompt]" = always ]] && compstate[last_prompt]=yes +_style '' last-prompt always && compstate[last_prompt]=yes _lastcomp=( "${(@kv)compstate}" ) _lastcomp[completer]="$comp" diff --git a/Completion/Core/_match b/Completion/Core/_match index f4e5fc0ee..35d7c2ecb 100644 --- a/Completion/Core/_match +++ b/Completion/Core/_match @@ -1,7 +1,7 @@ #autoload # This is intended to be used as a completer function after the normal -# completer as in: `compconf completer=_complete:_match'. +# completer as in: `compstyle "*" completer _complete _match'. # It temporarily switches on pattern matching, allowing you to try # completion on patterns without having to setopt glob_complete. # @@ -9,7 +9,8 @@ # expand-or-complete function because otherwise the pattern will # be expanded using globbing. -local tmp opm="$compstate[pattern_match]" ret=0 +local tmp opm="$compstate[pattern_match]" ret=0 curcontext="$curcontext" +local orig ins # Do nothing if we don't have a pattern or there are still global # match specifications to try. @@ -18,9 +19,16 @@ tmp="${${:-$PREFIX$SUFFIX}#[~=]}" [[ "$tmp:q" = "$tmp" || compstate[matcher] -ne compstate[total_matchers] ]] && return 1 +# Probably set initial context. + +[[ -z "$curcontext" ]] && curcontext=':match' + +_style -s '' original orig +_style -s '' insert ins + # Try completion without inserting a `*'? -if [[ -n "$compconfig[match_original]" ]]; then +if [[ -n "$orig" ]]; then compstate[matcher]=-1 compstate[pattern_match]='-' _complete && ret=1 @@ -28,7 +36,7 @@ if [[ -n "$compconfig[match_original]" ]]; then compstate[matcher]="$compstate[total_matchers]" if (( ret )); then - [[ "$compconfig[match_insert]" = unambig* && + [[ "$ins" = unambig* && $#compstate[unambiguous] -ge ${#:-${PREFIX}${SUFFIX}} ]] && compstate[pattern_insert]=unambiguous return 0 @@ -37,7 +45,7 @@ fi # No completion with inserting `*'? -[[ "$compconfig[match_original]" = only ]] && return 1 +[[ "$orig" = only ]] && return 1 compstate[matcher]=-1 compstate[pattern_match]='*' @@ -45,7 +53,7 @@ _complete && ret=1 compstate[pattern_match]="$opm" compstate[matcher]="$compstate[total_matchers]" -[[ ret -eq 1 && "$compconfig[match_insert]" = unambig* && +[[ ret -eq 1 && "$ins" = unambig* && $#compstate[unambiguous] -ge ${#:-${PREFIX}${SUFFIX}} ]] && compstate[pattern_insert]=unambiguous diff --git a/Completion/Core/_menu b/Completion/Core/_menu index 4cbda4e14..e9558fe05 100644 --- a/Completion/Core/_menu +++ b/Completion/Core/_menu @@ -1,10 +1,16 @@ #autoload +local curcontext="$curcontext" + +# Probably set initial context. + +[[ -z "$curcontext" ]] && curcontext=':menu' + # This completer is an example showing how menucompletion can be # implemented with the new completion system. # Use this one before the normal _complete completer, as in: # -# compconf completer=_menu:_complete +# compstyle "*" completer _menu _complete if [[ -n "$compstate[old_list]" ]]; then diff --git a/Completion/Core/_message b/Completion/Core/_message index ee869d33b..5c5c42e06 100644 --- a/Completion/Core/_message +++ b/Completion/Core/_message @@ -2,9 +2,9 @@ local format -_tags any messages || return 1 +_tags messages || return 1 -format="${compconfig[message_format]:-$compconfig[description_format]}" +_style -s messages format format || _style -s descriptions format format if [[ -n "$format" ]]; then if [[ $compstate[nmatches] -eq 0 ]]; then diff --git a/Completion/Core/_normal b/Completion/Core/_normal index 5d0a18406..f31e7e6fc 100644 --- a/Completion/Core/_normal +++ b/Completion/Core/_normal @@ -1,7 +1,7 @@ #autoload local comp command cmd1 cmd2 pat val name i ret=1 _compskip="$_compskip" -local _sub_context +local curcontext="$curcontext" # If we get the option `-s', we don't reset `_compskip'. This ensures # that a value set in the function for the `-first-' context is kept, @@ -16,19 +16,24 @@ local _sub_context command="$words[1]" if [[ CURRENT -eq 1 ]]; then + curcontext="${curcontext}:-command-" + comp="$_comps[-command-]" [[ -z "$comp" ]] || "$comp" && ret=0 return ret -elif [[ "$command[1]" == '=' ]]; then - eval cmd1\=$command - cmd2="$command[2,-1]" -elif [[ "$command" == */* ]]; then - cmd1="$command" - cmd2="${command:t}" else - cmd1="$command" - cmd2="$commands[$command]" + if [[ "$command[1]" == '=' ]]; then + eval cmd1\=$command + cmd2="$command[2,-1]" + elif [[ "$command" == */* ]]; then + cmd1="$command" + cmd2="${command:t}" + else + cmd1="$command" + cmd2="$commands[$command]" + fi + curcontext="${curcontext}:${cmd1}" fi # See if there are any matching pattern completions. diff --git a/Completion/Core/_oldlist b/Completion/Core/_oldlist index 2efc08119..2408613da 100644 --- a/Completion/Core/_oldlist +++ b/Completion/Core/_oldlist @@ -1,18 +1,26 @@ #autoload +local curcontext="$curcontext" list menu + +# Probably set initial context. + +[[ -z "$curcontext" ]] && curcontext=':oldlist' + +_style -s '' list list +_style -s '' menu menu + # If this is a listing widget and there is already an old list, -# and either the compconfig key oldlist_list is `always', or it is not `never' +# and either the style :oldlist:list is `always', or it is not `never' # and the list is not already shown, then use the existing list for listing # (even if it was generated by another widget). # Do this also if there is an old list and it was generated by the # completer named by the oldlist_list key. -if [[ -n $compstate[old_list] && $compconfig[oldlist_list] != never ]]; then - if [[ $WIDGET = *list* && - ( $compconfig[oldlist_list] = always || - $compstate[old_list] != shown ) ]]; then + +if [[ -n $compstate[old_list] && $list != never ]]; then + if [[ $WIDGET = *list* && ( $list = always || $list != shown ) ]]; then compstate[old_list]=keep return 0 - elif [[ $compconfig[oldlist_list] = *${_lastcomp[completer]}* ]]; then + elif [[ $list = *${_lastcomp[completer]}* ]]; then [[ "$_lastcomp[insert]" = unambig* ]] && compstate[to_end]=single compstate[old_list]=keep if [[ -o automenu ]]; then @@ -25,16 +33,16 @@ if [[ -n $compstate[old_list] && $compconfig[oldlist_list] != never ]]; then fi # If this is a completion widget, and we have a completion inserted already, -# and the compconfig key oldlist_menu is not never, then we cycle through the +# and the style :oldlist:menu is not never, then we cycle through the # existing list (even if it was generated by another widget). -if [[ $compconfig[oldlist_menu] = verbose && +if [[ $menu = verbose && $LASTWIDGET = _verbose_list && $WIDGET != _verbose_list && -z $compstate[old_insert] && -n $compstate[old_list] ]]; then compstate[old_list]=keep elif [[ $WIDGET = *complete(|-prefix|-word) && - $compconfig[oldlist_menu] != (never|verbose) ]]; then + $menu != (never|verbose) ]]; then if [[ -n $compstate[old_insert] ]]; then compstate[old_list]=keep if [[ $WIDGET = *reverse* ]]; then diff --git a/Completion/Core/_options b/Completion/Core/_options index 0dd92cf69..8664e239e 100644 --- a/Completion/Core/_options +++ b/Completion/Core/_options @@ -4,8 +4,6 @@ local expl -_tags any zsh-options || return 1 - -_description expl 'zsh option' -compadd "$expl[@]" "$@" -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' - \ - "${(@k)options}" +_wanted zsh-options expl 'zsh option' && + compadd "$expl[@]" "$@" -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' - \ + "${(@k)options}" diff --git a/Completion/Core/_parameters b/Completion/Core/_parameters index da479097e..3735702df 100644 --- a/Completion/Core/_parameters +++ b/Completion/Core/_parameters @@ -5,16 +5,13 @@ local pars expl -_tags any parameters || return 1 - -_description expl parameter +_wanted parameters expl parameter || return 1 pars=( ${(k)parameters[(R)^*local*]} ) compadd "$expl[@]" "$@" - $pars - # The `-e' option does everything for parameter expansions of us. If # we wouldn't have it, we would use something like: diff --git a/Completion/Core/_path_files b/Completion/Core/_path_files index 6468215cc..41956d543 100644 --- a/Completion/Core/_path_files +++ b/Completion/Core/_path_files @@ -331,11 +331,11 @@ for prepath in "$prepaths[@]"; do SUFFIX="${tsuf}" fi -tmp4="$testpath" -compquote tmp1 tmp4 + tmp4="$testpath" + compquote tmp1 tmp4 - if [[ -n $menu || "$compconfig[path_expand]" != *suffix* ]]; then - [[ -n "$compconfig[path_cursor]" ]] && compstate[to_end]='' + if [[ -n $menu ]] || ! _style paths expand '*suffix*'; then + _style paths cursor && compstate[to_end]='' if [[ "$tmp3" = */* ]]; then compadd -Qf -p "$linepath$tmp4" -s "/${tmp3#*/}" \ -W "$prepath$realpath$testpath" "$ignore[@]" \ @@ -423,8 +423,8 @@ done exppaths=( "${(@)exppaths:#$orig}" ) -if [[ "$compconfig[path_expand]" = *prefix* && - $#exppaths -gt 0 && nm -eq compstate[nmatches] ]]; then +if _style paths expand '*prefix*' && + [[ $#exppaths -gt 0 && nm -eq compstate[nmatches] ]]; then PREFIX="${opre}" SUFFIX="${osuf}" compadd -Q -S '' "$group[@]" "$expl[@]" \ diff --git a/Completion/Core/_requested b/Completion/Core/_requested index 09c57ee09..6641afdcf 100644 --- a/Completion/Core/_requested +++ b/Completion/Core/_requested @@ -1,9 +1,9 @@ #autoload -# Reset the current context. +comptags -C _cur_context -_cur_contexts="${_tag_contexts[$tname]}" - -# Test if the tag given as argument was requested. - -[[ "${_cur_tags[${funcstack[2,-1]}]}" = *:${1}:* ]] +comptags -R "$1" && + if [[ $# -gt 1 ]]; then + _description "${(@)argv[2,-1]}" + return 0 + fi diff --git a/Completion/Core/_set_options b/Completion/Core/_set_options index 55388d0c8..ae4d3784e 100644 --- a/Completion/Core/_set_options +++ b/Completion/Core/_set_options @@ -6,7 +6,6 @@ local expl -_tags any zsh-options || return 1 - -_description expl 'set zsh option' -compadd "$expl[@]" "$@" -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' - $=_set_options +_wanted zsh-options expl 'set zsh option' && + compadd "$expl[@]" "$@" -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' - \ + $=_set_options diff --git a/Completion/Core/_sort_tags b/Completion/Core/_sort_tags index f1740511d..f44479d56 100644 --- a/Completion/Core/_sort_tags +++ b/Completion/Core/_sort_tags @@ -3,18 +3,18 @@ comptry arguments values comptry options -case "$contexts" in +case "$curcontext" in # Some silly examples commented out: # # *p[bgpn]m*) # change the order for file-completion # comptry globbed-files directories # comptry all-files # ;; -# *:dvips,-o*) # automatic context set by _arguments +# *:dvips:-o*) # automatic context set by _arguments # comptry all-files # return # ;; -# *:kill,*) +# *:kill:*) # comptry processes # return # this return ensures that we use only processes # ;; diff --git a/Completion/Core/_style b/Completion/Core/_style index a3b54686f..6e2de23df 100644 --- a/Completion/Core/_style +++ b/Completion/Core/_style @@ -1,50 +1,44 @@ #autoload -local all get val i +local val ret # Should we return the value? -if [[ "$1" = -g ]]; then - get=yes - shift -fi - -# Get all styles defined for this context. - -all=() -for i in "${(s.:.)_cur_contexts}"; do - all=("$all[@]" "${(@)_compstyles[(K)${i},${1}]}" ) -done -all=":${(j.:.)${(@o)all:#}##??}:" +case "$1" in +-b) + compstyles -S "$context" "$2" val + ret="$?" -if [[ "$all" = *:${2}[:\=]* ]]; then - - # We have a definition for the style. + if [[ "$val" = (#I)(yes|true|1|on) ]]; then + eval "${3}=yes" + else + eval "${3}=no" + fi + return ret; + ;; +-s) + compstyles -S "${curcontext}${2:+:${2}}" "$3" "$4" + return + ;; +-a) + compstyles -A "${curcontext}${2:+:${2}}" "$3" "$4" + return + ;; +-h) + compstyles -H "${curcontext}${2:+:${2}}" "$3" "$4" + return + ;; +esac + +[[ "$1" = -(|-) ]] && shift + +if compstyles -S "${curcontext}${1:+:${1}}" "$2" val; then if [[ $# -eq 3 ]]; then - if [[ -n "$get" ]]; then - - # We have to return the value. - - if [[ "$all" = *,${2}\=* ]]; then - eval "${3}=\"${${all#*:${2}\=}%%:*}\"" - else - eval "${3}=''" - fi - else - - # We have to test the value. - - if [[ "$all" = *:${2}\=* ]]; then - [[ "${${all#*:${2}\=}%%:*}" = ${~3} ]] - else - [[ '' -eq ${~3} ]] - fi - - return - fi + [[ "$val" = ${~3} ]] + else + [[ "$val" = (#I)(yes|true|1|on) ]] fi - return 0 +else + return 1 fi - -return 1 diff --git a/Completion/Core/_tags b/Completion/Core/_tags index 5ed56df6e..5294ab3c7 100644 --- a/Completion/Core/_tags +++ b/Completion/Core/_tags @@ -1,40 +1,26 @@ #autoload -# We use the funcstack names to communicate to neighboring functions. - -local tname="$funcstack[2,-1]" - if (( $# )); then # We have arguments: the tags supported in this context. - local command="${_tag_context:-${words[1]}}" _tags contexts name + local curcontext="$curcontext" - # We are given the `-c command-name' option. - - if [[ "$1" = -c?* ]]; then - command="${1[3,-1]}" + if [[ "$1" = -C?* ]]; then + curcontext="${curcontext}:${1[3,-1]}" shift - elif [[ "$1" = -c ]]; then - command="$2" + elif [[ "$1" = -C ]]; then + curcontext="${curcontext}:${2}" shift 2 + else + targs=() fi [[ "$1" = -(|-) ]] && shift - # Get the context names. - - if [[ -n "$_sub_context" ]]; then - contexts="${1}:${_sub_context}" - else - contexts="${1}" - fi - contexts=":${command},${${contexts//::/:}//:/:${command},}:" - shift + # Set and remember offered tags. - _tags=() - - # Remember offered tags. + comptags -i "$curcontext" "$@" _offered_tags=( "$_offered_tags[@]" "$@" ) _last_tags=() @@ -43,46 +29,35 @@ if (( $# )); then "${_sort_tags:-_sort_tags}" "$@" - # The sets are reported in $_tags, one element per set. Remove - # tags that weren't requested. - - _tags=( "${(M@)_tags:#*:(${(j:|:)~argv}):*}" ) - - # Store the sets in a `hidden' array. - - name="_prio_arr$(( _prio_num++ ))" - _prio_names[$tname]="$name" - eval "${name}=( \"\$_tags[@]\" )" - # Also store the context (used below and in _requested). - _cur_contexts="$contexts[2,-2]" - _tag_contexts[$tname]="$_cur_contexts" + _cur_context="$curcontext" # Return non-zero if at least one set of tags should be used. - return \!$#_tags + comptags -T + + return fi # The other mode: switch to the next set of tags. -local prios="$_prio_names[$tname]" +local tags # Reset the current context. -_cur_contexts="${_tag_contexts[$tname]}" +comptags -C _cur_context -_failed_tags=( "$_failed_tags[@]" "$_last_tags" ) +_failed_tags=( "$_failed_tags[@]" "$_last_tags[@]" ) # Return failure if no sets remaining. -(( ${(P)#prios} )) || return 1 +comptags -N || return 1 # Otherwise get the next tags. -_cur_tags[$tname]="${(@)${(@P)prios}[1]}:" +comptags -S _last_tags -_last_tags=( "${(@)${(@s.:.)${(@P)prios}[1]}:#}" ) _tried_tags=( "$_tried_tags[@]" "$_last_tags[@]" ) shift 1 "$prios" diff --git a/Completion/Core/_unset_options b/Completion/Core/_unset_options index 0c7b91b7a..8c8ed780d 100644 --- a/Completion/Core/_unset_options +++ b/Completion/Core/_unset_options @@ -6,7 +6,6 @@ local expl -_tags any zsh-options || return 1 - -_description expl 'unset zsh option' -compadd "$expl[@]" "$@" -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' - $=_unset_options +_wanted zsh-options expl 'unset zsh option' && + compadd "$expl[@]" "$@" -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' - \ + $=_unset_options diff --git a/Completion/Core/_wanted b/Completion/Core/_wanted new file mode 100644 index 000000000..7baa3e724 --- /dev/null +++ b/Completion/Core/_wanted @@ -0,0 +1,21 @@ +#autoload + +local targs + +if [[ "$1" = -C?* ]]; then + targs=( -C "${1[3,-1]}" ) + shift +elif [[ "$1" = -C ]]; then + targs=( -C "$2" ) + shift 2 +else + targs=() +fi + +[[ "$1" = -(|-) ]] && shift + +if [[ $# -gt 1 ]]; then + _tags "$targs[@]" "$1" && _description "${(@)argv[2,-1]}" +else + _tags "$targs[@]" "$1" +fi diff --git a/Completion/Core/compdump b/Completion/Core/compdump index b4530ea8e..67b6e0865 100644 --- a/Completion/Core/compdump +++ b/Completion/Core/compdump @@ -17,7 +17,7 @@ emulate -L zsh typeset _d_file _d_f _d_bks _d_line _d_als -_d_file=${compconfig[dumpfile]-${0:h}/compinit.dump}.$HOST.$$ +_d_file=${_comp_dumpfile-${0:h}/compinit.dump}.$HOST.$$ typeset -U _d_files _d_files=( ${^~fpath:/.}/_(|*[^~])(N:t) ) diff --git a/Completion/Core/compinit b/Completion/Core/compinit index 0f614f322..6f2f39fcb 100644 --- a/Completion/Core/compinit +++ b/Completion/Core/compinit @@ -91,27 +91,14 @@ _postpatcomps=() typeset -gA _lastcomp -# This is the associative array used for configuration. - -typeset -gA compconfig - -# Standard initialisation for `compconfig'. +# Remember dumpfile. if [[ -n $_i_dumpfile ]]; then # Explicitly supplied dumpfile. - compconfig[dumpfile]="$_i_dumpfile" + _comp_dumpfile="$_i_dumpfile" else - compconfig[dumpfile]="${ZDOTDIR:-$HOME}/.zcompdump" + _comp_dumpfile="${ZDOTDIR:-$HOME}/.zcompdump" fi -(( ${+compconfig[correct_accept]} )) || compconfig[correct_accept]=2n -(( ${+compconfig[correct_prompt]} )) || - compconfig[correct_prompt]='correct to:' -(( ${+compconfig[completer]} )) || compconfig[completer]=_complete - -# This holds the style definitions. - -typeset -gA _compstyles - # This can hold names of functions that are to be called after all # matches have been generated. @@ -321,119 +308,181 @@ compdef() { fi } -# Functional interface to configuration. This takes its arguments -# and sets the according values in `compconfig'. -# Arguments may be `foo=bar' to set key `foo' to `bar' or `baz' to -# set key `baz' to the empty string. -# If no arguments are given, all configurations keys set are displayed. -# With the option `-l' as the first argument, the other arguments are -# taken to be key names and the values for theses keys are printed, one -# per line. -# When listing is done and the `-L' option is given, the keys and -# values are printed as invocations for this function, usable to be put -# inte a setup script. +# Do *not* use this... compconf() { - local i opt list - while getopts "lL" opt; do - if [[ "$opt" = l ]]; then - [[ -z "$list" ]] && list=yes - else - list=long - fi - done - shift OPTIND-1 + local style name val i tmp cmt - if (( $# )); then - if [[ -n $list ]]; then - for i; do - if [[ $list = long ]]; then - (( ${+compconfig[$i]} )) && print "compconf $i='$compconfig[$i]'" - else - print $compconfig[$i] - fi - done - else - for i; do - if [[ "$i" = *\=* ]]; then - compconfig[${i%%\=*}]="${i#*\=}" - else - compconfig[$i]='' - fi - done - fi - else - for i in ${(ok)compconfig}; do - if [[ $list = long ]]; then - print "compconf $i='$compconfig[$i]'" - else - print ${(r:25:)i} "$compconfig[$i]" - fi - done + if [[ -z "$_compconf_warn" ]]; then + _compconf_warn=yep + + print " + +Hello + +\`compconf' will be removed in the near future. The \`styles' form of +your setup should be available in the file: + + \`${HOME}/.zsh-styles' + + +Have fun + + Sven +" 1>&2 + command rm -f ${HOME}/.zsh-styles fi + + for i; do + name="${i%%\=*}" + val="${i#*\=}" + + tmp='' + cmt='' + + case "$name" in + urls_path) + tmp="'*:urls' path '$val'" + ;; + urls_localhttp) + tmp="'*:urls' local '${val//:/ }'" + ;; + describe_options) + tmp="'*:options' description '$val'" + ;; + describe_values) + tmp="'*:values' description '$val'" + ;; + autodescribe_options) + tmp="'*:options' auto-description '$val'" + ;; + description_format) + tmp="'*:descriptions' format '$val'" + ;; + message_format) + tmp="'*:messages' format '$val'" + ;; + warning_format) + tmp="'*:warnings' format '$val'" + ;; + option_prefix) + tmp="'*:options' prefix-needed yes" + [[ "$val" = hide* ]] && + tmp="$tmp +compstyle '*:options' prefix-hidden yes" + ;; + group_matches) + tmp="'*:matches' group 'yes'" + ;; + colors_path) + tmp="'*:colors' path '$val'" + ;; + path_expand) + tmp="'*:paths' expand '$val'" + ;; + path_cursor) + tmp="'*:paths' cursor '$val'" + ;; + (approximate|incremental|predict|list|oldlist|match)_*) + tmp="':${name%%_*}' ${${name#*_}//_/-} '$val'" + ;; + correct_*) + cmt="# This one is a bit ugly. You may want to use only \`*:correct' +# if you also have the \`correctword_*' or \`approximate_*' keys. +" + tmp="':(correct(|-word)|approximate)' ${name#*_} '$val'" + ;; + correctword_*) + tmp="':correct-word' ${name#correctword_} '$val'" + ;; + expand_*) + cmt="# This one is a bit ugly. You may want to use only \`*:expand' +# if you also have the \`expandword_*' keys. +" + tmp="':expand(|expand-word)' ${name#*_} '$val'" + ;; + expandword_*) + tmp="':expand-word' ${name#expandword_} '$val'" + ;; + history_*) + tmp="'*:history-entries' ${name#history_} '$val'" + ;; + completer) + tmp="'*' completer ${val//:/ }" + ;; + last_prompt) + tmp="'*' last-prompt '$val'" + ;; + esac + [[ -n "$tmp" ]] && style="${style}${cmt}compstyle ${tmp} +" + done + + eval "${style}" + + print "$style" >> ${HOME}/.zsh-styles } # Very simple interface for setting styles: # # compstyle context -styles... context -styles ... # -# Where context is of the form cmd-pat:ctxt-pat:tag-pat. +# Where context is of the form :ctxt-pats:...:tag-pat. # # This will be improved if needed. Promised. compstyle() { if (( ! $# )); then - local pat + local pats styles vals pat style + + compstyles -G pats - for pat in "${(@k)_compstyles}"; do - print -- "${(r:20:: :)pat} -- ${_compstyles[$pat]#??}" + for pat in "$pats[@]"; do + print "$pat" + compstyles -G styles "$pat" + for style in "$styles[@]"; do + compstyles -G vals "$pat" "$style" + print " $style = $vals" + done done return 0 fi - local sep pat test - typeset -Z 2 num - - while (( $# )); do - num=0 - for pat in "${(s:,:)1}"; do - if [[ "$pat" = \* ]]; then - (( num += 3 )) - elif [[ "$pat" = any ]]; then - (( num += 2 )) - elif [[ "$pat" != "$pat:q" ]]; then - (( num++ )) - fi - done + if [[ "$1" = -d ]]; then + case "$#" in + 1) compstyles -d ;; + 2) compstyles -d "$2" ;; + *) + local pat="$2" style - pat="$1" - shift + shift + + for style; do + compstyles -d "$pat" "$style" + done + ;; + esac - sep=$argv[(I)[^-]*] + return 0 + fi - if (( sep )); then - _compstyles[$pat]="${num}${(j.:.)${(@)argv[1,sep-1]#-}}" - shift sep-1 - else - _compstyles[$pat]="${num}${(j.:.)${(@)argv#-}}" - break - fi - done + [[ "$1" = -(|-) ]] && shift + + compstyles -a "$@" return 0 } -# Default styles. - -compstyle '*,*,*' -description=yes -prefix-needed=yes -prefix-hidden=no +# Default styles. This should be executed conditionally somehow. -# Helper function for `_tags'. Will be moved into C-code. - -comptry() { - _tags=( "$_tags[@]" ":${(j.:.)argv}:" ) -} +compstyle '*' description 'yes' +compstyle '*' prefix-needed 'yes' +compstyle '*' prefix-hidden 'no' +compstyle ':correct' accept '2n' +compstyle ':correct' prompt 'correct to:' +compstyle '*' completer '_complete' # Utility function to call a function if it exists. # @@ -506,10 +555,10 @@ autoload -U compdump compinstall # If we have a dump file, load it. -if [[ -f "$compconfig[dumpfile]" ]]; then - read -rA _i_line < "$compconfig[dumpfile]" +if [[ -f "$_comp_dumpfile" ]]; then + read -rA _i_line < "$_comp_dumpfile" if [[ _i_autodump -eq 1 && $_i_line[2] -eq $#_i_files ]]; then - builtin . "$compconfig[dumpfile]" + builtin . "$_comp_dumpfile" _i_done=yes fi fi diff --git a/Completion/Core/compinstall b/Completion/Core/compinstall index bd58d643b..f7cf94209 100644 --- a/Completion/Core/compinstall +++ b/Completion/Core/compinstall @@ -29,7 +29,7 @@ emulate -L zsh typeset _ci_options _ci_f _ci_fdir _ci_files _ci_dumpfile _ci_lines typeset _ci_type _ci_completer _ci_accept _ci_cprompt _ci_startline -typeset _ci_endline _ci_ifile _ci_tmpf _ci_compconf _ci_warn +typeset _ci_endline _ci_ifile _ci_tmpf _ci_compstyle _ci_warn typeset _ci_dtype _ci_existing _ci_line _ci_end # Look for the defaults. @@ -45,14 +45,14 @@ typeset -A _ci_defaults if [[ -f $_ci_ifile ]]; then # This assumes the lines haven't been altered by the user too much # after they were added. - _ci_compconf=0 + _ci_compstyle=0 sed -n "/^$_ci_startline/,/^$_ci_endline/p" $_ci_ifile | while read -rA _ci_line; do - if (( $_ci_compconf )); then - # parse a compconf component as first argument + if (( $_ci_compstyle )); then + # parse a compstyle component as first argument if [[ $_ci_line[-1] != \\ ]]; then _ci_end=-1 - _ci_compconf=0 + _ci_compstyle=0 else _ci_end=-2 fi @@ -72,11 +72,11 @@ if [[ -f $_ci_ifile ]]; then [[ $_ci_line[-2] = -d ]] && _ci_dumpfile=$_ci_line[-1] elif [[ $_ci_line[1] = _compdir=* ]]; then _ci_fdir=${_ci_line[1]##_compdir=} - elif [[ $_ci_line[1] = compconf ]]; then - # parse a compconf component as second argument (should be completer) - [[ $_ci_line[2] = completer=* ]] && - _ci_completer=${_ci_line[2]#completer=} - [[ $_ci_line[-1] == \\ ]] && _ci_compconf=1 + elif [[ $_ci_line[1] = compstyle ]]; then + # parse a compstyle component as second argument (should be completer) + [[ $_ci_line[3] = completer ]] && + _ci_completer=${_ci_line[3,-1]} + [[ $_ci_line[-1] == \\ ]] && _ci_compstyle=1 _ci_existing="${_ci_existing}$_ci_line " elif [[ $_ci_line[1] != \#* && $_ci_line[1] != (autoload|\[\[) ]]; then @@ -208,7 +208,7 @@ approximate completion if that fails. Would you like: A: Approximate completion B: Both" if [[ -n $_ci_completer ]]; then - print " Default: use the current completer:\n$_ci_completer" + print " Default: use the current completers:\n$_ci_completer" else print "Please type one of the keys above." fi @@ -218,13 +218,13 @@ approximate completion if that fails. Would you like: 0*) _ci_completer=_complete break ;; - [cC]*) _ci_completer=_complete:_correct + [cC]*) _ci_completer='_complete _correct' break ;; - [aA]*) _ci_completer=_complete:_approximate + [aA]*) _ci_completer='_complete _approximate' break; ;; - [bB]*) _ci_completer=_complete:_correct:_approximate + [bB]*) _ci_completer='_complete _correct _approximate' break ;; *) [[ -n $_ci_completer ]] && break @@ -233,7 +233,7 @@ approximate completion if that fails. Would you like: esac done - _ci_lines="${_ci_lines}compconf completer=$_ci_completer" + _ci_lines="${_ci_lines}compstyle '*' completer $_ci_completer" if [[ $_ci_completer = *(correct|approx)* ]]; then |