zsh-workers
 help / color / mirror / code / Atom feed
* _path_files and the -M option
@ 2000-02-27 20:41 Bart Schaefer
  0 siblings, 0 replies; only message in thread
From: Bart Schaefer @ 2000-02-27 20:41 UTC (permalink / raw)
  To: zsh-workers

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2000-02-27 20:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-02-27 20:41 _path_files and the -M option Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).