zsh-users
 help / color / mirror / code / Atom feed
* completion with separator
@ 2022-05-07 10:40 Pier Paolo Grassi
  2022-05-07 20:12 ` Bart Schaefer
  2022-05-07 23:37 ` Bart Schaefer
  0 siblings, 2 replies; 12+ messages in thread
From: Pier Paolo Grassi @ 2022-05-07 10:40 UTC (permalink / raw)
  To: Zsh-Users List

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

Hello, I have a completion function that after calculating the possible
completion values uses

_values -s , categories $categories_array

to show the possible matches.

When I complete something I get this behavior:

> func a<tab>
<menu completion where I select a value with enter>
> func acat,<cursor>

I would like that the comma was not added automatically, or at least to be
removed automatically when I select a voice in menu selection with enter.
is this possible?

Pier Paolo Grassi

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

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

* Re: completion with separator
  2022-05-07 10:40 completion with separator Pier Paolo Grassi
@ 2022-05-07 20:12 ` Bart Schaefer
  2022-05-07 20:29   ` Pier Paolo Grassi
  2022-05-07 23:37 ` Bart Schaefer
  1 sibling, 1 reply; 12+ messages in thread
From: Bart Schaefer @ 2022-05-07 20:12 UTC (permalink / raw)
  To: Pier Paolo Grassi; +Cc: Zsh-Users List

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

On Sat, May 7, 2022 at 3:41 AM Pier Paolo Grassi <pierpaolog@gmail.com>
wrote:

>
> _values -s , categories $categories_array
>
> > func a<tab>
> <menu completion where I select a value with enter>
> > func acat,<cursor>
>
> I would like that the comma was not added automatically, or at least to be
> removed automatically when I select a voice in menu selection with enter.
> is this possible?
>

It should already be happening that way.  If you type a space or another
return after the comma, it should disappear.

If that's not happening the way you like, you can try some variation of

remove_comma=(-r '[:alnum:] \t\n\-')
_values -O remove_comma -s , categories $categories_array

to remove the comma when you type (in that example) anything alphanumeric
or whitespace, but whether that works depends on how you've defined the
specs in $categories_array (-O applies only to specs that have an "action"
component).

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

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

* Re: completion with separator
  2022-05-07 20:12 ` Bart Schaefer
@ 2022-05-07 20:29   ` Pier Paolo Grassi
  2022-05-07 20:31     ` Pier Paolo Grassi
  0 siblings, 1 reply; 12+ messages in thread
From: Pier Paolo Grassi @ 2022-05-07 20:29 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh-Users List

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

> It should already be happening that way.  If you type a space or another
return after the comma, it should disappear.

yes it is removed when I press a space after selection, and even if I press
enter after the selection. But this way, in the enter case, the line is
accepted and executed.
What I would like is for the comma not to be inserted after the completion,
I would like to insert it by myself if I want to insert multiple arguments.
So when I press enter in the menu selection the voice is selected and the
line is:

func acat<cursor>

instead of

func acat,<cursor>

thanks


Pier Paolo Grassi


Il giorno sab 7 mag 2022 alle ore 22:12 Bart Schaefer <
schaefer@brasslantern.com> ha scritto:

> On Sat, May 7, 2022 at 3:41 AM Pier Paolo Grassi <pierpaolog@gmail.com>
> wrote:
>
>>
>> _values -s , categories $categories_array
>>
>> > func a<tab>
>> <menu completion where I select a value with enter>
>> > func acat,<cursor>
>>
>> I would like that the comma was not added automatically, or at least to
>> be removed automatically when I select a voice in menu selection with enter.
>> is this possible?
>>
>
> It should already be happening that way.  If you type a space or another
> return after the comma, it should disappear.
>
> If that's not happening the way you like, you can try some variation of
>
> remove_comma=(-r '[:alnum:] \t\n\-')
> _values -O remove_comma -s , categories $categories_array
>
> to remove the comma when you type (in that example) anything alphanumeric
> or whitespace, but whether that works depends on how you've defined the
> specs in $categories_array (-O applies only to specs that have an "action"
> component).
>
>
>

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

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

* Re: completion with separator
  2022-05-07 20:29   ` Pier Paolo Grassi
@ 2022-05-07 20:31     ` Pier Paolo Grassi
  2022-05-07 20:56       ` Pier Paolo Grassi
  2022-05-07 20:57       ` Bart Schaefer
  0 siblings, 2 replies; 12+ messages in thread
From: Pier Paolo Grassi @ 2022-05-07 20:31 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh-Users List

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

I would like to test your solution, but idk how to add an action part to
my $categories_array. Right now it is just an array of strings to be used
for completion.

Pier Paolo Grassi


Il giorno sab 7 mag 2022 alle ore 22:29 Pier Paolo Grassi <
pierpaolog@gmail.com> ha scritto:

> > It should already be happening that way.  If you type a space or another
> return after the comma, it should disappear.
>
> yes it is removed when I press a space after selection, and even if I
> press enter after the selection. But this way, in the enter case, the line
> is accepted and executed.
> What I would like is for the comma not to be inserted after the
> completion, I would like to insert it by myself if I want to insert
> multiple arguments. So when I press enter in the menu selection the voice
> is selected and the line is:
>
> func acat<cursor>
>
> instead of
>
> func acat,<cursor>
>
> thanks
>
>
> Pier Paolo Grassi
>
>
> Il giorno sab 7 mag 2022 alle ore 22:12 Bart Schaefer <
> schaefer@brasslantern.com> ha scritto:
>
>> On Sat, May 7, 2022 at 3:41 AM Pier Paolo Grassi <pierpaolog@gmail.com>
>> wrote:
>>
>>>
>>> _values -s , categories $categories_array
>>>
>>> > func a<tab>
>>> <menu completion where I select a value with enter>
>>> > func acat,<cursor>
>>>
>>> I would like that the comma was not added automatically, or at least to
>>> be removed automatically when I select a voice in menu selection with enter.
>>> is this possible?
>>>
>>
>> It should already be happening that way.  If you type a space or another
>> return after the comma, it should disappear.
>>
>> If that's not happening the way you like, you can try some variation of
>>
>> remove_comma=(-r '[:alnum:] \t\n\-')
>> _values -O remove_comma -s , categories $categories_array
>>
>> to remove the comma when you type (in that example) anything alphanumeric
>> or whitespace, but whether that works depends on how you've defined the
>> specs in $categories_array (-O applies only to specs that have an "action"
>> component).
>>
>>
>>

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

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

* Re: completion with separator
  2022-05-07 20:31     ` Pier Paolo Grassi
@ 2022-05-07 20:56       ` Pier Paolo Grassi
  2022-05-07 21:00         ` Bart Schaefer
  2022-05-07 20:57       ` Bart Schaefer
  1 sibling, 1 reply; 12+ messages in thread
From: Pier Paolo Grassi @ 2022-05-07 20:56 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh-Users List

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

I found the specification of _arguments that describes the action part.
I don't understand, however, why the -r applies only to these, since the
compadd specification of this option does not describe this limitation

Pier Paolo Grassi


Il giorno sab 7 mag 2022 alle ore 22:31 Pier Paolo Grassi <
pierpaolog@gmail.com> ha scritto:

> I would like to test your solution, but idk how to add an action part to
> my $categories_array. Right now it is just an array of strings to be used
> for completion.
>
> Pier Paolo Grassi
>
>
> Il giorno sab 7 mag 2022 alle ore 22:29 Pier Paolo Grassi <
> pierpaolog@gmail.com> ha scritto:
>
>> > It should already be happening that way.  If you type a space or
>> another return after the comma, it should disappear.
>>
>> yes it is removed when I press a space after selection, and even if I
>> press enter after the selection. But this way, in the enter case, the line
>> is accepted and executed.
>> What I would like is for the comma not to be inserted after the
>> completion, I would like to insert it by myself if I want to insert
>> multiple arguments. So when I press enter in the menu selection the voice
>> is selected and the line is:
>>
>> func acat<cursor>
>>
>> instead of
>>
>> func acat,<cursor>
>>
>> thanks
>>
>>
>> Pier Paolo Grassi
>>
>>
>> Il giorno sab 7 mag 2022 alle ore 22:12 Bart Schaefer <
>> schaefer@brasslantern.com> ha scritto:
>>
>>> On Sat, May 7, 2022 at 3:41 AM Pier Paolo Grassi <pierpaolog@gmail.com>
>>> wrote:
>>>
>>>>
>>>> _values -s , categories $categories_array
>>>>
>>>> > func a<tab>
>>>> <menu completion where I select a value with enter>
>>>> > func acat,<cursor>
>>>>
>>>> I would like that the comma was not added automatically, or at least to
>>>> be removed automatically when I select a voice in menu selection with enter.
>>>> is this possible?
>>>>
>>>
>>> It should already be happening that way.  If you type a space or another
>>> return after the comma, it should disappear.
>>>
>>> If that's not happening the way you like, you can try some variation of
>>>
>>> remove_comma=(-r '[:alnum:] \t\n\-')
>>> _values -O remove_comma -s , categories $categories_array
>>>
>>> to remove the comma when you type (in that example) anything
>>> alphanumeric or whitespace, but whether that works depends on how you've
>>> defined the specs in $categories_array (-O applies only to specs that have
>>> an "action" component).
>>>
>>>
>>>

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

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

* Re: completion with separator
  2022-05-07 20:31     ` Pier Paolo Grassi
  2022-05-07 20:56       ` Pier Paolo Grassi
@ 2022-05-07 20:57       ` Bart Schaefer
  1 sibling, 0 replies; 12+ messages in thread
From: Bart Schaefer @ 2022-05-07 20:57 UTC (permalink / raw)
  To: Pier Paolo Grassi; +Cc: Zsh-Users List

On Sat, May 7, 2022 at 1:32 PM Pier Paolo Grassi <pierpaolog@gmail.com> wrote:
>
> I would like to test your solution, but idk how to add an action part to my $categories_array. Right now it is just an array of strings to be used for completion.

In that case it won't work, sorry.  That is, the desired completion
has to have the categories following some kind of introducing word
that triggers the action.


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

* Re: completion with separator
  2022-05-07 20:56       ` Pier Paolo Grassi
@ 2022-05-07 21:00         ` Bart Schaefer
  2022-05-07 21:10           ` Pier Paolo Grassi
  0 siblings, 1 reply; 12+ messages in thread
From: Bart Schaefer @ 2022-05-07 21:00 UTC (permalink / raw)
  To: Pier Paolo Grassi; +Cc: Zsh-Users List

On Sat, May 7, 2022 at 1:57 PM Pier Paolo Grassi <pierpaolog@gmail.com> wrote:
>
> I don't understand, however, why the -r applies only to these, since the compadd specification of this option does not describe this limitation

The short answer is that _values already creates its own -r option for
simple lists of values, but doesn't have enough information to do so
for arbitrary actions.

It's possible this could be improved.


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

* Re: completion with separator
  2022-05-07 21:00         ` Bart Schaefer
@ 2022-05-07 21:10           ` Pier Paolo Grassi
  2022-05-07 21:44             ` Bart Schaefer
  0 siblings, 1 reply; 12+ messages in thread
From: Pier Paolo Grassi @ 2022-05-07 21:10 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh-Users List

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

I am trying with

remove_comma=(-r '[:alnum:] \t\n\-')
_values -O remove_comma -s , categories :message:'(aa bb cc)'

but all I get for completion is
func <tab>
func =<cursor>

instead of the string I have inserted as possible completion

I've tried also
_values -O remove_comma -s , categories \
:message:'(aa bb cc)'

to the same result

Pier Paolo Grassi


Il giorno sab 7 mag 2022 alle ore 23:00 Bart Schaefer <
schaefer@brasslantern.com> ha scritto:

> On Sat, May 7, 2022 at 1:57 PM Pier Paolo Grassi <pierpaolog@gmail.com>
> wrote:
> >
> > I don't understand, however, why the -r applies only to these, since the
> compadd specification of this option does not describe this limitation
>
> The short answer is that _values already creates its own -r option for
> simple lists of values, but doesn't have enough information to do so
> for arbitrary actions.
>
> It's possible this could be improved.
>

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

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

* Re: completion with separator
  2022-05-07 21:10           ` Pier Paolo Grassi
@ 2022-05-07 21:44             ` Bart Schaefer
  2022-05-07 21:49               ` Pier Paolo Grassi
  0 siblings, 1 reply; 12+ messages in thread
From: Bart Schaefer @ 2022-05-07 21:44 UTC (permalink / raw)
  To: Pier Paolo Grassi; +Cc: Zsh-Users List

On Sat, May 7, 2022 at 2:11 PM Pier Paolo Grassi <pierpaolog@gmail.com> wrote:
>
> I am trying with
>
> remove_comma=(-r '[:alnum:] \t\n\-')
> _values -O remove_comma -s , categories :message:'(aa bb cc)'
>
> but all I get for completion is
> func <tab>
> func =<cursor>

Yes, that's what I mean about it not working for simple lists of
values.  It's looking for something to appear on the left of the "="
to tell it which action to select on the right.

Sadly it's also not interpreting [:alnum:] correctly.

remove_comma=(-r 'A-Za-z0-9 \t\n\-')
_values -O remove_comma -s , -S '' categories -::message:'(aa bb cc)'

works for

func -<tab>

but you need something non-empty before ::message: to start it off.


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

* Re: completion with separator
  2022-05-07 21:44             ` Bart Schaefer
@ 2022-05-07 21:49               ` Pier Paolo Grassi
  0 siblings, 0 replies; 12+ messages in thread
From: Pier Paolo Grassi @ 2022-05-07 21:49 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh-Users List

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

ok thanks Bart, I will try experimenting on this for fun but I have
understood why it cannot work for my initial problem
regards

Il giorno sab 7 mag 2022 alle 23:44 Bart Schaefer <schaefer@brasslantern.com>
ha scritto:

> On Sat, May 7, 2022 at 2:11 PM Pier Paolo Grassi <pierpaolog@gmail.com>
> wrote:
> >
> > I am trying with
> >
> > remove_comma=(-r '[:alnum:] \t\n\-')
> > _values -O remove_comma -s , categories :message:'(aa bb cc)'
> >
> > but all I get for completion is
> > func <tab>
> > func =<cursor>
>
> Yes, that's what I mean about it not working for simple lists of
> values.  It's looking for something to appear on the left of the "="
> to tell it which action to select on the right.
>
> Sadly it's also not interpreting [:alnum:] correctly.
>
> remove_comma=(-r 'A-Za-z0-9 \t\n\-')
> _values -O remove_comma -s , -S '' categories -::message:'(aa bb cc)'
>
> works for
>
> func -<tab>
>
> but you need something non-empty before ::message: to start it off.
>
-- 
Pier Paolo Grassi

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

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

* Re: completion with separator
  2022-05-07 10:40 completion with separator Pier Paolo Grassi
  2022-05-07 20:12 ` Bart Schaefer
@ 2022-05-07 23:37 ` Bart Schaefer
  2022-05-08  8:07   ` Pier Paolo Grassi
  1 sibling, 1 reply; 12+ messages in thread
From: Bart Schaefer @ 2022-05-07 23:37 UTC (permalink / raw)
  To: Pier Paolo Grassi; +Cc: Zsh-Users List

On Sat, May 7, 2022 at 3:41 AM Pier Paolo Grassi <pierpaolog@gmail.com> wrote:
>
> _values -s , categories $categories_array
>
> I would like that the comma was not added automatically

Sometimes you have to go closer to the metal, so to speak.

_comma_cats() {
  local categories_array=(aa bb cc)
  if compset -P '*,'
  then
    local already_there=${${IPREFIX//,/|}%|}
    categories_array=(${categories_array:#${~already_there}})
  fi
  compadd -S '' -X categories -a categories_array
}


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

* Re: completion with separator
  2022-05-07 23:37 ` Bart Schaefer
@ 2022-05-08  8:07   ` Pier Paolo Grassi
  0 siblings, 0 replies; 12+ messages in thread
From: Pier Paolo Grassi @ 2022-05-08  8:07 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh-Users List

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

Thanks, I'll check it out.

Il giorno dom 8 mag 2022 alle 01:37 Bart Schaefer <schaefer@brasslantern.com>
ha scritto:

> On Sat, May 7, 2022 at 3:41 AM Pier Paolo Grassi <pierpaolog@gmail.com>
> wrote:
> >
> > _values -s , categories $categories_array
> >
> > I would like that the comma was not added automatically
>
> Sometimes you have to go closer to the metal, so to speak.
>
> _comma_cats() {
>   local categories_array=(aa bb cc)
>   if compset -P '*,'
>   then
>     local already_there=${${IPREFIX//,/|}%|}
>     categories_array=(${categories_array:#${~already_there}})
>   fi
>   compadd -S '' -X categories -a categories_array
> }
>
-- 
Pier Paolo Grassi

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

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

end of thread, other threads:[~2022-05-08  8:08 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-07 10:40 completion with separator Pier Paolo Grassi
2022-05-07 20:12 ` Bart Schaefer
2022-05-07 20:29   ` Pier Paolo Grassi
2022-05-07 20:31     ` Pier Paolo Grassi
2022-05-07 20:56       ` Pier Paolo Grassi
2022-05-07 21:00         ` Bart Schaefer
2022-05-07 21:10           ` Pier Paolo Grassi
2022-05-07 21:44             ` Bart Schaefer
2022-05-07 21:49               ` Pier Paolo Grassi
2022-05-07 20:57       ` Bart Schaefer
2022-05-07 23:37 ` Bart Schaefer
2022-05-08  8:07   ` Pier Paolo Grassi

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