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

Anybody know what's going on here in _expand? Patch?



Line numbers for reference:

103 # Now try globbing.
104 
105 [[ "$force" = *g* ]] || zstyle -T ":completion:${curcontext}:" glob &&
106     eval 'exp=( ${~exp//(#b)\\[         
107 ]/$match[1]} ); exp=( ${(q)exp} )' 2>/dev/null

There is a trailing space and tab on line 106.

That stuff starting with //(#b) appears to want to replace any
whitespace that is preceded by a backslash with *something*, but as
there are no parens for the $match array to refer to, it ends up simply
removing the whitespace (along with the backslash), at least as far as I
can tell.  That can't be correct ...?

A bit further up is this:

 89   eval 'exp=( ${${(e)exp//\\[   
 90 ]/ }//(#b)([    
 91 ])/\\$match[1]} )' 2>/dev/null

That looks pretty similar (trailing space+tab on both lines 89 and 90)
except there it's turning backslash-whitespace into just a space, and
then adding back the backslash to any space that appears after applying
the (e) flag.

As it turns out, that eval on line 106 is where Yuri D'Elia's examples
[from the "Expanding quotes" thread over on zsh-users] go wrong. Adding
quote marks as well as whitespace to the character class on 106 "fixes"
both examples.

If nobody can explain what's correct about lines 106 and 107 as is,
then I propose the following patch, which adds the seemingly missing
backreference parens as well as putting quote chars in the class.


diff --git a/Completion/Base/Completer/_expand b/Completion/Base/Completer/_expand
index 44954a2..e52144c 100644
--- a/Completion/Base/Completer/_expand
+++ b/Completion/Base/Completer/_expand
@@ -103,8 +103,8 @@ subd=("$exp[@]")
 # Now try globbing.
 
 [[ "$force" = *g* ]] || zstyle -T ":completion:${curcontext}:" glob &&
-    eval 'exp=( ${~exp//(#b)\\[ 	
-]/$match[1]} ); exp=( ${(q)exp} )' 2>/dev/null
+    eval 'exp=( ${~exp//(#b)\\([ 	\"'"\'"'
+])/$match[1]} ); exp=( ${(q)exp} )' 2>/dev/null
 
 ### Don't remember why we once used this instead of the (q) above.
 #    eval 'exp=( ${~exp} ); exp=( ${exp//(#b)([][()|*?^#~<>\\=])/\\${match[1]}} )' 2>/dev/null



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