jwiegley / use-package

A use-package declaration for simplifying your .emacs
https://jwiegley.github.io/use-package
GNU General Public License v3.0
4.39k stars 259 forks source link

Unexpected early load #956

Closed memeplex closed 2 years ago

memeplex commented 2 years ago

Sorry if this is a misunderstanding on my part but I've read the README and the use-package docstring and I can't figure out why the following is happening.

In my early-init.el I have:

(setq package-enable-at-startup nil)

In my init.el I have the standard straight bootstrap plus:

(setq straight-use-package-by-default t
      use-package-verbose t)

(straight-use-package 'use-package)

Then, take for example:

(use-package projectile
  :config (projectile-mode 1)
  :bind-keymap ("C-c p" . projectile-command-map))

AFAICU this form should defer loading of projectile because of the keymap binding.

But immediately after initialization a lot of M-x projectile- functions are available. Interestingly enough, *Messages* doesn't show the loading message for projectile. But still the functions are there ready to be called (and autoloadp returns nil on them).

If I comment out the use-package form, no projectile functions are available instead.

memeplex commented 2 years ago

With the example that is in the documentation:

(use-package projectile
  :bind-keymap
  ("C-c p" . projectile-command-map))

about which it's stated:

This is handled behind the scenes by generating custom code that loads the package containing the keymap, and then re-executes your keypress after the first load, to reinterpret that keypress as a prefix key.

The stub is indeed there:

C-c p runs the command (lambda nil (interactive)
(use-package-autoload-keymap 'projectile-command-map 'projectile nil))
(found in global-map), which is an interactive Lisp function.

But as I said, M-x projectile show a number of matches (78) even before calling the stub by pressing C-c p.

memeplex commented 2 years ago

Ok, I think I now understand what happens. There is this projectile-autoloads.el file which is obviously providing the stubs. So if my understanding is correct, autoloads are always done, what is deferred is the require of the file. I'm closing this because I'm 99% sure this is like I've said, but if the author were so kind as to provide some explanation regarding the phases of the loading process, I'd be very grateful.

Also, what's the point of the stubs that use-package itself generates when a package already provides its autoloads? Wouldn't it be two levels of indirection to achieve the same? Are most packages poorly behaved in this regard?