This is difficult with package.el
because package.el
is not designed for modular package management. I suggest you use a different package manager, such as straight.el
(which I wrote in order to solve the problems of package.el
).
With straight.el
, conditionally loading a package is trivial: just conditionally load it:
(when some-condition
(straight-use-package 'my-slow-package))
This works because (unlike package.el
), straight.el
does exactly what you ask it to, and nothing more. Thus, preventing straight.el
from installing and loading a package is as simple as not asking it to do so.
You can read verbose documentation about straight.el
, including comparisons to other package managers, in the README.
Footnote for advanced straight.el
users
If you use version lockfiles, then you want to be sure that the revisions of all your packages are recorded in your lockfile, even if they are not currently being loaded. This can be accomplished via
(if some-condition
(straight-use-package 'my-slow-package)
(straight-register-package 'my-slow-package))
although a more convenient syntax using use-package
is planned in this issue.