prodissues

use-package's :config vs. :init

Tue 25 October 2016 by yaniv

I read this Reddit thread about favorite themes, and got intrigued by the spacemacs theme1.

I added that theme to my init file, and tried making it the default theme. I use use-package, and configured the theme as follows:

(use-package spacemacs-theme
:ensure t
:config
(load-theme 'spacemacs-light t)
)

When re-evaluating my init file, the theme didn't load. I tried to run only the (load-theme 'spacemacs-light t) line, and the theme loaded. I changed the :config to :init in the package configuration, and it loaded when I re-loaded emacs.

What, then, is the difference between :init and :config in use-package?

The answer to that question, which I found it in this stack-overflow answer, is that in use-package, whatever defined inside the :init keyword, will load whenever emacs is loading. What's in the :config, though, will be executed only when the package is actually loaded (i.e lazy loading)2.

Here's how my configuration for that theme looks like now:

(use-package spacemacs-theme
:ensure t
:init
(load-theme 'spacemacs-light t)
)

  1. I tried spacemacs before, and liked its look and feel, but didn't know I can take it back with me to gnu emacs 

  2. Needless to say that, going back to the use-package documentation, the difference between :init and :config is clearly described…