1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-10 08:10:21 -08:00

Implement new autoload macro expansion declare form

Currently, a hard-coded set of macros is automatically expanded
during generation of autoloads.  To allow user macros to request
such expansion, this implements a new declare form
`autoload-macro' (Bug#78995), with supported value `expand'.
For example, macros which wrap `define-minor-mode', can declare
`(autoload-macro expand)' to request that ;;;###autoload-adorned
calls to the macro are expanded during generation, such that an
autoload for the resulting function is created.

* lisp/emacs-lisp/byte-run.el (byte-run--set-autoload-macro):
Handle autoload-macro declare forms.
(macro-declarations-alist) Add handler for 'autoload-macro
declare forms.
(defmacro, defun):
* lisp/emacs-lisp/cl-generic.el (cl-defgeneric, cl-defun)
(cl-iter-defun, cl-defmacro, cl-defstruct):
* lisp/emacs-lisp/easy-mmode.el
(define-minor-mode, define-globalized-minor-mode, iter-defun):
* lisp/emacs-lisp/inline.el (define-inline):
* lisp/emacs-lisp/pcase.el (pcase-defmacro):
Declare (autoload-macro expand) to request expansion of the
macro during autoload generation.

* lisp/emacs-lisp/loaddefs-gen.el (loaddefs-generate--make-autoload):
Handle the `autoload-macro=expand' property for macros.  Load
the ;;;###autoload-containing file if an unknown symbol is
encountered in the car of the following form, to give packages a
chance to define their macros and request expansion.  Factor
list of special function-defining macros out as a constant
variable: `loaddefs--defining-macros'.

* doc/lispref/functions.texi (Declare Form):
* doc/lispref/loading.texi (Autoload): Document `autoload-macro'.
This commit is contained in:
JD Smith 2025-07-24 15:42:10 -04:00
parent 3d7f51d872
commit 7486e5c368
10 changed files with 164 additions and 56 deletions

View file

@ -286,6 +286,12 @@ This is used by `declare'.")
(list 'put (list 'quote name)
''edebug-form-spec (list 'quote spec)))))
(defalias 'byte-run--set-autoload-macro
#'(lambda (name _args spec)
(list 'function-put (list 'quote name)
''autoload-macro (list 'quote spec)))
"Handle autoload-macro declarations")
(defalias 'byte-run--set-no-font-lock-keyword
#'(lambda (name _args val)
(list 'function-put (list 'quote name)
@ -365,8 +371,13 @@ This is used by `declare'.")
(cons
(list 'debug #'byte-run--set-debug)
(cons
(list 'no-font-lock-keyword #'byte-run--set-no-font-lock-keyword)
defun-declarations-alist))
;; macros can declare (autoload-macro expand) to request expansion
;; during autoload generation of forms calling them. See
;; `loaddefs-generate--make-autoload'.
(list 'autoload-macro #'byte-run--set-autoload-macro)
(cons
(list 'no-font-lock-keyword #'byte-run--set-no-font-lock-keyword)
defun-declarations-alist)))
"List associating properties of macros to their macro expansion.
Each element of the list takes the form (PROP FUN) where FUN is a function.
For each (PROP . VALUES) in a macro's declaration, the FUN corresponding
@ -412,6 +423,8 @@ The return value is undefined.
(if declarations
(cons 'prog1 (cons def (car declarations)))
def))))))
;; Expand to defalias and related forms on autoload gen
(function-put 'defmacro 'autoload-macro 'expand) ; Since we cannot `declare' it
;; Now that we defined defmacro we can use it!
(defmacro defun (name arglist &rest body)
@ -424,7 +437,9 @@ INTERACTIVE is an optional `interactive' specification.
The return value is undefined.
\(fn NAME ARGLIST [DOCSTRING] [DECL] [INTERACTIVE] BODY...)"
(declare (doc-string 3) (indent 2))
(declare (doc-string 3) (indent 2)
;; Expand to defalias on autoload gen
(autoload-macro expand))
(or name (error "Cannot define '%s' as a function" name))
(if (null
(and (listp arglist)