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

PATCH: allow scalars as completion variables



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 <pws@xxxxxx>       Tel: +39 50 911239
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica Teorica
Piazza Torricelli 2, 56100 Pisa, Italy



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