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#57955: 29.0.50; Allow session-local ERC modules Date: Wed, 18 Oct 2023 06:36:26 -0700 Message-ID: <87cyxccasl.fsf__18471.2333882757$1697636274$gmane$org@neverwas.me> References: <8735cm2o2l.fsf@neverwas.me> <87o7h8jvet.fsf@neverwas.me> <87edhy9hne.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="1279"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: emacs-erc@gnu.org To: 57955@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Oct 18 15:37:46 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 1qt6k5-00005L-Mm for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 18 Oct 2023 15:37:45 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qt6jy-0005yU-Uk; Wed, 18 Oct 2023 09:37:38 -0400 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 1qt6jw-0005s4-IT for bug-gnu-emacs@gnu.org; Wed, 18 Oct 2023 09:37:36 -0400 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 1qt6jw-00061Z-5J for bug-gnu-emacs@gnu.org; Wed, 18 Oct 2023 09:37:36 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qt6kL-00009g-QB for bug-gnu-emacs@gnu.org; Wed, 18 Oct 2023 09:38:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "J.P." Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 18 Oct 2023 13:38:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 57955 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 57955-submit@debbugs.gnu.org id=B57955.1697636227522 (code B ref 57955); Wed, 18 Oct 2023 13:38:01 +0000 Original-Received: (at 57955) by debbugs.gnu.org; 18 Oct 2023 13:37:07 +0000 Original-Received: from localhost ([127.0.0.1]:33471 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qt6jS-00008M-W9 for submit@debbugs.gnu.org; Wed, 18 Oct 2023 09:37:07 -0400 Original-Received: from mail-108-mta96.mxroute.com ([136.175.108.96]:40753) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qt6jN-00007u-Ue for 57955@debbugs.gnu.org; Wed, 18 Oct 2023 09:37:05 -0400 Original-Received: from mail-111-mta2.mxroute.com ([136.175.111.2] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta96.mxroute.com (ZoneMTA) with ESMTPSA id 18b43008905000ff68.001 for <57955@debbugs.gnu.org> (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 18 Oct 2023 13:36:30 +0000 X-Zone-Loop: 5c73ae690846d270c71046532bffa50e01dc06039cf3 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=HYBTAfha2eFXb+I7AN92a1OwjBnajcfsY4pEpTSqbrM=; b=NBV5aO8Sli5I5xsg3Dw/vo/+OF HABf73ejVdI6OBnOR029ocoH50IZoMXlJ5nB68AzscZTyWJrfnO6/jj/lk3MsO4j9T0OjNHaQ2Vav ISyZf4jrGjQe2mySLT7CUTNod5XFitsbjED0XdA2Db0mXhmftf3dvqhH75RCzq8AXyRx98buIifZz RLgZrSWCrdVTfetjPsH16fbvogAAaqrnob/uqkkkbZmor3DmRcPn7b6AszrjVos0LTtxmo/SG0HfS ZJG3HW/gfMTfmRxnWLAfyniE59eAcWPVc4oof1VwTBJ9AAVJGT2V768YXqh4IU1UZbK4G0HTMkVlU YHacQFOg==; In-Reply-To: <87edhy9hne.fsf@neverwas.me> (J. P.'s message of "Fri, 13 Oct 2023 17:23:01 -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:272654 Archived-At: --=-=-= Content-Type: text/plain "J.P." writes: > I've added something similar to the proposed change as > > https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=d46c016f Actually, this has proved insufficient for detecting top-level and `eval-after-load' calls to `erc-update-modules'. The attached tweak hopefully addresses that. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-5.6-Warn-about-top-level-erc-update-modules-calls.patch >From 1e2b653b3b4af5f19f24b700bdd55cb30c198670 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Tue, 17 Oct 2023 23:36:12 -0700 Subject: [PATCH] [5.6] Warn about top-level erc-update-modules calls * doc/misc/erc.texi (Modules): Mention risk of infinite recursion when packages run `erc-update-modules' on load. * lisp/erc/erc.el (erc--warn-about-aberrant-modules): Tweak warning message. (erc--requiring-module-mode-p): New internal variable. (erc--find-mode): Guard against recursive `require's. (Bug#57955) --- doc/misc/erc.texi | 21 ++++++++++++--------- lisp/erc/erc.el | 21 ++++++++++++++++----- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/doc/misc/erc.texi b/doc/misc/erc.texi index 3bfa240cacc..c654c97731c 100644 --- a/doc/misc/erc.texi +++ b/doc/misc/erc.texi @@ -666,17 +666,17 @@ Modules @code{} in @code{erc-modules} lacks a corresponding @code{erc--mode} command, ERC will attempt to load the library @code{erc-} prior to connecting. If this fails, ERC signals an -error. Users wanting to define modules in an init files should +error. Users defining personal modules in an init file should @code{(provide 'erc-)} somewhere to placate ERC. Dynamically generating modules on the fly is not supported. -Sometimes, packages attempt to autoload a module's definition instead -of its minor-mode command, which breaks the link between the library -and the module. This means that enabling the mode by invoking its -command toggle isn't enough to load its defining library. Such -packages should instead only supply autoload cookies featuring an -explicit @code{autoload} form for their module's minor-mode command. -As mentioned above, packages can also usually avoid autoload cookies +Some packages attempt to autoload a module's definition instead of its +minor-mode command, which breaks the link between the library and the +module. This means that enabling the mode by invoking its command +toggle isn't enough to load its defining library. Such packages +should instead only supply autoload cookies featuring an explicit +@code{autoload} form for their module's minor-mode command. As +mentioned above, packages can also usually avoid autoload cookies entirely so long as their module's prefixed name matches that of its defining library and the latter's provided feature. @@ -686,7 +686,10 @@ Modules itself in an autoloaded form. Doing this tricks Customize into displaying the widget for @code{erc-modules} incorrectly, with built-in modules moved from the predefined checklist to the -user-provided free-form area. +user-provided free-form area. Similarly, some packages run +@code{erc-update-modules} in top-level and autoloaded forms or in +@code{after-load-functions} members, which can trigger recursive +invocations. @c PRE5_4: Document every option of every module in its own subnode diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 5bf6496e926..f841e385ab7 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -2129,12 +2129,17 @@ erc--aberrant-modules (defun erc--warn-about-aberrant-modules () (when (and erc--aberrant-modules (not erc--target)) (erc-button--display-error-notice-with-keys-and-warn - "The following modules exhibited strange loading behavior: " + "The following modules exhibit strange loading behavior: " (mapconcat (lambda (s) (format "`%s'" s)) erc--aberrant-modules ", ") ". Please contact ERC with \\[erc-bug] if you believe this to be untrue." " See Info:\"(erc) Module Loading\" for more.") (setq erc--aberrant-modules nil))) +(defvar erc--requiring-module-mode-p nil + "Non-nil when `require'ing `erc-mymod' from `erc-update-modules'. +Used for detecting top-level calls to `erc-update-modules' by +third-party packages.") + (defun erc--find-mode (sym) (setq sym (erc--normalize-module-symbol sym)) (if-let ((mode (intern-soft (concat "erc-" (symbol-name sym) "-mode"))) @@ -2144,10 +2149,16 @@ erc--find-mode (symbol-file mode) (ignore (cl-pushnew sym erc--aberrant-modules))))) mode - (and (require (or (get sym 'erc--feature) - (intern (concat "erc-" (symbol-name sym)))) - nil 'noerror) - (setq mode (intern-soft (concat "erc-" (symbol-name sym) "-mode"))) + (and (or (and erc--requiring-module-mode-p + ;; Also likely non-nil: (eq sym (car features)) + (cl-pushnew sym erc--aberrant-modules)) + (let ((erc--requiring-module-mode-p t)) + (require (or (get sym 'erc--feature) + (intern (concat "erc-" (symbol-name sym)))) + nil 'noerror)) + (memq sym erc--aberrant-modules)) + (or mode (setq mode (intern-soft (concat "erc-" (symbol-name sym) + "-mode")))) (fboundp mode) mode))) -- 2.41.0 --=-=-=--