diff options
author | Paul Ackersviller <packersv@users.sourceforge.net> | 2007-11-05 03:28:03 +0000 |
---|---|---|
committer | Paul Ackersviller <packersv@users.sourceforge.net> | 2007-11-05 03:28:03 +0000 |
commit | b2c0cbbc1a2cc8b28d3d8d4f0c94e2ef41f8d7cd (patch) | |
tree | 2e108022a5048f0c51f6a81d4f8da95252d1157c | |
parent | 6f2f15ae31a4fb82b5cbb45edb90787943cf2f75 (diff) | |
download | zsh-b2c0cbbc1a2cc8b28d3d8d4f0c94e2ef41f8d7cd.tar.gz zsh-b2c0cbbc1a2cc8b28d3d8d4f0c94e2ef41f8d7cd.tar.xz zsh-b2c0cbbc1a2cc8b28d3d8d4f0c94e2ef41f8d7cd.zip |
Merge of users/10989: add fake-always style that overrides ignored-patterns.
-rw-r--r-- | Completion/Base/Core/_description | 108 | ||||
-rw-r--r-- | Doc/Zsh/compsys.yo | 25 |
2 files changed, 133 insertions, 0 deletions
diff --git a/Completion/Base/Core/_description b/Completion/Base/Core/_description new file mode 100644 index 000000000..593369a0a --- /dev/null +++ b/Completion/Base/Core/_description @@ -0,0 +1,108 @@ +#autoload + +local name gropt nopt xopt format gname hidden hide match opts tag sort + +opts=() + +gropt=(-J) +xopt=(-X) +nopt=() +zparseopts -K -D -a nopt 1 2 V=gropt J=gropt x=xopt + +3="${${3##[[:blank:]]#}%%[[:blank:]]#}" +[[ -n "$3" ]] && _lastdescr=( "$_lastdescr[@]" "$3" ) + +zstyle -s ":completion:${curcontext}:$1" group-name gname && + [[ -z "$gname" ]] && gname="$1" + +_setup "$1" "${gname:--default-}" + +name="$2" + +zstyle -s ":completion:${curcontext}:$1" format format || + zstyle -s ":completion:${curcontext}:descriptions" format format + +if zstyle -s ":completion:${curcontext}:$1" hidden hidden && + [[ "$hidden" = (all|yes|true|1|on) ]]; then + [[ "$hidden" = all ]] && format='' + opts=(-n) +fi +zstyle -s ":completion:${curcontext}:$1" matcher match && + opts=($opts -M "$match") +[[ -n "$_matcher" ]] && opts=($opts -M "$_matcher") + +# Use sort style, but ignore `menu' value to help _expand. +# Also don't override explicit use of -V. +if { zstyle -s ":completion:${curcontext}:$1" sort sort || + zstyle -s ":completion:${curcontext}:" sort sort; } && + [[ "$gropt" = -J && $sort != menu ]]; then + if [[ "$sort" = (yes|true|1|on) ]]; then + gropt=(-J) + else + gropt=(-V) + fi +fi + +if [[ -z "$_comp_no_ignore" ]]; then + zstyle -a ":completion:${curcontext}:$1" ignored-patterns _comp_ignore || + _comp_ignore=() + + zstyle -s ":completion:${curcontext}:$1" ignore-line hidden && + case "$hidden" in + true|yes|on|1) _comp_ignore=( "$_comp_ignore[@]" "$words[@]" );; + current) _comp_ignore=( "$_comp_ignore[@]" "$words[CURRENT]" );; + current-shown) [[ "$compstate[old_list]" = *shown* ]] && + _comp_ignore=( "$_comp_ignore[@]" "$words[CURRENT]" );; + other) _comp_ignore=( "$_comp_ignore[@]" + "${(@)words[1,CURRENT-1]}" + "${(@)words[CURRENT+1,-1]}" );; + esac + + # Ensure the ignore option is first so we can override it + # for fake-always. + (( $#_comp_ignore )) && opts=( -F _comp_ignore $opts ) +else + _comp_ignore=() +fi + +tag="$1" + +shift 2 +if [[ -z "$1" && $# -eq 1 ]]; then + format= +elif [[ -n "$format" ]]; then + zformat -f format "$format" "d:$1" "${(@)argv[2,-1]}" +fi + +if [[ -n "$gname" ]]; then + if [[ -n "$format" ]]; then + set -A "$name" "$opts[@]" "$nopt[@]" "$gropt" "$gname" "$xopt" "$format" + else + set -A "$name" "$opts[@]" "$nopt[@]" "$gropt" "$gname" + fi +else + if [[ -n "$format" ]]; then + set -A "$name" "$opts[@]" "$nopt[@]" "$gropt" -default- "$xopt" "$format" + else + set -A "$name" "$opts[@]" "$nopt[@]" "$gropt" -default- + fi +fi + +if ! (( ${funcstack[2,-1][(I)_description]} )); then + local fakestyle descr + for fakestyle in fake fake-always; do + zstyle -a ":completion:${curcontext}:$tag" $fakestyle match || + continue + + descr=( "${(@M)match:#*[^\\]:*}" ) + + opts=("${(@P)name}") + if [[ $fakestyle = fake-always && $opts[1,2] = "-F _comp_ignore" ]]; then + shift 2 opts + fi + compadd "${(@)opts}" - "${(@)${(@)match:#*[^\\]:*}:s/\\:/:/}" + (( $#descr )) && _describe -t "$tag" '' descr "${(@)opts}" + done +fi + +return 0 diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index f65f15223..74cb26a0a 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -1308,6 +1308,31 @@ It is important to use a sufficiently restrictive context when specifying fake strings. Note that the styles tt(fake-files) and tt(fake-parameters) provide additional features when completing files or parameters. ) +kindex(fake-always, completion style) +item(tt(fake-always))( +This works identically to the tt(fake) style except that +the tt(ignored-patterns) style is not applied to it. This makes it +possible to override a set of matches completely by setting the +ignored patterns to `tt(*)'. + +The following shows a way of supplementing any tag with arbitrary data, but +having it behave for display purposes like a separate tag. In this example +we use the features of the tt(tag-order) style to divide the +tt(named-directories) tag into two when performing completion with +the standard completer tt(complete) for arguments of tt(cd). The tag +tt(named-directories-normal) behaves as normal, but the tag +tt(named-directories-mine) contains a fixed set of directories. +This has the effect of adding the match group `tt(extra directories)' with +the given completions. + +example(zstyle ':completion::complete:cd:*' tag-order \ + 'named-directories:-mine:extra\ directories + named-directories:-normal:named\ directories *' +zstyle ':completion::complete:cd:*:named-directories-mine' \ + fake-always mydir1 mydir2 +zstyle ':completion::complete:cd:*:named-directories-mine' \ + ignored-patterns '*') +) kindex(fake-files, completion style) item(tt(fake-files))( This style is used when completing files and looked up |