zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ibmth.df.unipi.it>
To: zsh-workers@sunsite.auc.dk (Zsh hackers list)
Subject: PATCH: 3.1.5-pws-8: using pattern completions
Date: Fri, 19 Feb 1999 10:58:16 +0100	[thread overview]
Message-ID: <9902190958.AA20622@ibmth.df.unipi.it> (raw)

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@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy


             reply	other threads:[~1999-02-19 10:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-02-19  9:58 Peter Stephenson [this message]
1999-02-19 10:27 ` Peter Stephenson
1999-02-19 10:33 ` Peter Stephenson
1999-02-22 13:28   ` Peter Stephenson
1999-02-19 11:12 Sven Wischnowsky
1999-02-19 14:53 ` Peter Stephenson
1999-02-19 11:46 Sven Wischnowsky
1999-02-22  7:51 Sven Wischnowsky
1999-02-22 13:44 Sven Wischnowsky
1999-02-22 14:07 Sven Wischnowsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9902190958.AA20622@ibmth.df.unipi.it \
    --to=pws@ibmth.df.unipi.it \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).