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

Re: match again



Andrej Borsenkow wrote:

> This does not work:
> 
> bor@itsrm2% patch -p0 --dry-run < /u/p/u/z/p/*/9441<TAB>
> 
> with settings
> 
> bor@itsrm2% compstyle -L
> compstyle ':correct:' prompt 'correct to:'
> ...

[ Time to use zstyle instead of compstyle (but maybe you just used it
for output?). ]

> 
> But this one does
> 
> bor@itsrm2% patch -p0 --dry-run <
> /u2/pub/unix/zsh/patches/3.1.6-dev-16/<9440-><TAB>
> bor@itsrm2% patch -p0 --dry-run < /u2/pub/unix/zsh/patches/3.1.6-dev-16/9441
> 9441   9442

I've already explained this at least twice. The problem is that the
completion code gets a PREFIX of the form f/*/b with
`compadd -p foo/baz/ - bar'. It tries to match `foo/baz/' with `f/*'
which doesn't work, because we can only either match the whole thing
with pattern matching (messing up braces and things) or do what we do
now, i.e. try to match the prefix (and suffix) normally and use
pattern matching for the strings (like `bar' in the example).

But we can try to make _path_files a bit cleverer... the patch below
makes it stop its ambiguous-part searching loop if it arrives at a
part with a pattern. It then changes the way the cursor style is
tested to hopefully give more sensible behaviour.

Andrej, is this, finally, acceptable for you?

Bye
 Sven

diff -ru ../z.old/Completion/Core/_path_files Completion/Core/_path_files
--- ../z.old/Completion/Core/_path_files	Fri Jan 28 10:23:55 2000
+++ Completion/Core/_path_files	Fri Jan 28 10:58:33 2000
@@ -172,7 +172,7 @@
 eorig="$orig"
 
 [[ $compstate[insert] = (*menu|[0-9]*) || -n "$_comp_correct" ||
-   ( $#compstate[pattern_match] -ne 0 &&
+   ( -n "$compstate[pattern_match]" &&
      "${orig#\~}" != "${${orig#\~}:q}" ) ]] && menu=yes
 
 # If given no `-F' option, we may want to use $fignore, turned into patterns.
@@ -442,7 +442,17 @@
       tmp4=( "${(@)tmp1:#${tmp1[1]}}" )
     fi
 
-    if (( $#tmp4 )); then
+    if [[ "$tpre" = */* ]]; then
+      PREFIX="${donepath}${linepath}${cpre}${tpre%%/*}"
+      SUFFIX="/${tsuf#*/}"
+    else
+      PREFIX="${donepath}${linepath}${cpre}${tpre}"
+      SUFFIX="${tsuf}"
+    fi
+
+    if (( $#tmp4 )) ||
+       [[ -n "$compstate[pattern_match]" &&
+          "$PREFIX$SUFFIX" != "${(q)PREFIX}${(q)SUFFIX}" ]]; then
 
       # It is. For menucompletion we now add the possible completions
       # for this component with the unambigous prefix we have built
@@ -451,29 +461,21 @@
       # collected as the suffixes to make the completion code expand
       # it as far as possible.
 
-      if [[ "$tpre" = */* ]]; then
-        PREFIX="${donepath}${linepath}${cpre}${tpre%%/*}"
-	SUFFIX="/${tsuf#*/}"
-      else
-        PREFIX="${donepath}${linepath}${cpre}${tpre}"
-	SUFFIX="${tsuf}"
-      fi
-
-      tmp4="$testpath"
-      compquote tmp1 tmp4
+      tmp2="$testpath"
+      compquote tmp1 tmp2
 
       if [[ -n $menu ]] ||
          ! zstyle -t ":completion${curcontext}:paths" expand suffix; then
-        zstyle -t ":completion${curcontext}:paths" cursor &&
+        (( $#tmp4 )) && zstyle -t ":completion${curcontext}:paths" cursor &&
             compstate[to_end]=''
         if [[ "$tmp3" = */* ]]; then
-	  compadd -Qf "$mopts[@]" -p "$linepath$tmp4" -s "/${tmp3#*/}" \
+	  compadd -Qf "$mopts[@]" -p "$linepath$tmp2" -s "/${tmp3#*/}" \
 	          -W "$prepath$realpath$testpath" \
 		  "$addpfx[@]" "$addsfx[@]" "$remsfx[@]" \
                   -M "r:|/=* r:|=* $mspec" "$group[@]" "$expl[@]" \
 		  - "${(@)tmp1%%/*}"
 	else
-	  compadd -Qf "$mopts[@]" -p "$linepath$tmp4" \
+	  compadd -Qf "$mopts[@]" -p "$linepath$tmp2" \
 	          -W "$prepath$realpath$testpath" \
 		   "$addpfx[@]" "$addsfx[@]" "$remsfx[@]" \
                    -M "r:|/=* r:|=* $mspec" "$group[@]" "$expl[@]" \
@@ -481,7 +483,7 @@
 	fi
       else
         if [[ "$tmp3" = */* ]]; then
-	  atmp=( -Qf "$mopts[@]" -p "$linepath$tmp4"
+	  atmp=( -Qf "$mopts[@]" -p "$linepath$tmp2"
 	         -W "$prepath$realpath$testpath"
 	         "$addpfx[@]" "$addsfx[@]" "$remsfx[@]"
                  -M "r:|/=* r:|=* $mspec" "$group[@]" "$expl[@]" )
@@ -489,7 +491,7 @@
 	    compadd "$atmp[@]" -s "/${i#*/}" - "${i%%/*}"
 	  done
         else
-	  compadd -Qf "$mopts[@]" -p "$linepath$tmp4" \
+	  compadd -Qf "$mopts[@]" -p "$linepath$tmp2" \
 		  -W "$prepath$realpath$testpath" \
 		  "$addpfx[@]" "$addsfx[@]" "$remsfx[@]" \
                   -M "r:|/=* r:|=* $mspec" "$group[@]" "$expl[@]" \

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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