Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: Re: double-listing with completion?



[ moved to workers, CC'ed to Matt ]

Matthew Lovell wrote:

> On 14 June 2000, Matthew Lovell writes:
>  > 
>  > If I follow the example given in the User Guide,
>  > 
>  >  zstyle ':completion:*:descriptions' format 'Completing %d'
>  >  zstyle ':completion:*' group-name ''
>  > 
>  > and then try "ls <complete>", I end up with a double-listing of
>  > completions:
>  > 
>  > lovell@mblhome:~
>  > % ls
>  > Completing file
>  > Chess  Desktop  Mail  Office50  autosave  axhome  bin  lale  misc
>  > Completing file
>  > Chess  Desktop  Mail  Office50  autosave  axhome  bin  lale  misc
> 
> Sorry to answer my own email...
> 
> Ah, I think it's being caused by another zstyle command (this one came
> from the man pages)
> 
>   zstyle ':completion:*' file-patterns \
>     '%p:globbed-files *(-/):directories' '*:all-files'
> 
> A somewhat odd interaction!  Generally, I liked that example a lot.
> I've always wanted the ability to do something like
> 
>    gv path/down/to<complete>
> 
> and get completion for paths and then just get completion for *.ps at
> the end.  Perhaps I can restrict that last zstyle to everything but
> the ls command.

Well, it isn't *that* odd, is it? You told it to complete files
matching the pattern supplied by the function (which is `*' for
default completion) and, at the same time, complete directories.

I should have written that in the manual , though.

And I probably should also have written the stuff below, which makes
patterns be tried only once and which makes _files stop after trying
the pattern `*'. One can, of course, still use tag labels to split the 
filenames into multiple groups and so on.

Bye
 Sven

Index: Completion/Core/_files
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Core/_files,v
retrieving revision 1.13
diff -u -r1.13 _files
--- Completion/Core/_files	2000/05/19 08:26:47	1.13
+++ Completion/Core/_files	2000/06/15 09:02:36
@@ -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 @@
 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 @@
   fi
 fi
 
+tried=()
 for def in "$pats[@]"; do
   eval "def=( ${${def:s/\\:/\\\\\\\\\\\\:}//(#b)([][()|*?^#~<>])/\\${match[1]}} )"
   for sdef in "$def[@]"; do
@@ -55,6 +57,10 @@
     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 @@
       done
       (( ret )) || break
     done
+    [[ "$pat" = '*' ]] && return ret
   done
   (( ret )) || return 0
 done
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.64
diff -u -r1.64 compsys.yo
--- Doc/Zsh/compsys.yo	2000/06/13 12:14:32	1.64
+++ Doc/Zsh/compsys.yo	2000/06/15 09:02:39
@@ -1033,6 +1033,10 @@
 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.

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author