zsh-users
 help / color / mirror / code / Atom feed
* Help with completion of option arguments
@ 2005-07-08  7:06 Travis Spencer
  2005-07-09  7:02 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Travis Spencer @ 2005-07-08  7:06 UTC (permalink / raw)
  To: zsh-users

Hey,

I have a command for which I'm trying to write a completion widget. 
The command has options that take arguments that must follow the
option without any white space.  For example, the command takes
options such as these: `-A', `-Aa', `-B', and `-Bb'.  But these option
arguments are invalid because of the space: `-A a' and `-B b'.  I have
figured out how to enable the completion for `-A' and `-B' before any
space is entered with a command such as this:

_arguments -C \
    "-A-[this is a test]:test:((a\:'test sub-message'))"
    "-B-[notify (e-mail) admins]:notify:((
          b\:'suppress interactive query (for use in crontab)'))"

But the problem is, with only a single argument like this, after
typing `-A' or `-B', the sole completion `a' and `b' are run rather
than outputting the descriptions.

Is there some way to get _arguments to output the messages `test
sub-message' and `suppress interactive query (for use in crontab)'
when `-A' or `-B' have been input rather than completing them
directly?

TIA.

-- 

Regards,

Travis Spencer
Portland, OR USA


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

* Re: Help with completion of option arguments
  2005-07-08  7:06 Help with completion of option arguments Travis Spencer
@ 2005-07-09  7:02 ` Bart Schaefer
  2005-07-09  8:42   ` Travis Spencer
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2005-07-09  7:02 UTC (permalink / raw)
  To: zsh-users

On Jul 8, 12:06am, Travis Spencer wrote:
} Subject: Help with completion of option arguments
}
} I have a command for which I'm trying to write a completion widget. 
} 
} _arguments -C \
}     "-A-[this is a test]:test:((a\:'test sub-message'))"
}     "-B-[notify (e-mail) admins]:notify:((
}           b\:'suppress interactive query (for use in crontab)'))"

This wouldn't work as written, because you left off the backslash on
the second line, and because -A is an *option of* _arguments, so it
is necessary to use
    _arguments -C : "-A-..."
in order to get "-A-..." to be treated as an *argument* of _arguments.

I mention this to point out that it's almost always better to show the
real example you're working with, rather than attempt to make up an
equivalent one.  The exception would be when you're showing a minimal
test case for a bug, but then you should have tried the example to be
sure it demonstrates what you intend it to.

By the way, does your call to _arguments use the ->state mechanism at
any point?  If not, you don't need the -C in there.

} The command has options that take arguments that must follow the
} option without any white space.  For example, the command takes
} options such as these: `-A', `-Aa', `-B', and `-Bb'.
} 
} But the problem is, with only a single argument like this, after
} typing `-A' or `-B', the sole completion `a' and `b' are run rather
} than outputting the descriptions.

I interpret this to mean that you're trying to use the completion as a
sort of interactive help lookup ("I don't remember what -A does, please
tell me").  If that's what you want, don't press TAB to complete further;
rather, type ctrl-d (or whatever you have bound to list-choices) to show
the possible alternatives.

However, the literal answer to your question ...

} Is there some way to get _arguments to output the messages `test
} sub-message' and `suppress interactive query (for use in crontab)'
} when `-A' or `-B' have been input rather than completing them
} directly?

... is, insert an empty string element into the double-parens like this:

_arguments : \
    "-A-[this is a test]:test:(('' a\:'test sub-message'))" \
    "-B-[notify (e-mail) admins]:notify:((''
	b\:'suppress interactive query (for use in crontab)'))"


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

* Re: Help with completion of option arguments
  2005-07-09  7:02 ` Bart Schaefer
@ 2005-07-09  8:42   ` Travis Spencer
  2005-07-09 17:21     ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Travis Spencer @ 2005-07-09  8:42 UTC (permalink / raw)
  To: zsh-users

On 7/9/05, Bart Schaefer <schaefer@brasslantern.com> wrote:
> I mention this to point out that it's almost always better to show the
> real example you're working with, rather than attempt to make up an
> equivalent one.  The exception would be when you're showing a minimal
> test case for a bug, but then you should have tried the example to be
> sure it demonstrates what you intend it to.

OK.  I'll do that next time for sure.  Sorry about the confusion.  The
completion, which is my first, is at
http://www.travisspencer.com/scripts/_snot.txt.  I'm kinda pleased
with the way it turned out.  Thanks for all the help with it, Bart!

> By the way, does your call to _arguments use the ->state mechanism at
> any point?  If not, you don't need the -C in there.

Ya, I am using the state mechanism.

> However, the literal answer to your question ...
> 
> } Is there some way to get _arguments to output the messages `test
> } sub-message' and `suppress interactive query (for use in crontab)'
> } when `-A' or `-B' have been input rather than completing them
> } directly?
> 
> ... is, insert an empty string element into the double-parens like this:
> 
> _arguments : \
>     "-A-[this is a test]:test:(('' a\:'test sub-message'))" \
>     "-B-[notify (e-mail) admins]:notify:((''
>         b\:'suppress interactive query (for use in crontab)'))"

Wow. Tricky.  I would never have figured that out on my own.

-- 

Regards,

Travis Spencer
Portland, OR USA


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

* Re: Help with completion of option arguments
  2005-07-09  8:42   ` Travis Spencer
@ 2005-07-09 17:21     ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2005-07-09 17:21 UTC (permalink / raw)
  To: zsh-users

On Jul 9,  1:42am, Travis Spencer wrote:
} Subject: Re: Help with completion of option arguments
}
} > ... is, insert an empty string element into the double-parens like this:
} > 
} > _arguments : \
} >     "-A-[this is a test]:test:(('' a\:'test sub-message'))" \
} >     "-B-[notify (e-mail) admins]:notify:((''
} >         b\:'suppress interactive query (for use in crontab)'))"
} 
} Wow. Tricky.  I would never have figured that out on my own.

You might have.  '-A' by itself is '-A' with an empty argument, right?

Try it this way to see better:

_arguments : \
    "-A-[this is a test]:test:(('\:by itself, -A is a simple test'
        a\:'with this argument, -A tests a sub-message'))"


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

end of thread, other threads:[~2005-07-09 18:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-08  7:06 Help with completion of option arguments Travis Spencer
2005-07-09  7:02 ` Bart Schaefer
2005-07-09  8:42   ` Travis Spencer
2005-07-09 17:21     ` Bart Schaefer

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