Use-package now has a :vc keyword

Posted on 2023-05-18  ·  1 min read  · 

Just a quick heads-up: use-package, which was merged into Emacs in November last year, now has a :vc keyword!

The change was merged two days ago, and supersedes—indeed, is a rewrite of—vc-use-package, which is now only needed for people who prefer to stick to released versions of Emacs.
There is no reason for that, of course. Building Emacs is just a
BUILD_OPTS=$(emacs \
  --batch \
  --eval "(prin1 system-configuration-options)")

echo "$BUILD_OPTS" | sed 's/^"\(.*\)"$/\1/' \
                   | xargs ./configure
make bootstrap
sudo make install

In short, the keyword enables one to install packages directly from their remote source:
(use-package modus-themes
  :vc (:url ""
       :branch "main"))

This is not dependent on git, but should work for all version control systems that Emacs knows about; see vc-handled-backends.

By default, :vc installs the latest release of a package—the last commit that bumped the "Version" tag inside of the main elisp file (yes, really). Installing the most recent commit instead, which should feel more familiar to users coming from package archives like melpa, can be done by giving :vc a :rev :newest argument. Additionally, :rev can also be used to pin specific revisions of a package. Other niceties, like specifying alternative lisp directories, are also included:
(use-package vertico
  :vc (:url ""
       :rev :newest
       :lisp-dir "extensions/"))

For more information on the specific syntax, refer to C-h v package-vc-selected-packages RET, and the relevant info node (emacs)Fetching Package Sources.