zsh-users
 help / color / mirror / code / Atom feed
* _arguments: repeated option with multiple optargs
@ 2006-09-19  1:46 Roman Neuhauser
  2006-09-19 13:19 ` Roman Neuhauser
       [not found] ` <20060919172825.3f7c6232.pws@csr.com>
  0 siblings, 2 replies; 3+ messages in thread
From: Roman Neuhauser @ 2006-09-19  1:46 UTC (permalink / raw)
  To: zsh users

Hello,

_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?

Hints appreciated.

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE.             http://bash.org/?255991


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

* Re: _arguments: repeated option with multiple optargs
  2006-09-19  1:46 _arguments: repeated option with multiple optargs Roman Neuhauser
@ 2006-09-19 13:19 ` Roman Neuhauser
       [not found] ` <20060919172825.3f7c6232.pws@csr.com>
  1 sibling, 0 replies; 3+ messages in thread
From: Roman Neuhauser @ 2006-09-19 13:19 UTC (permalink / raw)
  To: zsh users

# neuhauser@sigpipe.cz / 2006-09-19 01:46:39 +0000:
> Hello,
> 
> _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?

    Thought I might be more specific.

    I have the following command (ABNF with implied whitespace at
    obvious places):

    cmdline = "tence" ["-h"] *("-i" dirlist) 1*("-r" file 1*(test))

    and this completion function:

    -------------------------
    #compdef tence

    local context line state
    typeset -A opt_args

    _arguments -s : \
        {-h,--help} \
        '*'{-i,--include-path}'=:include_path:->incpath' \
        '*'{-r,--run}'=:file:->testfile:*::class:->testclass'

    case $state in
    incpath)
        _dir_list && return 0
        ;;
    testfile)
        _files -g '*(.)' && return 0
        ;;
    testclass)
        # offer tests defined by this file for completion
        local -a tests
        tests=($(_call_program tests tence -C $words[1]))
        compadd "$@" -a tests && return 0
        ;;
    esac

    return 1
    -------------------------

    with "mycmd -r F a b c <CURSOR>" on the command line, completion
    should offer not only further tests (d e f), but "-r" as well.

    I don't want to pollute the interface with dummy arguments to halt
    the class optarg processing on, and also would love to defer as much
    as possible work to the standard functions.
    
    _arguments is already there, I don't want to write another parser.

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE.             http://bash.org/?255991


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

* Re: _arguments: repeated option with multiple optargs
       [not found]   ` <20060919225628.GA46070@dagan.sigpipe.cz>
@ 2006-09-20  9:10     ` Peter Stephenson
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2006-09-20  9:10 UTC (permalink / raw)
  To: Roman Neuhauser, Zsh users list

Roman Neuhauser wrote:
>     That reminds me: the message part of optarg must not be empty,
>     otherwise I get no completions, is that a bug?

Generally two colons together mean special things.  It should work if
there's at least a space, otherwise it's certainly a bug.

>     I looked inside _arguments, it contains (4.2.5) 10 calls to
>     comparguments, but zsh/computil is basically undocumented with the
>     excuse that it's "not very interesting" to users. Funny.

Yes, that's a real nuisance in working out what's going on.

>     Thinking some more... In "tence -r file t1 <CURSOR>", _complete_help
>     says the $context is ":completion::complete:tence::option-r-rest:".
>     How can I access the value from inside my completion function? I
>     thought I saw this info somewhere, but cannot find it.  I'd like to
>     see what happens if I change the argument member from option-r-rest
>     to "" before the call to _arguments, IFF $words[$CURRENT] is "-".

You need to manipulate curcontext.  The usual idiom is

local curcontext="${curcontext}:extra:bits"

or something.

>     BTW, you sent this only to me. Was that intentional?

No, I passed on the mail to the list (and this one, too).

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


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

end of thread, other threads:[~2006-09-20  9:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-19  1:46 _arguments: repeated option with multiple optargs Roman Neuhauser
2006-09-19 13:19 ` Roman Neuhauser
     [not found] ` <20060919172825.3f7c6232.pws@csr.com>
     [not found]   ` <20060919225628.GA46070@dagan.sigpipe.cz>
2006-09-20  9:10     ` 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).