Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Does add-zle-hook-widget violate the contract of ZLE hook widgets?

% 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
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 -- "$@"
    zle "$hook" -f "nolast" -Nw -- "$@"
fi || return  # <-- This is the offending line.
    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?

Messages sorted by: Reverse Date, Date, Thread, Author