From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22092 invoked from network); 22 Mar 2001 09:28:11 -0000 Received: from sunsite.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 22 Mar 2001 09:28:11 -0000 Received: (qmail 58 invoked by alias); 22 Mar 2001 09:27:57 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 13701 Received: (qmail 47 invoked from network); 22 Mar 2001 09:27:56 -0000 Date: Thu, 22 Mar 2001 10:27:56 +0100 (MET) Message-Id: <200103220927.KAA03218@beta.informatik.hu-berlin.de> From: Sven Wischnowsky To: zsh-workers@sunsite.dk In-reply-to: Mario Lang's message of 21 Mar 2001 17:56:31 +0100 Subject: Re: Completing option/value pairs without space Mario Lang wrote: > ... > > _arguments \ > '-c[Start in interactive mode]' \ > '-d\:[Debug level]:Debug level:' \ > '-D[Print all debug information to stderr]' \ > '-q[Quiet mode, no output]' \ > '--help[Show help]' \ > '--version[Show version information]' \ > '-n\:[Set the name of chainsetup]' \ > '-s\:[Create a new chainsetup from file]:filename:_files' \ > '-sr\:[Set internal sampling rate]:Sampling rate:(8000 11025 22050 44100 48000)' > > When I now e.g. do: > ecasound -sr: > i get a space, and when hitting tab again, I get the sampling rates for completion. You have to tell _arguments that the option's argument comes directly after the option. That's done by adding `-' after the option name (before the description), as in: '-sr\:-[Set internal sampling rate]:Sampling rate:(8000 11025 22050 44100 48000)' \ > The same problem would strike when I come to the more complicated > effects. e.g. I would like to have: > ecasound ... -efs: > and get > -efs: -- Resonator center freq > > and when doing > ecasound ... -efs:100, > Id like to get > -efs:*, -- resonator width That's done using actions of the `->state' form, e.g.: '-efs\:-[Set resonator parameters]: :->efs' \ After the call to _arguments one can then test if the real action for `efs' has to be taken: case $state in efs) if compset -P '*,'; then _message 'Resonator width' else _message 'Resonator center frequency' fi ;; ... esac > And a really reall neat(tm) gadget would be: > ecasound ... -efs:100,50 -kl: > should give > -kl:1 -- Linear controller controlling Resonator freq > -kl:2 -- Linear controller controlling Resonator width > > and so on. You didn't describe `-kl' so I don't know what it gets as arguments. If you only need it to complete `1' or `2' (or `3',...) with some description and some other values separated by commas one woul use another: '-kl\:-[linear controller]: :->kl' with a case-branch such as: kl) if compset -P '*,'; then _message 'Linear controller value...' else _values 'Linear controller parameters' \ '1[Linear controller controlling resonator freq]' \ '2[Linear controller controlling resonator width]' fi If the values and descriptions completed after `-kl' depend on previous options one could still do it but one would have to look either into the opt_args associative array to find the options set on the line (and their values) or one could loop through the $words array set up by the completion system to contain the words on the line (one would probably start at element $CURSOR-1 -- the word before the cursor -- and go back to the first word to find the options on which one has to decide what to complete). Below are all the code snippets above merged into your function. Two remarks: without a `->state' action one doesn't need to make local all those parameters. And the `&& return 0' makes sure that the function is left if `_arguments' says that it's sure to have completely handled completion in the current context. And one remark to all -workers: with the function below completion after `ecasound -efs:' makes _arguments report (and show) `-efs:' as a possible completion. That's correct somehow, but looks very weird in this case. Hm. Bye Sven #compdef ecasound local context state line typeset -A opt_args _arguments \ '-c[Start in interactive mode]' \ '-d\:[Debug level]:Debug level:' \ '-D[Print all debug information to stderr]' \ '-q[Quiet mode, no output]' \ '--help[Show help]' \ '--version[Show version information]' \ '-n\:[Set the name of chainsetup]' \ '-s\:[Create a new chainsetup from file]:filename:_files' \ '-sr\:-[Set internal sampling rate]:Sampling rate:(8000 11025 22050 44100 48000)' \ '-efs\:-[Set resonator parameters]: :->efs' \ '-kl\:-[linear controller]: :->kl' && return 0 case $state in efs) if compset -P '*,'; then _message 'Resonator width' else _message 'Resonator center frequency' fi ;; kl) if compset -P '*,'; then _message 'Linear controller value...' else _values 'Linear controller parameters' \ '1[Linear controller controlling resonator freq]' \ '2[Linear controller controlling resonator width]' fi ;; esac -- Sven Wischnowsky wischnow@informatik.hu-berlin.de