0

When moving to use-package, I'd to replace

(require 'markdown-mode)
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))

with

(use-package markdown-mode
  :mode "\\.md\\'"
  :config ...
)

use-package's documentation on :defer says it's unneeded when using :mode:

Defer loading of a package -- this is implied when using ‘:commands’, ‘:bind’, ‘:bind*’, ‘:mode’, ‘:magic’, ‘:hook’, ‘:magic-fallback’, or ‘:interpreter’. This can be an integer, to force loading after N seconds of idle time, if the package has not already been loaded.

so only when I open a file ending .md, will markdown-mode be loaded and configured.

However, there're extensions where there're

  1. No additions to auto-mode-alist e.g. .rs files automatically have rust-mode as major
  2. Some additions to auto-mode-alist
(use-package cc-mode
  ;; not adding .c, .cpp, .cc, .h, etc. since it's automatically
  ;; associated to the right cc mode
  :mode (("\\.inl\\'" . c++-mode)
         ("\\.mm\\'" . objc-mode))
)

In these cases will use-package do deferred loading?

When I open a .c file, I see that the major mode is rightly c-mode but I don't know if this was early/lazy loaded.

3
  • 1
    :commands (cc-mode c-mode) would defer loading for sure. You could also check values of mode specific variables, before loading a c-file to verify cc-mode hasn't (yet) been loaded.
    – jue
    Commented Dec 11, 2019 at 11:02
  • Though this doesn't answer the question, this helped me -- thank you. Also for future viewers, it should be :commands (c++-mode c-mode).
    – legends2k
    Commented Dec 12, 2019 at 10:52
  • Thanks for mentioning c++-mode, I didn't spot that error!
    – jue
    Commented Dec 13, 2019 at 13:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.