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

PATCH: 3.1.5-pws-8: using pattern completions



Unless I'm missing a patch or two, pattern completions aren't handled
properly.  They work rather differently, so it's necessary to pass extra
arguments to callcomplete.  Possibly these could be passed anyway, saving
an array look-up in most cases.

Now, can anyone tell me how to avoid getting a default completion list for
the pattern completions as well?  This is rather crucial since I'm trying
to get all zf* files to use zftp completion, and I don't want a side dish
of local filenames with every order.

--- Functions/Completion/__normal.pat	Fri Feb 19 10:50:41 1999
+++ Functions/Completion/__normal	Fri Feb 19 10:50:57 1999
@@ -24,11 +24,13 @@
 # See if there are any matching pattern completions.
 
 if (( $#patcomps )); then
+  integer num
   for i in "$patcomps[@]"; do
-    pat="${i% *}"
+    (( num++ ))
+    pat="${i%% *}"
     val="${i#* }"
     if [[ "$cmd1" == $~pat || "$cmd2" == $~pat ]]; then
-      callcomplete patcomps "$pat" "$@" || return 1
+      callcomplete -d "$pat" "$val" patcomps "$num" "$@" || return 1
     fi
   done
 fi
--- Functions/Completion/init.pat	Fri Feb 19 10:50:41 1999
+++ Functions/Completion/init	Fri Feb 19 10:50:57 1999
@@ -175,11 +175,19 @@
 # to the completion function (containing the arguments from the command line).
 
 callcomplete() {
-  local file def
+  local file def pat
 
-  # Get the definition from the array.
-
-  eval "def=\$${1}[${2}]"
+  if [[ $1 = -d ]]; then
+    # We've already got the definition.
+    shift
+    pat=$1
+    shift
+    def=$1
+    shift
+  else
+    # Get the definition from the array.
+    eval "def=\$${1}[${2}]"
+  fi
 
   # If the definition starts with a space then this means that we should
   # source a file to get the definition for an array.
@@ -191,7 +199,11 @@
     file="$def[2,-1]"
     builtin . "$file"
     def="${file:t}"
-    eval "${1}[${2}]=$def"
+    if [[ -n $pat ]]; then
+      eval "${1}[${2}]='$pat $def'"
+    else
+      eval "${1}[${2}]=$def"
+    fi
   fi
 
   # Get rid of the array-name and -index.
@@ -236,7 +248,7 @@
       elif [[ $func = '#pattern-function' ]]; then
 	defpatcomp -a ${__i_file:t} "${__i_line[@]}"
       elif [[ $func = '#pattern-array' ]]; then
-	defcomp " $__i_file" "${__i_line[@]}"
+	defpatcomp " $__i_file" "${__i_line[@]}"
       elif [[ $func = '#key-function' ]]; then
 	defkeycomp -a "${__i_file:t}" "${__i_line[@]}"
       elif [[ $func = '#key-array' ]]; then

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxx>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy



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