1

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 sexps, 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.

2
  • 1
    Have a look at emacs.stackexchange.com/questions/61276/… for how to understand what use-package is doing. The main point is that use-package is a fancy wrapper around require and, thought of that way, it seems that multiple calls to (use-package foo...) is probably not the right way to go. Aug 27, 2023 at 13:32
  • You can just split up the 'single' use-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 that use-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) Aug 27, 2023 at 19:01

1 Answer 1

2

Following the examples of SqrtMinusOne's config and zzamboni's old config, I decided to use Noweb to tangle different code blocks into a single use-package declaration for each package.

For example, I would have:

#+begin_src emacs-lisp :results silent :noweb no-export
(use-package mu4e
  :ensure t
  :defer t
  :commands (mu4e)

  :config

   <<mu4e-config>>


   <<mu4e-contexts>>



   )

#+end_src

and then, at a more convenient location in my literate .org file, I would have the block:

#+name: mu4e-config
#+begin_src emacs-lisp :results silent :tangle no
(require 'smtpmail)


(setq mu4e-maildir "~/maildir"
      mu4e-get-mail-command "mbsync GrMil"
      mu4e-update-interval 300
      mu4e-view-show-images t
      mu4e-view-scroll-to-next nil
      mu4e-use-fancy-chars t
      mu4e-attachment-dir "~/Downloads"
      mu4e-change-filenames-when-moving t
      mu4e-sent-messages-behavior 'delete
      mu4e-headers-date-format "%+4Y-%m-%d"
      message-send-mail-function 'smtpmail-send-it
      )
#+end_src

where the value of the #+name: block header is the one that is referred to within << >> in the use-package block.

It took a while to re-factor my config, but I think it was worth it in the end.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.