zsh-workers
 help / color / mirror / code / Atom feed
* [BUG] compadd -R callback function not triggered by custom widget
@ 2023-11-06 11:48 Marlon Richert
  2023-11-06 21:53 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Marlon Richert @ 2023-11-06 11:48 UTC (permalink / raw)
  To: Zsh hackers list

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

Given this setup:

% zmodload zsh/complist
% autoload compinit
% compinit
% bindkey '^I' tst-complete
% zle -C tst-complete menu-select tst-complete
% tst-complete() { compadd -Ssuffix -R tst-suffix -- a b }
% tst-suffix() { LBUFFER+="len=$1" }
% bindkey '^[i' tst-custom
% zle -N tst-custom
% tst-custom() { zle beginning-of-line }


Then the following is expected behavior:

# press `:`+Space+Tab
% : asuffix
a  b
# completion menu opened

# press Escape+`i`
% : asuffixlen=6
# tst-suffix was called and cursor was moved to beginning of line


However, if we do not call any built-in widget inside our custom widget,
then tst-suffix does not get called:

% tst-custom() { CURSOR=0 }

# press `:`+Space+Tab
% : asuffix
a  b
# completion menu opened

# press Escape+`i`
% : asuffix
# cursor was moved to beginning of line, but tst-suffix was not called


Interestingly, if we then activate a built-in widget right after,
then tst-suffix gets called after all, but with the wrong value:

# press Space
% len=0 : asuffix

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

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

* Re: [BUG] compadd -R callback function not triggered by custom widget
  2023-11-06 11:48 [BUG] compadd -R callback function not triggered by custom widget Marlon Richert
@ 2023-11-06 21:53 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2023-11-06 21:53 UTC (permalink / raw)
  To: Marlon Richert; +Cc: Zsh hackers list

On Mon, Nov 6, 2023 at 3:49 AM Marlon Richert <marlon.richert@gmail.com> wrote:
>
> However, if we do not call any built-in widget inside our custom widget,
> then tst-suffix does not get called:

I believe this is because you're in the menuselect keymap, which
supports only a limited set of operations.  When you hit ESC-i at this
point without invoking any zle operations, you are still in menu mode,
so the existing suffix is still active.  You can see this if you
immediately hit TAB again twice -- "asuffix" is replaced by "bsuffix"
and the cursor is back at the end of the line again.  Suffix removal
is not invoked because as far as zle knows, you've never left the
menu.

If you call a builtin from tst-custom, the menu is aborted and you're
back at the top-level.

This could still be considered a bug -- changing CURSOR and possibly
some other ZLE parameters during menu completion should also abort the
menu.

> Interestingly, if we then activate a built-in widget right after,
> then tst-suffix gets called after all, but with the wrong value:
>
> # press Space
> % len=0 : asuffix

This actually isn't wrong (given the foregoing) -- Space breaks out of
menu completion, so the suffix removal is invoked, and at that moment
the cursor is at the beginning of the line so there is no LBUFFER so
len=0.


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

end of thread, other threads:[~2023-11-06 21:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-06 11:48 [BUG] compadd -R callback function not triggered by custom widget Marlon Richert
2023-11-06 21:53 ` 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).