zsh-workers
 help / color / mirror / code / Atom feed
* Does add-zle-hook-widget violate the contract of ZLE hook widgets?
@ 2021-06-23 20:30 Marlon Richert
  2021-06-23 21:57 ` Daniel Shahaf
  0 siblings, 1 reply; 19+ messages in thread
From: Marlon Richert @ 2021-06-23 20:30 UTC (permalink / raw)
  To: Zsh hackers list

% foo() { [[ -n $foo ]] && print foo }
% zle -N zle-line-init foo
% autoload -Uz add-zle-hook-widget
% bar() { print bar }
% add-zle-hook-widget line-init bar
%

foo implements a perfectly fine zle-line-init widget. It obeys the
contract laid out at
https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Special-Widgets,
which says nothing about return values. There are plenty of such
zle-xxx widgets out there in the wild, written before the introduction
of add-zle-hook-widget.

bar is also a perfectly fine hook function, implementing the contract
laid out by add-zle-hook-widget.

However, through no fault of its own, bar will never get called,
because once foo has return non-zero, azsh:zle-line-init will not call
any further hook widgets:

function azhw:${^hooktypes} {
    local -a hook_widgets
    local hook
    # Values of these styles look like number:name
    # and we run them in number order
    zstyle -a $WIDGET widgets hook_widgets
    for hook in "${(@)${(@on)hook_widgets[@]}#<->:}"; do
if [[ "$hook" = user:* ]]; then
    # Preserve $WIDGET within the renamed widget
    zle "$hook" -f "nolast" -N -- "$@"
else
    zle "$hook" -f "nolast" -Nw -- "$@"
fi || return  # <-- This is the offending line.
    done
    return 0
}

(Comment mine.)

Isn't add-zle-hook-widget here violating the contract between foo and
zle -N zle-line-init? Should that `|| return` be removed?


^ permalink raw reply	[flat|nested] 19+ messages in thread
* Re: Does add-zle-hook-widget violate the contract of ZLE hook widgets?
@ 2021-06-27  8:19 Marlon Richert
  2021-06-29  2:06 ` Bart Schaefer
  0 siblings, 1 reply; 19+ messages in thread
From: Marlon Richert @ 2021-06-27  8:19 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Lawrence Velázquez, Zsh hackers list

On 26 Jun 2021, at 17:52, Bart Schaefer <schaefer@brasslantern.com> wrote:
> 
> On Sat, Jun 26, 2021 at 6:14 AM Marlon Richert <marlon.richert@gmail.com> wrote:
>> However, my understanding of Yodl is limited. Is there a simpler way to do this?

Did you notice I asked a question? You left it out of your reply.



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

end of thread, other threads:[~2021-06-29 14:51 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-23 20:30 Does add-zle-hook-widget violate the contract of ZLE hook widgets? Marlon Richert
2021-06-23 21:57 ` Daniel Shahaf
2021-06-23 23:33   ` Lawrence Velázquez
2021-06-24  0:09     ` Daniel Shahaf
2021-06-24 10:34   ` Marlon Richert
2021-06-24 10:45     ` Roman Perepelitsa
2021-06-24 18:54       ` Daniel Shahaf
2021-06-24 19:51         ` Roman Perepelitsa
2021-06-24 18:30     ` Daniel Shahaf
2021-06-24 21:48       ` Marlon Richert
2021-06-24 22:29         ` Lawrence Velázquez
2021-06-26 10:12           ` Marlon Richert
2021-06-26 14:51             ` Bart Schaefer
2021-06-24 23:52         ` Daniel Shahaf
2021-06-26 10:49           ` Marlon Richert
2021-06-25 17:34         ` Bart Schaefer
2021-06-27  8:19 Marlon Richert
2021-06-29  2:06 ` Bart Schaefer
2021-06-29 14:50   ` Marlon Richert

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