Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

For "add-hook"s, should they be in the :init or :config #228

Closed
xarthurx opened this Issue Jul 16, 2015 · 3 comments

Comments

Projects
None yet
3 participants

I've seen many .emacs file from the Internet, and the settings vary with where to put those hooks...

For example:

(add-hook 'prog-mode-hook 'flyspell-prog-mode)
(add-hook 'text-mode-hook 'flyspell-mode)

My aim is to decrease Emacs loading time.
But it seems working all right if I put all the add-hooks in config, which will be loaded after the package is loaded.

I've read the help for use-package and am still a little confused.

So theoretically, where should these lines go?

Owner

jwiegley commented Jul 16, 2015

They would go into the :init block for flyspell, along with :commands (flyspell-prog-mode flyspell-mode).

For more general cases, it almost goes this way or case by case?

Like:

(add-hook 'after-init-hook 'global-company-mode)
(add-hook 'global-company-mode-hook 'company-statistics-mode)

and so on?

unhammer commented Feb 2, 2016

I would put (add-hook 'after-init-hook #'global-company-mode) into :init of company, and (add-hook 'global-company-mode-hook #'company-statistics-mode) into the :init of company-statistics.

Reasoning: A line like (add-hook 'foo-hook #'bar) is harmless if the package defining foo-hook doesn't exist, but if the foo-hook runs and #'bar doesn't exist you will get an error, so you've got to look at the #'bar-part in order to decide which use-package-form to put it in.

@jwiegley jwiegley closed this Feb 26, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment