Subject: bug#78995: [PATCH] ;;;autoload-expand for special macros

From: "J.D. Smith" <[email-masked]>
Date: Wed, 23 Jul 2025 17:20:13 -0400

Stefan, can you take a look at this?

I think I now understand why there are slight differences in the
loaddefs.el file generated by my declare-based, eager-loading patch.
There is a /bug/ in the fallback "list 3" generation of autoloads,
leading to incorrect autoload statements being written out.

The `INTERACTIVE' arg to `autoload' is supposed to be formed as follows:

  If INTERACTIVE is a list, it is interpreted as a list of modes the
  function is applicable for.

The current code mistakenly injects the actual ARG-DESCRIPTOR list into
the autoload file, for those (few) macros which are not expanded but
fall through to list 2, possibly just `cl-defun's.  You might see for
example the full `(let...` descriptors for `erc` in your loaddefs.el
file.

That's a bug I believe, and will presumably mess with the mode-specific
M-S-x type functionality. So by expanding more eagerly with `(declare
(autoload macro-expand))', this bug was "eliminated".  The attached
fixes it for any cases which still use fall-through to list 2.

Thoughts?

diff --git a/lisp/emacs-lisp/loaddefs-gen.el b/lisp/emacs-lisp/loaddefs-gen.el
index 0f136df1fe2..ba7ec21eaed 100644
--- a/lisp/emacs-lisp/loaddefs-gen.el
+++ b/lisp/emacs-lisp/loaddefs-gen.el
@@ -257,8 +257,8 @@ loaddefs-generate--make-autoload
                       t)
                  (and (eq (car-safe (car body)) 'interactive)
                       ;; List of modes or just t.
-                      (or (if (nthcdr 1 (car body))
-                              (list 'quote (nthcdr 1 (car body)))
+                      (or (if (nthcdr 2 (car body))
+                              (list 'quote (nthcdr 2 (car body)))
                             t))))
             ,(if macrop ''macro nil)))))