Skip to content

Confusion about how certain keywords behave #1082

@sellout

Description

@sellout

I think this is a documentation issue, because I can’t seem to figure out what I can expect from certain keywords.

tl;dr: I think a flow chart of some sort would really help me understand which keywords fire when.

For example,

(use-package foo
  :defer t
  :init (foo-global-mode) ; assume this is defined with `autoload`

The docs say “Use the :init keyword to execute code before a package is loaded”, but what does “before a package is loaded” mean? Will :init fire linearly when the use-package is encountered, or will it wait until something else forces the loading of this package?

What I expect this form to do is execute the :init immediately, which will then cause the package to be loaded (without use-package handling the loading). The actual situation I have is that I have use-package-always-defer t, and I’m wondering if I can expect packages to be loaded because of the autoloads on their init form.

Or should I be doing something else re: loading packages? The examples in the README show a lot of examples like

(use-package foo
  :config (foo-global-mode t)

but that seems backward to me. It should be the package-defined autoload that causes a call to (foo-global-mode) to load the package (but I get that there’s not a lot of difference without :defer).

Similarly, how does :after interact with :init? This somewhat depends on the answer to the previous question, but assuming :init normally fires immediately, does :after defer it until after its dependencies are loaded, or will it still fire immediately?

(use-package bar
  :after foo
  :init (bar-global-mode)

(use-package foo
  :custom (foo-var t))

Does bar-global-mode get run before or after foo-var is set? And, if it‘s after, I assume that that’s no longer true if there’s a (require 'foo) above (use-package bar …, right?

Sorry for this rambling description. I just come up with these questions time and time again when I’m working on my config, and sometimes bother to trace through the code to see what’s happening and sometimes don’t, but it seems like it should be more obvious. I have more questions like this, but I’m hoping it’s possible to include a somewhat comprehensive description of all of these things without enumerating more of the specific confusions I’ve had.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions