Trying to clean up my configuration and make it more readable, but also reduce load time from current time of about 13 seconds down to < 10.
Suppose I have a large use-package
macro for a package of this form:
(use-package foo
:ensure t
:defer t
:init
(do-something)
:bind
(<f5> . foo-fight)
:config
(setq bar) )
I'd like to split this into three separate declarations like this:
(use-package foo
:ensure t
:defer t
:init
(do-something) )
(use-package foo
:bind
(<f5> . foo-fight) )
(use-package foo
:config
(setq bar) )
The idea is that each mini use-package
macro is in it's own org-src
block, and I have some text outside annotating what it does, or links to
where I found the settings, or notes about changes. Additionally, when
running Emacs and making a set of changes to e.g. the keybindings of a
package, I could just go to that org-src block, edit the sexp
s, and do
C-c C-c
to update the config – rather than re-evaluate the entire config.
I want to ensure that :defer t
isn't affected by splitting this. My experience implementing this so far is that this does work in some cases, but in others, splitting the use-package
macro seems to lead to the package being loaded. Has anyone tried checking this and determining if this works or not?
I've seen e.g. this GitHub issue discussing the same thing, which is a tentative yes. This literate config seems to implement this idea profusely.
There is also the suggestion of using noweb to combine all org-src-block outputs for a package into a single use-package
macro when tangling. That sounds great – even the proper way to do it – but it would require a lot of re-writing on my part at this time.
use-package
is doing. The main point is thatuse-package
is a fancy wrapper aroundrequire
and, thought of that way, it seems that multiple calls to(use-package foo...)
is probably not the right way to go. – Fran Burstall Aug 27 '23 at 13:32use-package
macro over different blocks (although the opening parenthesis would be in the first block and the closing one in the last). However, I would suggest to consider using the elisp primitives. You will find thatuse-package
really does not make things much easier (perhaps just a little, but the main advantage is the slightly more readable syntax. However, you are already using a nicely readable literate org file) – dalanicolai Aug 27 '23 at 19:01