1

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?

Chen Levy
  • 385
  • 3
  • 12

1 Answers1

2

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.

Heikki
  • 2,961
  • 11
  • 18