11

If my :config section is entirely wrapped in with-eval-after-load, is that equivalent to simply specifying an :after directive? That is, can I replace this:

(use-package company-tern
  :config
  (with-eval-after-load 'company
    (add-to-list 'company-backends 'company-tern)))

with this

(use-package company-tern
  :after company
  :config
  (add-to-list 'company-backends 'company-tern))

Am I correct in my understanding that if there is other configuration that isn't inside of the with-eval-after-load then it wouldn't be useful to replace it with an :after directive since that would defer the loading of the entire package just for the subset of the configuration that depends on the feature?

I should note, in the above situation it seems simple enough to just nest company-tern's use-package under company's :config section, since they're logically related. However, my question is for the more general case where the "dependency" doesn't necessarily have a logical connection, or when there is more than one "dependency."

Drew
  • 75,699
  • 9
  • 109
  • 225
Jorge Israel Peña
  • 1,265
  • 9
  • 17
  • From what I understand of use-package's semantics, an alternative (cleaner?) possibility would be to put this `(add-to-list ...)` line in `company`'s `:config`. And if you want to defer the loading of the entire `company-tern` package, you could put `(use-package company-tern :config (add-to-list...))` in `company`'s `:config`. – T. Verron Jan 20 '16 at 08:58
  • Thank you for responding @T.Verron! I actually had a larger post/question and I split it up at the request of another user. I forgot to migrate over to this one the fact that I wanted to find a way to avoid nesting `use-package` inside of the `:config`. The reason for this doesn't apply to the example I gave, but consider other situations where there is no real logical connection other than using e.g. a function of another package, or when there is more than one such "dependencies," it wouldn't make sense to nest the package under more than one package's `:config` section after all. – Jorge Israel Peña Jan 20 '16 at 09:04
  • Nesting use-packages is not a proper way to handle dependencies indeed. But for situations where the second package provides additional configuration to the first one, it kinda makes sense. Someone wrote blog posts on managing a configuration using use-package (maybe it was the author of the package himself), and he made extensive use of that, for example encapsulating his configuration into "personal" packages. – T. Verron Jan 20 '16 at 09:09
  • I agree completely. I'm already doing this for example with evil-related plugins, nesting them under evil's `:config`. I'm looking for approaches to situations where there isn't really a logical connection. I will clarify my question for other readers. By the way, if you find and link me those posts I would really appreciate it! – Jorge Israel Peña Jan 20 '16 at 09:11
  • 2
    Here are a couple : http://www.lunaryorn.com/2015/01/06/my-emacs-configuration-with-use-package.html http://sachachua.com/blog/2014/12/emacs-configuration-use-package/ (the second contains a link to a video demonstration by the author of use-package, but I didn't watch it) Sadly, I cannot find the one post that I had in mind. – T. Verron Jan 20 '16 at 09:19

1 Answers1

7

Yes, I believe those are equivalent. If there's additional configuration outside of with-eval-after-load, then switching to use :after should be semantically equivalent to moving them inside the with-eval-after-load form and so may change when they are executed. Whether this is a problem or not will depend on the exact configuration details.

Now, I don't know the exact details of how things are implemented, so it's possible that there's some very subtle timing issue, but at least your intuition seems to match mine here.

Aaron Harris
  • 2,664
  • 17
  • 22