From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2058 invoked from network); 19 Feb 1999 10:15:01 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 19 Feb 1999 10:15:01 -0000 Received: (qmail 6138 invoked by alias); 19 Feb 1999 10:14:09 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 5425 Received: (qmail 6130 invoked from network); 19 Feb 1999 10:14:04 -0000 Message-Id: <9902190958.AA20622@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 From: Peter Stephenson 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 Tel: +39 050 844536 WWW: http://www.ifh.de/~pws/ Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy