But for some packages that doesn't work. Such as
(use-package tex :ensure t) doesn't work for
auctex is because
auctex names a GNU ELPA package (see
(emacs) Packages), whereas
tex names a feature (see
(elisp) Named Features) provided by the
In other words,
tex names a single file
tex.el which is distributed as part of the
auctex package. Consider the following examples:
pp-macroexpand-last-sexpRET with point after
gives a form which boils down to
(use-package-ensure-elpa 'tex '(t) 'nil)
(require 'tex nil t))
whereas doing the same with
effectively expands to
(use-package-ensure-elpa 'tex '(auctex) 'nil)
(require 'tex nil t))
This illustrates the difference in purpose between the
NAME argument to
use-package and its
:ensure keyword. The former declares which named feature the rest of the stanza pertains/defaults to, with exactly the same meaning as in
(elisp) Hooks for Loading.
The latter just asks for the given package(s) to be installed via the second argument to the function
t just means the package named by the current
use-package-ensure-elpa, in turn, calls
package-install; for details on this see
(emacs) Package Installation.
According to this blog/tutorial/site the reason is
because, once installed, auctex overrides the tex package.
What does that mean
Unfortunately, this is both wrong and misleading. "Overriding" usually refers to replacing or monkey-patching existing functionality, e.g. via advice. When one package provides the same named feature as another, thus hiding the latter from Emacs load functions, this is called "shadowing".
The AUCTeX distribution overrides and extends various built-in TeX-related functionality, but it does not shadow any built-in libraries. You can confirm this by inspecting the result of M-x
A better authority is the
use-package documentation itself: https://github.com/jwiegley/use-package/#package-installation.
how can I tell when to do that for other packages?
It depends both on how you want to group your
use-package stanzas and the name of the corresponding package. For example, if you want to put all or most of your Org-related settings under a single
(use-package org ...), but want to use the
org-plus-contrib distribution of Org instead of the built-in one, then you would write
You wouldn't write
because there is no file named
org-plus-contrib.el, even if there is a package with the name
org-plus-contrib. You similarly wouldn't write
for the same reason - there is no named feature
auctex (there is a file
auctex.el, but it does not call
Note that none of these discrepancies/semantics are specific to
use-package; these are all (powerful and useful) Emacs features which
use-package can only go so far in abstracting.