zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ifh.de>
To: zsh-workers@math.gatech.edu (Zsh hackers list), zsh@peak.org
Subject: PATCH: allow scalars as completion variables
Date: Thu, 20 Nov 1997 14:39:34 +0100	[thread overview]
Message-ID: <199711201339.OAA01692@hydra.ifh.de> (raw)
In-Reply-To: "Peter Stephenson"'s message of "Thu, 20 Nov 1997 10:22:29 MET." <199711200922.KAA06895@sgi.ifh.de>

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


  reply	other threads:[~1997-11-20 13:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-11-19 17:00 PATCH: User-defined completion listing Peter Stephenson
1997-11-19 19:41 ` Bart Schaefer
1997-11-20  9:22   ` Peter Stephenson
1997-11-20 13:39     ` Peter Stephenson [this message]
1997-11-20 16:57     ` Bart Schaefer
1997-11-21  9:26       ` Peter Stephenson
1997-11-21 18:39         ` Bart Schaefer
1997-11-27 10:10           ` PATCH: completion lists revisted Peter Stephenson

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=199711201339.OAA01692@hydra.ifh.de \
    --to=pws@ifh.de \
    --cc=zsh-workers@math.gatech.edu \
    --cc=zsh@peak.org \
    /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).