about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>2000-02-17 10:59:46 +0000
committerTanaka Akira <akr@users.sourceforge.net>2000-02-17 10:59:46 +0000
commit0e3f4cecde90d9c07bfae1a9d522b285bcc8d6a3 (patch)
treefcd47ed650a154650b9c11111338fed7ab22932e
parentf82d790d908588684a9f19ace5523a033f0cde99 (diff)
downloadzsh-0e3f4cecde90d9c07bfae1a9d522b285bcc8d6a3.tar.gz
zsh-0e3f4cecde90d9c07bfae1a9d522b285bcc8d6a3.tar.xz
zsh-0e3f4cecde90d9c07bfae1a9d522b285bcc8d6a3.zip
zsh-workers/9772
-rw-r--r--Completion/Core/_approximate9
-rw-r--r--Completion/Core/_description2
-rw-r--r--Completion/Core/_expand2
-rw-r--r--Completion/Core/_list2
-rw-r--r--Completion/Core/_main_complete27
-rw-r--r--Completion/Core/_match2
-rw-r--r--Completion/Core/_menu2
-rw-r--r--Completion/Core/_oldlist2
-rw-r--r--Completion/Core/_prefix10
-rw-r--r--Doc/Zsh/compsys.yo85
10 files changed, 80 insertions, 63 deletions
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
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index c3ae77ec0..1ba3d1dad 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -1089,11 +1089,50 @@ matches as described in
 ifzman(the section `Matching Control' in zmanref(zshcompwid))\
 ifnzman(noderef(Matching Control))\
 .
-
-This style is also used by the tt(_matcher) completer, see
-ifzman(the section `Control Functions' below)\
-ifnzman(noderef(Control Functions)) 
-for more information.
+)
+item(tt(matcher-list))(
+This style is used by the main completion function to retrieve match
+specifications that are to be used everywhere. Its value should be a
+list of such specifications. The completion system will try them one
+after another for each completer selected. For example, to first try
+simple completion and, if that generates no matches, case-insensitive
+completion one would do:
+
+example(zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}')
+
+But the style allows even finer control: the style is looked up for
+every completer tried with the name of the completer (without the
+leading underscore) in the context name. For example, if one uses the
+completers tt(_complete) and tt(_prefix) and wants to try
+case-insensitive completion only when using the tt(_complete)
+completer, one would do:
+
+example(zstyle ':completion:*' completer _complete _prefix
+zstyle ':completion:*:complete*:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}')
+
+Note that there is no colon directly after the `tt(complete)'. That's
+because the completion system really uses the name of the completer
+followed by a minus sign and a number in the var(completer) field of
+the context name. This is useful if, for example, one wants to try
+normal completion without a match specification and with
+case-insensitive matching first, correction if that doesn't generate
+any matches and partial-word completion if that doesn't yield any
+matches either. In such a case one can give the tt(_complete)
+completer more than once in the tt(completer) style and give different
+match specification to them, as in:
+
+example(zstyle ':completion:*' completer _complete _correct _complete
+zstyle ':completion:*:complete-1:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}'
+zstyle ':completion:*:complete-2:*' matcher-list \
+    'm:{a-zA-Z}={A-Za-z} r:|[-_./]=* r:|=*')
+
+Note that in any case an unset style makes the completion code use no
+global match specification. Also, some completers (like tt(_correct)
+and tt(_approximate)) do not use the match specifications. But even if 
+such completers are used one can use the simple form to set this style 
+(as in the first example above) because such completers will make sure 
+that they are executed only once even if multiple match specifications 
+have been given.
 )
 item(tt(max-errors))(
 This is used by the tt(_approximate) and tt(_correct) completer functions
@@ -1609,42 +1648,6 @@ could be generated that is at least as long as the original string.
 Note that the matcher specifications defined globally or used by the
 completion functions will not be used.
 )
-findex(_matcher)
-item(tt(_matcher))(
-This completer allows to define a match specification (see
-ifzman(the section `Matching Control' in zmanref(zshcompwid))\
-ifnzman(noderef(Matching Control))\
-) that is to be used by all following completers. This is comparable
-to the global match specifications that can be defined for the
-tt(compctl) builtin, but gives much better control. The match
-specification to use is looked up using the tt(matcher) style. For
-this, the completer field of the context name will contain the string
-`tt(matcher-)var(n)', where `var(n)' is the number of the call to
-tt(_matcher). For example:
-
-example(zstyle ':completion:::::' completer _matcher _complete _matcher _complete
-zstyle ':completion:*:matcher-1:::' matcher 'm:{a-z-}={A-Z_}'
-zstyle ':completion:*:matcher-2:::' matcher 'm:{a-z-}={A-Z_}' 'r:|[-_./]=* r:|=*')
-
-Since tt(_matcher) is called as the first completer, the tt(_complete) 
-completer called after it will first use the match specification
-`tt(m:{a-z-}={A-Z_})'. If that doesn't generate any matches, the next
-call to tt(_matcher) will make the second call to tt(_complete) use
-the specification `tt(r:|[-_./]=* r:|=*)' in addition to the one
-already used by the first attempt (but note that the specification has 
-to be given again).
-
-If the tt(matcher) style is not set for one of the invocations of
-tt(_matcher), this has the same effect as setting it to the empty
-string: it makes the following completion function not use any match
-specifications besides those used by the functions themselves.
-
-Note that currently only the tt(_complete) completer and the
-tt(_prefix) completer (if it has its own tt(completer) style
-containing tt(_complete)) use the match specifications, so one doesn't 
-need to repeat all completers one wants to use after each call to
-tt(_matcher) in the completer list.
-)
 findex(_expand)
 item(tt(_expand))(
 This completer function does not really do completion, but instead