From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "J.P." Newsgroups: gmane.emacs.bugs Subject: bug#62947: 30.0.50; ERC 5.6: Improve partitioning of outgoing messages Date: Wed, 06 Dec 2023 23:19:18 -0800 Message-ID: <875y1a7a4p.fsf__49381.2479822495$1701933616$gmane$org@neverwas.me> References: <87wn27ncnk.fsf@neverwas.me> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35339"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: emacs-erc@gnu.org To: 62947@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 07 08:20:07 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rB8g2-0008xt-Vi for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 07 Dec 2023 08:20:07 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rB8fp-0008Rw-WD; Thu, 07 Dec 2023 02:19:54 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rB8fn-0008QN-2z for bug-gnu-emacs@gnu.org; Thu, 07 Dec 2023 02:19:51 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rB8fm-0002yQ-Qt for bug-gnu-emacs@gnu.org; Thu, 07 Dec 2023 02:19:50 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rB8fy-0006OB-Hq for bug-gnu-emacs@gnu.org; Thu, 07 Dec 2023 02:20:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: "J.P." Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 07 Dec 2023 07:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62947 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 62947-submit@debbugs.gnu.org id=B62947.170193358124506 (code B ref 62947); Thu, 07 Dec 2023 07:20:02 +0000 Original-Received: (at 62947) by debbugs.gnu.org; 7 Dec 2023 07:19:41 +0000 Original-Received: from localhost ([127.0.0.1]:40915 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rB8fd-0006NB-3i for submit@debbugs.gnu.org; Thu, 07 Dec 2023 02:19:41 -0500 Original-Received: from mail-108-mta225.mxroute.com ([136.175.108.225]:37179) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rB8fX-0006Mt-JI for 62947@debbugs.gnu.org; Thu, 07 Dec 2023 02:19:39 -0500 Original-Received: from filter006.mxroute.com ([136.175.111.2] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta225.mxroute.com (ZoneMTA) with ESMTPSA id 18c43253985000190b.001 for <62947@debbugs.gnu.org> (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Thu, 07 Dec 2023 07:19:22 +0000 X-Zone-Loop: 6dca6b42d5b5bee9dc03cc5c7a5b8a3f732aabebb72e X-Originating-IP: [136.175.111.2] DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=neverwas.me ; s=x; h=Content-Type:MIME-Version:Message-ID:Date:References:In-Reply-To: Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=bReDod67dVzy7ljnipPfkOvT5d7D7RoOMIvi+hxm7VM=; b=CrM5T0pZEIeoxc6k5fIb7THIQh B8HrHdx+NxEzCACQfr5PqS6/PMrx1XLTHFZDW6AGNUYCmvR8qB5sHA0euWNNdJJQoBJpSqg2JM208 aiz4k9QYw2BijvFjW/HcLaW+30CbvwSKLWI7/b7V3H11nPsKdYb5io1PVw27pDlukIFvb0MPz2GkB szrBj7HWIM3qzprMBCetENsyo5EKINbdFNa+HDO1C9PTvz2ZAp6f+LAOxLj/uzwcFlnF7jfwdV2FH r39EwJTbIZ1uqhHlM43UuF2v9onEKaruyXVjvog0KAO4gXQ5XbAh5mZvQ+UKbWwi4C8V0ZHLO50u4 Vn6rzsJg==; In-Reply-To: <87wn27ncnk.fsf@neverwas.me> (J. P.'s message of "Wed, 19 Apr 2023 07:56:47 -0700") X-Authenticated-Id: masked@neverwas.me X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:275648 Archived-At: --=-=-= Content-Type: text/plain This fix introduced an innocuous though technically breaking change in the definition of `erc-input' (the struct). Basically, it added a new slot, `refoldp', to allow users access to something resembling the pre-5.6 behavior, where protocol-oriented message splitting would take place after `erc-pre-send-functions' ran. That is, setting the slot to t is meant to buy you some of that old functionality in the form of a second split. (The new behavior of only splitting beforehand favors interactive client users over bot/module authors.) However, reflecting back on this, I think it wouldn't kill us to account for the unlikely possibility of someone "subclassing" `erc-input' for use outside this hook. In most cases, I believe simply recompiling their dependent libraries would solve the issue, but why chance it if we don't have to? Hence the attached change, which removes the slot but "spoofs" its would-be accessor, `erc-input-refoldp', while the hook runs. I originally went with a name that differed from that of the would-be accessor, but this feature has been on HEAD for a while, so keeping it seemed the less disruptive option. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0006-5.6-Make-erc-input-s-refoldp-slot-conditionally-avai.patch >From 6d6bfee8180c9ba37545c18aed46ddc8dc43732f Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Fri, 1 Dec 2023 13:54:12 -0800 Subject: [PATCH 06/11] [5.6] Make erc-input's refoldp slot conditionally available * etc/ERC-NEWS: Fix entry regarding `erc-input-refoldp'. * lisp/erc/erc-common.el (erc-input): Remove `refoldp' slot to reduce churn in the unlikely event that third-party code subclasses `erc-input' for use outside of `erc-pre-send-functions'. (erc--input-split) Add `refoldp' slot here instead. * lisp/erc/erc.el (erc-pre-send-functions): Amend doc string to stress that `refoldp' is not a real slot. (erc--input-ensure-hook-context, erc-input-refoldp): New function, an impostor accessor for the nonexistent `refoldp' slot of `erc-input', and a helper function for asserting a valid context at runtime. (erc--run-send-hooks): Don't copy over `refoldp' from the `erc--input-lines' object to the working `erc-insert' object. Check the insertion context's `erc--input-split' object instead of the hook's `erc-insert' object when deciding whether to resplit. * test/lisp/erc/erc-tests.el: Adjust test environment to satisfy assertion. (Bug#62947) --- etc/ERC-NEWS | 5 +++-- lisp/erc/erc-common.el | 3 ++- lisp/erc/erc.el | 31 +++++++++++++++++++++++++------ test/lisp/erc/erc-tests.el | 7 ++++--- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/etc/ERC-NEWS b/etc/ERC-NEWS index f6a9d934e80..540d9e98751 100644 --- a/etc/ERC-NEWS +++ b/etc/ERC-NEWS @@ -460,8 +460,9 @@ ERC now adjusts input lines to fall within allowed length limits before showing hook members the result. For compatibility, third-party code can request that the final input be adjusted again prior to being sent. To facilitate this, the 'erc-input' object -shared among hook members has gained a new 'refoldp' slot, making this -a breaking change, if only in theory. See doc string for details. +shared among hook members has gained a "phony" 'refoldp' slot that's +only accessible from 'erc-pre-send-functions'. See doc string for +details. *** ERC's prompt survives the insertion of user input and messages. Previously, ERC's prompt and its input marker disappeared while diff --git a/lisp/erc/erc-common.el b/lisp/erc/erc-common.el index e9e494720e5..cb820c812b3 100644 --- a/lisp/erc/erc-common.el +++ b/lisp/erc/erc-common.el @@ -49,7 +49,7 @@ erc-session-server (declare-function widget-type "wid-edit" (widget)) (cl-defstruct erc-input - string insertp sendp refoldp) + string insertp sendp) (cl-defstruct (erc--input-split (:include erc-input (string :read-only) @@ -57,6 +57,7 @@ erc-input (sendp (with-suppressed-warnings ((obsolete erc-send-this)) erc-send-this)))) + (refoldp nil :type boolean) (lines nil :type (list-of string)) (abortp nil :type (list-of symbol)) (cmdp nil :type boolean)) diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 9084b7ee042..bb05f17bee6 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -1197,13 +1197,18 @@ erc-pre-send-functions `string': The current input string. `insertp': Whether the string should be inserted into the erc buffer. `sendp': Whether the string should be sent to the irc server. + +And one \"phony\" slot only accessible by hook members at runtime: + `refoldp': Whether the string should be re-split per protocol limits. This hook runs after protocol line splitting has taken place, so the value of `string' is originally \"pre-filled\". If you need -ERC to refill the entire payload before sending it, set the -`refoldp' slot to a non-nil value. Preformatted text and encoded -subprotocols should probably be handled manually." +ERC to refill the entire payload before sending it, set the phony +`refoldp' slot to a non-nil value. Note that this refilling is +only a convenience, and modules with special needs, such as +preserving \"preformatted\" text or encoding for subprotocol +\"tunneling\", should handle splitting manually." :group 'erc :type 'hook :version "27.1") @@ -7424,6 +7429,22 @@ erc--split-lines (setf (erc--input-split-lines state) (mapcan #'erc--split-line (erc--input-split-lines state))))) +(defun erc--input-ensure-hook-context () + (unless (erc--input-split-p erc--current-line-input-split) + (error "Invoked outside of `erc-pre-send-functions'"))) + +(defun erc-input-refoldp (_) + "Impersonate accessor for phony `erc-input' `refoldp' slot. +This function only works inside `erc-pre-send-functions' members." + (declare (gv-setter (lambda (v) + `(progn + (erc--input-ensure-hook-context) + (setf (erc--input-split-refoldp + erc--current-line-input-split) + ,v))))) + (erc--input-ensure-hook-context) + (erc--input-split-refoldp erc--current-line-input-split)) + (defun erc--run-send-hooks (lines-obj) "Run send-related hooks that operate on the entire prompt input. Sequester some of the back and forth involved in honoring old @@ -7443,8 +7464,6 @@ erc--run-send-hooks (run-hook-with-args 'erc-send-pre-hook str) (make-erc-input :string str :insertp erc-insert-this - :refoldp (erc--input-split-refoldp - lines-obj) :sendp erc-send-this)))) (run-hook-with-args 'erc-pre-send-functions state) (setf (erc--input-split-sendp lines-obj) (erc-input-sendp state) @@ -7456,7 +7475,7 @@ erc--run-send-hooks (if erc--allow-empty-outgoing-lines-p lines (cl-nsubst " " "" lines :test #'equal)))) - (when (erc-input-refoldp state) + (when (erc--input-split-refoldp lines-obj) (erc--split-lines lines-obj))))) (when (and (erc--input-split-cmdp lines-obj) (cdr (erc--input-split-lines lines-obj))) diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el index 2c70f100c3f..28c1e403e41 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el @@ -2256,10 +2256,11 @@ erc--run-send-hooks erc-pre-send-functions (lambda (o) (setf (erc-input-string o) "foo bar baz" (erc-input-refoldp o) t))) - (let ((erc-split-line-length 8)) + (let* ((split (make-erc--input-split :string "foo" :lines '("foo"))) + (erc--current-line-input-split split) + (erc-split-line-length 8)) (should - (pcase (erc--run-send-hooks (make-erc--input-split - :string "foo" :lines '("foo"))) + (pcase (erc--run-send-hooks split) ((cl-struct erc--input-split (string "foo") (sendp 't) (insertp 't) (lines '("foo bar " "baz")) (cmdp 'nil)) -- 2.42.0 --=-=-=--