Question - the canonical way to delay loading

Currently I’m (ab)using (use-package! some-package :defer-incrementally t) as a mechanism to load stuff that just needs to be brought in at some point but I really don’t want to wait for it to load. An example is (which-function-mode) where it doesn’t make sense to force it in a hook. It’s nice when it shows up but not truly needed before and doom already has nice support for delayed loading and pausing it.

I understand that use-package! is going away and the official recommendation is to use after! instead, but that still requires something to trigger the loading.

I have my own delay-start! helper that uses a timer, but that of course doesn’t have the nice “back-off if something else is going on” that doom does.

Any suggestions?

Why do you say use-package! is going away? In favor of what?

use-package! is going away, but custom keywords like :defer-incrementally are not. use-package, and our configuration for it, are simply being moved to a :config use-package module (which is currently hardcoded to be enabled until use-package is ready to be fully removed – don’t enable it now, or it might break load order). When this change finally happens, the module will become opt-in, but there will be ample warning before this happens.

In any case, this :config use-package module will keep Doom’s custom keywords, it will only be dropping the use-package! and use-package-hook! macros, because use-package itself is enough without them (and I’ll add :pre-init, :post-init, :pre-config, and :post-config keywords to replace use-package-hook!).

That’s not quite right. The recommendation is to use whatever you like. If that happens to be use-package, the module just needs to be enabled (later, when the change becomes official) and any use-package! calls need to be renamed to use-package, and you’ll be good to go. Or you can install your own (leaf? setup-el?). Or you can use the vanilla Emacs API (and/or after!). Up to you.

I’m only removing our internal dependency on use-package because it’s more complex than Doom needs, and I prefer users have the choice than have use-package forced upon them.

If you still wanted to abandon use-package, then you could simply use doom-load-packages-incrementally directly:

(doom-load-packages-incrementally '(some-package other-package))

The two packages are then added to the package iloader list, the same way :defer-incrementally works.


Hope that clears some things up!

2 Likes

Thanks for the detailed input Henrik.

If you still wanted to abandon use-package, then you could simply use doom-load-packages-incrementally directly:

Abandoning use-package(!) isn’t a goal - I simply wanted to know what the “official” way to archive this was considering the approach I’m dependant on is eventually going away. So I figured people would be doing something different.

(doom-load-packages-incrementally ’(some-package other-package))

This seems like a straight-forward way to handle it.

Thanks again.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.