From 7eb928e2663197d52898b55cd2ccbe10c3222236 Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Mon, 13 Sep 1999 10:41:28 +0000 Subject: manual/7796 --- Completion/Base/_arguments | 19 +++++++++------ Completion/Base/_values | 60 ++++++++++++++++++++++++++++++++-------------- Completion/Core/_display | 5 ++-- Completion/Core/_list | 2 +- Doc/Zsh/compsys.yo | 5 +++- 5 files changed, 62 insertions(+), 29 deletions(-) diff --git a/Completion/Base/_arguments b/Completion/Base/_arguments index b9af1c072..e0443930b 100644 --- a/Completion/Base/_arguments +++ b/Completion/Base/_arguments @@ -209,7 +209,7 @@ if [[ "$*" != "$_args_cache_descr" ]]; then # Description for both the `-foo' and `+foo' form? - if [[ "$1" = (\*|)(-+|+-)* ]]; then + if [[ "$1" = (\*|)(-+|+-)[^:]* ]]; then # With a `*' at the beginning, the option may appear more than # once. @@ -257,7 +257,7 @@ if [[ "$*" != "$_args_cache_descr" ]]; then [[ "$tmp" = *[-+] ]] && tmp="$tmp[1,-2]" else tmp="${1%%:*}" - [[ "$tmp" = *[-+] ]] && tmp="$tmp[1,-2]" + [[ "$tmp" = [-+]?*[-+] ]] && tmp="$tmp[1,-2]" xor="$xor ${tmp%\=}" fi @@ -275,7 +275,7 @@ if [[ "$*" != "$_args_cache_descr" ]]; then else _args_cache_opts[$tmp]='' fi - _args_cache_odescr=( "$_args_cache_odescr[@]" "${tmp%[-+=]}:$descr" ) + _args_cache_odescr=( "$_args_cache_odescr[@]" "${tmp%\=}:$descr" ) [[ -n "$xor" ]] && _args_cache_xors[${tmp%\=}]="${${xor##[ ]#}%%[ ]#}" elif [[ "$1" = \*::* ]]; then @@ -774,11 +774,16 @@ while true; do eval ws\=\( "${action[3,-3]}" \) - if _display tmp ws -M 'r:|[_-]=* r:|=*'; then - compadd "$expl[@]" -y tmp - "${(@)ws%%:*}" + if [[ -n "$compconfig[describe_values]" && + "$compconfig[describe_values]" != *\!${cmd}* ]]; then + if _display tmp ws -M 'r:|[_-]=* r:|=*'; then + compadd "$expl[@]" -y tmp - "${(@)ws%%:*}" + else + [[ -n "$matched" ]] && compadd -Q -S -s "$SUFFIX" - "$PREFIX" + _message "$descr" + fi else - [[ -n "$matched" ]] && compadd -Q -S -s "$SUFFIX" - "$PREFIX" - _message "$descr" + compadd "$expl[@]" - "${(@)ws%%:*}" fi elif [[ "$action" = \(*\) ]]; then diff --git a/Completion/Base/_values b/Completion/Base/_values index 4be3e8203..9be2d97f3 100644 --- a/Completion/Base/_values +++ b/Completion/Base/_values @@ -3,7 +3,7 @@ setopt localoptions extendedglob local name arg def descr xor str tmp ret=1 expl nm="$compstate[nmatches]" -local snames odescr gdescr sep +local snames odescr gdescr sep esep spat typeset -A names onames xors _values # Probably fill our cache. @@ -11,7 +11,7 @@ typeset -A names onames xors _values if [[ "$*" != "$_vals_cache_args" ]]; then _vals_cache_args="$*" - unset _vals_cache_{sep,descr,names,onames,snames,xors,odescr} + unset _vals_cache_{sep,esep,descr,names,onames,snames,xors,odescr} typeset -gA _vals_cache_{names,onames,xors} _vals_cache_snames=() @@ -21,6 +21,7 @@ if [[ "$*" != "$_vals_cache_args" ]]; then if [[ "$1" = -s ]]; then _vals_cache_sep="$2" + [[ -z "$2" ]] && _vals_cache_esep=yes shift 2 fi @@ -107,20 +108,33 @@ xors=( "${(@kv)_vals_cache_xors}" ) odescr=( "$_vals_cache_odescr[@]" ) gdescr="$_vals_cache_descr" sep="$_vals_cache_sep" +esep="$_vals_cache_esep" -if [[ -n "$sep" ]]; then +if [[ -n "$sep$esep" ]]; then # We have a separator character. We parse the PREFIX and SUFFIX to # see if any of the values that must not appear more than once are # already on the line. - while [[ "$PREFIX" = *${sep}* ]]; do + if [[ -n "$esep" ]]; then + spat='?*' + else + spat="*${sep}*" + fi + + while [[ "$PREFIX" = $~spat ]]; do # Get one part, remove it from PREFIX and put it into IPREFIX. - tmp="${PREFIX%%${sep}*}" - PREFIX="${PREFIX#*${sep}}" - IPREFIX="${IPREFIX}${tmp}${sep}" + if [[ -n "$esep" ]]; then + tmp="$PREFIX[1]" + IPREFIX="${IPREFIX}${tmp}" + PREFIX="${PREFIX[2,-1]}" + else + tmp="${PREFIX%%${sep}*}" + PREFIX="${PREFIX#*${sep}}" + IPREFIX="${IPREFIX}${tmp}${sep}" + fi # Get the value `name'. @@ -138,24 +152,34 @@ if [[ -n "$sep" ]]; then if [[ -n "$xors[$name]" ]]; then snames=( "${(@)snames:#(${(j:|:)~${=xors[$name]}})}" ) odescr=( "${(@)odescr:#(${(j:|:)~${=xors[$name]}}):*}" ) - unset {names,onames,xors}\[${^=tmp}\] + unset {names,onames,xors}\[$name\] fi done - if [[ "$SUFFIX" = *${sep}* ]]; then + if [[ "$SUFFIX" = $~spat ]]; then # The same for the suffix. - str="${SUFFIX%%${sep}*}" - SUFFIX="${SUFFIX#*${sep}}" + if [[ -n "$esep" ]]; then + str='' + else + str="${SUFFIX%%${sep}*}" + SUFFIX="${SUFFIX#*${sep}}" + fi + while [[ -n "$SUFFIX" ]]; do - tmp="${PREFIX%%${sep}*}" - if [[ "$SUFFIX" = *${sep}* ]]; then - SUFFIX="${SUFFIX#*${sep}}" + if [[ -n "$esep" ]]; then + tmp="$SUFFIX[-1]" + ISUFFIX="${SUFFIX[-1]}$ISUFFIX" + SUFFIX="$SUFFIX[1,-2]" else - SUFFIX='' + tmp="${SUFFIX##*${sep}}" + if [[ "$SUFFIX" = *${sep}* ]]; then + SUFFIX="${SUFFIX%${sep}*}" + else + SUFFIX='' + fi + ISUFFIX="${sep}${tmp}${ISUFFIX}" fi - PREFIX="${PREFIX#*${sep}}" - IPREFIX="${IPREFIX}${tmp}${sep}" name="${tmp%%\=*}" @@ -168,7 +192,7 @@ if [[ -n "$sep" ]]; then if [[ -n "$xors[$name]" ]]; then snames=( "${(@)snames:#(${(j:|:)~${=xors[$name]}})}" ) odescr=( "${(@)odescr:#(${(j:|:)~${=xors[$name]}}):*}" ) - unset {names,onames,xors}\[${^=tmp}\] + unset {names,onames,xors}\[$name\] fi done SUFFIX="$str" diff --git a/Completion/Core/_display b/Completion/Core/_display index 210e866ec..d23361653 100644 --- a/Completion/Core/_display +++ b/Completion/Core/_display @@ -23,11 +23,12 @@ local _param="$1" _arr _len _i _tmp _simple # Remove all descriptions not matched by the string on the line. if [[ "${2[1]}" = \( ]]; then - _arr=( ${(o)=2[2,-2]} ) + _arr=( ${(Qo)=2[2,-2]} ) else _arr=( "${(@Po)2}" ) fi +_arr=( "${(@)_arr:#}" ) compadd -D _arr "${(@)argv[3,-1]}" - "${(@)_arr%%:*}" [[ "${2[1]}" != \( ]] && eval "${2}=( \"\$_arr[@]\" )" @@ -68,7 +69,7 @@ ${(r:_len:: :)_i%%:*} -- ${_i#*:}" (( $#_simple )) && _tmp="${_tmp} $(print -c - $_simple)" - eval "${_param}=${(q)_tmp[2,-1]}" + eval "${_param}=\"\${_tmp[2,-1]}\"" return 0 else diff --git a/Completion/Core/_list b/Completion/Core/_list index 28a5161d1..25dcdfe8f 100644 --- a/Completion/Core/_list +++ b/Completion/Core/_list @@ -43,7 +43,7 @@ fi # Should we only show a list now? if [[ ( -z "$compconfig[list_condition]" || - "${(e):-\$[$compconfig[expand_glob]]}" -eq 1 ) && + "${(e):-\$[$compconfig[list_condition]]}" -eq 1 ) && ( "$pre" != "$_list_prefix" || "$suf" != "$_list_suffix" ) ]]; then # Yes. Tell the completion code about it and save the new values diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index f14ab4799..6ce13fc35 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -797,7 +797,10 @@ a list in parentheses, as in `tt(:foo:(foo bar baz))'. Such a list in doubled parentheses, as in `tt(:foo:((a\:bar b\:baz)))' should contain strings consisting of the string to complete followed by a colon (which needs to be preceded by a backslash) and a description. The -matches will be listed together with their descriptions. +matches will be listed together with their descriptions if the +value of configuration key tt(describe_values) is non-empty and does +not contain the substring `tt(!)var(command)', where `var(command)' is +the name of the command on the line. An var(action) of the form `tt(->)var(string)' is used by functions that implement a state machine. In this case, the `var(string)' (with -- cgit 1.4.1