2

Given a major mode package foo and foo-x that extends foo, with feature x is there a recommended way to configure them with use-package (assuming :defer t and :ensure t for all?

  • nested use-package
    (use-package foo :config (use-package foo-x :ensure t)) 
  • requite
    (use-package foo :config (require 'foo-x)) (use-package foo-x) 
  • after:
    (use-package foo) (use-package foo-x :after foo) 
  • hook
    (use-package foo) (use-package foo-x :hook foo) 

Or some other different way. What are the pros an cons of each?

2 Answers 2

3

use-package is a macro around require. Macros are expanded before code execution. The purpose of a macro is to create syntactic sugar to make code easier to read, understand, and maintain. Your different alternatives have minimal effect to the execution time. In the end, it is a personal choice which one you prefer.

I use mostly the :after key for terseness, but sometimes nest short use-package calls within larger ones to make sure all relevant code stays in one place.

You should check yourself what the use-package macro does. Install macro-expand, place cursor before the macro and call macro-expand to see how the expanded code looks like.

0

I don't know if the :after keyword was available when this question was asked, but that seems to be exactly the solution to this now: https://www.gnu.org/software/emacs/manual/html_node/use-package/Loading-sequentially.html

You would do

(use-package foo) (use-package foo-x :after (foo)) 

and, indeed, foo-x would be loaded after foo.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.