From 0e3f4cecde90d9c07bfae1a9d522b285bcc8d6a3 Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Thu, 17 Feb 2000 10:59:46 +0000 Subject: zsh-workers/9772 --- Completion/Core/_approximate | 9 +++++---- Completion/Core/_description | 2 +- Completion/Core/_expand | 2 ++ Completion/Core/_list | 2 ++ Completion/Core/_main_complete | 27 ++++++++++++++++++--------- Completion/Core/_match | 2 ++ Completion/Core/_menu | 2 ++ Completion/Core/_oldlist | 2 ++ Completion/Core/_prefix | 10 ++-------- 9 files changed, 36 insertions(+), 22 deletions(-) (limited to 'Completion/Core') diff --git a/Completion/Core/_approximate b/Completion/Core/_approximate index ac2b69aad..6c7ae5d77 100644 --- a/Completion/Core/_approximate +++ b/Completion/Core/_approximate @@ -5,12 +5,13 @@ # shown in a list and one can cycle through them as in a menucompletion # or get the corrected prefix. -local _comp_correct _correct_expl comax cfgacc -local curcontext="${curcontext}" oldcontext opm="$compstate[pattern_match]" +# We don't try correction if the string is too short or we have tried it +# already. -# We don't try correction if the string is too short. +[[ _matcher_num -gt 1 || "${#:-$PREFIX$SUFFIX}" -le 1 ]] && return 1 -[[ "${#:-$PREFIX$SUFFIX}" -le 1 ]] && return 1 +local _comp_correct _correct_expl comax cfgacc +local curcontext="${curcontext}" oldcontext opm="$compstate[pattern_match]" [[ "$curcontext" != [^:]#:correct:* ]] && curcontext="${curcontext/:[^:]#:/:approximate:}" diff --git a/Completion/Core/_description b/Completion/Core/_description index 970ee8f6a..6326d1f03 100644 --- a/Completion/Core/_description +++ b/Completion/Core/_description @@ -27,7 +27,7 @@ zstyle -s ":completion:${curcontext}:$1" group-name gname && [[ -z "$gname" ]] && gname="$1" zstyle -s ":completion:${curcontext}:$1" matcher match && opts=($opts -M "${(q)match}") -[[ -n "$_comp_matcher" ]] && opts=($opts -M "${(q)_comp_matcher}") +[[ -n "$_matcher" ]] && opts=($opts -M "${(q)_matcher}") if zstyle -a ":completion:${curcontext}:$1" ignored-patterns _comp_ignore; then opts=( $opts -F _comp_ignore) diff --git a/Completion/Core/_expand b/Completion/Core/_expand index 2bb7d4fb3..8279a1406 100644 --- a/Completion/Core/_expand +++ b/Completion/Core/_expand @@ -7,6 +7,8 @@ # the expansions done produce no result or do not change the original # word from the line. +[[ _matcher_num -gt 1 ]] && return 1 + local exp word="$PREFIX$SUFFIX" sort expr expl subd suf=" " local curcontext="${curcontext/:[^:]#:/:expand:}" diff --git a/Completion/Core/_list b/Completion/Core/_list index 597d173ad..ea85ca13d 100644 --- a/Completion/Core/_list +++ b/Completion/Core/_list @@ -4,6 +4,8 @@ # insert possible completions only after the list has been shown at # least once. +[[ _matcher_num -gt 1 ]] && return 1 + local pre suf expr curcontext="${curcontext/:[^:]#:/:list:}" # Get the strings to compare. diff --git a/Completion/Core/_main_complete b/Completion/Core/_main_complete index 3f71e2554..dc546d763 100644 --- a/Completion/Core/_main_complete +++ b/Completion/Core/_main_complete @@ -20,7 +20,8 @@ setopt localoptions nullglob rcexpandparam extendedglob unsetopt markdirs globsubst shwordsplit nounset ksharrays local comp post ret=1 _compskip format _comp_ignore \ - _completers _completers_left _comp_matcher \ + _completers _completer _completer_num \ + _matchers _matcher _matcher_num \ 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]}" \ @@ -62,14 +63,22 @@ _last_menu_style=() # And now just call the completer functions defined. _completers=( "$@" ) -_completers_left=( "$@" ) - -for comp; do - if "$comp"; then - ret=0 - break; - fi - shift 1 _completers_left +_completer_num=1 + +for _completer; do + _matcher="${_completer[2,-1]}-${(M)#_completers[1,_completer_num]:#$_completer}" + zstyle -a ":completion:${curcontext/::/:${_matcher}:}:" matcher-list _matchers || + _matchers=( '' ) + + _matcher_num=1 + for _matcher in "$_matchers[@]"; do + if "$_completer"; then + ret=0 + break 2 + fi + (( _matcher_num++ )) + done + (( _completer_num++ )) done if [[ $compstate[nmatches] -gt 1 ]]; then diff --git a/Completion/Core/_match b/Completion/Core/_match index ad481f23b..5dc7936bc 100644 --- a/Completion/Core/_match +++ b/Completion/Core/_match @@ -9,6 +9,8 @@ # expand-or-complete function because otherwise the pattern will # be expanded using globbing. +[[ _matcher_num -gt 1 ]] && return 1 + local tmp opm="$compstate[pattern_match]" ret=0 orig ins local curcontext="${curcontext/:[^:]#:/:match:}" diff --git a/Completion/Core/_menu b/Completion/Core/_menu index 5ec1a1a55..6528fc542 100644 --- a/Completion/Core/_menu +++ b/Completion/Core/_menu @@ -1,5 +1,7 @@ #autoload +[[ _matcher_num -gt 1 ]] && return 1 + local curcontext="${curcontext/:[^:]#:/:menu:}" # This completer is an example showing how menucompletion can be diff --git a/Completion/Core/_oldlist b/Completion/Core/_oldlist index 450e3cb29..74e48d6e0 100644 --- a/Completion/Core/_oldlist +++ b/Completion/Core/_oldlist @@ -1,5 +1,7 @@ #autoload +[[ _matcher_num -gt 1 ]] && return 1 + local curcontext="${curcontext/:[^:]#:/:oldlist:}" list zstyle -s ":completion:${curcontext}:" list list diff --git a/Completion/Core/_prefix b/Completion/Core/_prefix index 34decf425..ed95140bd 100644 --- a/Completion/Core/_prefix +++ b/Completion/Core/_prefix @@ -4,10 +4,10 @@ [[ -n "$SUFFIX" ]] || return 1 -local curcontext="${curcontext/:[^:]#:/:prefix-${(M)#${(@)_completers[1,-$#_completers_left]}:#_prefix}:}" comp i +local curcontext="${curcontext/:[^:]#:/:prefix-${(M)#_completers[1,_completer_num]:#_prefix}:}" comp i zstyle -a ":completion:${curcontext}:" completer comp || - comp=( "${(@)_completers[1,-${#_completers_left}-1][(R)_prefix,-1]}" ) + comp=( "${(@)_completers[1,_completer_num][(R)_prefix,-1]}" ) if zstyle -t ":completion:${curcontext}:" add-space; then ISUFFIX=" $SUFFIX" @@ -16,14 +16,8 @@ else fi SUFFIX='' -local _completers _completer_left - -_completers=( "$comp[@]" ) -_completers_left=( "$comp[@]" ) - for i in "$comp[@]"; do [[ "$i" != _prefix ]] && "$i" && return 0 - shift 1 _completers_left done return 1 -- cgit 1.4.1