zsh-workers
 help / color / mirror / code / Atom feed
* Re: Wrapping special widget causes infinite recursion in add-zle-hook-widget
       [not found] <CAHLkEDvK0uagag2_Jq12M028fcfxS4CAM7km6GvGeAFMYpcGFw@mail.gmail.com>
@ 2021-06-18 16:34 ` Roman Perepelitsa
  0 siblings, 0 replies; only message in thread
From: Roman Perepelitsa @ 2021-06-18 16:34 UTC (permalink / raw)
  To: Marlon Richert; +Cc: Zsh hackers list, Daniel Shahaf

On Fri, Jun 18, 2021 at 3:32 PM Marlon Richert <marlon.richert@gmail.com> wrote:
>
> I originally reported this
> [here](https://github.com/zsh-users/zsh-syntax-highlighting/issues/816)
> but Daniel was of the opinion it should be fixed in
> add-zle-hook-widget.
>
> Steps to reproduce are as follows:
>
> % foo bar () { }
> % autoload -Uz add-zle-hook-widget
> % add-zle-hook-widget line-init foo
> % zle -N old-zle-line-init azhw:zle-line-init
> % new-zle-line-init() { zle old-zle-line-init }
> % zle -N zle-line-init new-zle-line-init
> % add-zle-hook-widget line-init bar
> [Process completed]
>
> The test case here uses zle-line-init, but it's not specific to that
> widget. It can be reproduced with any of the special widgets that
> add-zle-hook-widget handles.

I've bumped into similar issues with add-zle-hook-widget:
https://github.com/romkatv/powerlevel10k/issues/1205#issuecomment-767496102

The first test case:

    autoload -Uz add-zsh-hook-widget add-zle-hook-widget

    # Add `foo` hook to zle-line-finish.
    function foo() {}
    add-zle-hook-widget line-finish foo

    # Invoke `bar` on zle-line-finish, which in turn invokes the
original widget.
    zle -A zle-line-finish orig-zle-line-finish
    function bar() zle orig-zle-line-finish
    zle -N zle-line-finish bar

    # Add `baz` hook to zle-line-finish.
    function baz() {}
    add-zle-hook-widget line-finish baz

This produces `bar: job table full or recursion limit exceeded` on
zle-line-finish.

Here's a similar test case but with a different effect.

    autoload -Uz add-zsh-hook-widget add-zle-hook-widget

    # Add `foo` hook to zle-line-finish.
    function foo() print -rl '' foo
    add-zle-hook-widget line-finish foo

    # Invoke `bar` on zle-line-finish, which in turn invokes the
original widget.
    zle -A zle-line-finish orig-zle-line-finish
    function bar() { zle orig-zle-line-finish; print bar; }
    zle -N zle-line-finish bar

    # Add `foo` hook to zle-line-finish for the second time.
    add-zle-hook-widget line-finish foo

This results in `foo` being called on zle-line-finish but `bar`
doesn't get called.

These look like bugs in add-zle-hook-widget to me. Both can be fixed.
There is some choice w.r.t. the desired behavior of these test cases.
I think it would be reasonable for the first to invoke `bar`, `foo`,
`baz` (in this order) and for the second to invoke `bar`, `foo` (in
this order). Here's one more test case to complete the picture:

    autoload -Uz add-zsh-hook-widget add-zle-hook-widget

    # Add `foo` hook to zle-line-finish.
    function foo() print -rl '' foo
    add-zle-hook-widget line-finish foo

    # Invoke `bar` on zle-line-finish, which does nothing.
    function bar() {}
    zle -N zle-line-finish bar

    # Add `foo` hook to zle-line-finish for the second time.
    add-zle-hook-widget line-finish foo

I think it reasonable to require that `bar` and `foo` get called here
(in this order).

It's not too difficult to implement add-zle-hook-widget in a way that
it conforms to these requirements and doesn't break the existing code
that checks for `[[ $widgets[zle-line-finish] ==
user:azhw:zle-line-finish ]]`.

Roman.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-06-18 16:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CAHLkEDvK0uagag2_Jq12M028fcfxS4CAM7km6GvGeAFMYpcGFw@mail.gmail.com>
2021-06-18 16:34 ` Wrapping special widget causes infinite recursion in add-zle-hook-widget Roman Perepelitsa

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