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

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

Marlon Richert wrote on Wed, 23 Jun 2021 20:30 +00:00:
> 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.

That has two possible interpretations:

- Hook functions may set $? however they want

- Hook functions should set $? to zero on success and to non-zero

In favour of the first interpretation is that the manual's language
doesn't explicitly rule it out and compatibility with hook functions
that predate add-zle-hook-widget and don't set $? as
add-zle-hook-widget expects.

In favour of the second interpretation is that those semantics are the
default, ubiquitous, baked into the language's syntax, and extensible
(same thing as "This bit must be zero" in wire protocol specifications).

I'm voting for the second interpretation.

I suppose we could've added something to NEWS/README when add-zle-hook-widget
was introduced, if only because this is an interoperability issue (foo
and bar may be have separate maintainers).

> Isn't add-zle-hook-widget here violating the contract between foo and
> zle -N zle-line-init?

No.  The contract with foo is that it'll be called, and it does get called.

> Should that `|| return` be removed?

No, because that would break the case of _deliberately_ returning non-zero
from one a-z-h-w hook to prevent further a-z-h-w hooks from running.
Granted, that's not a documented promise, but there's no reason to break
it, either.

Hope that answers your question.

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