Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: add use-package-after-configure-all-hook #1066

Open
hab25 opened this issue Dec 17, 2023 · 0 comments
Open

Feature request: add use-package-after-configure-all-hook #1066

hab25 opened this issue Dec 17, 2023 · 0 comments

Comments

@hab25
Copy link

hab25 commented Dec 17, 2023

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 advice use-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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant