zsh-users
 help / color / mirror / code / Atom feed
* Setting state in _arguments
@ 2013-01-16  9:47 Jesper Nygårds
  2013-01-16 13:43 ` Oliver Kiddle
  0 siblings, 1 reply; 3+ messages in thread
From: Jesper Nygårds @ 2013-01-16  9:47 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1265 bytes --]

I am trying to improve the completion for the gradle command, and have run
into something I cannot explain. To simplify things as much as possible, I
have constructed this example file, calling it _myfoo:

#compdef myfoo

local curcontext="$curcontext" ret=1 state

_arguments -C \
    '--option1' \
    '--option2' \
    '*:a subcommand:->subcommand' \
    && ret=0

if [[ -n $state ]]; then
   print state: $state > /dev/pty2
fi

return ret

On the command line, I write: "myfoo --<tab>", and the completion kicks in
and gives me the options "--option1" and "--option2", which is what I
expected. However, on /dev/pty2 I see "state: subcommand", which I did NOT
expect. I would have thought that since only "--option1" or "--option2"
could possibly match after "--", state would not have been set*, *but it is.

The trouble with this is that in the gradle completion, the possible
subcommands are generated inside the if statement in this case, and thatis
time consuming. I would thus like to avoid going into it when the "--" on
the command line indicates that an option should be completed.

I would have thought that the call to _arguments did not set state since
found some matching options, but obviously I am using it incorrectly. What
should I do instead?

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

* Re: Setting state in _arguments
  2013-01-16  9:47 Setting state in _arguments Jesper Nygårds
@ 2013-01-16 13:43 ` Oliver Kiddle
  2013-01-17  6:39   ` Jesper Nygårds
  0 siblings, 1 reply; 3+ messages in thread
From: Oliver Kiddle @ 2013-01-16 13:43 UTC (permalink / raw)
  To: Jesper Nygårds; +Cc: zsh-users

=?ISO-8859-1?Q?Jesper_Nyg=E5rds?= wrote:
> On the command line, I write: "myfoo --<tab>", and the completion kicks in
> and gives me the options "--option1" and "--option2", which is what I
> expected. However, on /dev/pty2 I see "state: subcommand", which I did NOT
> expect. I would have thought that since only "--option1" or "--option2"
> could possibly match after "--", state would not have been set*, *but it is.

_arguments has no way of knowing that subcommands can't begin with "--"
so while it adds the completion matches for the options, it also
considers the *:... rule to be applicable.

> The trouble with this is that in the gradle completion, the possible
> subcommands are generated inside the if statement in this case, and thatis
> time consuming. I would thus like to avoid going into it when the "--" on
> the command line indicates that an option should be completed.

You can perform some explicit tests before starting the time consuming
operation, perhaps test whether the current word starts with "--".

Oliver


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

* Re: Setting state in _arguments
  2013-01-16 13:43 ` Oliver Kiddle
@ 2013-01-17  6:39   ` Jesper Nygårds
  0 siblings, 0 replies; 3+ messages in thread
From: Jesper Nygårds @ 2013-01-17  6:39 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 359 bytes --]

On Wed, Jan 16, 2013 at 2:43 PM, Oliver Kiddle <okiddle@yahoo.co.uk> wrote:

> _arguments has no way of knowing that subcommands can't begin with "--"
> so while it adds the completion matches for the options, it also
> considers the *:... rule to be applicable.
>

Ah, now I see. I had the wrong mental picture of what was going on. Thank
you for your help.

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

end of thread, other threads:[~2013-01-17  6:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-16  9:47 Setting state in _arguments Jesper Nygårds
2013-01-16 13:43 ` Oliver Kiddle
2013-01-17  6:39   ` Jesper Nygårds

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