What is use-package anyway?

Simply put, it’s a macro for easier package management within Emacs. I’ve used this for a while, and for me this is much more manageable than the default package declaration.

How to use it?

First we’ll need to activate it, from your Emacs init.el file:

1
(require 'use-package)

And since we’ll mostly use this for external package, also add:

1
(setq use-package-always-ensure t)

After that, use-package is ready to use. For example, installing which-key is simply by:

1
(use-package which-key)

If you don’t enable the variable use-package-always-ensure, then we’ll need to also use the keyword :ensure, to make sure the package is downloaded.

1
2
(use-package which-key
  :ensure)

Useful external packages

Which-key

Just like our example earlier, which-key is my most needed external packages. It display the keybinding following our incomplete command (or in Emacs term: a prefix). For example, in default Emacs when we want to open file we use the C-x C-f chord. When we input C-x and pause, nothing really shown.

Figure 1: default emacs prefix

Figure 1: default emacs prefix

There’s only C-x displayed in the echo area (in the bottom), but with which-key-mode activated:

Figure 2: which-key-mode

Figure 2: which-key-mode

Further which-key customization

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
(use-package which-key
  :ensure
  :custom
  (which-key-lighter "")
  (which-key-sort-order #'which-key-key-order-alpha)
  (which-key-sort-uppercase-first nil)
  (which-key-add-column-padding 1)
  (which-key-max-display-columns nil)
  (which-key-min-display-lines 6)
  (which-key-compute-remaps t)
  (which-key-side-window-slot -10)
  (which-key-separator " → ")
  (which-key-allow-evil-operators t)
  (which-key-use-C-h-commands t)
  (which-key-show-remaining-keys t)
  (which-key-show-prefix 'bottom)
  :config
  (which-key-mode)
  (which-key-setup-side-window-bottom)
  (which-key-setup-minibuffer)
  (define-key which-key-mode-map (kbd "C-x <f5>") 'which-key-C-h-dispatch))

This is the setup I used for which-key.