use-package
use-package copied to clipboard
An autoload alternative
Of late I have been making a push to accelerate startup by deferring as much default loading as possible.
The pattern that has emerged is that I identify some event with an associated hook corresponding to the very first time that I might a package to be loaded. Examples:
- yasnippet: find-file-not-found-functions
- selectrum: minibuffer-setup-hook
- marginalia: minibuffer-setup-hook
For each package I define a named function to add to the hook. The function removes itself from the hook and arranges for the subject package to be loaded.
Clearly there is a lot of boilerplate here. What I would like is an additional :load-hook keyword. At the very least this would eliminate the tedium of generating function names and writing formulaic add-hook / remove-hook lines. As an optimization, all packages needing to be conditioned on a given hook could be loaded by handled by a single hook function.
Further refinements:
- Allow specification of multiple hook variables
- Treat any additional forms as :config, to be executing following load-library