summary refs log tree commit diff
diff options
context:
space:
mode:
authorSven Wischnowsky <wischnow@users.sourceforge.net>2000-06-15 09:06:21 +0000
committerSven Wischnowsky <wischnow@users.sourceforge.net>2000-06-15 09:06:21 +0000
commit818cba3dbfb01030680237d248caaf2e9c3e5ac3 (patch)
tree44f04ea396616e2d92896749a8d3e41727e9d7c9
parent20789f5f92c9a70388af947691357bbb497a7a42 (diff)
downloadzsh-818cba3dbfb01030680237d248caaf2e9c3e5ac3.tar.gz
zsh-818cba3dbfb01030680237d248caaf2e9c3e5ac3.tar.xz
zsh-818cba3dbfb01030680237d248caaf2e9c3e5ac3.zip
make _files try each pattern only once (and stop after `*') (11915)
-rw-r--r--ChangeLog3
-rw-r--r--Completion/Core/_files11
-rw-r--r--Doc/Zsh/compsys.yo4
3 files changed, 16 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 6308f7fec..63b761f33 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2000-06-15  Sven Wischnowsky  <wischnow@zsh.org>
 
+	* 11915: Completion/Core/_files, Doc/Zsh/compsys.yo: make _files
+ 	try each pattern only once (and stop after `*')
+	
 	* 11910: Src/Zle/computil.c: fix for _arguments, it took
  	non-option strings as options
 	
diff --git a/Completion/Core/_files b/Completion/Core/_files
index 391d570a5..96bdbe0e7 100644
--- a/Completion/Core/_files
+++ b/Completion/Core/_files
@@ -1,6 +1,6 @@
 #autoload
 
-local opts tmp glob pat pats expl tag i def descr end ign ret=1 match
+local opts tmp glob pat pats expl tag i def descr end ign ret=1 match tried
 
 zparseopts -a opts \
     '/=tmp' 'f=tmp' 'g+:-=tmp' q n 1 2 P: S: r: R: W: X+: M+: F: J+: V+:
@@ -26,7 +26,8 @@ fi
 if zstyle -a ":completion:${curcontext}:" file-patterns tmp; then
   [[ "$type" = */* ]] && glob="$glob,*(-/)"
   pats=()
-  for i in ${tmp//%p/${${glob:-\*}//:/\\:} }; do
+
+  for i in ${tmp//%p/${${glob:-\*}//:/\\:}}; do
     if [[ $i = *[^\\]:* ]]; then
       pats=( "$pats[@]" " $i " )
     else
@@ -48,6 +49,7 @@ else
   fi
 fi
 
+tried=()
 for def in "$pats[@]"; do
   eval "def=( ${${def:s/\\:/\\\\\\\\\\\\:}//(#b)([][()|*?^#~<>])/\\${match[1]}} )"
   for sdef in "$def[@]"; do
@@ -55,6 +57,10 @@ for def in "$pats[@]"; do
     tag="${${sdef#*[^\\]:}%%:*}"
     pat="${${${sdef%%:${tag}*}//\\:/:}//,/ }"
 
+    (( $tried[(I)${(q)pat}] )) && continue
+
+    tried=( "$tried[@]" "$pat" )
+
     if [[ "$sdef" = *:${tag}:* ]]; then
       descr="${(Q)sdef#*:${tag}:}"
     else
@@ -75,6 +81,7 @@ for def in "$pats[@]"; do
       done
       (( ret )) || break
     done
+    [[ "$pat" = '*' ]] && return ret
   done
   (( ret )) || return 0
 done
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index ef0b28a3a..c2342850a 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -1033,6 +1033,10 @@ achieve this, one could do:
 example(zstyle ':completion:*' file-patterns \ 
     '%p:globbed-files *(-/):directories' '*:all-files')
 
+This works even for contexts in which all files would be completed,
+because tt(_files) will not try a pattern more than once and it stops
+when the pattern `tt(*)' was tried.
+
 Note also that during the execution of completion functions, the
 tt(EXTENDED_GLOB) option is in effect, so the characters `tt(#)',
 `tt(~)' and `tt(^)' have special meanings in the patterns.