zsh-workers
 help / color / mirror / code / Atom feed
* bug-or-feature - different completion context after "--option VALUE" vs "--option=VALUE"
@ 2022-07-21  4:18 Pavol Juhas
  2022-07-21 22:34 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Pavol Juhas @ 2022-07-21  4:18 UTC (permalink / raw)
  To: zsh-workers

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

Hello,

I am trying to write a completion function for my custom command,
which should offer different suggestions for positional arguments
after a long option with mandatory value.  I have a code which works as
desired
when the option is given in "--option VALUE" format, but not if specified
as "--option=VALUE".  In the latter case the completion
is the same as without any option.

Here is a reduced minimum example for a command "mycmd"
(for testing purpose mycmd can be a symlink to /bin/true):

# _mycmd
---------------------------------------------------------------------


#compdef mycmd



_arguments : \

    - name \

    '--name=[name of a person]:person-name:()' \

    '1:letters:(a b c)' \

    - without-name \

    '*:digits:(1 2 3)' \

    ;

#
----------------------------------------------------------------------------

The desired behavior is that command lines starting as either
"mycmd --name Alice "  and  "mycmd --name=Alice "
should offer argument suggestions a, b, c,
however the version with the equal sign completes 1, 2, 3,
as if completing without the --name option.
The completion context appears to be incorrect in that case (_ marks cursor
position):

$ mycmd --name Alice _

tags in context :completion::complete:mycmd::

    name-argument-1  (_arguments _mycmd)


versus

$ mycmd --name=Alice _

tags in context :completion::complete:mycmd::

    without-name-argument-rest  (_arguments _mycmd)



Is this a bug or feature?
If feature, am I perhaps missing some special specification flag to make it
work?

Thank you,

Pavol

[-- Attachment #2: Type: text/html, Size: 11127 bytes --]

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

* Re: bug-or-feature - different completion context after "--option VALUE" vs "--option=VALUE"
  2022-07-21  4:18 bug-or-feature - different completion context after "--option VALUE" vs "--option=VALUE" Pavol Juhas
@ 2022-07-21 22:34 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2022-07-21 22:34 UTC (permalink / raw)
  To: Pavol Juhas; +Cc: Zsh hackers list

On Wed, Jul 20, 2022 at 9:19 PM Pavol Juhas <pavol.juhas@gmail.com> wrote:
>
> _arguments : \
>     - name \
>     '--name=[name of a person]:person-name:()' \
>     '1:letters:(a b c)' \
>     - without-name \
>     '*:digits:(1 2 3)' \
>     ;

The "sets of arguments" notation has always been a bit tricky.  Oliver
may have some insight here.  I think the problem is that because the
without-name set has ONLY a catch-all, it is always the preferred
context, that is, when parsing the command line to see which set is
present, the without-name set is always chosen.  The sets aren't
necessarily matched and made mutually exclusive in the order they
appear.

I would suggest instead that you use the explicit exclusion notation:

_arguments : \
  '(*)--name=[name of a person]:person-name' \
  '1:letters:(a b c)' \
  '*:digits:(1 2 3)'

Something interesting is going on when you append ':()' to the --name
spec, and I don't know if that's intentional on your part.  What that
says, if I read things correctly, is that the mandatory argument to
--name can be the empty string, which effectively makes it an optional
argument, so there are some puzzling side-effects.  I've dropped ':()'
from my example to avoid that.


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

end of thread, other threads:[~2022-07-21 22:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-21  4:18 bug-or-feature - different completion context after "--option VALUE" vs "--option=VALUE" Pavol Juhas
2022-07-21 22:34 ` Bart Schaefer

Code repositories for project(s) associated with this 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).