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

PATCH: accept-exact style in _expand



The accept-exact style (with value false) in _expand was bailing out
after things like ~/ and ~+/ and even ~/Mail/*. To take the last
example, it was looking for named directories or users named '/Mail/*'
and returning if it didn't find exactly one. It finds none in this
case. Fix is to only return if it found more than one:

-       ( "$word" = \~* && ${#userdirs[(I)${word[2,-1]}*]}+${#nameddirs[(I)${word[2,-1]}*]} -ne 1 ) ||
+       ( "$word" = \~* && ${#userdirs[(I)${word[2,-1]}*]}+${#nameddirs[(I)${word[2,-1]}*]} -gt 1 ) ||

I'll commit that to 4.0.

The second bug is with the use of [[ -o recexact ]] to determine the
default. This was done back-to-front. But should that be fixed in the
4.0 branch? So you may find you want to set the style after this
change.

The patch below however, adds a new feature too. With it, if you set the
accept-exact style to `continue', it will add the expansion as a match
but return 1 so other completers will also get a chance. The result is
this:

% foo=value
% foobar=whatever
% echo $foo<tab>
all expansions
/usr/local
parameter
foo     foobar

Unfortunately, you can't use a tag-order with these because
_main_complete doesn't have a tag loop. I've only applied this after
something like `~foo' or `$foo' and not after something like just `~',
`~+' or `~+1' though because I didn't like that. If you do want those
expansons added, let me know and I'll make it more flexible.

Oliver

Index: Completion/Base/Completer/_expand
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Completer/_expand,v
retrieving revision 1.7
diff -u -r1.7 _expand
--- Completion/Base/Completer/_expand	15 May 2001 13:52:23 -0000	1.7
+++ Completion/Base/Completer/_expand	7 Jul 2003 09:37:04 -0000
@@ -12,6 +12,7 @@
 [[ _matcher_num -gt 1 ]] && return 1
 
 local exp word sort expr expl subd suf=" " force opt asp tmp opre pre epre
+local continue=0
 
 (( $# )) &&
     while getopts gsco opt; do
@@ -37,13 +38,17 @@
      "${(e)word}" != *[][^*?\(\)\<\>\{\}\|]* ]] &&
   return 1
 
-zstyle -t ":completion:${curcontext}:" accept-exact ||
-  [[ $? -eq 2 && ! -o recexact ]] ||
+zstyle -s ":completion:${curcontext}:" accept-exact tmp ||
+    [[ ! -o recexact ]] || tmp=1
+
+if [[ "$tmp" != (yes|true|on|1) ]]; then
   { [[ "$word" = \~(|[-+]) ||
-       ( "$word" = \~[-+][1-9]## && $word[3,-1] -le $#dirstack ) ||
-       ( "$word" = \~* && ${#userdirs[(I)${word[2,-1]}*]}+${#nameddirs[(I)${word[2,-1]}*]} -ne 1 ) ||
+       ( "$word" = \~[-+][1-9]## && $word[3,-1] -le $#dirstack ) ]] && return 1 }
+  { [[ ( "$word" = \~* && ${#userdirs[(I)${word[2,-1]}*]}+${#nameddirs[(I)${word[2,-1]}*]} -gt 1 ) ||
        ( "$word" = *\$[a-zA-Z0-9_]## && 
-         ${#parameters[(I)${word##*\$}*]} -ne 1 ) ]] && return 1 }
+         ${#parameters[(I)${word##*\$}*]} -ne 1 ) ]] && continue=1 }
+  [[ continue -eq 1 && "$tmp" != continue ]] && return 1
+fi
 
 # In exp we will collect the expansions.
 
@@ -217,4 +222,4 @@
   compstate[insert]=menu
 fi
 
-return 0
+return continue
Index: Doc/Zsh/compsys.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/compsys.yo,v
retrieving revision 1.170
diff -u -r1.170 compsys.yo
--- Doc/Zsh/compsys.yo	5 Jun 2003 09:51:31 -0000	1.170
+++ Doc/Zsh/compsys.yo	7 Jul 2003 09:37:04 -0000
@@ -1034,7 +1034,9 @@
 expanded.  For example, if there are parameters
 tt(foo) and tt(foobar), the string `tt($foo)' will only be expanded if 
 tt(accept-exact) is set to `true'; otherwise the completion system will
-be allowed to complete tt($foo) to tt($foobar).
+be allowed to complete tt($foo) to tt($foobar). If the style is set to
+`continue', _expand will add the expansion as a match and the completion
+system will also be allowed to continue.
 )
 kindex(add-space, completion style)
 item(tt(add-space))(



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