Emacs: Use-package

October 11, 2018

use-package is my preferred way of dealing with emacs packages. You can find more information about it here. What I ended up with before I started to really get into use-package is that you have all of these packages, that are installed and loaded in a specific way. Where you have some config stuff in the beginning and modes and other stuff are loaded in a specific order to make it all work etc. Use-package tries to fix this by making these simple idependent statments that can be in any order you want.

The way it works is that you write for example (use-package foo) this tells us that this package should be loaded. And then you can add :ensure t if you want use-package to also install it if it needs to. If you also need to do something (like setting a variable or ten) before loading it you can do this by adding something like :init (setq b 1)(run-function) etc. And you can also add code you want to run after it have been loaded like enabling a mode with :config (foo-mode 1).

The complete result would look something like (use-package foobar :ensure t :init (setq a 1)(run-function) :config (foo-mode 1))

Then you can also add stuff like :after (org org-babel) if you need to control that something should first load after all of some other packages have loaded.

I think use-package is a very useful tool to keep a flat sturcutre to your package configuration, while still making sure all of them are independednt. My config got a lot cleaner after I started using it.