zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: Zsh users list <zsh-users@sunsite.dk>
Subject: Fw: Re: _arguments: repeated option with multiple optargs
Date: Wed, 20 Sep 2006 10:06:25 +0100	[thread overview]
Message-ID: <20060920100625.78614b8e.pws@csr.com> (raw)

I meant to send this to the list, not just to Roman...

Roman Neuhauser <neuhauser@sigpipe.cz> wrote:
> _arguments -s : '*-r=::->file:*:::->test'
> 
> does exactly what the manual say it does, IOW all the remaining words on
> the line are to be completed as described by the action. That's not what
> I want, though: the whole (-r file 1*test) can be repeated, and I'd like
> it to offer also -r.
> 
> Can _arguments do this for me somehow, or is this up to me?

I haven't much experience with multiple arguments, but it looks from the
manual page like you ought to be able to tell it that it should stop at the
next argument that starts with -r; which isn't logically correct, but ought
to do the trick:

              Each optarg following an optspec must take one of the  following
              forms:
...
              :*pattern:message:action
              :*pattern::message:action
              :*pattern:::message:action
                     This  describes multiple arguments.  Only the last optarg
                     for an option taking multiple arguments may be  given  in
                     this  form.  If the pattern is empty (i.e., :*:), all the
                     remaining words on  the  line  are  to  be  completed  as
                     described by the action; otherwise, all the words up to a
                     word matching the pattern are to be completed  using  the
                     action.

(Typically, it never actually defines what it means by an "optarg", but it
obviously means everything from the first colon onwards.)  It's quite
possible this isn't well tested.  The guy who wrote _arguments (and most of
the rest of the completion system) has been in hiding for several years.

However, I don't think _arguments is very good at this sort of complexity.
Somewhere there's a parser that implements a finite state machine for
completion arguments, but currently no one in the entire world understands
that.  It could do with resurrecting in a more friendly fashion.

When things get complicated, I tend to use the *::<stuff>:<morestuff> form
of argument which restricts the command line to the arguments I'm looking
at and take it from there.  It usually means a call to an additional
_arguments (in Unix/Command/_perforce, for example, which isn't a
particularly simple example).  However, I'm really thinking of the case
where you have something like <cmd> <subcmd> <subcmd-specific-args>, which
is a little different from what you've got.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php


             reply	other threads:[~2006-09-20  9:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-20  9:06 Peter Stephenson [this message]
2006-09-20 15:50 ` Bart Schaefer

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=20060920100625.78614b8e.pws@csr.com \
    --to=pws@csr.com \
    --cc=zsh-users@sunsite.dk \
    /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).