1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -08:00

(lisp-indent-function): Auto-load macros to get the indent info

Rather than preload the `lisp-indent-function` property for
autoloaded macros, auto-load them to fetch their property.
In terms of cost, this slightly reduces the heap size at
startup, while tending to increase the heap size while editing
ELisp code since more packages will be (auto)loaded.

The benefit is elsewhere: by loading the definition the macro we
will also load other (non-autoloaded) definitions, so we get
better behavior for things like `ert.el` and `inline.el` where
only some of the macros are autoloaded, because there's a good
chance that we'll end up loading them to indent the autoloaded
macro, after which indentation of the other macros will be
performed correctly (bug#68818).

* lisp/emacs-lisp/byte-run.el (byte-run--dont-autoload): New function.
(macro-declarations-alist): Use it to override `byte-run--set-indent`.

* lisp/emacs-lisp/lisp-mode.el (lisp-indent-function): Auto-load macros
if needed to get the indent info.
This commit is contained in:
Stefan Monnier 2025-11-18 17:23:11 -05:00
parent 6b389a61c1
commit be2b38ce14
2 changed files with 16 additions and 8 deletions

View file

@ -246,6 +246,12 @@ declaration" f2 f))
(list 'function-put (list 'quote f)
''function-type (list 'quote val))))
(defalias 'byte-run--dont-autoload
#'(lambda (fn)
#'(lambda (&rest args)
(let ((code (apply fn args)))
(list 'progn ':autoload-end code)))))
;; Add any new entries to info node `(elisp)Declare Form'.
(defvar defun-declarations-alist
(list
@ -368,16 +374,18 @@ This is used by `declare'.")
(cons actions cl-decls))))
(defvar macro-declarations-alist
(cons
(list 'debug #'byte-run--set-debug)
(cons
(nconc
(list
(list 'debug #'byte-run--set-debug)
;; 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)))
;; Override the entry from `defun-declarations-alist', because we
;; prefer to autoload the macro when trying to indent it (bug#68818).
(list 'indent (byte-run--dont-autoload #'byte-run--set-indent))
(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

View file

@ -861,7 +861,7 @@ or to switch back to an existing one."
:type '(choice (const nil) integer)
:safe (lambda (x) (or (null x) (integerp x))))
(defcustom lisp-indent-function 'lisp-indent-function
(defcustom lisp-indent-function #'lisp-indent-function
"A function to be called by `calculate-lisp-indent'.
It indents the arguments of a Lisp function call. This function
should accept two arguments: the indent-point, and the
@ -1256,7 +1256,7 @@ Lisp function does not specify a special indentation."
(progn (forward-sexp 1) (point))))
method)
(setq method (or (function-get (intern-soft function)
'lisp-indent-function)
'lisp-indent-function 'macro)
(get (intern-soft function) 'lisp-indent-hook)))
(cond ((or (eq method 'defun)
;; Check whether we are in flet-like form.