I.e. a hook that runs immediately after the last-to-be-configured package of all current use-package definitions is configured. The name can be something else.
One use case is adding an element to a list with meaningful order, such as emulation-mode-map-alists, such that one wants to have it as the first element. Modifying such a list only after all packages have been loaded and configured decreases the chance that such an undesirable override happens.
Given that I use (setopt use-package-compute-statistics t), these are the problematic alternatives I've considered:
1) In init.el, putting the following after all other usages of use-package:
(eval
`(use-package
my-virtual-package
:after
,(copy-tree (hash-table-keys use-package-statistics))
:config (message "I'm running my code after all use-package declarations have run their configuration!")
:no-require t))
This does not work if one is has a lot `use-package` declarations; one encounters this error
https://github.com/emacs-mirror/emacs/blob/c4541a35770fe7925f733fcdaa9e4e3348a3c85c/src/fns.c#L2754
In my case, `(length (hash-table-keys use-package-statistics))` is 152.
2) "Map" (hash-table-keys use-package-statistics) into multiple nested eval-after-loads:
It doesn't meet my needs: this will run after the last package is loaded. What I want is to run after the last package is configured.
3) Assume that at least one package managed by use-package has not yet been loaded by the end of init.el (this assumption breaks, for example, if one uses :demand t in all of their use-package declarations). One can adviceuse-package-statistics-gather at the end of their init.el like so:
(advice-add
'use-package-statistics-gather
:after
(lambda (&rest _)
(when (cl-every
(lambda (use-package-statistic)
(equal
(use-package-statistics-status
use-package-statistic)
"Configured"))
(hash-table-values use-package-statistics))
(message "I'm running my code after all use-package declarations have run their configuration!"))))))
This is roughly what I'm doing and works fine, but, as is typical with pieces of `advice`, relies on fragile assumptions (i.e. that are easy to be broken by code updates to this repository) about the internal workings of `use-package`, e.g. the fact that this is the only function that calls `(puthash KEY VALUE use-package-statistics)`.
I.e. a hook that runs immediately after the last-to-be-configured package of all current
use-package
definitions is configured. The name can be something else.One use case is adding an element to a list with meaningful order, such as
emulation-mode-map-alists
, such that one wants to have it as the first element. Modifying such a list only after all packages have been loaded and configured decreases the chance that such an undesirable override happens.Given that I use
(setopt use-package-compute-statistics t)
, these are the problematic alternatives I've considered: 1) Ininit.el
, putting the following after all other usages ofuse-package
:2) "Map"
(hash-table-keys use-package-statistics)
into multiple nestedeval-after-load
s: It doesn't meet my needs: this will run after the last package is loaded. What I want is to run after the last package is configured.3) Assume that at least one package managed by
use-package
has not yet been loaded by the end ofinit.el
(this assumption breaks, for example, if one uses:demand t
in all of theiruse-package
declarations). One canadvice
use-package-statistics-gather
at the end of theirinit.el
like so: