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

Calling use-package multiple times on the same package #662

Closed
wagk opened this issue Mar 26, 2018 · 9 comments
Closed

Calling use-package multiple times on the same package #662

wagk opened this issue Mar 26, 2018 · 9 comments
Labels

Comments

@wagk
Copy link

wagk commented Mar 26, 2018

After some testing, I'm currently running under the assumption that yes, you can call use-package multiple times on a single package.

However, it would be nice to get some confirmation as well; Is it possible to call use-package multiple times on a single package? Are there any caveats that I should be looking out for when doing this?

@npostavs
Copy link
Contributor

npostavs commented Mar 26, 2018

Are there any caveats that I should be looking out for when doing this?

The old :config block is not replaced (assuming there is deferred loading). For example,

(use-package 'foo
   :defer t
   :config (message "configuring foo"))
(use-package 'foo
   :defer t
   :config (message "configuring foo again"))
(require 'foo)

would print both configuring foo and configuring foo again. This may or may not be what you want. If you're changing a use-package form and then re-evaluating it, it's likely not what you want.

@wagk
Copy link
Author

wagk commented Mar 26, 2018

I'm currently in the process of migrating my configuration into an .org file, leaving behind a small .el file to bootstrap the environment needed for the rest of the configuration.

Within the bootstrap file I would like to define core features I'll need (things like a tiny evil config and a very basic helm config) while leaving the more heavyweight configurations in the org file, explaining why I would potentially want to call use-package more than once per init.

I assume the chained :config blocks are called in order when the package loads?

@npostavs
Copy link
Contributor

I assume the chained :config blocks are called in order when the package loads?

Yes, I think so.

@zzamboni
Copy link

@wagk FWIW, you can also use org-mode's noweb features to bring together multiple snippets into the corresponding section of the use-package declaration. You can see what I mean in my init.org: https://github.com/zzamboni/dot-emacs/blob/master/init.org#org-mode

If you look at the raw org file, you'll see that many of the src blocks are labeled with the :noweb-ref header to indicate the section under the main use-package org statement where they need to be placed.

@dieggsy
Copy link

dieggsy commented Apr 16, 2018

@zzamboni holy hell. now that's cool. Been using org for my config for a while now, hadn't seen that usage before.

@zzamboni
Copy link

Glad you found it neat! My first attempt at literate programming was in fact using noweb many years ago, so I found it nice that org-mode supports it too. I think it's nice, although I wish there were better support to indicate the block name/noweb-ref when exporting. As it stands, I think the unnamed blocks can be confusing. There was a question about this recently in the org-mode mailing list, and I learned that you can customize org-babel-exp-code-template to achieve a similar effect, but that approach doesn't work for :noweb-ref (only for #+NAME), so I'm still playing with it.

@TLATER
Copy link

TLATER commented Sep 6, 2019

Just to provide another use case; I like setting up built-in packages with use-package. When setting up gnus, I want to add another mail source on my work machine in a block somewhat like this:

(cond ((string-equal (system-name) "work")
           (progn
             (add-to-list 'gnus-secondary-select-methods '(nnimap "Work"...)))

With multiple use-package declarations I can do that without breaking the whole load timing chain :D

@mankoff
Copy link

mankoff commented Jun 13, 2020

I've run into an issue with multiple calls to use-package.

If package A is loaded multiple times, and package B has an :after A, then B may load after the first A load, even if it depends on features set in subsequent A loads. I solved this by setting an explicit and long defer option for B, but that fix has its own drawbacks.

I'm going to solve this by having only one use-package call per package, and making use of <<noweb>> blocks.

@skangas
Copy link
Collaborator

skangas commented Nov 29, 2022

It seems like all questions here were resolved, so I'm closing this issue now. Please report back if I missed something.

@skangas skangas closed this as completed Nov 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants