From b9a533f3823c3b6d69fad80a21f573670856823f Mon Sep 17 00:00:00 2001 From: Sven Wischnowsky Date: Thu, 22 Jun 2000 08:42:36 +0000 Subject: allow subscripts for compadd -[ak]; new style for history completion; better list-colors handling (12029) --- Completion/Core/_history | 33 ++++++++++++++++++++++++++------- Completion/Core/_main_complete | 8 ++++++-- Completion/Core/_parameters | 8 ++++---- Completion/Core/_setup | 12 +++--------- Completion/Core/_tags | 14 ++------------ 5 files changed, 41 insertions(+), 34 deletions(-) (limited to 'Completion/Core') diff --git a/Completion/Core/_history b/Completion/Core/_history index 109bda91f..dafd61407 100644 --- a/Completion/Core/_history +++ b/Completion/Core/_history @@ -11,12 +11,12 @@ # # Available styles: # -# :history-words:sort -- sort matches lexically (default is to sort by age) -# :history-words:remove-all-dups -- -# remove /all/ duplicate matches rather than just -# consecutives +# sort -- sort matches lexically (default is to sort by age) +# remove-all-dups -- +# remove /all/ duplicate matches rather than just consecutives +# range -- range of history words to complete -local opt expl h_words +local opt expl max slice hmax=$#historywords beg=2 if zstyle -t ":completion:${curcontext}:" remove-all-dups; then opt=- @@ -30,6 +30,19 @@ else opt="${opt}V" fi +if zstyle -s ":completion:${curcontext}:" range max; then + if [[ $max = *:* ]]; then + slice=${max#*:} + max=${max%:*} + else + slice=$max + fi + [[ max -gt hmax ]] && max=$hmax +else + max=$hmax + slice=$max +fi + PREFIX="$IPREFIX$PREFIX" IPREFIX= SUFFIX="$SUFFIX$ISUFFIX" @@ -37,5 +50,11 @@ ISUFFIX= # We skip the first element of historywords so the current word doesn't # interfere with the completion -h_words=( "${(@)historywords[2,-1]}" ) -_wanted "$opt" history-words expl 'history word' compadd -Q -a h_words + +while [[ $compstate[nmatches] -eq 0 && beg -lt max ]]; do + _wanted "$opt" history-words expl 'history word' \ + compadd -Q -a 'historywords[beg,beg+slice]' + (( beg+=slice )) +done + +(( $compstate[namtches] )) diff --git a/Completion/Core/_main_complete b/Completion/Core/_main_complete index b0798f67d..f238c88ac 100644 --- a/Completion/Core/_main_complete +++ b/Completion/Core/_main_complete @@ -34,7 +34,7 @@ local func funcs ret=1 tmp _compskip format nm call match \ _saved_insert="${compstate[insert]}" \ _saved_colors="$ZLS_COLORS" -typeset -U _lastdescr _comp_ignore +typeset -U _lastdescr _comp_ignore _comp_colors [[ -z "$curcontext" ]] && curcontext=::: @@ -263,7 +263,11 @@ fi ( "$_comp_force_list" = ?* && nm -ge _comp_force_list ) ]] && compstate[list]="${compstate[list]//messages} force" -[[ "$compstate[old_list]" = keep ]] && ZLS_COLORS="$_saved_colors" +if [[ "$compstate[old_list]" = keep ]]; then + ZLS_COLORS="$_saved_colors" +else + ZLS_COLORS="${(j.:.)_comp_colors}" +fi # Now call the post-functions. diff --git a/Completion/Core/_parameters b/Completion/Core/_parameters index 0e8c548f7..d3a163b49 100644 --- a/Completion/Core/_parameters +++ b/Completion/Core/_parameters @@ -1,8 +1,8 @@ #autoload # This should be used to complete parameter names if you need some of the -# extra options of compadd. It first tries to complete only non-local -# parameters. All arguments are given to compadd. +# extra options of compadd. It completes only non-local parameters. -compadd "$@" - "${(@)${(@)${(@)${(@f)$(typeset)}:#*local *\=*}%%\=*}##* }" || - compadd "$@" - "${(@)${(@)${(@f)$(typeset)}%%\=*}##* }" +local expl + +_wanted parameters expl parameter compadd "$@" -k 'parameters[(R)^*local*]' diff --git a/Completion/Core/_setup b/Completion/Core/_setup index 50e3dbfd8..1278fa1ba 100644 --- a/Completion/Core/_setup +++ b/Completion/Core/_setup @@ -7,16 +7,10 @@ local val nm="$compstate[nmatches]" if zstyle -a ":completion:${curcontext}:$1" list-colors val; then zmodload -i zsh/complist if [[ "$1" = default ]]; then - ZLS_COLORS="${(j.:.)${(@)val:gs/:/\\\:}}" + _comp_colors=( "$val[@]" ) else - local simple grouped - - simple=( "(${2})${(@)^val:#\(*\)*}" ) - grouped=( "${(M@)val:#\(*\)*}" ) - simple="${(j.:.)simple}:" - grouped="${(j.:.)grouped}:" - [[ "$ZLS_COLORS" != *${simple}* ]] && ZLS_COLORS="${simple}$ZLS_COLORS" - [[ "$ZLS_COLORS" != *${grouped}* ]] && ZLS_COLORS="${grouped}$ZLS_COLORS" + _comp_colors=( "$_comp_colors[@]" + "(${2})${(@)^val:#\(*\)*}" "${(M@)val:#\(*\)*}" ) fi # Here is the problem mentioned in _main_complete. diff --git a/Completion/Core/_tags b/Completion/Core/_tags index c98990cec..5a1015356 100644 --- a/Completion/Core/_tags +++ b/Completion/Core/_tags @@ -30,18 +30,8 @@ if (( $# )); then [[ "$1" = -(|-) ]] && shift - if zstyle -a ":completion:${curcontext}:" group-order order; then - local name - - for name in "$order[@]"; do - compadd -J "$name" - compadd -V "$name" - compadd -J "$name" -1 - compadd -V "$name" -1 - compadd -J "$name" -2 - compadd -V "$name" -2 - done - fi + zstyle -a ":completion:${curcontext}:" group-order order && + compgroups "$order[@]" # Set and remember offered tags. -- cgit 1.4.1