From 188e6569dbb250b25bf3fe74b9d13007d5207b51 Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Fri, 10 Dec 1999 14:47:55 +0000 Subject: manual/8992 --- Completion/Base/_arguments | 4 +- Completion/Base/_combination | 2 +- Completion/Base/_describe | 5 +- Completion/Base/_first | 2 +- Completion/Base/_jobs | 9 +- Completion/Base/_regex_arguments | 2 +- Completion/Base/_subscript | 4 +- Completion/Base/_tilde | 4 +- Completion/Builtins/_pids | 6 +- Completion/Builtins/_popd | 5 +- Completion/Builtins/_sched | 2 +- Completion/Builtins/_signals | 5 +- Completion/Builtins/_stat | 3 +- Completion/Commands/_history_complete_word | 12 +- Completion/Core/_approximate | 7 +- Completion/Core/_description | 10 +- Completion/Core/_expand | 11 +- Completion/Core/_list | 4 +- Completion/Core/_main_complete | 9 +- Completion/Core/_match | 4 +- Completion/Core/_message | 5 +- Completion/Core/_oldlist | 5 +- Completion/Core/_path_files | 10 +- Completion/Core/_requested | 2 - Completion/Core/_setup | 12 +- Completion/Core/_tags | 10 +- Completion/Core/compinit | 32 +- Completion/Debian/_apt | 2 +- Completion/User/_cvs | 3 +- Completion/User/_groups | 2 +- Completion/User/_hosts | 2 +- Completion/User/_ports | 2 +- Completion/User/_socket | 3 +- Completion/User/_urls | 5 +- Completion/User/_users | 2 +- Completion/X/_x_color | 2 +- Doc/Zsh/compsys.yo | 157 ++---- Doc/Zsh/mod_clone.yo | 2 +- Doc/Zsh/mod_complete.yo | 2 +- Doc/Zsh/mod_computil.yo | 22 +- Doc/Zsh/mod_zutil.yo | 109 +++++ Doc/Zsh/modules.yo | 6 + Etc/completion-style-guide | 51 +- Functions/Zle/incremental-complete-word | 8 +- Src/Modules/zutil.c | 761 +++++++++++++++++++++++++++++ Src/Modules/zutil.mdd | 3 + Src/Zle/computil.c | 429 ---------------- Src/Zle/computil.mdd | 2 +- Src/xmods.conf | 1 + 49 files changed, 1062 insertions(+), 700 deletions(-) create mode 100644 Doc/Zsh/mod_zutil.yo create mode 100644 Src/Modules/zutil.c create mode 100644 Src/Modules/zutil.mdd diff --git a/Completion/Base/_arguments b/Completion/Base/_arguments index 591cb6ac7..16293a098 100644 --- a/Completion/Base/_arguments +++ b/Completion/Base/_arguments @@ -162,7 +162,7 @@ while [[ "$1" = -(O*|C) ]]; do esac done -_style -s options auto-description autod +zstyle -s ":completion${curcontext}:options" auto-description autod if (( $# )) && comparguments -i "$autod" "$@"; then local nm="$compstate[nmatches]" action noargs aret expl local @@ -258,7 +258,7 @@ if (( $# )) && comparguments -i "$autod" "$@"; then fi if [[ -z "$matched" ]] && _requested options && - { ! _style options prefix-needed || + { ! zstyle -t ":completion${curcontext}:options" prefix-needed || [[ "$origpre" = [-+]* ]] } ; then local prevpre="$PREFIX" previpre="$IPREFIX" diff --git a/Completion/Base/_combination b/Completion/Base/_combination index 97da22a5f..ffda5cae9 100644 --- a/Completion/Base/_combination +++ b/Completion/Base/_combination @@ -78,7 +78,7 @@ key="${1%:*}" num="${${1##*:}:-1}" shift -if _style -a "$tag" "$style" tmp; then +if zstyle -a ":completion${curcontext}:$tag" "$style" tmp; then eval "tmp=( \"\${(@M)tmp:#\${(j($sep))~pats}}\" )" if (( keys[(in:num:)$key] != 1 )); then eval "tmp=( \${tmp#\${(j(${sep}))~\${(@)\${(@)keys[2,(rn:num:)\$key]}/*/*}}$sep} )" diff --git a/Completion/Base/_describe b/Completion/Base/_describe index 7be7ea29f..1db7e6fb6 100644 --- a/Completion/Base/_describe +++ b/Completion/Base/_describe @@ -16,7 +16,7 @@ fi _tags "$_type" || return 1 -_style "$_type" verbose && _showd=yes +zstyle -t ":completion${curcontext}:$_type" verbose && _showd=yes _description "$_type" _expl "$1" shift @@ -27,7 +27,8 @@ else compdescribe -i "$@" fi -[[ "$_type" = options ]] && _style options prefix-hidden && _hide=yes +[[ "$_type" = options ]] && + zstyle -t ":completion${curcontext}:options" prefix-hidden && _hide=yes while compdescribe -g _args _tmpd _tmpmd _tmps _tmpms; do diff --git a/Completion/Base/_first b/Completion/Base/_first index 6740c00c5..f81ab465e 100644 --- a/Completion/Base/_first +++ b/Completion/Base/_first @@ -50,7 +50,7 @@ # # We first search in the last ten words, then in the last # # twenty words, and so on... # while [[ i -le max ]]; do -# if _style history-words sort; then +# if zstyle -t ":completion${curcontext}:history-words" sort; then # _description history-words expl "history ($n)" # else # _description -V history-words expl "history ($n)" diff --git a/Completion/Base/_jobs b/Completion/Base/_jobs index addc88607..ff9fa5a62 100644 --- a/Completion/Base/_jobs +++ b/Completion/Base/_jobs @@ -4,9 +4,10 @@ local expl disp jobs job jids pfx='%' desc _tags jobs || return 1 -_style jobs prefix-needed && [[ "$PREFIX" != %* ]] && return 1 -_style jobs prefix-hidden && pfx='' -_style jobs verbose && desc=yes +zstyle -t ":completion${curcontext}:jobs" prefix-needed && + [[ "$PREFIX" != %* ]] && return 1 +zstyle -t ":completion${curcontext}:jobs" prefix-hidden && pfx='' +zstyle -t ":completion${curcontext}:jobs" verbose && desc=yes if [[ "$1" = -r ]]; then jids=( "${(@k)jobstates[(R)running*]}" ) @@ -30,7 +31,7 @@ if [[ -n "$desc" ]]; then done fi -if _style jobs strings; then +if zstyle -t ":completion${curcontext}:jobs" strings; then local texts i text str tmp # Find shortest unambiguous strings. diff --git a/Completion/Base/_regex_arguments b/Completion/Base/_regex_arguments index 918eafc5c..653aeedbe 100644 --- a/Completion/Base/_regex_arguments +++ b/Completion/Base/_regex_arguments @@ -330,7 +330,7 @@ _regex_arguments () { local i state next local cache_dir - _style -s regex cache-path cache_dir + zstyle -s ":completion${curcontext}:regex" cache-path cache_dir [[ -z "$cache_dir" ]] && cache_dir="$HOME/.zsh/regex_arguments" local cache_file="$cache_dir/$1" local cache_test diff --git a/Completion/Base/_subscript b/Completion/Base/_subscript index 21e62e8aa..fdda19301 100644 --- a/Completion/Base/_subscript +++ b/Completion/Base/_subscript @@ -21,14 +21,14 @@ elif [[ ${(Pt)${compstate[parameter]}} = array* ]]; then while _tags; do if _requested -V indexes expl 'array index'; then ind=( {1..${#${(P)${compstate[parameter]}}}} ) - if _style indexes verbose; then + if zstyle -t ":completion${curcontext}:indexes" verbose; then list=() for i in "$ind[@]"; do [[ "$i" = ${PREFIX}*${SUFFIX} ]] && list=( "$list[@]" "${i}:$(print -D ${(P)${compstate[parameter]}[$i]})" ) done - compdisplay list ' -- ' "$list[@]" + zformat -a list ' -- ' "$list[@]" disp=( -d list) else disp=() diff --git a/Completion/Base/_tilde b/Completion/Base/_tilde index 4aceca6ce..bba928f50 100644 --- a/Completion/Base/_tilde +++ b/Completion/Base/_tilde @@ -22,9 +22,9 @@ while _tags; do compadd "$suf[@]" "$expl[@]" "$@" - "${(@k)nameddirs}" if _requested -V directory-stack expl 'directory stack' && - { ! _style directory-stack prefix-needed || + { ! zstyle -t ":completion${curcontext}:directory-stack" prefix-needed || [[ "$PREFIX" = [-+]* ]] }; then - if _style directory-stack verbose; then + if zstyle -t ":completion${curcontext}:directory-stack" verbose; then integer i lines=("${PWD}" "${dirstack[@]}") diff --git a/Completion/Builtins/_pids b/Completion/Builtins/_pids index d383d6b99..af88a5920 100644 --- a/Completion/Builtins/_pids +++ b/Completion/Builtins/_pids @@ -12,11 +12,11 @@ if [[ "$1" = -m ]]; then shift 2 fi -_style -a ps list-arguments listargs -_style -a ps arguments args +zstyle -a ":completion${curcontext}:ps" list-arguments listargs +zstyle -a ":completion${curcontext}:ps" arguments args (( $#listargs )) || listargs=( "$args[@]" ) -if _style processes verbose; then +if zstyle -t ":completion${curcontext}:processes" verbose; then list=("${(@Mr:COLUMNS-1:)${(f@)$(command ps $listargs 2>/dev/null)}[2,-1]:#[ ]#${PREFIX}[0-9]#${SUFFIX}[ ]*${~match}}") desc=(-ld list) else diff --git a/Completion/Builtins/_popd b/Completion/Builtins/_popd index 604bcecd5..9c5981d17 100644 --- a/Completion/Builtins/_popd +++ b/Completion/Builtins/_popd @@ -11,9 +11,10 @@ local expl list lines revlines disp _wanted -V directory-stack expl 'directory stack' || return 1 -! _style directory-stack prefix-needed || [[ $PREFIX = [-+]* ]] || return 1 +! zstyle -t ":completion${curcontext}:directory-stack" prefix-needed || + [[ $PREFIX = [-+]* ]] || return 1 -if _style directory-stack verbose; then +if zstyle -t ":completion${curcontext}:directory-stack" verbose; then # get the list of directories with their canonical number # and turn the lines into an array, removing the current directory lines=("${PWD}" "${dirstack[@]}") diff --git a/Completion/Builtins/_sched b/Completion/Builtins/_sched index 5e1086518..ea11eeb65 100644 --- a/Completion/Builtins/_sched +++ b/Completion/Builtins/_sched @@ -7,7 +7,7 @@ if [[ CURRENT -eq 2 ]]; then _wanted -C - jobs expl 'scheduled jobs' || return 1 lines=(${(f)"$(sched)"}) - if _style jobs verbose; then + if zstyle -t ":completion${curcontext}:jobs" verbose; then disp=( -ld lines ) else disp=() diff --git a/Completion/Builtins/_signals b/Completion/Builtins/_signals index c79350044..545d83924 100644 --- a/Completion/Builtins/_signals +++ b/Completion/Builtins/_signals @@ -21,11 +21,12 @@ done [[ "$1" = -(|-) ]] && shift if _wanted signals expl signal && - { [[ -z "$minus" ]] || ! _style signals prefix-needed || + { [[ -z "$minus" ]] || + ! zstyle -t ":completion${curcontext}:signals" prefix-needed || [[ "$PREFIX" = -* ]] } ; then local disp tmp - if _style signals prefix-hidden; then + if zstyle -t ":completion${curcontext}:signals" prefix-hidden; then tmp=( "${(@)signals[1,last]}" ) disp=(-d tmp) else diff --git a/Completion/Builtins/_stat b/Completion/Builtins/_stat index d0ec85550..232cf672b 100644 --- a/Completion/Builtins/_stat +++ b/Completion/Builtins/_stat @@ -9,7 +9,8 @@ else while _tags; do _requested options expl 'inode element' && - { ! _style options prefix-needed || [[ "$PREFIX[1]" = + ]] } && + { ! zstyle -t ":completion${curcontext}:options" prefix-needed || + [[ "$PREFIX[1]" = + ]] } && compadd "$expl[@]" - +device +inode +mode +nlink +uid +gid +rdev \ +size +atime +mtime +ctime +blksize +block +link fi diff --git a/Completion/Commands/_history_complete_word b/Completion/Commands/_history_complete_word index 08fc1ea79..7867189e8 100644 --- a/Completion/Commands/_history_complete_word +++ b/Completion/Commands/_history_complete_word @@ -25,9 +25,9 @@ _history_complete_word () { direction=older fi - _style -s history-words stop stop + zstyle -s ":completion${curcontext}:history-words" stop stop - _style history-words list || compstate[list]='' + zstyle -t ":completion${curcontext}:history-words" list || compstate[list]='' if [[ -n "$compstate[old_list]" && ( -n "$stop" || "$compstate[insert]" = menu ) ]] ; then @@ -67,14 +67,14 @@ _history_complete_word () { } _history_complete_word_gen_matches () { - if _style history-words list; then - if _style history-words sort; then + if zstyle -t ":completion${curcontext}:history-words" list; then + if zstyle -t ":completion${curcontext}:history-words" sort; then _description history-words expl 'history word' else _description -V history-words expl 'history word' fi else - if _style history-words sort; then + if zstyle -t ":completion${curcontext}:history-words" sort; then expl=() else expl=('-V' '') @@ -84,7 +84,7 @@ _history_complete_word_gen_matches () { [[ -n "$_hist_stop" ]] && PREFIX="$_hist_old_prefix" local rem_dups - if _style history-words remove-all-dups; then + if zstyle -t ":completion${curcontext}:history-words" remove-all-dups; then rem_dups='' else rem_dups='-1' diff --git a/Completion/Core/_approximate b/Completion/Core/_approximate index fc2d6afa0..bb1faa7b3 100644 --- a/Completion/Core/_approximate +++ b/Completion/Core/_approximate @@ -20,7 +20,7 @@ local curcontext="${curcontext}" oldcontext oldcontext="$curcontext" -_style -s '' max-errors cfgacc +zstyle -s ":completion${curcontext}:" max-errors cfgacc # Get the number of errors to accept. @@ -79,11 +79,12 @@ while [[ _comp_correct -le comax ]]; do "e:$_comp_correct" "o:$PREFIX$SUFFIX" if _complete; then - if _style '' insert-unambiguous && + if zstyle -t ":completion${curcontext}:" insert-unambiguous && [[ "${#compstate[unambiguous]}" -ge "${#:-$PREFIX$SUFFIX}" ]]; then compstate[pattern_insert]=unambiguous elif _requested original && - ( [[ compstate[nmatches] -gt 1 ]] || _style '' original ); then + ( [[ compstate[nmatches] -gt 1 ]] || + zstyle -t ":completion${curcontext}:" original ); then local expl _description -V original expl original diff --git a/Completion/Core/_description b/Completion/Core/_description index 3bf15d320..89a0733a8 100644 --- a/Completion/Core/_description +++ b/Completion/Core/_description @@ -16,17 +16,19 @@ _setup "$1" name="$2" -_style -s "$1" format format || _style -s descriptions format format +zstyle -s ":completion${curcontext}:$1" format format || + zstyle -s ":completion${curcontext}:descriptions" format format -_style -s "$1" hidden hidden +zstyle -s ":completion${curcontext}:$1" hidden hidden if [[ "$hidden" = (all|yes|true|1|on) ]]; then [[ "$hidden" = all ]] && format='' hide=(-n) fi -_style -s "$1" group-name gname && [[ -z "$gname" ]] && gname="$1" +zstyle -s ":completion${curcontext}:$1" group-name gname && + [[ -z "$gname" ]] && gname="$1" shift 2 -[[ -n "$format" ]] && compfmt format "$format" "d:$1" "${(@)argv[2,-1]}" +[[ -n "$format" ]] && zformat -f format "$format" "d:$1" "${(@)argv[2,-1]}" if [[ -n "$gname" ]]; then if [[ -n "$format" ]]; then diff --git a/Completion/Core/_expand b/Completion/Core/_expand index bde5ee2f8..cdfc2a8d1 100644 --- a/Completion/Core/_expand +++ b/Completion/Core/_expand @@ -13,7 +13,8 @@ local exp word="$PREFIX$SUFFIX" sort expr expl curcontext="${curcontext}" # First, see if we should insert all *completions*. -if _style -s '' completions expr && [[ "${(e):-\$[$expr]}" -eq 1 ]]; then +if zstyle -s ":completion${curcontext}:" completions expr && + [[ "${(e):-\$[$expr]}" -eq 1 ]]; then compstate[insert]=all return 1 fi @@ -29,7 +30,8 @@ exp=("$word") # First try substitution. That weird thing spanning multiple lines # changes quoted spaces, tabs, and newlines into spaces. -_style -s '' substitute expr && [[ "${(e):-\$[$expr]}" -eq 1 ]] && +zstyle -s ":completion${curcontext}:" substitute expr && + [[ "${(e):-\$[$expr]}" -eq 1 ]] && exp=( "${(e)exp//\\[ ]/ }" ) @@ -39,7 +41,8 @@ _style -s '' substitute expr && [[ "${(e):-\$[$expr]}" -eq 1 ]] && # Now try globbing. -_style -s '' glob expr && [[ "${(e):-\$[$expr]}" -eq 1 ]] && +zstyle -s ":completion${curcontext}:" glob expr && + [[ "${(e):-\$[$expr]}" -eq 1 ]] && exp=( ${~exp}(N) ) # If we don't have any expansions or only one and that is the same @@ -50,7 +53,7 @@ _style -s '' glob expr && [[ "${(e):-\$[$expr]}" -eq 1 ]] && # Now add as matches whatever the user requested. -_style -s '' sort sort +zstyle -s ":completion${curcontext}:" sort sort [[ "$sort" = (yes|true|1|on) ]] && exp=( "${(@o)exp}" ) diff --git a/Completion/Core/_list b/Completion/Core/_list index 6c72bc9e9..294467eca 100644 --- a/Completion/Core/_list +++ b/Completion/Core/_list @@ -8,7 +8,7 @@ local pre suf curcontext="${curcontext}:list" expr # Get the strings to compare. -if _style '' word; then +if zstyle -t ":completion${curcontext}:" word; then pre="$HISTNO$LBUFFER" suf="$RBUFFER" else @@ -18,7 +18,7 @@ fi # Should we only show a list now? -_style -s '' condition expr +zstyle -s ":completion${curcontext}:" condition expr if [[ ( -z "$expr" || "${(e):-\$[$expr]}" -eq 1 ) && ( "$pre" != "$_list_prefix" || "$suf" != "$_list_suffix" ) ]]; then diff --git a/Completion/Core/_main_complete b/Completion/Core/_main_complete index 2bacad88b..285413726 100644 --- a/Completion/Core/_main_complete +++ b/Completion/Core/_main_complete @@ -17,7 +17,7 @@ # state than the global one for which you are completing. -local comp post ret=1 _compskip _prio_num=1 _cur_context format \ +local comp post ret=1 _compskip _prio_num=1 format \ context state line opt_args val_args curcontext="$curcontext" \ _last_nmatches=-1 _last_menu_style _def_menu_style _menu_style sel \ _saved_exact="$compstate[exact]" \ @@ -56,7 +56,7 @@ _last_menu_style=() if (( ! $# )); then local tmp - _style -a '' completer tmp + zstyle -a ":completion${curcontext}:" completer tmp set -- "$tmp[@]" fi @@ -139,7 +139,7 @@ fi if [[ compstate[nmatches] -eq 0 && compstate[matcher] -eq compstate[total_matchers] && $#_lastdescr -ne 0 ]] && - _style -s warnings format format; then + zstyle -s ":completion${curcontext}:warnings" format format; then local str compstate[list]='list force' @@ -151,7 +151,8 @@ if [[ compstate[nmatches] -eq 0 && *) str="${(j:, :)_lastdescr[1,-2]}, or $_lastdescr[-1]";; esac - compadd -UX "${format//\\%d/$str}" -n '' + zformat -f format "$format" "d:$str" + compadd -UX "$format" -n '' fi _lastcomp=( "${(@kv)compstate}" ) diff --git a/Completion/Core/_match b/Completion/Core/_match index d5556dfcd..0a9d755c4 100644 --- a/Completion/Core/_match +++ b/Completion/Core/_match @@ -19,8 +19,8 @@ tmp="${${:-$PREFIX$SUFFIX}#[~=]}" [[ "$tmp:q" = "$tmp" || compstate[matcher] -ne compstate[total_matchers] ]] && return 1 -_style -s '' original orig -_style -b '' insert-unambiguous ins +zstyle -s ":completion${curcontext}:" original orig +zstyle -b ":completion${curcontext}:" insert-unambiguous ins # Try completion without inserting a `*'? diff --git a/Completion/Core/_message b/Completion/Core/_message index 6b2666253..8ae93f973 100644 --- a/Completion/Core/_message +++ b/Completion/Core/_message @@ -4,10 +4,11 @@ local format _tags messages || return 1 -_style -s messages format format || _style -s descriptions format format +zstyle -s ":completion${curcontext}:messages" format format || + zstyle -s ":completion${curcontext}:descriptions" format format if [[ -n "$format" ]]; then - compfmt format "$format" "d:$1" "${(@)argv[2,-1]}" + zformat -f format "$format" "d:$1" "${(@)argv[2,-1]}" if [[ $compstate[nmatches] -eq 0 ]]; then compstate[list]='list force' compstate[insert]='' diff --git a/Completion/Core/_oldlist b/Completion/Core/_oldlist index ba57ed6b4..b0092d586 100644 --- a/Completion/Core/_oldlist +++ b/Completion/Core/_oldlist @@ -2,7 +2,7 @@ local curcontext="${curcontext}:oldlist" list -_style -s '' list list +zstyle -s ":completion${curcontext}:" list list # If this is a listing widget and there is already an old list, # and either the style :oldlist:list is `always', or it is not `never' @@ -33,7 +33,8 @@ fi if [[ -z $compstate[old_insert] && -n $compstate[old_list] ]]; then compstate[old_list]=keep -elif [[ $WIDGET = *complete(|-prefix|-word) ]] && _style '' menu; then +elif [[ $WIDGET = *complete(|-prefix|-word) ]] && + zstyle -t ":completion${curcontext}:" menu; then if [[ -n $compstate[old_insert] ]]; then compstate[old_list]=keep if [[ $WIDGET = *reverse* ]]; then diff --git a/Completion/Core/_path_files b/Completion/Core/_path_files index e5135a422..2dcfa625c 100644 --- a/Completion/Core/_path_files +++ b/Completion/Core/_path_files @@ -116,7 +116,7 @@ orig="${PREFIX}${SUFFIX}" # If given no `-F' option, we want to use the `ignored-suffixes'-style. if (( ! $#ignore )); then - if _style -a files ignored-suffixes ignore; then + if zstyle -a ":completion${curcontext}:files" ignored-suffixes ignore; then ignore=(-F "( $ignore )") else @@ -347,8 +347,10 @@ for prepath in "$prepaths[@]"; do tmp4="$testpath" compquote tmp1 tmp4 - if [[ -n $menu ]] || ! _style paths expand '*suffix*'; then - _style paths cursor && compstate[to_end]='' + if [[ -n $menu ]] || + ! zstyle -t ":completion${curcontext}:paths" expand suffix; then + zstyle -t ":completion${curcontext}:paths" cursor && + compstate[to_end]='' if [[ "$tmp3" = */* ]]; then compadd -Qf "$mopts[@]" -p "$linepath$tmp4" -s "/${tmp3#*/}" \ -W "$prepath$realpath$testpath" "$ignore[@]" \ @@ -436,7 +438,7 @@ done exppaths=( "${(@)exppaths:#$orig}" ) -if _style paths expand '*prefix*' && +if zstyle -t ":completion${curcontext}:paths" expand prefix && [[ $#exppaths -gt 0 && nm -eq compstate[nmatches] ]]; then PREFIX="${opre}" SUFFIX="${osuf}" diff --git a/Completion/Core/_requested b/Completion/Core/_requested index 3bc6f3b40..a582adfb9 100644 --- a/Completion/Core/_requested +++ b/Completion/Core/_requested @@ -8,8 +8,6 @@ else tag="$1" fi -comptags -C _cur_context - comptags -R "$tag" && if [[ $# -gt 1 ]]; then _description "$@" diff --git a/Completion/Core/_setup b/Completion/Core/_setup index bdef1bf8e..fa1495ced 100644 --- a/Completion/Core/_setup +++ b/Completion/Core/_setup @@ -2,7 +2,7 @@ local val nm="$compstate[nmatches]" -if _style -a "$1" list-colors val; then +if zstyle -a ":completion${curcontext}:$1" list-colors val; then if [[ "$1" = default ]]; then ZLS_COLORS="${(j.:.)${(@)val:gs/:/\\\:}}" else @@ -10,7 +10,7 @@ if _style -a "$1" list-colors val; then fi fi -if _style -s "$1" list-packed val; then +if zstyle -s ":completion${curcontext}:$1" list-packed val; then if [[ "$val" = (yes|true|1|on) ]]; then compstate[list]="${compstate[list]} packed" else @@ -20,7 +20,7 @@ else compstate[list]="$_saved_list" fi -if _style -s "$1" list-rows-first val; then +if zstyle -s ":completion${curcontext}:$1" list-rows-first val; then if [[ "$val" = (yes|true|1|on) ]]; then compstate[list]="${compstate[list]} rows" else @@ -30,7 +30,7 @@ else compstate[list]="$_saved_list" fi -if _style -s "$1" last-prompt val; then +if zstyle -s ":completion${curcontext}:$1" last-prompt val; then if [[ "$val" = (yes|true|1|on) ]]; then compstate[last_prompt]=yes else @@ -40,7 +40,7 @@ else compstate[last_prompt]="$_saved_lastprompt" fi -if _style -s "$1" accept-exact val; then +if zstyle -s ":completion${curcontext}:$1" accept-exact val; then if [[ "$val" = (yes|true|1|on) ]]; then compstate[exact]=accept else @@ -53,7 +53,7 @@ fi [[ _last_nmatches -ge 0 && _last_nmatches -ne nm ]] && _menu_style=( "$_last_menu_style[@]" "$_menu_style[@]" ) -if _style -a "$1" menu val; then +if zstyle -a ":completion${curcontext}:$1" menu val; then _last_nmatches="$nm" _last_menu_style=( "$val[@]" ) else diff --git a/Completion/Core/_tags b/Completion/Core/_tags index b39c0fff5..fcef91061 100644 --- a/Completion/Core/_tags +++ b/Completion/Core/_tags @@ -18,7 +18,7 @@ if (( $# )); then [[ "$1" = -(|-) ]] && shift - if _style -a '' group-order order; then + if zstyle -a ":completion${curcontext}" group-order order; then local name for name in "$order[@]"; do @@ -42,10 +42,6 @@ if (( $# )); then "${_sort_tags:-_sort_tags}" "$@" - # Also store the context (used below and in _requested). - - _cur_context="$curcontext" - # Return non-zero if at least one set of tags should be used. comptags -T @@ -57,10 +53,6 @@ fi local tags -# Reset the current context. - -comptags -C _cur_context - _failed_tags=( "$_failed_tags[@]" "$_last_tags[@]" ) # Return failure if no sets remaining. diff --git a/Completion/Core/compinit b/Completion/Core/compinit index 06586cdc4..0d99aadd5 100644 --- a/Completion/Core/compinit +++ b/Completion/Core/compinit @@ -440,19 +440,19 @@ compstyle() { if (( ! $# )); then local pats styles vals pat style pre eq - compstyles -G pats + zstyle -g pats - for pat in "$pats[@]"; do + for pat in "${(@M)pats:#:completion*}"; do if [[ -n "$long" ]]; then - pre="compstyle ${(qq)pat} " + pre="compstyle ${(qq)pat#:completion} " else - print "$pat" + print "${pat#:completion}" pre=' ' eq=' =' fi - compstyles -G styles "$pat" + zstyle -g styles "$pat" for style in "$styles[@]"; do - compstyles -G vals "$pat" "$style" + zstyle -g vals "$pat" "$style" print "${pre}${style}${eq}" "${(@qq)vals}" done done @@ -461,26 +461,24 @@ compstyle() { fi if [[ "$1" = -d ]]; then - case "$#" in - 1) compstyles -d ;; - 2) compstyles -d "$2" ;; - *) - local pat="$2" style + if [[ $# -gt 1 ]]; then + zstyle -d ":completion$2" "${(@)argv[3,-1]}" + else + local pats - shift + zstyle -g pats - for style; do - compstyles -d "$pat" "$style" + for pat in "${(@M)pats:#:completion}"; do + zstyle -d "$pat" done - ;; - esac + fi return 0 fi [[ "$1" = -(|-) ]] && shift - compstyles -a "$@" + zstyle - ":completion$1" "${(@)argv[2,-1]}" return 0 } diff --git a/Completion/Debian/_apt b/Completion/Debian/_apt index 80f9d8ab6..9d51533ab 100644 --- a/Completion/Debian/_apt +++ b/Completion/Debian/_apt @@ -106,7 +106,7 @@ tmp2=("$tmp2[@]" $_ra_left${(M)^short_bool:#$~tmp1} $_ra_left${(M)^short_intleve tmp3=("$tmp3[@]" $_ra_left${(M)^short_hasarg:#$~tmp1} $_ra_left${(M)^short_configfile:#$~tmp1} $_ra_left${(M)^short_arbitem:#$~tmp1}) _describe -o option tmp2 -- tmp3 -S=' - comp_opt='{ ! _style options prefix-needed || [[ "$PREFIX" = -* ]] }'" && { $comp_short; $comp_long }" + comp_opt='{ ! zstyle -t ":completion${curcontext}:options" prefix-needed || [[ "$PREFIX" = -* ]] }'" && { $comp_short; $comp_long }" regex_short=() regex_long=() diff --git a/Completion/User/_cvs b/Completion/User/_cvs index 484d5c88c..fc0ab3116 100644 --- a/Completion/User/_cvs +++ b/Completion/User/_cvs @@ -488,7 +488,8 @@ _cvs_extract_file_entries () { (( $+functions[_cvs_extract_modifiedfile_entries] )) || _cvs_extract_modifiedfile_entries () { - if _style cvs disable-stat || ! { zmodload -e stat || zmodload stat }; then + if zstyle -t ":completion${curcontext}:cvs" disable-stat || + ! { zmodload -e stat || zmodload stat }; then _cvs_extract_file_entries return fi diff --git a/Completion/User/_groups b/Completion/User/_groups index 0007c1791..fbd884688 100644 --- a/Completion/User/_groups +++ b/Completion/User/_groups @@ -4,7 +4,7 @@ local expl groups _wanted groups expl group || return 1 -if ! _style -a groups groups groups; then +if ! zstyle -a ":completion${curcontext}:groups" groups groups; then (( $+_cache_groups )) || if (( ${+commands[ypcat]} )); then : ${(A)_cache_groups:=${${(s: :)$(ypcat group.byname)}%%:*}} # If you use YP diff --git a/Completion/User/_hosts b/Completion/User/_hosts index 196f40c83..9de9b2d96 100644 --- a/Completion/User/_hosts +++ b/Completion/User/_hosts @@ -2,7 +2,7 @@ local expl hosts -if ! _style -a hosts hosts hosts; then +if ! zstyle -a ":completion${curcontext}:hosts" hosts hosts; then (( $+_cache_hosts )) || : ${(A)_cache_hosts:=${(s: :)${(ps:\t:)${${(f)"$(next; + + zsfree(s->name); + if (s->vals) + freearray(s->vals); + zfree(s, sizeof(*s)); + + s = n; + } +} + +static void +freestypat(Stypat p) +{ + Stypat n; + + while (p) { + n = p->next; + + zsfree(p->pat); + freepatprog(p->prog); + zfree(p, sizeof(*p)); + + p = n; + } +} + +/* Get the struct for a pattern, if any. */ + +static Stypat +getstypat(char *pat) +{ + Stypat p; + + for (p = zstyles; p; p = p->next) + if (!strcmp(pat, p->pat)) + return p; + + return NULL; +} + +/* Get the style stuff for a name. */ + +static Style +getstyle(Stypat p, char *name) +{ + Style s; + + for (s = p->styles; s; s= s->next) + if (!strcmp(name, s->name)) + return s; + + return NULL; +} + +/* Store a value for a style. */ + +static void +setstyle(Stypat p, char *name, char **vals) +{ + Style s; + + for (s = p->styles; s; s = s->next) + if (!strcmp(name, s->name)) { + + /* Exists -> replace. */ + + if (s->vals) + freearray(s->vals); + PERMALLOC { + s->vals = arrdup(vals); + } LASTALLOC; + + return; + } + + /* New style. */ + + s = (Style) zalloc(sizeof(*s)); + + s->name = ztrdup(name); + PERMALLOC { + s->vals = arrdup(vals); + } LASTALLOC; + s->next = NULL; + + if (p->lstyles) + p->lstyles->next = s; + else + p->styles = s; + p->lstyles = s; +} + +/* Add a new pattern. */ + +static Stypat +addstypat(char *pat, Patprog prog) +{ + Stypat p, q, qq; + int weight, tmp, first; + char *s; + + /* Calculate the weight. */ + + for (weight = 0, tmp = 2, first = 1, s = pat; *s; s++) { + if (first && *s == '*' && (!s[1] || s[1] == ':')) { + /* Only `*' in this component. */ + tmp = 0; + continue; + } + first = 0; + + if (*s == '(' || *s == '|' || *s == '*' || *s == '[' || *s == '<' || + *s == '?' || *s == '#' || *s == '^') + /* Is pattern. */ + tmp = 1; + + if (*s == ':') { + /* Yet another component. */ + + first = 1; + weight += tmp; + tmp = 2; + } + } + weight += tmp; + + p = (Stypat) zalloc(sizeof(*p)); + + p->pat = ztrdup(pat); + p->weight = weight; + p->prog = prog; + p->styles = p->lstyles = NULL; + + for (qq = NULL, q = zstyles; q && q->weight >= weight; + qq = q, q = q->next); + + p->next = q; + if (qq) + qq->next = p; + else + zstyles = p; + if (!q) + lzstyles = p; + + return p; +} + +/* Delete a style. */ + +static void +deletestyle(Stypat p, char *name) +{ + Style ps, s; + + for (ps = NULL, s = p->styles; s; ps = s, s = s->next) + if (!strcmp(name, s->name)) { + if (ps) + ps->next = s->next; + else + p->styles = s->next; + if (s == p->lstyles) + p->lstyles = ps; + + s->next = NULL; + freestyle(s); + + return; + } +} + +/* Delete a whole pattern with all its styles. */ + +static void +deletestypat(Stypat pat) +{ + Stypat pp, p; + + for (pp = NULL, p = zstyles; p; pp = p, p = p->next) + if (p == pat) { + if (pp) + pp->next = p->next; + else + zstyles = p->next; + if (p == lzstyles) + lzstyles = pp; + + p->next = NULL; + zsfree(p->pat); + freepatprog(p->prog); + freestyle(p->styles); + zfree(p, sizeof(*p)); + + return; + } +} + +/* Look up a style for a context pattern. This does the matching. */ + +static Style +lookupstyle(char *ctxt, char *style) +{ + Stypat p; + Style s; + + for (p = zstyles; p; p = p->next) + if (pattry(p->prog, ctxt)) + for (s = p->styles; s; s = s->next) + if (!strcmp(style, s->name)) + return s; + + return NULL; +} + +static int +bin_zstyle(char *nam, char **args, char *ops, int func) +{ + int min, max, n, add = 0, list = 0; + + if (!args[0]) + list = 1; + else if (args[0][0] == '-') { + char oc; + + if ((oc = args[0][1]) && oc != '-') { + if (args[0][2]) { + zerrnam(nam, "invalid argument: %s", args[0], 0); + return 1; + } + if (oc == 'L') + list = 2; + } else { + add = 1; + args++; + } + } else + add = 1; + + if (add) { + Stypat p; + + if (arrlen(args) < 2) { + zerrnam(nam, "not enough arguments", NULL, 0); + return 1; + } + if (!(p = getstypat(args[0]))) { + Patprog prog; + char *pat = dupstring(args[0]); + + tokenize(pat); + + if (!(prog = patcompile(pat, PAT_ZDUP, NULL))) { + zerrnam(nam, "invalid pattern: %s", args[0], 0); + return 1; + } + p = addstypat(args[0], prog); + } + setstyle(p, args[1], args + 2); + + return 0; + } + if (list) { + Stypat p; + Style s; + char **v; + + for (p = zstyles; p; p = p->next) { + if (list == 1) { + quotedzputs(p->pat, stdout); + putchar('\n'); + } + for (s = p->styles; s; s = s->next) { + if (list == 1) + printf(" %s", s->name); + else { + printf("zstyle "); + quotedzputs(p->pat, stdout); + printf(" %s", s->name); + } + for (v = s->vals; *v; v++) { + putchar(' '); + quotedzputs(*v, stdout); + } + putchar('\n'); + } + } + return 0; + } + switch (args[0][1]) { + case 'd': min = 0; max = -1; break; + case 's': min = 3; max = 4; break; + case 'b': min = 3; max = 3; break; + case 'a': min = 3; max = 3; break; + case 'h': min = 3; max = 3; break; + case 't': min = 2; max = -1; break; + case 'm': min = 3; max = 3; break; + case 'g': min = 1; max = 3; break; + default: + zerrnam(nam, "invalid option: %s", args[0], 0); + return 1; + } + n = arrlen(args) - 1; + if (n < min) { + zerrnam(nam, "not enough arguments", NULL, 0); + return 1; + } else if (max >= 0 && n > max) { + zerrnam(nam, "too many arguments", NULL, 0); + return 1; + } + switch (args[0][1]) { + case 'd': + { + Stypat p; + + if (args[1]) { + if ((p = getstypat(args[1]))) { + if (args[2]) { + char **ap = args + 2; + + while (*ap) + deletestyle(p, *ap++); + + if (!p->styles) + deletestypat(p); + } else + deletestypat(p); + } + } else { + freestypat(zstyles); + zstyles = lzstyles = NULL; + } + } + break; + case 's': + { + Style s; + char *ret; + int val; + + if ((s = lookupstyle(args[1], args[2])) && s->vals[0]) { + PERMALLOC { + ret = sepjoin(s->vals, (args[4] ? args[4] : " ")); + } LASTALLOC; + val = 0; + } else { + ret = ztrdup(""); + val = 1; + } + setsparam(args[3], ret); + + return val; + } + break; + case 'b': + { + Style s; + char *ret; + int val; + + if ((s = lookupstyle(args[1], args[2])) && + s->vals[0] && !s->vals[1] && + (!strcmp(s->vals[0], "yes") || + !strcmp(s->vals[0], "true") || + !strcmp(s->vals[0], "on") || + !strcmp(s->vals[0], "1"))) { + ret = "yes"; + val = 0; + } else { + ret = "no"; + val = 1; + } + setsparam(args[3], ztrdup(ret)); + + return val; + } + break; + case 'a': + case 'h': + { + Style s; + char **ret; + int val; + + if ((s = lookupstyle(args[1], args[2]))) { + PERMALLOC { + ret = arrdup(s->vals); + } LASTALLOC; + val = 0; + } else { + char *dummy = NULL; + + PERMALLOC { + ret = arrdup(&dummy); + } LASTALLOC; + val = 1; + } + if (args[0][1] == 'a') + setaparam(args[3], ret); + else + sethparam(args[3], ret); + + return val; + } + break; + case 't': + { + Style s; + + if ((s = lookupstyle(args[1], args[2])) && s->vals[0]) { + if (args[3]) { + char **ap = args + 3, **p; + + while (*ap) { + p = s->vals; + while (*p) + if (!strcmp(*ap, *p++)) + return 0; + ap++; + } + return 1; + } else + return !(!strcmp(s->vals[0], "true") || + !strcmp(s->vals[0], "yes") || + !strcmp(s->vals[0], "on") || + !strcmp(s->vals[0], "1")); + } + return 1; + } + break; + case 'm': + { + Style s; + Patprog prog; + + tokenize(args[3]); + + if ((s = lookupstyle(args[1], args[2])) && + (prog = patcompile(args[3], PAT_STATIC, NULL))) { + char **p = s->vals; + + while (*p) + if (pattry(prog, *p++)) + return 0; + } + return 1; + } + break; + case 'g': + { + LinkList l = newlinklist(); + int ret = 1; + Stypat p; + + if (args[2]) { + if ((p = getstypat(args[2]))) { + Style s; + + if (args[3]) { + if ((s = getstyle(p, args[3]))) { + char **v = s->vals; + + while (*v) + addlinknode(l, *v++); + + ret = 0; + } + } else { + for (s = p->styles; s; s = s->next) + addlinknode(l, s->name); + + ret = 0; + } + } + } else { + for (p = zstyles; p; p = p->next) + addlinknode(l, p->pat); + + ret = 0; + } + set_list_array(args[1], l); + + return ret; + } + } + return 0; +} + +/* Format stuff. */ + +static int +bin_zformat(char *nam, char **args, char *ops, int func) +{ + char opt; + + if (args[0][0] != '-' || !(opt = args[0][1]) || args[0][2]) { + zerrnam(nam, "invalid argument: %s", args[0], 0); + return 1; + } + args++; + + switch (opt) { + case 'f': + { + char **ap, *specs[256], *out, *s; + int olen, oused = 0; + + memset(specs, 0, 256 * sizeof(char *)); + + for (ap = args + 2; *ap; ap++) { + if (!ap[0][0] || ap[0][0] == '-' || ap[0][0] == '.' || + (ap[0][0] >= '0' && ap[0][0] <= '9') || + ap[0][1] != ':') { + zerrnam(nam, "invalid argument: %s", *ap, 0); + return 1; + } + specs[STOUC(ap[0][0])] = ap[0] + 2; + } + out = (char *) zhalloc(olen = 128); + + for (s = args[1]; *s; s++) { + if (*s == '%') { + int right, min = -1, max = -1, outl; + char *spec, *start = s; + + if ((right = (*++s == '-'))) + s++; + + if (*s >= '0' && *s <= '9') { + for (min = 0; *s >= '0' && *s <= '9'; s++) + min = (min * 10) + (int) STOUC(*s) - '0'; + } + if (*s == '.' && s[1] >= '0' && s[1] <= '9') { + for (max = 0, s++; *s >= '0' && *s <= '9'; s++) + max = (max * 10) + (int) STOUC(*s) - '0'; + } + if ((spec = specs[STOUC(*s)])) { + int len; + + if ((len = strlen(spec)) > max && max >= 0) + len = max; + outl = (min >= 0 ? (min > len ? min : len) : len); + + if (oused + outl >= olen) { + int nlen = olen + outl + 128; + char *tmp = (char *) zhalloc(nlen); + + memcpy(tmp, out, olen); + olen = nlen; + out = tmp; + } + if (len >= outl) { + memcpy(out + oused, spec, outl); + oused += outl; + } else { + int diff = outl - len; + + if (right) { + while (diff--) + out[oused++] = ' '; + memcpy(out + oused, spec, len); + oused += len; + } else { + memcpy(out + oused, spec, len); + oused += len; + while (diff--) + out[oused++] = ' '; + } + } + } else { + int len = s - start + 1; + + if (oused + len >= olen) { + int nlen = olen + len + 128; + char *tmp = (char *) zhalloc(nlen); + + memcpy(tmp, out, olen); + olen = nlen; + out = tmp; + } + memcpy(out + oused, start, len); + oused += len; + } + } else { + if (oused + 1 >= olen) { + char *tmp = (char *) zhalloc(olen << 1); + + memcpy(tmp, out, olen); + olen <<= 1; + out = tmp; + } + out[oused++] = *s; + } + } + out[oused] = '\0'; + + setsparam(args[0], ztrdup(out)); + return 0; + } + break; + case 'a': + { + char **ap, *cp; + int nbc = 0, colon = 0, pre = 0, suf = 0; + + for (ap = args + 2; *ap; ap++) { + for (nbc = 0, cp = *ap; *cp && *cp != ':'; cp++) + if (*cp == '\\' && cp[1]) + cp++, nbc++; + if (*cp == ':' && cp[1]) { + int d; + + colon++; + if ((d = cp - *ap - nbc) > pre) + pre = d; + if ((d = strlen(cp + 1)) > suf) + suf = d; + } + } + { + int sl = strlen(args[1]); + VARARR(char, buf, pre + suf + sl + 1); + char **ret, **rp, *copy, *cpp, oldc; + + ret = (char **) zalloc((arrlen(args + 2) + 1) * + sizeof(char *)); + + memcpy(buf + pre, args[1], sl); + suf = pre + sl; + + for (rp = ret, ap = args + 2; *ap; ap++) { + copy = dupstring(*ap); + for (cp = cpp = copy; *cp && *cp != ':'; cp++) { + if (*cp == '\\' && cp[1]) + cp++; + *cpp++ = *cp; + } + oldc = *cpp; + *cpp = '\0'; + if (((cpp == cp && oldc == ':') || *cp == ':') && cp[1]) { + memset(buf, ' ', pre); + memcpy(buf, copy, (cpp - copy)); + strcpy(buf + suf, cp + 1); + *rp++ = ztrdup(buf); + } else + *rp++ = ztrdup(copy); + } + *rp = NULL; + + setaparam(args[0], ret); + return 0; + } + } + break; + } + zerrnam(nam, "invalid option: -%c", 0, opt); + return 1; +} + +static struct builtin bintab[] = { + BUILTIN("zstyle", 0, bin_zstyle, 0, -1, 0, NULL, NULL), + BUILTIN("zformat", 0, bin_zformat, 3, -1, 0, NULL, NULL), +}; + + +/**/ +int +setup_zutil(Module m) +{ + zstyles = NULL; + + return 0; +} + +/**/ +int +boot_zutil(Module m) +{ + return !addbuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)); +} + +/**/ +int +cleanup_zutil(Module m) +{ + deletebuiltins(m->nam, bintab, sizeof(bintab)/sizeof(*bintab)); + return 0; +} + +/**/ +int +finish_zutil(Module m) +{ + freestypat(zstyles); + + return 0; +} diff --git a/Src/Modules/zutil.mdd b/Src/Modules/zutil.mdd new file mode 100644 index 000000000..edc1f0d32 --- /dev/null +++ b/Src/Modules/zutil.mdd @@ -0,0 +1,3 @@ +objects="zutil.o" + +autobins="zformat zstyle" diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c index ae7dba5a8..bb69e5bf8 100644 --- a/Src/Zle/computil.c +++ b/Src/Zle/computil.c @@ -102,24 +102,6 @@ cdisp_build(Cdisp disp, char *sep, char **args) return ret; } -/**/ -static int -bin_compdisplay(char *nam, char **args, char *ops, int func) -{ - struct cdisp disp; - - if (incompfunc != 1) { - zerrnam(nam, "can only be called from completion function", NULL, 0); - return 1; - } - disp.pre = disp.suf = disp.colon = 0; - - cdisp_calc(&disp, args + 2); - setaparam(args[0], cdisp_build(&disp, args[1], args + 2)); - - return !disp.colon; -} - /* Help fuer `_describe'. */ typedef struct cdset *Cdset; @@ -2179,411 +2161,6 @@ bin_compquote(char *nam, char **args, char *ops, int func) return 0; } -/* Style stuff. */ - -typedef struct cspat *Cspat; -typedef struct cstyle *Cstyle; - -/* A pattern and the styles for it. */ - -struct cspat { - Cspat next; - char *pat; /* pattern string */ - Patprog prog; /* compiled pattern */ - int weight; /* how specific is the pattern? */ - Cstyle styles, lstyles; /* first/last style */ -}; - -struct cstyle { - Cstyle next; - char *name; - char **vals; -}; - -/* List of styles. */ - -static Cspat compstyles, lcompstyles; - -/* Memory stuff. */ - -static void -freecstyle(Cstyle s) -{ - Cstyle n; - - while (s) { - n = s->next; - - zsfree(s->name); - if (s->vals) - freearray(s->vals); - zfree(s, sizeof(*s)); - - s = n; - } -} - -static void -freecspat(Cspat p) -{ - Cspat n; - - while (p) { - n = p->next; - - zsfree(p->pat); - freepatprog(p->prog); - zfree(p, sizeof(*p)); - - p = n; - } -} - -/* Get the struct for a pattern, if any. */ - -static Cspat -getcspat(char *pat) -{ - Cspat p; - - for (p = compstyles; p; p = p->next) - if (!strcmp(pat, p->pat)) - return p; - - return NULL; -} - -/* Get the style stuff for a name. */ - -static Cstyle -getcstyle(Cspat p, char *name) -{ - Cstyle s; - - for (s = p->styles; s; s= s->next) - if (!strcmp(name, s->name)) - return s; - - return NULL; -} - -/* Store a value for a style. */ - -static void -setcstyle(Cspat p, char *name, char **vals) -{ - Cstyle s; - - for (s = p->styles; s; s = s->next) - if (!strcmp(name, s->name)) { - - /* Exists -> replace. */ - - if (s->vals) - freearray(s->vals); - PERMALLOC { - s->vals = arrdup(vals); - } LASTALLOC; - - return; - } - - /* New style. */ - - s = (Cstyle) zalloc(sizeof(*s)); - - s->name = ztrdup(name); - PERMALLOC { - s->vals = arrdup(vals); - } LASTALLOC; - s->next = NULL; - - if (p->lstyles) - p->lstyles->next = s; - else - p->styles = s; - p->lstyles = s; -} - -/* Add a new pattern. */ - -static Cspat -addcspat(char *pat, Patprog prog) -{ - Cspat p, q, qq; - int weight, tmp, first; - char *s; - - /* Calculate the weight. */ - - for (weight = 0, tmp = 2, first = 1, s = pat; *s; s++) { - if (first && *s == '*' && (!s[1] || s[1] == ':')) { - /* Only `*' in this component. */ - tmp = 0; - continue; - } - first = 0; - - if (*s == '(' || *s == '|' || *s == '*' || *s == '[' || *s == '<' || - *s == '?' || *s == '#' || *s == '^') - /* Is pattern. */ - tmp = 1; - - if (*s == ':') { - /* Yet another component. */ - - first = 1; - weight += tmp; - tmp = 2; - } - } - weight += tmp; - - p = (Cspat) zalloc(sizeof(*p)); - - p->pat = ztrdup(pat); - p->weight = weight; - p->prog = prog; - p->styles = p->lstyles = NULL; - - for (qq = NULL, q = compstyles; q && q->weight >= weight; - qq = q, q = q->next); - - p->next = q; - if (qq) - qq->next = p; - else - compstyles = p; - if (!q) - lcompstyles = p; - - return p; -} - -/* Delete a style. */ - -static void -deletecstyle(Cspat p, char *name) -{ - Cstyle ps, s; - - for (ps = NULL, s = p->styles; s; ps = s, s = s->next) - if (!strcmp(name, s->name)) { - if (ps) - ps->next = s->next; - else - p->styles = s->next; - if (s == p->lstyles) - p->lstyles = ps; - - s->next = NULL; - freecstyle(s); - - return; - } -} - -/* Delete a whole pattern with all its styles. */ - -static void -deletecspat(Cspat pat) -{ - Cspat pp, p; - - for (pp = NULL, p = compstyles; p; pp = p, p = p->next) - if (p == pat) { - if (pp) - pp->next = p->next; - else - compstyles = p->next; - if (p == lcompstyles) - lcompstyles = pp; - - p->next = NULL; - zsfree(p->pat); - freepatprog(p->prog); - freecstyle(p->styles); - zfree(p, sizeof(*p)); - - return; - } -} - -/* Look up a style for a context pattern. This does the matching. */ - -static Cstyle -lookupcstyle(char *ctxt, char *style) -{ - Cspat p; - Cstyle s; - - for (p = compstyles; p; p = p->next) - if (pattry(p->prog, ctxt)) - for (s = p->styles; s; s = s->next) - if (!strcmp(style, s->name)) - return s; - - return NULL; -} - -static int -bin_compstyles(char *nam, char **args, char *ops, int func) -{ - int min, max, n; - - if (args[0][0] != '-' || !args[0][1] || args[0][2]) { - zerrnam(nam, "invalid argument: %s", args[0], 0); - return 1; - } - switch (args[0][1]) { - case 'a': min = 2; max = -1; break; - case 'd': min = 0; max = 2; break; - case 'S': min = 3; max = 3; break; - case 'A': min = 3; max = 3; break; - case 'H': min = 3; max = 3; break; - case 'T': min = 2; max = 2; break; - case 'G': min = 1; max = 3; break; - default: - zerrnam(nam, "invalid option: %s", args[0], 0); - return 1; - } - n = arrlen(args) - 1; - if (n < min) { - zerrnam(nam, "not enough arguments", NULL, 0); - return 1; - } else if (max >= 0 && n > max) { - zerrnam(nam, "too many arguments", NULL, 0); - return 1; - } - switch (args[0][1]) { - case 'a': - { - Cspat p; - - if (!(p = getcspat(args[1]))) { - Patprog prog; - char *pat = dupstring(args[1]); - - tokenize(pat); - - if (!(prog = patcompile(pat, PAT_ZDUP, NULL))) { - zerrnam(nam, "invalid pattern: %s", args[1], 0); - return 1; - } - p = addcspat(args[1], prog); - } - setcstyle(p, args[2], args + 3); - } - break; - case 'd': - { - Cspat p; - - if (args[1]) { - if ((p = getcspat(args[1]))) { - if (args[2]) { - deletecstyle(p, args[2]); - if (!p->styles) - deletecspat(p); - } else - deletecspat(p); - } - } else { - freecspat(compstyles); - compstyles = lcompstyles = NULL; - } - } - break; - case 'S': - { - Cstyle s; - char *ret; - int val; - - if ((s = lookupcstyle(args[1], args[2])) && s->vals[0]) { - PERMALLOC { - ret = sepjoin(s->vals, NULL); - } LASTALLOC; - val = 0; - } else { - ret = ztrdup(""); - val = 1; - } - setsparam(args[3], ret); - - return val; - } - break; - case 'A': - case 'H': - { - Cstyle s; - char **ret; - int val; - - if ((s = lookupcstyle(args[1], args[2]))) { - PERMALLOC { - ret = arrdup(s->vals); - } LASTALLOC; - val = 0; - } else { - char *dummy = NULL; - - PERMALLOC { - ret = arrdup(&dummy); - } LASTALLOC; - val = 1; - } - if (args[0][1] == 'A') - setaparam(args[3], ret); - else - sethparam(args[3], ret); - - return val; - } - break; - case 'T': - return !lookupcstyle(args[1], args[2]); - case 'G': - { - LinkList l = newlinklist(); - int ret = 1; - Cspat p; - - if (args[2]) { - if ((p = getcspat(args[2]))) { - Cstyle s; - - if (args[3]) { - if ((s = getcstyle(p, args[3]))) { - char **v = s->vals; - - while (*v) - addlinknode(l, *v++); - - ret = 0; - } - } else { - for (s = p->styles; s; s = s->next) - addlinknode(l, s->name); - - ret = 0; - } - } - } else { - for (p = compstyles; p; p = p->next) - addlinknode(l, p->pat); - - ret = 0; - } - set_list_array(args[1], l); - - return ret; - } - } - return 0; -} - /* Tags stuff. */ typedef struct ctags *Ctags; @@ -2855,12 +2432,10 @@ bin_compfmt(char *nam, char **args, char *ops, int func) } static struct builtin bintab[] = { - BUILTIN("compdisplay", 0, bin_compdisplay, 2, -1, 0, NULL, NULL), BUILTIN("compdescribe", 0, bin_compdescribe, 3, -1, 0, NULL, NULL), BUILTIN("comparguments", 0, bin_comparguments, 1, -1, 0, NULL, NULL), BUILTIN("compvalues", 0, bin_compvalues, 1, -1, 0, NULL, NULL), BUILTIN("compquote", 0, bin_compquote, 1, -1, 0, NULL, NULL), - BUILTIN("compstyles", 0, bin_compstyles, 1, -1, 0, NULL, NULL), BUILTIN("comptags", 0, bin_comptags, 1, -1, 0, NULL, NULL), BUILTIN("comptry", 0, bin_comptry, 0, -1, 0, NULL, NULL), BUILTIN("compfmt", 0, bin_compfmt, 2, -1, 0, NULL, NULL), @@ -2874,8 +2449,6 @@ setup_computil(Module m) memset(cadef_cache, 0, sizeof(cadef_cache)); memset(cvdef_cache, 0, sizeof(cvdef_cache)); - compstyles = NULL; - memset(comptags, 0, sizeof(comptags)); lasttaglevel = 0; @@ -2909,8 +2482,6 @@ finish_computil(Module m) for (i = 0; i < MAX_CVCACHE; i++) freecvdef(cvdef_cache[i]); - freecspat(compstyles); - for (i = 0; i < MAX_TAGS; i++) freectags(comptags[i]); diff --git a/Src/Zle/computil.mdd b/Src/Zle/computil.mdd index 0246f24b3..cf2a13b60 100644 --- a/Src/Zle/computil.mdd +++ b/Src/Zle/computil.mdd @@ -2,4 +2,4 @@ moddeps="complete zle" objects="computil.o" -autobins="compdisplay compdescribe comparguments compvalues compquote compstyles comptags comptry" +autobins="compdescribe comparguments compvalues compquote comptags comptry" diff --git a/Src/xmods.conf b/Src/xmods.conf index db72b4933..ed7769dbc 100644 --- a/Src/xmods.conf +++ b/Src/xmods.conf @@ -4,6 +4,7 @@ complete compctl sched complist +zutil computil parameter zleparameter -- cgit 1.4.1