zsh-workers
 help / color / mirror / code / Atom feed
From: Roman Perepelitsa <roman.perepelitsa@gmail.com>
To: Marlon Richert <marlon.richert@gmail.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>,
	Daniel Shahaf <d.s@daniel.shahaf.name>
Subject: Re: Wrapping special widget causes infinite recursion in add-zle-hook-widget
Date: Fri, 18 Jun 2021 18:34:47 +0200	[thread overview]
Message-ID: <CAN=4vMr6RFha-MncaOtkv-6gowE9CxiPLOTqdfvKMmt9wV9tAw@mail.gmail.com> (raw)
In-Reply-To: <CAHLkEDvK0uagag2_Jq12M028fcfxS4CAM7km6GvGeAFMYpcGFw@mail.gmail.com>

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.


           reply	other threads:[~2021-06-18 16:35 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <CAHLkEDvK0uagag2_Jq12M028fcfxS4CAM7km6GvGeAFMYpcGFw@mail.gmail.com>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAN=4vMr6RFha-MncaOtkv-6gowE9CxiPLOTqdfvKMmt9wV9tAw@mail.gmail.com' \
    --to=roman.perepelitsa@gmail.com \
    --cc=d.s@daniel.shahaf.name \
    --cc=marlon.richert@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).