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

_path_files and the -M option



I was experimenting with using match specs as documented in PWS's guide
(section 6.7) and made up this little function:

   function _test { _files -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' }

You may recognize that -M as the one from the example setopts completion.
So what I'm trying to accomplish -- for no reason other than to play with
it -- is to complete file names after an optional "no" prefix, with case
and underscores ignored.

Unfortunately, it doesn't work.

Everything is fine up to through the point where _path_files calls

compadd -D tmp1 -F _comp_ignore -M "L:|[nN][oO]= M:_= M:{A-Z}={a-z}" - ...

(somewhere between lines 300 and 310 in my current copy of _path_files,
the line numbers reported by xtrace appear to be somewhat off).

This correctly leaves the right set of matches in tmp1, but doesn't
actually add the matches yet.  That happens down after line 440 or so,
after "if (( tmp4 ))" is tested, and the actual compadd is:

compadd -Qf -J -default- -F _comp_ignore -p '' -W '' -M "r:|/=* r:|=*" - ...

where the "..." is still the intended set of matches.

But none of those actually match what's on the line; the "L:|..." has
been lost, so (AFAICT) the presence of "no" on the line causes them all
to be discarded.

The following patch causes it to work by preserving the passed-in match
specs on *every* call to compadd, simply appending the one _path_files
supplied itself, but I'm not sure what else this might break.

Please don't apply this patch until Sven chimes in.  Sven?

Index: Completion/Core/_path_files
===================================================================
@@ -458,26 +458,26 @@
         if [[ "$tmp3" = */* ]]; then
 	  compadd -Qf "$mopts[@]" -p "$linepath$tmp2" -s "/${tmp3#*/}" \
 	          -W "$prepath$realpath$testpath" \
-		  "$pfxsfx[@]" -M "r:|/=* r:|=*" \
+		  "$pfxsfx[@]" "$matcher[@]" "r:|/=* r:|=*" \
 		  - "${(@)tmp1%%/*}"
 	else
 	  compadd -Qf "$mopts[@]" -p "$linepath$tmp2" \
 	          -W "$prepath$realpath$testpath" \
-		   "$pfxsfx[@]" -M "r:|/=* r:|=*" \
+		   "$pfxsfx[@]" "$matcher[@]" "r:|/=* r:|=*" \
 		   - "$tmp1[@]"
 	fi
       else
         if [[ "$tmp3" = */* ]]; then
 	  atmp=( -Qf "$mopts[@]" -p "$linepath$tmp2"
 	         -W "$prepath$realpath$testpath"
-	         "$pfxsfx[@]" -M "r:|/=* r:|=*" )
+	         "$pfxsfx[@]" "$matcher[@]" "r:|/=* r:|=*" )
           for i in "$tmp1[@]"; do
 	    compadd "$atmp[@]" -s "/${i#*/}" - "${i%%/*}"
 	  done
         else
 	  compadd -Qf "$mopts[@]" -p "$linepath$tmp2" \
                   -W "$prepath$realpath$testpath" \
-		  "$pfxsfx[@]" -M "r:|/=* r:|=*" \
+		  "$pfxsfx[@]" "$matcher[@]" "r:|/=* r:|=*" \
 		  - "$tmp1[@]"
         fi
       fi
@@ -525,7 +525,7 @@
     tmp4="$testpath"
     compquote tmp4 tmp1
     compadd -Qf "$mopts[@]" -p "$linepath$tmp4" -W "$prepath$realpath$testpath" \
-	    "$pfxsfx[@]" -M "r:|/=* r:|=*" - "$tmp1[@]"
+	    "$pfxsfx[@]" "$matcher[@]" "r:|/=* r:|=*" - "$tmp1[@]"
   fi
 done
 
@@ -541,7 +541,7 @@
   if (( $#exppaths )); then
     PREFIX="${opre}"
     SUFFIX="${osuf}"
-    compadd -Q "$mopts[@]" -S '' -M "r:|/=* r:|=*" -p "$linepath" - "$exppaths[@]"
+    compadd -Q "$mopts[@]" -S '' "$matcher[@]" "r:|/=* r:|=*" -p "$linepath" - "$exppaths[@]"
   fi
 fi
 

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



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