zsh-users
 help / color / mirror / code / Atom feed
* Having a tough time setting up completion.
@ 2011-12-15 22:06 Larry Schrof
  2011-12-15 22:54 ` Mikael Magnusson
  0 siblings, 1 reply; 4+ messages in thread
From: Larry Schrof @ 2011-12-15 22:06 UTC (permalink / raw)
  To: zsh-users

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

I've spent a lot to time studying the zshcompsys man page (the docs for _arguments specifically), but I"m still having a tough time specifying the syntax to do the following completion.

I have a command called foo. This command takes exactly one of three forms:

foo  -x  <exactly-one-of-fifty-strings>
foo --longword <exactly-one-of-fifty-strings>
foo <exactly-one-of-fifty-strings>

-x is a single-letter option, --longword is a double-dashed GNU-style long option. (These two options are synonymous.) Of these two options, either zero or exactly one of them should appear. IF one of them appears, it must appear immediately after foo (separated from foo, of course, by whitespace).

In all cases, <exactly-one-of-fifty-strings> is a single (non-leading-dash) word. As soon as this word is entered or completed, no other word from the (really large) set should appear on the command line.

If anyone can offer a general outline as to how I can use _arguments to implement this, that would be great. I need to manually enter in all fifty words at some point, and make them mutually exclusive. Will be interesting to see how to do that. Thanks!




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

* Re: Having a tough time setting up completion.
  2011-12-15 22:06 Having a tough time setting up completion Larry Schrof
@ 2011-12-15 22:54 ` Mikael Magnusson
  2011-12-16  0:17   ` Larry Schrof
  0 siblings, 1 reply; 4+ messages in thread
From: Mikael Magnusson @ 2011-12-15 22:54 UTC (permalink / raw)
  To: Larry Schrof; +Cc: zsh-users

On 15 December 2011 23:06, Larry Schrof <larrys@fb.com> wrote:
> I've spent a lot to time studying the zshcompsys man page (the docs for _arguments specifically), but I"m still having a tough time specifying the syntax to do the following completion.
>
> I have a command called foo. This command takes exactly one of three forms:
>
> foo  -x  <exactly-one-of-fifty-strings>
> foo --longword <exactly-one-of-fifty-strings>
> foo <exactly-one-of-fifty-strings>
>
> -x is a single-letter option, --longword is a double-dashed GNU-style long option. (These two options are synonymous.) Of these two options, either zero or exactly one of them should appear. IF one of them appears, it must appear immediately after foo (separated from foo, of course, by whitespace).
>
> In all cases, <exactly-one-of-fifty-strings> is a single (non-leading-dash) word. As soon as this word is entered or completed, no other word from the (really large) set should appear on the command line.
>
> If anyone can offer a general outline as to how I can use _arguments to implement this, that would be great. I need to manually enter in all fifty words at some point, and make them mutually exclusive. Will be interesting to see how to do that. Thanks!

I'm not sure if I should be happy or sad I got this on the first try
without even using backspace, without looking anything up, and it
worked (all on one line if gmail breaks it):

compdef '_arguments ''(-x --longword)''{-x,--longword}''[something]''
''1:fiftystrings:(one two three and so forth fifty)''' foo

(i use rcquotes so you want '\'' instead of '', or more likely,
putting the whole quoted string in a regular completer.)
If you want to give a description for each words, use double parens
instead and separate desc with :, as
...:fiftystrings:((one:a\ description\ of\ one two:...

-- 
Mikael Magnusson


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

* Re: Having a tough time setting up completion.
  2011-12-15 22:54 ` Mikael Magnusson
@ 2011-12-16  0:17   ` Larry Schrof
  2011-12-16  3:46     ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Larry Schrof @ 2011-12-16  0:17 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: zsh-users

Thanks - this is definitely getting there.

However, I have a problem. Many, but not all, of the strings in this set
contain internal hyphens. For example, we have 'create', 'delete', and
'add-property'.
Adding create and delete to the list of strings works great.

$ foo --<TAB>       # yields...
$ foo --longword    # Awesome!

$ foo --longword <TAB>   # Offers up 'create' and 'delete' - fantastic

When we try adding a hyphenated string into the mix, things break:

$ foo -<TAB>        # completes incorrectly to
$ foo add-property  # This should have offered -x and --longword as
completions

Any suggestions?

On 12/15/11 2:54 PM, "Mikael Magnusson" <mikachu@gmail.com> wrote:

>On 15 December 2011 23:06, Larry Schrof <larrys@fb.com> wrote:
>> I've spent a lot to time studying the zshcompsys man page (the docs for
>>_arguments specifically), but I"m still having a tough time specifying
>>the syntax to do the following completion.
>>
>> I have a command called foo. This command takes exactly one of three
>>forms:
>>
>> foo  -x  <exactly-one-of-fifty-strings>
>> foo --longword <exactly-one-of-fifty-strings>
>> foo <exactly-one-of-fifty-strings>
>>
>> -x is a single-letter option, --longword is a double-dashed GNU-style
>>long option. (These two options are synonymous.) Of these two options,
>>either zero or exactly one of them should appear. IF one of them
>>appears, it must appear immediately after foo (separated from foo, of
>>course, by whitespace).
>>
>> In all cases, <exactly-one-of-fifty-strings> is a single
>>(non-leading-dash) word. As soon as this word is entered or completed,
>>no other word from the (really large) set should appear on the command
>>line.
>>
>> If anyone can offer a general outline as to how I can use _arguments to
>>implement this, that would be great. I need to manually enter in all
>>fifty words at some point, and make them mutually exclusive. Will be
>>interesting to see how to do that. Thanks!
>
>I'm not sure if I should be happy or sad I got this on the first try
>without even using backspace, without looking anything up, and it
>worked (all on one line if gmail breaks it):
>
>compdef '_arguments ''(-x --longword)''{-x,--longword}''[something]''
>''1:fiftystrings:(one two three and so forth fifty)''' foo
>
>(i use rcquotes so you want '\'' instead of '', or more likely,
>putting the whole quoted string in a regular completer.)
>If you want to give a description for each words, use double parens
>instead and separate desc with :, as
>...:fiftystrings:((one:a\ description\ of\ one two:...
>
>-- 
>Mikael Magnusson


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

* Re: Having a tough time setting up completion.
  2011-12-16  0:17   ` Larry Schrof
@ 2011-12-16  3:46     ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2011-12-16  3:46 UTC (permalink / raw)
  To: zsh-users

On Dec 16, 12:17am, Larry Schrof wrote:
} 
} When we try adding a hyphenated string into the mix, things break:
} 
} $ foo -<TAB>        # completes incorrectly to
} $ foo add-property  # This should have offered -x and --longword as
} completions
} 
} Any suggestions?

I think you must have subtly misplaced a quote mark, or have an unexpected
value in matcher-list, or some other zstyle we don't know about.

Here's what I get starting from "zsh -f" plus "compinit -D" plus Mikael's
compdef with add-property/delete/create appended to the array:

torch% foo <TAB>
add-property  create        fifty         one           three
and           delete        forth         so            two
torch% foo --<TAB>
torch% foo --longword
torch% foo -<TAB>
--longword  -x  -- something

I even tried "setopt completeinword" without the above changing.  BUT:
If I both use my full configuration AND place the cursor BEFORE the
hyphen:

schaefer<504> foo <TAB>-
schaefer<504> foo add-property

There, matcher-list has kicked in and completed things where the part
before the hyphen is not empty.  Are you sure that's not what is
happening to you?


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

end of thread, other threads:[~2011-12-16  3:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-15 22:06 Having a tough time setting up completion Larry Schrof
2011-12-15 22:54 ` Mikael Magnusson
2011-12-16  0:17   ` Larry Schrof
2011-12-16  3:46     ` 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).