Caveat on using use-package with straight.el

Posted on September 07, 2023 in short


use-package is great. It's a declarative way to, well, use packages in Emacs, with built-in lazy loading and other niceties that would take a lot of typing to do for every package you wish to include in your Emacs installation otherwise. I also use straight.el as an alternative to the in-built package.el. Look into it if you do not use it, you might like it.

To use straight instead of package.el within a use-package declaration you would have to do something like

(use-package markdown-mode
 :straight t
 :mode "//.md//'")

Doing this for every single package would be silly if you wish to always use straight.
The solution for this is adding the following form to your init file: (straight-use-package-by-default t), which always uses straight.el with use-package.

The issue

If the use-package form includes :straight t, straight will try to install the package if it does not exist in the straight folder, even for packages like org which are in-built. This is not what we want, but the easy-to-miss problem is that if you have added (straight-use-package-by-default t), it implicitly adds :straight t to all your use-package forms.


This was causing me a lot of bugs when trying to set configuration for built-ins, but can be resolved easily by setting :straight to nil in such cases.

My configuration

Obligatory link to my Emacs configuration here, if you're interested. It's not the cleanest or the fastest (currently 1.5 seconds to load on MacOS) but I have elected to not spend too much time messing around with it.