diff options
author | Sven Wischnowsky <wischnow@users.sourceforge.net> | 2000-05-19 08:24:16 +0000 |
---|---|---|
committer | Sven Wischnowsky <wischnow@users.sourceforge.net> | 2000-05-19 08:24:16 +0000 |
commit | f9e65c2b1f448cd27c597ec727b63bebde2fbdff (patch) | |
tree | 816fd81472f634d8b19cc8aff9400c7644b22f77 /Completion/Core/_sep_parts | |
parent | aa86df8d1c3daeb0b267ad16cdca647247530696 (diff) | |
download | zsh-f9e65c2b1f448cd27c597ec727b63bebde2fbdff.tar.gz zsh-f9e65c2b1f448cd27c597ec727b63bebde2fbdff.tar.xz zsh-f9e65c2b1f448cd27c597ec727b63bebde2fbdff.zip |
don't use $match for something different than (#b)ackrefs (11464)
Diffstat (limited to 'Completion/Core/_sep_parts')
-rw-r--r-- | Completion/Core/_sep_parts | 112 |
1 files changed, 52 insertions, 60 deletions
diff --git a/Completion/Core/_sep_parts b/Completion/Core/_sep_parts index c1cda2b9a..0f9ef0fc4 100644 --- a/Completion/Core/_sep_parts +++ b/Completion/Core/_sep_parts @@ -9,40 +9,34 @@ # # _sep_parts '(foo bar)' @ hosts # -# This will make this function complete the strings in the array -# `friends'. If the string on the line contains a `@', the substring -# after it will be completed from the array `hosts'. Of course more -# arrays may be given, each preceded by another separator string. +# This will make this function complete the strings `foo' and `bar'. +# If the string on the line contains a `@', the substring after it +# will be completed from the array `hosts'. Of course more arrays +# may be given, each preceded by another separator string. # # This function understands the `-J group', `-V group', and # `-X explanation' options. -# -# This function does part of the matching itself and calls the functions -# `_match_test' and `_match_pattern' for this. local str arr sep test testarr tmparr prefix suffixes matchers autosuffix -local matchflags opt group expl nm=$compstate[nmatches] - -# Test if we should use this function for the global matcher in use. - -_match_test _sep_parts || return 1 +local matchflags opt group expl nm=$compstate[nmatches] opre osuf opts matcher # Get the options. -group=() -expl=() -while getopts "J:V:X:" opt; do - case "$opt" in - [JV]) group=("-$opt" "$OPTARG");; - X) expl=(-X "$OPTARG");; - esac -done -shift OPTIND-1 +zparseopts -D -a opts \ + 'J+:=group' 'V+:=group' P: F: S: r: R: q 1 2 n 'X+:=expl' 'M+:=matcher' + +if (( $#matcher )); then + matcher="${matcher[2]}" +else + matcher='' +fi # Get the string from the line. +opre="$PREFIX" +osuf="$SUFFIX" str="$PREFIX$SUFFIX" -[[ $#compstate[pattern_match] -ne 0 ]] || str="$str:q" +SUFFIX="" prefix="" # Walk through the arguments to find the longest unambiguous prefix. @@ -56,59 +50,53 @@ while [[ $# -gt 1 ]]; do tmparr=( ${=arr[2,-2]} ) arr=tmparr fi - # Is the separator on the line? - [[ "$str" != *${sep}* ]] && break - # Build a pattern matching the possible matches and get all these - # matches in an array. + # Is the separator on the line? - test="${str%%${sep}*}" - [[ -n "$_comp_correct" && $#test -le _comp_correct ]] && return 1 + [[ "$str" != *${sep}* ]] && break - matchflags="" - _match_pattern _sep_parts test matchflags - [[ -n "$_comp_correct" ]] && matchflags="$matchflags(#a$_comp_correct)" + # Get the matching array elements. - test="${matchflags}${test}" - testarr=( "${(@M)${(@P)arr}:#${~test}*}" ) - testarr=( "${(@)testarr:#}" ) + PREFIX="${str%%(|\\)${sep}*}" + builtin compadd -O testarr - "${(@P)arr}" + [[ $#testarr -eq 0 && -n "$_comp_correct" ]] && + compadd -O testarr - "${(@P)arr}" # If there are no matches we give up. If there is more than one # match, this is the part we will complete. + (( $#testarr )) || return 1 [[ $#testarr -gt 1 ]] && break # Only one match, add it to the prefix and skip over it in `str', # continuing with the next array and separator. + prefix="${prefix}${testarr[1]}${sep}" str="${str#*${sep}}" shift 2 done # Get the array to work upon. + arr="$1" if [[ "$arr[1]" == '(' ]]; then tmparr=( ${=arr[2,-2]} ) arr=tmparr fi + if [[ $# -le 1 || "$str" != *${2}* ]]; then # No more separators, build the matches. - test="$str" - [[ -n "$_comp_correct" && $#test -le _comp_correct ]] && return 1 - - matchflags="" - _match_pattern _sep_parts test matchflags - [[ -n "$_comp_correct" ]] && matchflags="$matchflags(#a$_comp_correct)" - - test="${matchflags}${test}" - testarr=( "${(@M)${(@P)arr}:#${~test}*}" ) - testarr=( "${(@)testarr:#}" ) + PREFIX="$str" + builtin compadd -O testarr - "${(@P)arr}" + [[ $#testarr -eq 0 && -n "$_comp_correct" ]] && + compadd -O testarr - "${(@P)arr}" fi [[ $#testarr -eq 0 || ${#testarr[1]} -eq 0 ]] && return 1 # Now we build the suffixes to give to the completion code. + shift matchers=() suffixes=("") @@ -116,23 +104,18 @@ autosuffix=() while [[ $# -gt 0 && "$str" == *${1}* ]]; do # Remove anything up to the the suffix. + str="${str#*${1}}" # Again, we get the string from the line up to the next separator # and build a pattern from it. + if [[ $# -gt 2 ]]; then - test="${str%%${3}*}" + PREFIX="${str%%${3}*}" else - test="$str" + PREFIX="$str" fi - [[ -n "$_comp_correct" && $#test -le _comp_correct ]] && return 1 - - matchflags="" - _match_pattern _sep_parts test matchflags - [[ -n "$_comp_correct" ]] && matchflags="$matchflags(#a$_comp_correct)" - test="${matchflags}${test}" - # We incrementally add suffixes by appending to them the seperators # and the strings from the next array that match the pattern we built. @@ -141,29 +124,38 @@ while [[ $# -gt 0 && "$str" == *${1}* ]]; do tmparr=( ${=arr[2,-2]} ) arr=tmparr fi - tmparr=( "${(@M)${(@P)arr}:#${~test}*}" ) - tmparr=( "${(@)tmparr:#}" ) - suffixes=("${(@)^suffixes[@]}${1}${(@)^tmparr}") + + builtin compadd -O tmparr - "${(@P)arr}" + [[ $#tmparr -eq 0 && -n "$_comp_correct" ]] && + compadd -O tmparr - "${(@P)arr}" + + suffixes=("${(@)^suffixes[@]}${(q)1}${(@)^tmparr}") # We want the completion code to generate the most specific suffix # for us, so we collect matching specifications that allow partial # word matching before the separators on the fly. + matchers=("$matchers[@]" "r:|${1:q}=*") shift 2 done # If we were given at least one more separator we make the completion # code offer it by appending it as a autoremovable suffix. -(( $# )) && autosuffix=(-qS "$1") + +(( $# )) && autosuffix=(-qS "${(q)1}") # If we have collected matching specifications, we build an array # from it that can be used as arguments to `compadd'. -[[ $#matchers -gt 0 ]] && matchers=(-M "$matchers") + +[[ $#matchers+$#matcher -gt 0 ]] && matchers=(-M "$matchers $matcher") # Add the matches for each of the suffixes. + +PREFIX="$pre" +SUFFIX="$suf" for i in "$suffixes[@]"; do - compadd -U "$group[@]" "$expl[@]" "$matchers[@]" "$autosuffix[@]" \ - -i "$IPREFIX" -p "$prefix" -s "$i" - "$testarr[@]" + compadd -U "$group[@]" "$expl[@]" "$matchers[@]" "$autosuffix[@]" "$opts[@]" \ + -i "$IPREFIX" -I "$ISUFFIX" -p "$prefix" -s "$i" - "$testarr[@]" done # This sets the return value to indicate that we added matches (or not). |