From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21405 invoked from network); 20 Nov 1997 13:52:54 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 20 Nov 1997 13:52:54 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id IAA25728; Thu, 20 Nov 1997 08:39:27 -0500 (EST) Resent-Date: Thu, 20 Nov 1997 08:39:27 -0500 (EST) Message-Id: <199711201339.OAA01692@hydra.ifh.de> To: zsh-workers@math.gatech.edu (Zsh hackers list), zsh@peak.org Subject: PATCH: allow scalars as completion variables In-reply-to: "Peter Stephenson"'s message of "Thu, 20 Nov 1997 10:22:29 MET." <199711200922.KAA06895@sgi.ifh.de> Date: Thu, 20 Nov 1997 14:39:34 +0100 From: Peter Stephenson Resent-Message-ID: <"0XpBK1.0.wH6.Fs3Tq"@math> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/3626 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu Peter Stephenson wrote: > "Bart Schaefer" wrote: > > If you're going to expand a variable, why does it have to be an array? > > The parameter to -X is just a string. > > Because -Y replaces a list; it's natural to generate the replacement > list as an array. As with literal arrays (quoted below), I'd quite > like to alter get_user_var() to turn a scalar into a single element > array, which will solve this problem quite neatly, it just wasn't > a necessary part of yesterday's patch. I certainly agree it's > desirable. Here's the corresponding patch: with this, any of the usual uses of variables within completion (including "reply") will allow a scalar, which is turned internally into a one-element array. I didn't implement my other suggestion because it was treated with scorn. This will work independently of the -Y patch, apart from the manual entry. (And I've finally updated my signature. I was waiting for an account here, but doomsday's a long way off at the moment, so if it looks oddly international, that's why.) *** Doc/Zsh/compctl.yo.YoY2 Wed Nov 19 17:34:51 1997 --- Doc/Zsh/compctl.yo Thu Nov 20 14:29:42 1997 *************** *** 365,372 **** The list provided by var(func-or-var) is displayed instead of the list of completions whenever a listing is required; the actual completions to be inserted are not affected. It can be provided in two ! ways. Firstly, if var(func-or-var) begins with a tt($) it defines an ! array variable, or if it begins with a left parenthesis a literal array, which contains the list. A variable may have been set by a call to a function using the tt(-K) option. Otherwise it contains the name of a function which will be executed to create the list. The --- 365,372 ---- The list provided by var(func-or-var) is displayed instead of the list of completions whenever a listing is required; the actual completions to be inserted are not affected. It can be provided in two ! ways. Firstly, if var(func-or-var) begins with a tt($) it defines a ! variable, or if it begins with a left parenthesis a literal array, which contains the list. A variable may have been set by a call to a function using the tt(-K) option. Otherwise it contains the name of a function which will be executed to create the list. The *************** *** 376,383 **** only be retrieved after a complete list of matches has been created. Note that the returned list does not have to correspond, even in ! length, to the original set of matches; the use of an array is purely ! a convenience for formatting. No special formatting of characters is performed on the output in this case; in particular, newlines are printed literally and if they appear output in columns is suppressed. ) --- 376,383 ---- only be retrieved after a complete list of matches has been created. Note that the returned list does not have to correspond, even in ! length, to the original set of matches, and may be passed as a scalar ! instead of an array. No special formatting of characters is performed on the output in this case; in particular, newlines are printed literally and if they appear output in columns is suppressed. ) *** Src/Zle/zle_tricky.c.YoY2 Wed Nov 19 17:46:32 1997 --- Src/Zle/zle_tricky.c Thu Nov 20 14:16:01 1997 *************** *** 3156,3164 **** while ((*aptr++ = (char *)ugetnode(arrlist))); uarr[count] = NULL; return uarr; ! } else /* Otherwise it should be a parameter name. */ ! return getaparam(nam); } /* This is strcmp with ignoring backslashes. */ --- 3156,3172 ---- while ((*aptr++ = (char *)ugetnode(arrlist))); uarr[count] = NULL; return uarr; ! } else { /* Otherwise it should be a parameter name. */ ! char **arr = NULL, *val; ! if (!(arr = getaparam(nam)) && (val = getsparam(nam))) { ! arr = (char *)ncalloc(2*sizeof(char *)); ! arr[0] = val; ! arr[1] = NULL; ! } ! return arr; ! } ! } /* This is strcmp with ignoring backslashes. */ -- Peter Stephenson Tel: +39 50 911239 WWW: http://www.ifh.de/~pws/ Dipartimento di Fisica Teorica Piazza Torricelli 2, 56100 Pisa, Italy