about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>2000-02-10 14:52:33 +0000
committerTanaka Akira <akr@users.sourceforge.net>2000-02-10 14:52:33 +0000
commitfc95f1a465638327704ba1bf28413b72c6a4226e (patch)
tree9801f747758a73d4bd77a64b1d94e70ecc18499f
parentff716aaa840fb9a9b5f29217150ddf3d587edbb6 (diff)
downloadzsh-fc95f1a465638327704ba1bf28413b72c6a4226e.tar.gz
zsh-fc95f1a465638327704ba1bf28413b72c6a4226e.tar.xz
zsh-fc95f1a465638327704ba1bf28413b72c6a4226e.zip
zsh-workers/9657
-rw-r--r--Completion/Core/_approximate4
-rw-r--r--Completion/Core/_description2
-rw-r--r--Completion/Core/_main_complete2
-rw-r--r--Completion/Core/_matcher5
-rw-r--r--Completion/Core/_path_files29
-rw-r--r--Completion/Core/_prefix8
-rw-r--r--Doc/Zsh/compsys.yo41
-rw-r--r--Src/Zle/complete.c1
8 files changed, 67 insertions, 25 deletions
diff --git a/Completion/Core/_approximate b/Completion/Core/_approximate
index 283f30e83..ef6e5b91d 100644
--- a/Completion/Core/_approximate
+++ b/Completion/Core/_approximate
@@ -6,7 +6,7 @@
 # or get the corrected prefix.
 
 local _comp_correct _correct_expl comax cfgacc
-local curcontext="${curcontext}" oldcontext
+local curcontext="${curcontext}" oldcontext opm="$compstate[pattern_match]"
 
 # Only if all global matchers have been tried.
 
@@ -100,6 +100,7 @@ while [[ _comp_correct -le comax ]]; do
     fi
     compstate[matcher]="$compstate[total_matchers]"
     unfunction compadd
+    compstate[pattern_match]="$opm"
 
     return 0
   fi
@@ -110,5 +111,6 @@ done
 
 compstate[matcher]="$compstate[total_matchers]"
 unfunction compadd
+compstate[pattern_match]="$opm"
 
 return 1
diff --git a/Completion/Core/_description b/Completion/Core/_description
index 06b54e807..970ee8f6a 100644
--- a/Completion/Core/_description
+++ b/Completion/Core/_description
@@ -27,6 +27,8 @@ 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}")
+
 if zstyle -a ":completion:${curcontext}:$1" ignored-patterns _comp_ignore; then
   opts=( $opts -F _comp_ignore)
 else
diff --git a/Completion/Core/_main_complete b/Completion/Core/_main_complete
index a6714cea6..33a492bae 100644
--- a/Completion/Core/_main_complete
+++ b/Completion/Core/_main_complete
@@ -20,7 +20,7 @@ setopt localoptions nullglob rcexpandparam extendedglob
 unsetopt markdirs globsubst shwordsplit nounset ksharrays
 
 local comp post ret=1 _compskip _prio_num=1 format _comp_ignore \
-      _completers _completers_left \
+      _completers _completers_left _comp_matcher \
       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]}" \
diff --git a/Completion/Core/_matcher b/Completion/Core/_matcher
new file mode 100644
index 000000000..6c0398e7b
--- /dev/null
+++ b/Completion/Core/_matcher
@@ -0,0 +1,5 @@
+#autoload
+
+zstyle -s ":completion:${curcontext%%:*}:matcher-${(M)#${(@)_completers[1,-$#_completers_left]}:#_matcher}:${curcontext#[^:]#:[^:]#:}:" matcher _comp_matcher || _comp_matcher=''
+
+return 1
diff --git a/Completion/Core/_path_files b/Completion/Core/_path_files
index 0ec311c64..5ff8d7dd5 100644
--- a/Completion/Core/_path_files
+++ b/Completion/Core/_path_files
@@ -6,7 +6,7 @@
 local linepath realpath donepath prepath testpath exppath skips skipped
 local tmp1 tmp2 tmp3 tmp4 i orig eorig pre suf tpre tsuf opre osuf cpre
 local pats haspats=no ignore pfxsfx rem remt sopt gopt opt
-local nm=$compstate[nmatches] menu mspec matcher mopts atmp sort match
+local nm=$compstate[nmatches] menu matcher mopts atmp sort match
 
 typeset -U prepaths exppaths
 
@@ -54,8 +54,6 @@ if (( $#ignore )); then
   fi
 fi  
 
-(( $#matcher )) && mspec="${matcher[2]}"
-
 if [[ -z "$_file_pat_checked" ]] &&
    zstyle -s ":completion:${curcontext}:files" file-patterns tmp1 &&
    [[ -n "$tmp1" ]]; then
@@ -92,7 +90,6 @@ if (( ! $mopts[(I)-[JVX]] )); then
   fi
   tmp1=$expl[(I)-M*]
   if (( tmp1 )); then
-    mspec="$mspec $expl[1+tmp1]"
     if (( $#matcher )); then
       matcher[2]="$matcher[2] $expl[1+tmp1]"
     else
@@ -452,30 +449,26 @@ for prepath in "$prepaths[@]"; do
         if [[ "$tmp3" = */* ]]; then
 	  compadd -Qf "$mopts[@]" -p "$linepath$tmp2" -s "/${tmp3#*/}" \
 	          -W "$prepath$realpath$testpath" \
-		  "$pfxsfx[@]" \
-                  -M "r:|/=* r:|=* $mspec" \
+		  "$pfxsfx[@]" -M "r:|/=* r:|=*" \
 		  - "${(@)tmp1%%/*}"
 	else
 	  compadd -Qf "$mopts[@]" -p "$linepath$tmp2" \
 	          -W "$prepath$realpath$testpath" \
-		   "$pfxsfx[@]" \
-                   -M "r:|/=* r:|=* $mspec" \
+		   "$pfxsfx[@]" -M "r:|/=* r:|=*" \
 		   - "$tmp1[@]"
 	fi
       else
         if [[ "$tmp3" = */* ]]; then
 	  atmp=( -Qf "$mopts[@]" -p "$linepath$tmp2"
 	         -W "$prepath$realpath$testpath"
-	         "$pfxsfx[@]" \
-                 -M "r:|/=* r:|=* $mspec" )
+	         "$pfxsfx[@]" -M "r:|/=* r:|=*" )
           for i in "$tmp1[@]"; do
 	    compadd "$atmp[@]" -s "/${i#*/}" - "${i%%/*}"
 	  done
         else
 	  compadd -Qf "$mopts[@]" -p "$linepath$tmp2" \
-		  -W "$prepath$realpath$testpath" \
-		  "$pfxsfx[@]" \
-                  -M "r:|/=* r:|=* $mspec" \
+                  -W "$prepath$realpath$testpath" \
+		  "$pfxsfx[@]" -M "r:|/=* r:|=*" \
 		  - "$tmp1[@]"
         fi
       fi
@@ -522,11 +515,8 @@ for prepath in "$prepaths[@]"; do
     fi
     tmp4="$testpath"
     compquote tmp4 tmp1
-    compadd -Qf "$mopts[@]" -p "$linepath$tmp4" \
-	    -W "$prepath$realpath$testpath" \
-	    "$pfxsfx[@]" \
-            -M "r:|/=* r:|=* $mspec" \
-	    - "$tmp1[@]"
+    compadd -Qf "$mopts[@]" -p "$linepath$tmp4" -W "$prepath$realpath$testpath" \
+	    "$pfxsfx[@]" -M "r:|/=* r:|=*" - "$tmp1[@]"
   fi
 done
 
@@ -542,8 +532,7 @@ if zstyle -t ":completion:${curcontext}:paths" expand prefix &&
   if (( $#exppaths )); then
     PREFIX="${opre}"
     SUFFIX="${osuf}"
-    compadd -Q "$mopts[@]" -S '' \
-            -M "r:|/=* r:|=* $mspec" -p "$linepath" - "$exppaths[@]"
+    compadd -Q "$mopts[@]" -S '' -M "r:|/=* r:|=*" -p "$linepath" - "$exppaths[@]"
   fi
 fi
 
diff --git a/Completion/Core/_prefix b/Completion/Core/_prefix
index 6306b4aa0..34decf425 100644
--- a/Completion/Core/_prefix
+++ b/Completion/Core/_prefix
@@ -4,7 +4,7 @@
 
 [[ -n "$SUFFIX" ]] || return 1
 
-local curcontext="${curcontext/:[^:]#:/:prefix:}" comp i
+local curcontext="${curcontext/:[^:]#:/:prefix-${(M)#${(@)_completers[1,-$#_completers_left]}:#_prefix}:}" comp i
 
 zstyle -a ":completion:${curcontext}:" completer comp ||
   comp=( "${(@)_completers[1,-${#_completers_left}-1][(R)_prefix,-1]}" )
@@ -16,8 +16,14 @@ 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 4cd2a0a61..27cc3c094 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -1097,6 +1097,11 @@ 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(max-errors))(
 This is used by the tt(_approximate) and tt(_correct) completer functions
@@ -1583,6 +1588,35 @@ 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 tt(compmatchers) special array, but gives finer 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.
+)
 findex(_expand)
 item(tt(_expand))(
 This completer function does not really do completion, but instead
@@ -1639,7 +1673,10 @@ try to generate matches. If this style is unset, the completers
 currently used by the whole completion are used -- except, of course,
 the tt(_prefix) completer itself. Also, if this completer appears more
 than once in the list of completers to use only those completers not
-already tried by the last invocation of tt(_prefix) will be called.
+already tried by the last invocation of tt(_prefix) will be
+called. The completer field used to look up styles contains the string 
+`tt(prefix-)var(n)', where `var(n)' is the number of the call to
+tt(_prefix).
 
 For example, consider this global tt(completer) style:
 
@@ -1653,7 +1690,7 @@ suffix ignored. If you want to use tt(_prefix) as the last resort and
 want it to try only normal completion, you need to do:
 
 example(zstyle ':completion:::::' completer _complete ... _prefix
-zstyle ':completion::prefix:::' completer _complete)
+zstyle ':completion::prefix-1:::' completer _complete)
 
 The tt(add-space) style is used, too. If it is set to `true' then
 tt(_prefix) will insert a space between the matches generated (if any) 
diff --git a/Src/Zle/complete.c b/Src/Zle/complete.c
index 8ba8019e7..dd3b59786 100644
--- a/Src/Zle/complete.c
+++ b/Src/Zle/complete.c
@@ -595,6 +595,7 @@ bin_compadd(char *name, char **argv, char *ops, int func)
 			mstr = tricat(mstr, " ", m);
 		    else
 			mstr = ztrdup(m);
+		    m = NULL;
 		}
 	    }
 	}