A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://stackoverflow.com/questions/21880139/what-is-with-eval-after-load-in-emacs-lisp below:

macros - What is "with-eval-after-load" in Emacs Lisp

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.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4