13

I've found the rather useful How Packages work in Emacs 24, however, I'd like a definitive answer from an experienced user or a core developer as to which of these is actually preferred in the typical case on 24.4.

Afaik, (add-hook 'after-init-hook ...) is the so-to-say brute-force approach to setting up customizations for packages. However, eval-after-load and its more syntactically sugary with-eval-after-load seem more appropriate for more dynamic and fine grained configuration that plays well with the gradual, separate and lazy loading of extensions.

Is my understand correct? What else should I keep in mind?

11

Afaik, (add-hook 'after-init-hook ...) is the so-to-say brute-force approach to setting up customizations for packages.

No. If you want to configure packages in your init file, the typical approach is to call (package-initialize) at the top of the file, and then do the configurations. after-init-hook is unnecessarily complicated for this purpose.

However, eval-after-load and its more syntactically sugary with-eval-after-load seem more appropriate for more dynamic and fine grained configuration that plays well with the gradual, separate and lazy loading of extensions.

(with-)eval-after-load is used for things you want to do after a package is loaded. package-initialize doesn't load the packages, it only “prepares” them (loads their autoloads).

If you use eval-after-load around every set of configurations, you won't need to call (package-initialize) at the top. But what people usually do is to call (package-initialize), so that most configurations can be written straight to the init file, and then only eval-after-load code which is very long or which depends on the package being loaded.

| improve this answer | |
  • but it would still be OK to put everything under eval-after-load for any given package, right, and not use (package-initialize) at all? – Erik Kaplun Nov 16 '14 at 23:56
  • @ErikAllik Yes. If you use eval-after-load around every set of configurations, you won't need to call (package-initialize) at the top. – Malabarba Nov 17 '14 at 0:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.