I came across the macro with-eval-after-load
when trying to install persp-mode
from here. But I am unable to find the macro inside Emacs and/or on Google. Where is it defined? Is it part of standard Emacs Lisp?
To load an Emacs Lisp file, type M-x load-file . This command reads a file name using the minibuffer, and executes the contents of that file as Emacs Lisp code. It is not necessary to visit the file first; this command reads the file directly from disk, not from an existing Emacs buffer.
#'... is short-hand for (function ...) which is simply a variant of '... / (quote ...) that also hints to the byte-compiler that it can compile the quoted form as a function.
From etc/NEWS
:
* Lisp Changes in Emacs 24.4 ... ** New macro `with-eval-after-load'. This is like the old `eval-after-load', but better behaved.
Emacs 24.4 was released on 20th October 2014.
eval-after-load
is considered ill-behaved because it is a function, not a macro, and thus requires the code inside it to be quoted, which means that it cannot be byte-compiled. It also accepts only one form, so if you have more than one, you need to use progn
. For example:
(eval-after-load "foo" '(progn (setq foo 42) (setq bar 17)))
The equivalent version with with-eval-after-load
would be:
(with-eval-after-load "foo" (setq foo 42) (setq bar 17))
As noted by Clément in a comment, one disadvantage of with-eval-after-load
is that you cannot rely on macros defined in the module in question, while with eval-after-load
you can be sure that such macros are defined and available to use. This was discussed on emacs-devel.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With