refactor!: redesign module init/config hooks

BREAKING CHANGE: For consistency and correctness, I've renamed the
module init/config hooks, and added new ones:

- Adds doom-before-modules-config-hook
- Adds doom-after-modules-config-hook (replaced doom-before-init-modules-hook)
- Adds doom-before-modules-init-hook
- Adds doom-after-modules-init-hook (replaced doom-init-modules-hook)
- Removed doom-after-init-modules-hook (replaced w/ after-init-hook)

The old naming (and timing) was counterintuitive. Now, it's named after
the loaded file group (init.el vs config.el), and I added before/after
variants. Altogether, this should make them less ambiguous.

I've also moved some functions in various modules to more correct hooks.

Load order before this change:
- $EMACSDIR/early-init.el
- $EMACSDIR/lisp/doom.el
- $EMACSDIR/lisp/doom-start.el
- $DOOMDIR/init.el
- {$DOOMDIR,~/.emacs.d}/modules/*/*/init.el
- `doom-before-init-modules-hook'
- {$DOOMDIR,~/.emacs.d}/modules/*/*/config.el
- `doom-init-modules-hook'
- $DOOMDIR/config.el
- `doom-after-init-modules-hook'
- `after-init-hook'
- `emacs-startup-hook'
- `window-setup-hook'

Load order after this change:
- $EMACSDIR/early-init.el
- $EMACSDIR/lisp/doom.el
- $EMACSDIR/lisp/doom-start.el
- $DOOMDIR/init.el
- `doom-before-modules-init-hook'
- {$DOOMDIR,~/.emacs.d}/modules/*/*/init.el
- `doom-after-modules-init-hook'
- `doom-before-modules-config-hook'
- {$DOOMDIR,~/.emacs.d}/modules/*/*/config.el
- `doom-after-modules-config-hook'
- $DOOMDIR/config.el
- `after-init-hook'
- `emacs-startup-hook'
- `window-setup-hook'
This commit is contained in:
Henrik Lissner 2022-09-14 14:48:21 +02:00
parent 57a91235bd
commit 7a2be67efa
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
8 changed files with 39 additions and 39 deletions

View file

@ -123,7 +123,7 @@ all hooks after it are ignored.")
(defalias 'undefine-key! #'general-unbind) (defalias 'undefine-key! #'general-unbind)
:config :config
;; Prevent "X starts with non-prefix key Y" errors except at startup. ;; Prevent "X starts with non-prefix key Y" errors except at startup.
(add-hook 'doom-after-init-modules-hook #'general-auto-unbind-keys)) (add-hook 'doom-after-modules-config-hook #'general-auto-unbind-keys))
;; HACK: `map!' uses this instead of `define-leader-key!' because it consumes ;; HACK: `map!' uses this instead of `define-leader-key!' because it consumes
@ -203,7 +203,7 @@ localleader prefix."
;; Bind `doom-leader-key' and `doom-leader-alt-key' as late as possible to give ;; Bind `doom-leader-key' and `doom-leader-alt-key' as late as possible to give
;; the user a chance to modify them. ;; the user a chance to modify them.
(add-hook! 'doom-after-init-modules-hook (add-hook! 'after-init-hook
(defun doom-init-leader-keys-h () (defun doom-init-leader-keys-h ()
"Bind `doom-leader-key' and `doom-leader-alt-key'." "Bind `doom-leader-key' and `doom-leader-alt-key'."
(let ((map general-override-mode-map)) (let ((map general-override-mode-map))

View file

@ -21,13 +21,13 @@
Init files are loaded early, just after Doom core, and before modules' config Init files are loaded early, just after Doom core, and before modules' config
files. They are always loaded, even in non-interactive sessions, and before files. They are always loaded, even in non-interactive sessions, and before
`doom-before-init-modules-hook'. Related to `doom-module-config-file'.") `doom-before-modules-init-hook'. Related to `doom-module-config-file'.")
(defvar doom-module-config-file "config" (defvar doom-module-config-file "config"
"The basename of config files for modules. "The basename of config files for modules.
Config files are loaded later, and almost always in interactive sessions. These Config files are loaded later, and almost always in interactive sessions. These
run before `doom-init-modules-hook'. Relevant to `doom-module-init-file'.") run before `doom-after-modules-config-hook'. Relevant to `doom-module-init-file'.")
(defconst doom-obsolete-modules (defconst doom-obsolete-modules
'((:feature (version-control (:emacs vc) (:ui vc-gutter)) '((:feature (version-control (:emacs vc) (:ui vc-gutter))
@ -75,15 +75,25 @@ your `doom!' block, a warning is emitted before replacing it with :emacs vc and
"If non-nil, don't emit deprecated or missing module warnings at startup.") "If non-nil, don't emit deprecated or missing module warnings at startup.")
;;; Custom hooks ;;; Custom hooks
(defvar doom-before-init-modules-hook nil (defcustom doom-before-modules-init-hook nil
"A list of hooks to run before Doom's modules' config.el files are loaded, but "Hooks run before module init.el files are loaded."
after their init.el files are loaded.") :group 'doom
:type 'hook)
(defvar doom-init-modules-hook nil (defcustom doom-after-modules-init-hook nil
"A list of hooks to run after Doom's modules' config.el files have loaded, but "Hooks run after module init.el files are loaded."
before the user's private module.") :group 'doom
:type 'hook)
(defvaralias 'doom-after-init-modules-hook 'after-init-hook) (defcustom doom-before-modules-config-hook nil
"Hooks run before module config.el files are loaded."
:group 'doom
:type 'hook)
(defcustom doom-after-modules-config-hook nil
"Hooks run after module config.el files are loaded (but before the user's)."
:group 'doom
:type 'hook)
(defvar doom--current-module nil) (defvar doom--current-module nil)
(defvar doom--current-flags nil) (defvar doom--current-flags nil)
@ -120,11 +130,13 @@ of Dooming. Will noop if used more than once, unless FORCE-P is non-nil."
(doom-initialize-core-modules)) (doom-initialize-core-modules))
(when-let (init-p (load! doom-module-init-file doom-user-dir t)) (when-let (init-p (load! doom-module-init-file doom-user-dir t))
(doom-log "Initializing user config") (doom-log "Initializing user config")
(doom-run-hooks 'doom-before-module-init-hook)
(maphash (doom-module-loader doom-module-init-file) doom-modules) (maphash (doom-module-loader doom-module-init-file) doom-modules)
(doom-run-hooks 'doom-before-init-modules-hook) (doom-run-hooks 'doom-after-module-init-hook)
(unless no-config-p (unless no-config-p
(doom-run-hooks 'doom-before-module-config-hook)
(maphash (doom-module-loader doom-module-config-file) doom-modules) (maphash (doom-module-loader doom-module-config-file) doom-modules)
(doom-run-hooks 'doom-init-modules-hook) (doom-run-hooks 'doom-after-module-config-hook)
(load! "config" doom-user-dir t) (load! "config" doom-user-dir t)
(when custom-file (when custom-file
(load custom-file 'noerror (not doom-debug-mode))))))) (load custom-file 'noerror (not doom-debug-mode)))))))
@ -457,21 +469,6 @@ packages are installed, `doom-autoloads-file' is loaded, `doom-packages-file'
cache exists (and is loaded) and, finally, loads your private init.el (which cache exists (and is loaded) and, finally, loads your private init.el (which
should contain your `doom!' block). should contain your `doom!' block).
The overall load order of Doom is as follows:
~/.emacs.d/init.el
~/.emacs.d/lisp/doom.el
$DOOMDIR/init.el
{$DOOMDIR,~/.emacs.d}/modules/*/*/init.el
`doom-before-init-modules-hook'
{$DOOMDIR,~/.emacs.d}/modules/*/*/config.el
`doom-init-modules-hook'
$DOOMDIR/config.el
`doom-after-init-modules-hook'
`after-init-hook'
`emacs-startup-hook'
`window-setup-hook'
Module load order is determined by your `doom!' block. See `doom-modules-dirs' Module load order is determined by your `doom!' block. See `doom-modules-dirs'
for a list of all recognized module trees. Order defines precedence (from most for a list of all recognized module trees. Order defines precedence (from most
to least)." to least)."

View file

@ -36,12 +36,13 @@
;; $EMACSDIR/lisp/doom.el ;; $EMACSDIR/lisp/doom.el
;; $EMACSDIR/lisp/doom-start.el ;; $EMACSDIR/lisp/doom-start.el
;; $DOOMDIR/init.el ;; $DOOMDIR/init.el
;; `doom-before-modules-init-hook'
;; {$DOOMDIR,~/.emacs.d}/modules/*/*/init.el ;; {$DOOMDIR,~/.emacs.d}/modules/*/*/init.el
;; `doom-before-init-modules-hook' ;; `doom-after-modules-init-hook'
;; `doom-before-modules-config-hook'
;; {$DOOMDIR,~/.emacs.d}/modules/*/*/config.el ;; {$DOOMDIR,~/.emacs.d}/modules/*/*/config.el
;; `doom-init-modules-hook' ;; `doom-after-modules-config-hook'
;; $DOOMDIR/config.el ;; $DOOMDIR/config.el
;; `doom-after-init-modules-hook'
;; `after-init-hook' ;; `after-init-hook'
;; `emacs-startup-hook' ;; `emacs-startup-hook'
;; `doom-init-ui-hook' ;; `doom-init-ui-hook'

View file

@ -109,9 +109,12 @@
:path (doom-module-locate-path (car key) (cdr key)))) :path (doom-module-locate-path (car key) (cdr key))))
doom-modules) doom-modules)
(--run--) (--run--)
(doom-run-hooks 'doom-before-modules-init-hook)
(maphash (doom-module-loader doom-module-init-file) doom-modules) (maphash (doom-module-loader doom-module-init-file) doom-modules)
(doom-run-hooks 'doom-after-modules-init-hook)
(doom-run-hooks 'doom-before-modules-config-hook)
(maphash (doom-module-loader doom-module-config-file) doom-modules) (maphash (doom-module-loader doom-module-config-file) doom-modules)
(doom-run-hooks 'doom-init-modules-hook))) (doom-run-hooks 'doom-after-modules-config-hook)))
(`vanilla-doom ; only Doom core (`vanilla-doom ; only Doom core
`(progn `(progn
(load-file ,(expand-file-name "doom.el" doom-core-dir)) (load-file ,(expand-file-name "doom.el" doom-core-dir))

View file

@ -29,7 +29,7 @@ directives. By default, this only recognizes C directives.")
(defvar evil-respect-visual-line-mode nil) (defvar evil-respect-visual-line-mode nil)
(use-package! evil (use-package! evil
:hook (doom-init-modules . evil-mode) :hook (doom-after-modules-config . evil-mode)
:demand t :demand t
:preface :preface
(setq evil-ex-search-vim-style-regexp t (setq evil-ex-search-vim-style-regexp t
@ -77,7 +77,7 @@ directives. By default, this only recognizes C directives.")
(advice-add #'help-with-tutorial :after (lambda (&rest _) (evil-emacs-state +1))) (advice-add #'help-with-tutorial :after (lambda (&rest _) (evil-emacs-state +1)))
;; Done in a hook to ensure the popup rules load as late as possible ;; Done in a hook to ensure the popup rules load as late as possible
(add-hook! 'doom-init-modules-hook (add-hook! 'doom-after-modules-config-hook
(defun +evil--init-popup-rules-h () (defun +evil--init-popup-rules-h ()
(set-popup-rules! (set-popup-rules!
'(("^\\*evil-registers" :size 0.3) '(("^\\*evil-registers" :size 0.3)
@ -85,7 +85,7 @@ directives. By default, this only recognizes C directives.")
;; Change the cursor color in emacs state. We do it this roundabout way ;; Change the cursor color in emacs state. We do it this roundabout way
;; to ensure changes in theme doesn't break these colors. ;; to ensure changes in theme doesn't break these colors.
(add-hook! '(doom-load-theme-hook doom-init-modules-hook) (add-hook! '(doom-load-theme-hook doom-after-modules-config-hook)
(defun +evil-update-cursor-color-h () (defun +evil-update-cursor-color-h ()
(put 'cursor 'evil-emacs-color (face-foreground 'warning)) (put 'cursor 'evil-emacs-color (face-foreground 'warning))
(put 'cursor 'evil-normal-color (face-background 'cursor)))) (put 'cursor 'evil-normal-color (face-background 'cursor))))

View file

@ -1,7 +1,7 @@
;;; editor/god/config.el -*- lexical-binding: t; -*- ;;; editor/god/config.el -*- lexical-binding: t; -*-
(use-package! god-mode (use-package! god-mode
:hook (doom-after-init-modules . god-mode-all) :hook (doom-after-modules-init . god-mode-all)
:config :config
(add-hook 'post-command-hook #'+god--configure-cursor-and-modeline-h) (add-hook 'post-command-hook #'+god--configure-cursor-and-modeline-h)
(add-hook 'overwrite-mode-hook #'+god--toggle-on-overwrite-h) (add-hook 'overwrite-mode-hook #'+god--toggle-on-overwrite-h)

View file

@ -1,6 +1,6 @@
;;; input/layout/config.el -*- lexical-binding: t; -*- ;;; input/layout/config.el -*- lexical-binding: t; -*-
(add-hook! 'doom-init-modules-hook (add-hook! 'doom-after-modules-config-hook
(defun +layout-init-h () (defun +layout-init-h ()
(cond ((modulep! +bepo) (cond ((modulep! +bepo)
(load! "+bepo")) (load! "+bepo"))

View file

@ -33,8 +33,7 @@
;; HACK Ensures that sly's contrib modules are loaded as soon as possible, but ;; HACK Ensures that sly's contrib modules are loaded as soon as possible, but
;; also as late as possible, so users have an opportunity to override ;; also as late as possible, so users have an opportunity to override
;; `sly-contrib' in an `after!' block. ;; `sly-contrib' in an `after!' block.
(add-hook! 'doom-after-init-modules-hook (add-hook! 'after-init-hook (after! sly (sly-setup)))
(after! sly (sly-setup)))
:config :config
(setq sly-mrepl-history-file-name (concat doom-cache-dir "sly-mrepl-history") (setq sly-mrepl-history-file-name (concat doom-cache-dir "sly-mrepl-history")