zsh-users
 help / color / mirror / code / Atom feed
* In the tla completion function: "${(@P)var_cmd-*:FILE:_files}"
@ 2004-08-16 21:32 Haakon Riiser
  2004-08-17  0:52 ` Jason McCarty
  0 siblings, 1 reply; 5+ messages in thread
From: Haakon Riiser @ 2004-08-16 21:32 UTC (permalink / raw)
  To: zsh-users

I was just browsing through the new completion function for tla
in zsh 4.2.1, and I was wondering about the expression shown in
the subject:

  "${(@P)var_cmd-*:FILE:_files}"

>From what I've read in the manual, I'd guess that the @ flag is
a harmless bug that has no effect since $var_cmd is not an array,
and that the P flag makes the expression expand to the expansion of
the variable name contained in $var_cmd, if $var_cmd is defined;
if $var_cmd is not defined, I'd expect the expansion to give the
string after the '-':

  *:FILE:_files

I tried it out in an interactive session, but the '-' expansion
doesn't work.

  ##
  ## This works:
  ##
  % myvar=hello
  % foo=myvar
  % echo "${(@P)foo-bar}"
  hello

  ##
  ## This does not:
  ##
  % unset foo
  % echo "${(@P)foo-bar}"
  zsh: bad substitution

Is this a bug in the completion file that has gone unnoticed
because var_cmd has always been defined?

-- 
 Haakon


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: In the tla completion function: "${(@P)var_cmd-*:FILE:_files}"
  2004-08-16 21:32 In the tla completion function: "${(@P)var_cmd-*:FILE:_files}" Haakon Riiser
@ 2004-08-17  0:52 ` Jason McCarty
  2004-08-20  8:55   ` Haakon Riiser
  0 siblings, 1 reply; 5+ messages in thread
From: Jason McCarty @ 2004-08-17  0:52 UTC (permalink / raw)
  To: zsh-users

Haakon Riiser wrote:
> I was just browsing through the new completion function for tla
> in zsh 4.2.1, and I was wondering about the expression shown in
> the subject:
> 
>   "${(@P)var_cmd-*:FILE:_files}"
> 
> >From what I've read in the manual, I'd guess that the @ flag is
> a harmless bug that has no effect since $var_cmd is not an array,
> and that the P flag makes the expression expand to the expansion of
> the variable name contained in $var_cmd, if $var_cmd is defined;

First the value of $var_cmd is substituted by "P", and then the value of
the resulting variable (which is an array) is prevented from being
joined by "@". See rules 3 and 4 in the "Parameter Expansion" section of
zshexpn(1).

> if $var_cmd is not defined, I'd expect the expansion to give the
> string after the '-':

$var_cmd is always defined to something of the form "cmd_*" on line 658.
I believe the P flag is evaluated before the - expansion, although I
don't see an explicit mention of it in the manpage. The variable named
by $var_cmd may or may not be defined, which is where the - expansion
comes into play.

I'm afraid I came up with many of my fancy substitutions by trial and
error ;-)

> Is this a bug in the completion file that has gone unnoticed
> because var_cmd has always been defined?

So no, I don't believe so. HTH,

-- 
Jason McCarty <bclg@iup.edu>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: In the tla completion function: "${(@P)var_cmd-*:FILE:_files}"
  2004-08-17  0:52 ` Jason McCarty
@ 2004-08-20  8:55   ` Haakon Riiser
  2004-08-20 16:05     ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Haakon Riiser @ 2004-08-20  8:55 UTC (permalink / raw)
  To: zsh-users

[Jason McCarty]

> > if $var_cmd is not defined, I'd expect the expansion to give the
> > string after the '-':
> 
> $var_cmd is always defined to something of the form "cmd_*" on line 658.
> I believe the P flag is evaluated before the - expansion, although I
> don't see an explicit mention of it in the manpage. The variable named
> by $var_cmd may or may not be defined, which is where the - expansion
> comes into play.
> 
> I'm afraid I came up with many of my fancy substitutions by trial and
> error ;-)

Hmm, strange that my shell gives 'bad substitution' when var_cmd
is not defined.

  % unset var_cmd
  % echo "${(@P)var_cmd-*:FILE:_files}"
  zsh: bad substitution

In your case, the result is

  % unset var_cmd
  % echo "${(@P)var_cmd-*:FILE:_files}"
  *:FILE:_files

Right?

-- 
 Haakon


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: In the tla completion function: "${(@P)var_cmd-*:FILE:_files}"
  2004-08-20  8:55   ` Haakon Riiser
@ 2004-08-20 16:05     ` Bart Schaefer
  2004-08-20 16:40       ` Haakon Riiser
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2004-08-20 16:05 UTC (permalink / raw)
  To: zsh-users

On Fri, 20 Aug 2004, Haakon Riiser wrote:

> [Jason McCarty]
> 
> > > if $var_cmd is not defined, I'd expect the expansion to give the
> > > string after the '-':
> > 
> > $var_cmd is always defined to something of the form "cmd_*" on line 658.
> 
> Hmm, strange that my shell gives 'bad substitution' when var_cmd
> is not defined.

So does Jason's, I'm sure.  Jason's point is that var_cmd should NEVER BE 
"not defined" in the _tla function.  It's defined at the point where it's 
declared, to be the second word on the command line.

>   % unset var_cmd
>   % echo "${(@P)var_cmd-*:FILE:_files}"
>   zsh: bad substitution

It is a little odd that ${(P)unset+full} and ${(P)unset-empty} don't both 
give this error.  Compare ${-empty} and ${:-empty} as well.  In any case 
the workaround is to use the ${(P)unset:-empty} form.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: In the tla completion function: "${(@P)var_cmd-*:FILE:_files}"
  2004-08-20 16:05     ` Bart Schaefer
@ 2004-08-20 16:40       ` Haakon Riiser
  0 siblings, 0 replies; 5+ messages in thread
From: Haakon Riiser @ 2004-08-20 16:40 UTC (permalink / raw)
  To: zsh-users

[Bart Schaefer]

>> Hmm, strange that my shell gives 'bad substitution' when
>> var_cmd is not defined.

> So does Jason's, I'm sure.  Jason's point is that var_cmd should
> NEVER BE "not defined" in the _tla function.  It's defined at the
> point where it's declared, to be the second word on the command
> line.

OK, now I get it; the '-' fallback doesn't test var_cmd, but
the variable named by the expansion of $var_cmd:

  % unset foo
  % var_cmd=foo
  % echo "${(@P)var_cmd-*:FILE:_files}"
  *:FILE:_files

-- 
 Haakon


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-08-20 16:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-16 21:32 In the tla completion function: "${(@P)var_cmd-*:FILE:_files}" Haakon Riiser
2004-08-17  0:52 ` Jason McCarty
2004-08-20  8:55   ` Haakon Riiser
2004-08-20 16:05     ` Bart Schaefer
2004-08-20 16:40       ` Haakon Riiser

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).