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

PATCH: Re: Global-alias problem with _expand



I wrote:

> Wayne Davison wrote:
> 
> > Global aliases can cause a problem in the _expand completer:
> > 
> > % zsh -f
> > 
> > % autoload -U compinit
> > % compinit
> > % zstyle ':completion:*' completer _expand
> > % alias -g T='|tail'
> > % l T<TAB>
> > _expand:-1: parse error near `|'
> 
> Rats. Look:
> 
>   % alias -g 'T=|foo'
>   % eval 'exp=( T )'
>   zsh: parse error near `|'
> 
> Anyone know how to avoid that?

I mean: other then by temporarily removing the global aliases or using 
$(...)?

Hm, maybe not. This patch makes it use $galiases to remove/restore
global aliases during those `eval's. But such global aliases could
probably break all `eval's in the completion system (and elsewhere),
so it's probably not the final solution.

Bye
 Sven

Index: Completion/Core/_expand
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Core/_expand,v
retrieving revision 1.30
diff -u -r1.30 _expand
--- Completion/Core/_expand	2000/10/06 13:01:53	1.30
+++ Completion/Core/_expand	2000/10/10 08:58:19
@@ -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 gal
 
 (( $# )) &&
     while getopts gsco opt; do
@@ -48,6 +49,12 @@
        ( "$word" = *\$[a-zA-Z0-9_]## && 
          ${#parameters[(I)${word##*\$}*]} -ne 1 ) ]] && return 1 }
 
+# We have to temporarily remove the global aliases because they can make
+# the evals fail.
+
+gal=( ${(kv)galiases} )
+(( $#gal )) && builtin unalias ${(k)galiases}
+
 # In exp we will collect the expansions.
 
 exp=("$word")
@@ -83,14 +90,20 @@
 
 (( $#exp )) || exp=("$subd[@]")
 
-[[ $#exp -eq 1 && "${exp[1]//\\}" = "${word//\\}"(|\(N\)) ]] && return 1
+if [[ $#exp -eq 1 && "${exp[1]//\\}" = "${word//\\}"(|\(N\)) ]]; then
+  galiases=( $gal )
+  return 1
+fi
 
 # With subst-globs-only we bail out if there were no glob expansions,
 # regardless of any substitutions
 
-{ [[ "$force" = *o* ]] ||
-  zstyle -t ":completion:${curcontext}:" subst-globs-only } &&
-    [[ "$subd" = "$exp"(|\(N\)) ]] && return 1
+if { [[ "$force" = *o* ]] ||
+    zstyle -t ":completion:${curcontext}:" subst-globs-only } &&
+    [[ "$subd" = "$exp"(|\(N\)) ]]; then
+  galiases=( $gal )
+  return 1
+fi
 
 zstyle -s ":completion:${curcontext}:" keep-prefix tmp || tmp=changed
 if [[ "$word" = [\~\$]*/* && "$tmp" = (yes|true|on|1|changed) ]]; then
@@ -101,7 +114,12 @@
     [[ "$tmp" != changed || $#exp -gt 1 ||
        "${opre}${exp[1]#${pre}}" != "$word" ]] && exp=( ${opre}${^exp#${pre}} )
   fi
+
+  galiases=( $gal )
+
   [[ $#exp -eq 1 && "$exp[1]" = "$word" ]] && return 1
+else
+  galiases=( $gal )
 fi
 
 # Now add as matches whatever the user requested.

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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