zsh-users
 help / color / mirror / code / Atom feed
* Q: _regex_arguments problem
@ 2011-12-02 13:14 Alexey I. Froloff
  2011-12-02 15:45 ` Bart Schaefer
  2011-12-02 16:15 ` Peter Stephenson
  0 siblings, 2 replies; 6+ messages in thread
From: Alexey I. Froloff @ 2011-12-02 13:14 UTC (permalink / raw)
  To: zsh-users

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

Hi!

A have complex completion written on top or
_regex_words/_regex_arguments functions.  This looks like:

===8<===
#compdef fubar

_fubar_variants()
{
    local -a variants

    variants=( 'one' 'two' 'three' 'four' )
    _describe -t vatiant-id 'variant id' variants -V variants
}

local -a args reply
args=(
    # Command word.  Don't care what that is.
    /$'[^\0]#\0'/
)

local -a variant_any_id_arg
variant_any_id_arg=(
  /$'[^\0]##\0'/ ':variant-id:variant id:_fubar_variants'
)

local -a opt_args
_regex_words \
  fubar-options "fubar options" \
  '--variants:variants list:$variant_any_id_arg'
args+=(
  '(' "$reply[@]" '|' ')'
)

_regex_arguments _fubar "${args[@]}"

_fubar "$@"
===>8===

I want to complete --variants option argument as a
comma-separated list of variants, like

fubar --variants one,two,four

The only example of _regex_words/_regex_arguments usage is ip(8)
completion, but it doesn't use such syntax.

Is it possible at all?  _fubar_variants function is also used
where exactly one variant is required, so I'd rather not to
change it.

P.S. I'm not offering this completion to main tree because this
is a completion for special service only used in ALT Linux -
http://en.altlinux.org/Git.alt_reference

I uses complex context-based syntax (just like ip(8)!), so I
decided to use _regex_words/_regex_arguments.

-- 
Regards,    --
Sir Raorn.   --- http://thousandsofhate.blogspot.com/

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: Q: _regex_arguments problem
  2011-12-02 13:14 Q: _regex_arguments problem Alexey I. Froloff
@ 2011-12-02 15:45 ` Bart Schaefer
  2011-12-02 16:15 ` Peter Stephenson
  1 sibling, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 2011-12-02 15:45 UTC (permalink / raw)
  To: zsh-users

On Dec 2,  5:14pm, Alexey I. Froloff wrote:
}
} A have complex completion written on top or
} _regex_words/_regex_arguments functions.

You may be very nearly on your own here.  _regex_arguments was
written a very long time ago by someone who is no longer involved
with zsh development.  I don't think anyone has seriously looked
at it since.  We need some volunteers to become expert ...

} The only example of _regex_words/_regex_arguments usage is ip(8)
} completion, but it doesn't use such syntax.

_regex_arguments was written for Completion/Debian/Command/_apt, so
that's the canonical example.  If _regex_arguments has any feature
not used somewhere in _apt, I'd be surprised.

It's also used in:

Completion/X/Command/_xset
Completion/X/Command/_xwit
Completion/Unix/Command/_git
Completion/Zsh/Command/_ztodo

I wish you good hunting.


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

* Re: Q: _regex_arguments problem
  2011-12-02 13:14 Q: _regex_arguments problem Alexey I. Froloff
  2011-12-02 15:45 ` Bart Schaefer
@ 2011-12-02 16:15 ` Peter Stephenson
  2011-12-02 17:37   ` Alexey I. Froloff
  1 sibling, 1 reply; 6+ messages in thread
From: Peter Stephenson @ 2011-12-02 16:15 UTC (permalink / raw)
  To: zsh-users

On Fri, 2 Dec 2011 17:14:18 +0400
"Alexey I. Froloff" <raorn@altlinux.org> wrote:
> I want to complete --variants option argument as a
> comma-separated list of variants, like
> 
> fubar --variants one,two,four
> 
> The only example of _regex_words/_regex_arguments usage is ip(8)
> completion, but it doesn't use such syntax.

Even though I didn't use this in _ip I don't think it's too hard if you
approach it the right way...

The key point is that in this case you are given the whole command line
at once, joined with NULLs --- you are not matching against individual
words, you are partially matching bits of the command line until you get
to the command position, at which point it tries to complete whatever
the possible matches are at that point.  (That's why you tend to get all
those $'\0' strings around --- they're specifying the end of a word.)

So the idea is that when you have matched up to "fubar --variants one",
you need to tell it that at this point either you get end of word and a
new argument, or you get a "," and another variant.  If I'm right, that
ought to be fairly straightforward (but I've completely forgotten about
the details).

If I'm wrong, the may be some special fact about matching the end
of a word that I haven't twigged.  But I *think* it's general enough
to cope.

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


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog


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

* Re: Q: _regex_arguments problem
  2011-12-02 16:15 ` Peter Stephenson
@ 2011-12-02 17:37   ` Alexey I. Froloff
  2011-12-02 18:14     ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Alexey I. Froloff @ 2011-12-02 17:37 UTC (permalink / raw)
  To: zsh-users

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

On Fri, Dec 02, 2011 at 04:15:19PM +0000, Peter Stephenson wrote:
> The key point is that in this case you are given the whole command line
> at once, joined with NULLs
Oh, that explains a lot about the whole _regex_* stuff.

I've found so far, that the only utility function, that can
complete anything-but-space-separated list of values is _values.
And it accepts only predefined values.  My list of ids is not
static, it is fetched from remote server via executing special
ssh command, so I guess this problem is not related to _regex_*
completion, this is just not possible...

-- 
Regards,    --
Sir Raorn.   --- http://thousandsofhate.blogspot.com/

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: Q: _regex_arguments problem
  2011-12-02 17:37   ` Alexey I. Froloff
@ 2011-12-02 18:14     ` Bart Schaefer
  2011-12-02 20:25       ` Peter Stephenson
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2011-12-02 18:14 UTC (permalink / raw)
  To: zsh-users

On Dec 2,  9:37pm, Alexey I. Froloff wrote:
}
} I've found so far, that the only utility function, that can
} complete anything-but-space-separated list of values is _values.
} And it accepts only predefined values.  My list of ids is not
} static, it is fetched from remote server via executing special
} ssh command, so I guess this problem is not related to _regex_*
} completion, this is just not possible...

The typical way you'd do this with the plain _arguments function
is with the ->state mechanism:  use _arguments to figure out the
context and set a state, then in a 'case' or the like on the state
value you call your ssh command to get the list of values and then
call _values with that.

I'm not familiar enough with _regex_arguments to know if it can be
used in a similar two-stage manner.


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

* Re: Q: _regex_arguments problem
  2011-12-02 18:14     ` Bart Schaefer
@ 2011-12-02 20:25       ` Peter Stephenson
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Stephenson @ 2011-12-02 20:25 UTC (permalink / raw)
  To: zsh-users

On Fri, 02 Dec 2011 10:14:28 -0800
Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Dec 2,  9:37pm, Alexey I. Froloff wrote:
> }
> } I've found so far, that the only utility function, that can
> } complete anything-but-space-separated list of values is _values.
> } And it accepts only predefined values.  My list of ids is not
> } static, it is fetched from remote server via executing special
> } ssh command, so I guess this problem is not related to _regex_*
> } completion, this is just not possible...
> 
> The typical way you'd do this with the plain _arguments function
> is with the ->state mechanism:  use _arguments to figure out the
> context and set a state, then in a 'case' or the like on the state
> value you call your ssh command to get the list of values and then
> call _values with that.

The documentation says the actions supported by _regex_arguments are the
same as those supported by _arguments, although I didn't try it; in nay
case I don't see why you shouldn't use a function to complete for the
context, either.

You'll probably need to make _regex_arguments skip up to the last comma,
so you don't need to figure out a valid last of values until you know
you're trying to complete one.  I think _ip does that sort of thing.

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


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

end of thread, other threads:[~2011-12-02 20:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-02 13:14 Q: _regex_arguments problem Alexey I. Froloff
2011-12-02 15:45 ` Bart Schaefer
2011-12-02 16:15 ` Peter Stephenson
2011-12-02 17:37   ` Alexey I. Froloff
2011-12-02 18:14     ` Bart Schaefer
2011-12-02 20:25       ` Peter Stephenson

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