Closed syl20bnr closed 9 years ago
@jwiegley Great for the simplifications but it does not address my (spacemacs users) use case....
You wrote that you don't see a need for pre
and post
but this is what the whole issue is all about :-)
Do you want me to explain it again ?
I also want to make it clear again that I don't propose new keywords, I propose additional hooks to put some code before and after init
and config
bodies.
In spacemacs there is a dotfile (~/.spacemacs
) with 2 functions:
dotspacemacs/init
dotspacemacs/config
The initialization pipeline is (roughly):
dotspacemacs/init
(1) > eval use-package blocks (2) > dotspacemacs/config
(3)
I need to provide spacemacs users a way to alter the :init
of (2) in (1) and the lazy loaded stuff in :config
in (2) in (3). I cannot tell them to use use-package
again it is already used in (2) so I need a better way that is consistent accros all the packages, and I hoped that use-package
could provide it, this is the perfect place for this.
I propose to put these hooks in place:
<package-name>-pre-init-hook
<package-name>-post-init-hook
(not very useful)<package-name>-pre-config-hook
(not very usefull)<package-name>-post-config-hook
The only thing to add in use-package
is 4 run-hook
(with the appropriate check), the rest is pure naming convention. We can even add a configuration variable in use-package
to disable these hooks: use-package-generate-hooks
.
@syl20bnr Sure, I'd happy be happy to support your use case.
So, are you saying that at the beginning and end of :init
and :config
blocks, I should inject calls to run-hooks use-package-pre-init
, etc.?
@syl20bnr Are you on IRC or Google Talk? I'd love to chat with you directly to support your use case.
@jwiegley Thank you for the fast reply. We can catch each other tomorrow on IRC, I have to sleep a bit now (3am) ;-)
So, are you saying that at the beginning and end of :init and :config blocks, I should inject calls to run-hooks use-package-pre-init, etc.?
Yes, but it has to be namespaced with the package name.
@syl20bnr Ok, great, I'm johnw
there. My only question is how we can support what you need, without injecting those calls for those not using spacemacs. I'll give it some thought, but I think we can just add a configuration variable which, at macro expansion time, will cause hooks to be injected at the selected places, and under the requested names.
@syl20bnr Let me know if ef0bcf3840506637a93da0bee08cfc9931dc689f does what you need.
The initialization pipeline is (roughly): dotspacemacs/init (1) > eval use-package blocks (2) > dotspacemacs/config (3)
I need to provide spacemacs users a way to alter the :init of (2) in (1) and the lazy loaded stuff in :config in (2) in (3).
If I understand correctly, (2) is non-user configured code that comes with spacemacs? Why don't you just put some calls to spacemacs hooks in there?
(use-package foo
:defer t ; we must lazy load the :config block
:init (progn (run-hooks spacemacs-foo-init-hook) <more-spacemacs-stuff>)
:config (progn (run-hooks spacemacs-foo-config-hook) <more-spacemacs-stuff>))
@jwiegley This is perfect, the control over the block depending on the returned value is a nice plus :+1:
My only remark would be to add a -hook
suffix to the generated hook names to be more conventional.
@npostavs indeed I could do that but spacemacs has grown a lot lately and the package coverage is becoming big (currently there are 262 use-package
occurrences), so in practice it would be really tedious.
Thank you!
@syl20bnr Another note: in your document at http://thume.ca/howto/2015/03/07/configuring-spacemacs-a-tutorial/, your use of :defer
there is unnecessary. It is implied by :mode
.
@jwiegley You are right, I'll make a pass in spacemacs to clean this. Thank you for pointing it.
In spacemacs the configuration is organized with configuration layers stacked on top of each other. The user has a dotfile with two functions:
init
is called at the very beginning before initializing the layersconfig
is called at the very end after initializing the layersPackages initialization try to use
use-package
as much as possible to leverage the emacs lazy-loading mechanism exposed by the macro with its various keywords.A
post-init
hook could allow some users to safely and consistently override the variables that need to be set before requiring a package. Indeed spacemacs comes with default values and it can be tricky to override them in some scenarios in the spacemacs user space (i.e. the package is not lazy loaded). While I believe (need someone to confirm) thateval-after-load
should make apost-config
hook unnecessary I would find it very convenient and symmetric if the idea ofpost-init
hook variable is accepted.This feature could be a game changer for spacemacs but: