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

PATCH: Re: Tags again



Peter Stephenson wrote:

> I've got to stop using zsh's productivity-enhancing features at work, it's
> ruining my productivity...
> 
> What am I doing wrong this time?  I want a script `asrcs' to complete *.lst
> files and directories.  So I set up:
> 
> zstyle ':completion:*:*:asrcs:*:*' file-patterns '*.lst:globbed-files' \
>   '*(-/):directories'  '*:all-files'
> zstyle ':completion:*:*:asrcs:*:*' tag-order 'globbed-files directories' \
>   all-files
> 
> (Note that asrcs is just using default, i.e. file, completion.)  I was
> expecting this to complete globbed files and directories with equal
> priority.  But it doesn't; it just completes the globbed files unless there
> aren't any, then directories.  If I change the order in the file-patterns so
> that directories are first, it uses them instead.  So tag-order doesn't
> seem to be working as I expect --- if that wasn't there, though, this would
> be pretty much the behaviour I would expect.  Am I expecting wrong?  The
> documentation tends to support my expectations (I'll look through the
> documentation nearer the release, but it's a massive job so I don't want
> to have to do it more than once).

The manual says that the tags are tried `one after another'. I.e. it
first offers globbed-files, if that fails directories, etc. It does
*not* offer them all at once.

I changed it to that in 10267. The main reason was the pattern-tag
stuff in tag-order. A `*' would have matched all tags, giving everyone 
the all-files behaviour on the first attempt. Also, file-patterns
already allows ordering, no need for a second way to order the tags
(and it may be confusing if done accidentally).

So, what you want is just:

  zstyle ':completion:*:*:asrcs:*:*' file-patterns '*.lst *(-/):globbed-files' \
                                                   '*:all-files'

No fiddling with tag-order needed.

> By the way, although that part seems to be working just as documented, it
> might be nice to allow file-patterns to have a default tag, such as
> `files', so that `*.lst' on its own would be interpreted as `*.lst:files'.
> It's a little confusing if you miss out the tag part at present: stuff just

Yes, that's sensible...

Bye
 Sven

Index: Completion/Core/_files
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Core/_files,v
retrieving revision 1.4
diff -u -r1.4 _files
--- Completion/Core/_files	2000/04/05 10:50:08	1.4
+++ Completion/Core/_files	2000/04/06 11:25:53
@@ -1,6 +1,6 @@
 #autoload
 
-local opts tmp glob pats expl tag i pat descr end ign ret=1
+local opts tmp glob pat pats expl tag i def descr end ign ret=1
 
 zparseopts -a opts \
     '/=tmp' 'f=tmp' 'g+:-=tmp' q n 1 2 P: S: r: R: W: X+: M+: F: J+: V+:
@@ -19,9 +19,16 @@
   ign=
 fi
 
-if zstyle -a ":completion:${curcontext}:" file-patterns pats; then
+if zstyle -a ":completion:${curcontext}:" file-patterns tmp; then
   [[ "$type" = */* ]] && glob="$glob *(-/)"
-  pats=( \ ${(M)^${pats//\\%p/ ${glob:-\*} }:#*[^\\]:*} )
+  pats=()
+  for i in ${tmp//\\%p/ ${${glob:-\*}//:/\\:} }; do
+    if [[ $i = *[^\\]:* ]]; then
+      pats=( "$pats[@]" " $i" )
+    else
+      pats=( "$pats[@]" " ${i}:files" )
+    fi
+  done
 else
   if [[ "$type" = *g* ]]; then
     if [[ "$type" = */* ]]; then
@@ -37,14 +44,14 @@
   fi
 fi
 
-for tag in "${(@)${(@)pats#*[^\\]:}%%:*}"; do
+for def in "$pats[@]"; do ###"${(@)${(@)pats#*[^\\]:}%%:*}"; do
 
-  i="$pats[(I)*[^\\\\]:${tag}(|:*)]"
-  pat="${${pats[i]%%:${tag}*}//\\\\:/:}"
+  tag="${${def#*[^\\]:}%%:*}"
+  pat="${${def%%:${tag}*}//\\\\:/:}"
 
-  if [[ i -gt 0 && "$pat" != \ # ]]; then
-    if [[ "$pats[i]" = *:${tag}:* ]]; then
-      descr="${pats[i]#*:${tag}:}"
+  if [[ "$pat" != \ # ]]; then
+    if [[ "$def" = *:${tag}:* ]]; then
+      descr="${def#*:${tag}:}"
     else
       descr=file
       end=yes
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.9
diff -u -r1.9 compsys.yo
--- Doc/Zsh/compsys.yo	2000/04/05 19:29:15	1.9
+++ Doc/Zsh/compsys.yo	2000/04/06 11:25:57
@@ -942,7 +942,8 @@
 Colons in the pattern have to be preceded by a backslash to
 make them distinguishable from the colon before the var(tag). The
 var(tag)s of all strings in the value will be offered by tt(_files)
-(again, one after another) and used when looking up other styles. The
+(again, one after another) and used when looking up other styles. If
+no `tt(:)var(tag)' is given the tt(files) tag will be used. The
 var(tag) may also be
 followed by an optional second colon and a description. If that is
 given, this description will be used for the `tt(%d)' in the value of

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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