From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 5635 invoked from network); 24 Jun 2021 18:30:34 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 24 Jun 2021 18:30:34 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1624559434; b=SbrnnOzW3QV1ZqWxDZNeJpjrEb8YR8HklfOsnRp8US91MF9KVoK4ITOVBI0Z/ICbGCZMcrGucl wGf2KBfI9hDk9CZqOcKbKaHwQ8nt1VvU0ZyAfxV1WgGSNyQPD0EzG4LJwAD1sXUBr47QvP5NAU eFDbcnruJ0NB9/qLISg3pUPzfyedHMgfzDxim7NH80OUFpTcipMc6rsqFJu+GbF/50cJn92cBs +bA/5AwylspKny3zZDF9Ty/RLpcwGA81s0FzvtQHIqdkr4CivoLV1RpL0D+yl2Ur51fjgcAtCZ VAijmZqcm/3x+lBgztu2ike3/dJ/TDep0epR/QaARlIWVw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (wout1-smtp.messagingengine.com) smtp.remote-ip=64.147.123.24; dkim=pass header.d=daniel.shahaf.name header.s=fm3 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm3 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1624559434; bh=UdRMrWU1yZbFuQzcQu8AaiAcOyQHdsIakfYcn3Ym004=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:DKIM-Signature: DKIM-Signature:DKIM-Signature; b=makR66h9omOyxahue2syrvU1/6Q5aTlyZDcSmyDfqlapRhHv8+uaClZ/7GTeFlmj/aeY5M2wZD 7oXrTL/n23ABUi0YDxa9xWQwZSQYC1Hi4l3ZhG/kskONqOXRMirE3ieIGVVet5YLWPUDI5N4Or BFhPj5yAyPpasO06CgcAP8fwiORsZA53I1JQd0YjZwss5WwKBMcU5D+yQphlQmd8pwZA2RRjCx utGMpAFb6abP1QNPFkl3UYMhqODTkMDNcUfWbQrNSjTLLgVv6lijxFklwnrCzInkQg2aEwZsKl onrzD0Mst6o7MmlZE/bCdrXnmt8ffxpaR6Izs1eDbvXcHQ==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID; bh=GLTOKGVl48tI9H/H6X4md1DN5hnPnw6fyLm4/Q/V4cU=; b=qiADp/OWatvYDXnoMcv8i8LhRu SyGIsdIA0P4UTp7ILKYxaJQldn/dKf0qLcUqk6ELHGrcF8bv6gxBMoTbqQexKru+CIwM2dJ8vWEvD meRf09qMs8odjhJIx2sdLSmt3gp6Bnr5/6nlNYIkC4t7sH+qpdoxp47Cq8x8jIyv6vkW8nPTSrqE7 ceX5MInVya6c+S5xKqQ4eRtXpqoYw6aymPsLKStWRbMKwiF+O9eC/AlgV89QLXIfItlFRYDuXMJL4 hrQK04wVMM2/pEb+q3SYRX7KvILfVRBSuRMs1dT+6V8d/g+WVIWGYEN6NJCNDm1BBfbo4fEKMgUcy /WrQEIpg==; Received: from authenticated user by zero.zsh.org with local id 1lwU7V-0000Cs-LN; Thu, 24 Jun 2021 18:30:33 +0000 Authentication-Results: zsh.org; iprev=pass (wout1-smtp.messagingengine.com) smtp.remote-ip=64.147.123.24; dkim=pass header.d=daniel.shahaf.name header.s=fm3 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm3 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none Received: from wout1-smtp.messagingengine.com ([64.147.123.24]:54933) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1lwU7C-000Pvf-Sb; Thu, 24 Jun 2021 18:30:16 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id 0C240320090D; Thu, 24 Jun 2021 14:30:09 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 24 Jun 2021 14:30:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=date:from:to:cc:subject:message-id :references:mime-version:content-type:content-transfer-encoding :in-reply-to; s=fm3; bh=GLTOKGVl48tI9H/H6X4md1DN5hnPnw6fyLm4/Q/V 4cU=; b=FdPscOgMgLZWOxhbQL1n8+w0q6XQqufvD0jlG9Eu6YTa0Ifg+014OCAg 9vjtdDTWhE0PcCFqFNf8wHC12EH2AcC9FJ6vEbcs+NtlEdx/F5+FFEZq4v1ngsXG Sncdz+vHiXlNd7ZEWRC25NrSK0HVGUC5nwADec7GH3bEXXMPv3jeTYlGkD3HQbK3 zxy3bvEG8qFRmEwnvv7MmWgfkIthwKfaE20lgdoYBg3e/IvKpc7g6lU6vprZuX96 M2g4zFkH+qz32fYbHIe0iSHmRsIlYvKyKZUwcQITgerdA7w8kKzELE8N1pBBGg0b Pd7uqH/g+/+6FNTK9QqHDIrxIVsVog== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=GLTOKGVl48tI9H/H6X4md1DN5hnPnw6fyLm4/Q/V4 cU=; b=VCfxc+9l7yrbMsg9+VJZEuk6T/hYrqCSco581lFrjdw2koPBcAHrMAqu9 f9I4xbPzBAUN/RO+FuWo63TKT2J5rLpG6IX6RsGrvrB+9JL+NXX76ke61HWXcrTF VSezwKUpmIV1i6Nb285dSSR/2/ntWMXEfuKSki1tXHaF2JTzqCaOKgJIsZoXzopn 2jYmHCteP4Sy59nqcnLWq7taR4OO91z9XFQ+aRLrLFumFUNfG9Us+1us52kyHErq x47EzoRO8Ja5eGoqRlfnr1RyHznAp9vd31t2++oSa45BbiRW8RakDgDyw/Tfsuqk IeaCgWueIyOmdpDOWp11ayXnC+XNg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfeeghedguddviecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvuffkfhggtggugfgjfgesthektddttderudenucfhrhhomhepffgr nhhivghlucfuhhgrhhgrfhcuoegurdhssegurghnihgvlhdrshhhrghhrghfrdhnrghmvg eqnecuggftrfgrthhtvghrnhepueetgfdvleeiledvvdffueehleehtddtfeeiudfhheeh ledvhfehfffhheelffegnecuffhomhgrihhnpehsohhurhgtvghfohhrghgvrdhiohenuc evlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegurdhssegu rghnihgvlhdrshhhrghhrghfrdhnrghmvg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 24 Jun 2021 14:30:09 -0400 (EDT) Received: by tarpaulin.shahaf.local2 (Postfix, from userid 1005) id 4G9pb24KS9z3Sj; Thu, 24 Jun 2021 18:30:06 +0000 (UTC) Date: Thu, 24 Jun 2021 18:30:06 +0000 From: Daniel Shahaf To: Marlon Richert Cc: Zsh hackers list Subject: Re: Does add-zle-hook-widget violate the contract of ZLE hook widgets? Message-ID: <20210624183006.GA16386@tarpaulin.shahaf.local2> References: <9c56f50a-d061-4175-958a-6f89f6bae822@www.fastmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Seq: 49113 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Marlon Richert wrote on Thu, Jun 24, 2021 at 13:34:00 +0300: > On Thu, Jun 24, 2021 at 1:06 PM Daniel Shahaf wrote: > > > > 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 > > otherwise > > > > 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). > > I think this should be mentioned permanently in the manual, exactly > because we see foo and bar from separate maintainers in the wild. I'm ambivalent about this. On the one hand, as mentioned, "set $? correctly" is a ground rule that shouldn't need to be made explicit everywhere it matters. I don't want to create an expectation that where the manual _doesn't_ explicitly specify that $? should be set correctly, $?'s value doesn't matter. On the one hand, someone who uses «zle -N zle-line-init foo» may not be aware of a-z-h-w and of the fact that the return value does have an effect. In balance, I think I would rather see it documented globally that $? should always be set to zero/non-zero unless explicitly specified otherwise. Makes sense? > > > 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. > > For hooks added through azhw, yes. But hooks added through zle -N > zle- have no reason to expect that their return value has any > effect. > I did give some reasons in my previous reply; and compare how drivers should use their turn indicators even when they don't see anyone on the road. > How about if azhw would ignore the return value _only_ of any > pre-existing zle -N zle-X widget? For example, this part of the azhw > code could be modified to wrap the original widget function in a > function that always returns zero: > > # Check for an existing widget, add it as the first hook > if [[ ${widgets[$hook]:-} != "user:azhw:$hook" ]]; then > if [[ -n ${widgets[$hook]:-} ]]; then > zle -A "$hook" "${widgets[$hook]}" # <-- This line could be changed. --M > extant_hooks=(0:"${widgets[$hook]}" "${extant_hooks[@]}") > fi > zle -N "$hook" azhw:"$hook" > fi > At this point, given that the current behaviour has appeared in stable releases for 4.5 years now and is _a priori_ preferable, I think it's better to document the current behaviour and move on. So, basically, an addition to the incompatible changes section in README (for 5.9) that describes the change in 5.3. WDYT? > Also, regardless of the above, the documentation in > https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Special-Widgets > could be updated to guide the user towards azhw. +1. Anyone interested in writing a patch? > And the documentation of azhw could be updated to mention the > canceling behavior. Sure. Also, the documentation of a-z-h-w should spell out "zle-line-init", "zle-line-finish", etc., in full for greppability. > > Hope that answers your question. > > I didn't mean this as a Q&A, but more as a point of discussion. :) > Ack. I did take it this way; sorry for my unclarity. > If we are happy with the behavior as-is, then this should be > documented. In particular, 3rd-party developers should be strongly > encouraged to use azhw and not zle -N zle-X. Some sort of "Best practices for third-party plugin maintainers" document might be a good idea. Could make it a bit more general and also answer "Where do I install my completion function to?" for third-party packages (e.g., _curl) and so on. It could start as additions to the FAQ. Cheers, Daniel