all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "J.P." <jp@neverwas.me>
To: 57955@debbugs.gnu.org
Cc: emacs-erc@gnu.org
Subject: bug#57955: 29.0.50; Allow session-local ERC modules
Date: Wed, 18 Oct 2023 06:36:26 -0700	[thread overview]
Message-ID: <87cyxccasl.fsf__18471.2333882757$1697636274$gmane$org@neverwas.me> (raw)
In-Reply-To: <87edhy9hne.fsf@neverwas.me> (J. P.'s message of "Fri, 13 Oct 2023 17:23:01 -0700")

[-- Attachment #1: Type: text/plain, Size: 323 bytes --]

"J.P." <jp@neverwas.me> 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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-5.6-Warn-about-top-level-erc-update-modules-calls.patch --]
[-- Type: text/x-patch, Size: 5002 bytes --]

From 1e2b653b3b4af5f19f24b700bdd55cb30c198670 Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <jp@neverwas.me>
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{<mymod>} in @code{erc-modules} lacks a corresponding
 @code{erc-<mymod>-mode} command, ERC will attempt to load the library
 @code{erc-<mymod>} 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-<my-mod>)} 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


  parent reply	other threads:[~2023-10-18 13:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <8735cm2o2l.fsf@neverwas.me>
2022-10-26 13:16 ` bug#57955: 29.0.50; Allow session-local ERC modules J.P.
2022-11-15 15:07   ` J.P.
     [not found]   ` <877czww91p.fsf@neverwas.me>
2023-05-22  4:05     ` J.P.
2023-10-09  4:02 ` J.P.
     [not found] ` <87o7h8jvet.fsf@neverwas.me>
2023-10-14  0:23   ` J.P.
     [not found]   ` <87edhy9hne.fsf@neverwas.me>
2023-10-18 13:36     ` J.P. [this message]
2024-02-10 20:36 ` J.P.
     [not found] ` <87wmrcxdjf.fsf@neverwas.me>
2024-03-01  0:25   ` J.P.
2022-09-20 13:05 J.P.
2022-09-20 17:43 ` Michael Albinus
2022-09-21 13:15   ` J.P.

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='87cyxccasl.fsf__18471.2333882757$1697636274$gmane$org@neverwas.me' \
    --to=jp@neverwas.me \
    --cc=57955@debbugs.gnu.org \
    --cc=emacs-erc@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.