progfolio / elpaca

An elisp package manager
GNU General Public License v3.0
634 stars 31 forks source link

[Feature]: Warn if elpaca is waiting on a queue after emacs initialization complete #260

Closed nacl closed 5 months ago

nacl commented 7 months ago

Feature Description

Hello! This is quite a nice package. :)

When I initially set up my init file, I broke it up into sections split by elpaca-wait blocks. Due some misunderstandings on my part due to how desktop-mode worked, I had code that looked like this:

;; Rest of init.el...
;; ...
(elpaca-wait)
(desktop-save-mode)

The main result was that elpaca-after-init-time was not set, ultimately leading to confusing early load warnings when I tried to manually packages or tweak recipes after initialization was very much complete.

This is sorta like #116, but this was unintentional. Could elpaca perhaps warn in this case be a warning here? Might be possible if elpaca--finalize-queue knew it was being run from the after-init hooks (elpaca's or otherwise).

Updating the wiki to indicate this may also be sufficient.

Confirmation

progfolio commented 7 months ago

Feature Description

Hello! This is quite a nice package. :)

Thank you for the kind words and giving it a shot.

When I initially set up my init file, I broke it up into sections split by elpaca-wait blocks. Due some misunderstandings on my part due to how desktop-mode worked, I had code that looked like this:

;; Rest of init.el...
;; ...
(elpaca-wait)
(desktop-save-mode)

elpaca-wait is intended to only be used sparingly. Unless it's absolutely necessary (elpaca-after-init-hook should take care of most cases) it shouldn't be used at the end of one's init file.

However, if you do use it at the end of your init file, you'll have to manually set elpaca-after-init-time as shown here:

https://github.com/progfolio/elpaca/wiki/after-init-hook%3F-emacs-startup-hook%3F

Could elpaca warn [when] elpaca--finalize-queue [is] run from the after-init hooks (elpaca's or otherwise) [?]

elpaca--finalize-queue can't know if the queue it's finalizing is the last one, because there could always be another one after. The only possible way is for the user to manually indicate that. The best advice I can give right now is to minimize use of elpaca-wait and rely on elpaca-after-init-hook.

Does that help?

nacl commented 7 months ago

Yup, thanks for the explanation. My main observation is that there wasn't a good way to know what was causing this a problem (in this case the early load warnings) without digging into the issue tracker and reading the code, which took a little time.

Given this, I was thinking that it might be good to have a warning here to alleviate future user surprise. For example, if elpaca-process-queues knew it was running in after-init-hook, and elpaca--waiting was set, then perhaps the user did something wrong and elpaca should emit a warning? It seems possible, but I don't know if it's a good idea.

Otherwise (and this would be good enough for me) a documentation update WRT the early load warnings could help here too.

progfolio commented 7 months ago

there wasn't a good way to know what was causing [...] the early load warnings

I'm still not 100% sure I understand exactly how you were running into that issue. I understand elpaca-after-init-time was not set, but can you provide an init file and the steps which reproduce the issue? The following test case works without any warnings:

(elpaca-test
  :interactive t
  :init
  (elpaca elpaca-use-package)
  (elpaca-wait)
  (desktop-save-mode 1))

Given this, I was thinking that it might be good to have a warning here to alleviate future user surprise. For example, if elpaca-process-queues knew it was running in after-init-hook, and elpaca--waiting was set, then perhaps the user did something wrong and elpaca should emit a warning? It seems possible, but I don't know if it's a good idea.

A function can't easily detect if it's being run during a specific hook. Given a reproduction recipe, I may be able to work out if/when we should warn.

nacl commented 7 months ago

I'm still not 100% sure I understand exactly how you were running into that issue.

It just happened to be that elpaca-wait was one the last thing invoked in my init file other than desktop-save-mode. desktop-save-mode's use or otherwise has no impact as to whether the warning appears.

A function can't easily detect if it's being run during a specific hook.

Fair enough. There wasn't anything obvious that stood out to me either, but just a thought.

Given a reproduction recipe, I may be able to work out if/when we should warn.

Thanks much. Short (contrived) repro example (elpaca-test is neat btw):

(elpaca-test
  :interactive t
  :init
  (elpaca elpaca-use-package)
  (elpaca rainbow-mode (rainbow-mode))
  (elpaca-wait))

And then evaluate (elpaca rainbow-mode) in the *scratch* buffer. Didn't see an option for running anything after init.

progfolio commented 7 months ago

Thanks much. Short (contrived) repro example

Thank you. That example is crystal clear.

(elpaca-test is neat btw):

It's a life saver! Thanks for using it.

I have an idea for a solution. I'll try to get it implemented today.

progfolio commented 5 months ago

@nacl Apologies for the delay here.

I believe I've got it taken care of on latest master. elpaca-after-init-time , elpaca-after-init-hook should be set/ run when the last init queue is blocking. This will prevent the warning you were seeing. If it doesn't work after M-x elpaca-pull elpaca followed by M-x restart-emacs let me know and I'll take another look.