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

Re: Tar file and Re: Bad interaction between -iprefix and -string



Sven Wischnowsky wrote:
> If Peter sends us his autoloading stuff, maybe we can join all the
> nice ideas both of us had.

You've done a good bit more than I have; most of my time was spent
constructing replacement functions.  I found a couple of problems.
One was that autoloaded arrays needed an extra "" around to allow null
elements to be passed through; I found this from complist -H 0 ''
which was dropping the last part.  Another was that for some reason

for i in "$patcomps[@]"; do

was being called when patcomps was empty (should it really do that?)
when was calling all sorts of bother, so I added a (( $#patcomps ))
test.

>   - I also added support for Peter-like (sorry ;-) special completion
>     keys, see the comment in `init'

I think this could be a bit neater: in the patch, the widget defined
now has the same name as the file with the #key-array or #key-function
in it.  This was easy, it just needed $keycomps to be an assoc array.
This would be a limitation if you wanted to have widgets of a
different type (e.g. listing instead of completing) associated with
the same function; we could concatenate the names in that case.  I
vaguely thought of some extension to allow binding of multiple keys at
once by this, either
  #key-array \e/ \M/ history-complete
or perhaps better
  #key-array history-complete \e/ \M/
but I haven't done that here.

--- Misc/Completion/init	Thu Feb 11 16:16:40 1999
+++ /home/user2/pws/bin/comp/init	Thu Feb 11 17:38:02 1999
@@ -56,7 +56,7 @@
 # are the names of the command, the values are names of functions or variables
 # that are to be used to generate the matches.
 # Pattern completions will be stored in an normal array named `patcomps'.
-# Completion definitions bound directly to keys are store in an array
+# Completion definitions bound directly to keys are store in an assoc array
 # named `keycomps'.
 
 typeset -A comps
@@ -166,7 +166,7 @@
   if [[ ${(P)+def} -eq 1 ]]; then
     # It is a parameter name, call complist directly.
 
-    complist ${(@P)def}
+    complist "${(@P)def}"
   else
     # Otherwise it's a function name, call this function.
 
@@ -177,9 +177,10 @@
 
 # Now we make the files automatically autoloaded.
 
-local dir file line key=1
+local dir file line
 
 for dir in $fpath; do
+  [[ $dir = . ]] && continue
   for file in $dir/__*~*~(N); do
     read -rA line < $file
     if [[ $line[1] = '#function' ]]; then
@@ -191,16 +192,16 @@
     elif [[ $line[1] = '#pattern-array' ]]; then
       defcomp " $file" "$line[2]"
     elif [[ $line[1] = '#key-function' ]]; then
-      zle -C __complete_key_$key $line[3] __main_key_complete
-      bindkey "$line[2]" __complete_key_$key
+      (( ${+keycomps} )) || typeset -A keycomps
+      zle -C ${file:t} $line[3] __main_key_complete
+      bindkey "$line[2]" ${file:t}
       autoload ${file:t}
-      keycomps[key]=${file:t}
-      (( key++ ))
+      keycomps[${file:t}]=${file:t}
     elif [[ $line[1] = '#key-array' ]]; then
-      zle -C __complete_key_$key $line[3] __main_key_complete
-      bindkey "$line[2]" __complete_key_$key
-      keycomps[key]=" $file"
-      (( key++ ))
+      (( ${+keycomps} )) || typeset -A keycomps
+      zle -C ${file:t} $line[3] __main_key_complete
+      bindkey "$line[2]" ${file:t}
+      keycomps[${file:t}]=" $file"
     elif [[ $line[1] = '#helper' ]]; then
       autoload ${file:t}
     fi
--- Misc/Completion/__normal	Thu Feb 11 16:06:29 1999
+++ /home/user2/pws/bin/comp/__normal	Thu Feb 11 17:45:47 1999
@@ -23,13 +23,15 @@
 
 # See if there are any matching pattern completions.
 
-for i in "$patcomps[@]"; do
-  pat="${i% *}"
-  val="${i#* }"
-  if [[ "$cmd1" == $~pat || "$cmd2" == $~pat ]]; then
-    callcomplete patcomps "$pat" "$@" || return 1
-  fi
-done
+if (( $#patcomps )); then
+  for i in "$patcomps[@]"; do
+    pat="${i% *}"
+    val="${i#* }"
+    if [[ "$cmd1" == $~pat || "$cmd2" == $~pat ]]; then
+      callcomplete patcomps "$pat" "$@" || return 1
+    fi
+  done
+fi
 
 # Now look up the two names in the normal completion array.
 
-- 
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