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,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 18516 invoked from network); 24 Jun 2021 10:34:58 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 24 Jun 2021 10:34:58 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1624530898; b=GQ83ziEXOspFrp/+Ahfiw565sS4hk7zfkqHv+gPiK57x6ktgBv3fX4rCPz66RNXr9LASdkn1NV qyPemPE3SDKcTlVgzJ9szpj1cZiiJgw4XYALck532DR5609Df5o5Pz9qbMqb7jmWXeBKp1EZ1g lzrP+Oc1kWDJHYvx6qDSbqOWyOJj/xBWDdkoHPZkYDKGAqDcq3tTUCJZi93esmnm/Me/G0PnQf uxt9xwtwvLYtV/qZTmrU87Olk/hwHwd9WUOi5Ccw5Vtv0udfw1s5uqvNPM6dhla7KuqaYuMhwT QXc+4s2GQL02QW+Etb8HLM7O6/AkjGIP55sFbnBfg4MfQg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lf1-f42.google.com) smtp.remote-ip=209.85.167.42; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1624530898; bh=h5ckGV7ALUnUYSsWCGBPG7TOkfiYa4axOwLiNIQrOYQ=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=LNCJVhfr9XkJ/jgmLiLcbBU8fgncKbRPNsXVSHwRkWNErKmyJcoQVTVPq1SG4+Ysw94xw1Xx0C HWIrkxK2Ni9zfb8JSZM7SiGoGM/6mSO0RExpxW1JQxp8neJNpeT3MFJoCgjelBezuSUBlLHEm3 rxnPTXUUS2FAhn6dAm9dU5jvH6DvM2wDcZqiqWp7SrMI3te/yjWyhLAKH7AR5dLzZTfkQXHbNm bvNCcO7A4HeZE3QW+Ys/rKTvhL5LajdtcJBfoVaojUDOAkZ9tgvv41+pViLLUbQUss3joBKGQv GPXQ7iYCdJNAA6CWqCS7VUJ7OaIaX+ManuK7O3tbtM3CPA==; 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:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=ZUgb//xdDI9X6KR0YKpq0OIXtU1xu3h9BBG5aufiHXU=; b=BpWAM6p4P6NSj4UYYhEzfOOFpv mxsYUL8czbgnC5HBRjg+T12dTgicbIAtk5yDfaquDS/F43UzBnSH2dC2Hywy0mVM0/d8i3NSI+Dl5 zOEe9HCoZvdmCbv0l69snQbufSs2zqdZ2u6tc0PFanmrVYeH+dG2ppXOtHrmkMLjA13OU5df7lT8X +N285F3G0GFSdbYiHcAJUYrOfy8Lq9XEHqfTJwp5xcHZKtk6jByAgI5gA4xv04PwoVzTiiGB+q/Ez 8wxYuzAJO9buRRvLmVfLEYztli5B2WPDHS9V9SlrK2ocYYpWYiwOd8ThKWa7D1W3EntDWz7H8YOjv R20NaUCQ==; Received: from authenticated user by zero.zsh.org with local id 1lwMhF-0006PT-Lw; Thu, 24 Jun 2021 10:34:57 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lf1-f42.google.com) smtp.remote-ip=209.85.167.42; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-lf1-f42.google.com ([209.85.167.42]:35540) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1lwMgv-00065R-Cj; Thu, 24 Jun 2021 10:34:38 +0000 Received: by mail-lf1-f42.google.com with SMTP id u13so9472729lfk.2 for ; Thu, 24 Jun 2021 03:34:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ZUgb//xdDI9X6KR0YKpq0OIXtU1xu3h9BBG5aufiHXU=; b=UxVzBu05++ciQRxnZVnvzWsI8YGstT40wsKXr/36aH7TGxkdgZ86lfbostjyBl/Omy PHV3FlgatVDv1zs1t8PaS9m2ohpjv/VDTUofSE8mKxqvmrG0O8asQySWWoJqbsQucQrh GFwMopwge3H8rUabHtZgzp+nHNil0fDLyeX2CJKNsk12+9dTz4QVhTlOe334nfqcJz2B 8BVeaGC/ee8H/iL/5jNW1ghXpFqmuWo+qu+pQP+Z2r5hXwk+ennANOLZ9N4q/9QidWCQ yd07TgDIPNOGpciLjdfIr4PMaSvYGE9ddlI6N2vNuYfOItRHd1Owu5lPNk0/BBopGvIO Ilkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ZUgb//xdDI9X6KR0YKpq0OIXtU1xu3h9BBG5aufiHXU=; b=IPpsdcU4nz4t+Nrhvgo1nDT20oSL3WLElVZtMAdfJsmoH7sLy+S7Pn+IBW4W1+DoE9 1KLhhbb5U9QqeI/NTB9kdX4nrKF1xsQoq/Aux/Cc9/Viu3/RLK2XYqUvwFyZRR2t9hER VZ/URspf7l8ouemU6Ku5oUde/M2HVKZS1lWg0Q1EYxjQMNT2D06tMgPCgNaH0GjcBxL7 a6+vzmzZU9rDMutStjw1BzH4/idkhPHnKoK9+HRytFsKLi9Rnr/i4YOiI1ZYCcVxjTip 3fDoTJFXdai74Q1wI1mBIi/I0pfGB3elQ04AhujRp+yLkMrhP5dCAhhiM1IOQflIxMOK J5vQ== X-Gm-Message-State: AOAM533kcVE3wKpsiyJkRtsHmn+1od2qx2VBLCsEMmIUbrokDx7aV6mg Y39+c2DaEL18U3cuTB8knN4Or3zjlm40fYl+lxxkLBv8H8lElQ== X-Google-Smtp-Source: ABdhPJzSSuVIHNR7DBO6y0DhqJX+tzn7pItWkx2mY48nYTxKxQhDHeGgg8Zm+wSLMYy8+Vfvqka+H5NDBuQZovZJ2o0= X-Received: by 2002:a05:6512:1512:: with SMTP id bq18mr3473656lfb.102.1624530876500; Thu, 24 Jun 2021 03:34:36 -0700 (PDT) MIME-Version: 1.0 References: <9c56f50a-d061-4175-958a-6f89f6bae822@www.fastmail.com> In-Reply-To: <9c56f50a-d061-4175-958a-6f89f6bae822@www.fastmail.com> From: Marlon Richert Date: Thu, 24 Jun 2021 13:34:00 +0300 Message-ID: Subject: Re: Does add-zle-hook-widget violate the contract of ZLE hook widgets? To: Daniel Shahaf Cc: Zsh hackers list Content-Type: text/plain; charset="UTF-8" X-Seq: 49111 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: 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. > > 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. 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 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. And the documentation of azhw could be updated to mention the canceling behavior. > Hope that answers your question. I didn't mean this as a Q&A, but more as a point of discussion. :) 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.