core-ui: define doom-*-switch-*-hooks & minor refactor

doom-init-theme-hook is now obsolete; to be replaced with
doom-load-theme-hook.
This commit is contained in:
Henrik Lissner 2018-03-22 19:26:07 -04:00
parent fbb16b4c5e
commit 4fc2897372
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -32,10 +32,6 @@ shorter major mode name in the mode-line. See `doom|set-mode-name'.")
(defvar doom-init-ui-hook nil (defvar doom-init-ui-hook nil
"List of hooks to run when core-ui is initialized.") "List of hooks to run when core-ui is initialized.")
(defvar doom-init-theme-hook nil
"List of hooks to run when the theme (and font) is initialized (or reloaded
with `doom//reload-theme').")
(setq-default (setq-default
bidi-display-reordering nil ; disable bidirectional text for tiny performance boost bidi-display-reordering nil ; disable bidirectional text for tiny performance boost
blink-matching-paren nil ; don't blink--too distracting blink-matching-paren nil ; don't blink--too distracting
@ -284,6 +280,27 @@ DEFAULT is non-nil, set the default mode-line for all buffers."
;; Custom hooks ;; Custom hooks
;; ;;
(defvar doom-load-theme-hook nil
"Hook run when the theme (and font) is initialized (or reloaded
with `doom//reload-theme').")
(define-obsolete-variable-alias 'doom-init-theme-hook 'doom-load-theme-hook "2.1.0")
(defvar doom-before-switch-window-hook nil
"Hook run before `switch-window' or `switch-frame' are called. See
`doom-after-switch-window-hook'.")
(defvar doom-after-switch-window-hook nil
"Hook run after `switch-window' or `switch-frame' are called. See
`doom-before-switch-window-hook'.")
(defvar doom-before-switch-buffer-hook nil
"Hook run before `switch-to-buffer' and `display-buffer' are called. See
`doom-after-switch-buffer-hook'.")
(defvar doom-after-switch-buffer-hook nil
"Hook run before `switch-to-buffer' and `display-buffer' are called. See
`doom-before-switch-buffer-hook'.")
(defun doom*switch-window-hooks (orig-fn &rest args) (defun doom*switch-window-hooks (orig-fn &rest args)
(run-hook-with-args 'doom-before-switch-window-hook) (run-hook-with-args 'doom-before-switch-window-hook)
(prog1 (apply orig-fn args) (prog1 (apply orig-fn args)
@ -298,6 +315,10 @@ DEFAULT is non-nil, set the default mode-line for all buffers."
(advice-add #'switch-to-buffer :around #'doom*switch-buffer-hooks) (advice-add #'switch-to-buffer :around #'doom*switch-buffer-hooks)
(advice-add #'display-buffer :around #'doom*switch-buffer-hooks) (advice-add #'display-buffer :around #'doom*switch-buffer-hooks)
(defun doom*load-theme-hooks (&rest _)
(run-hook-with-args 'doom-load-theme-hook))
(advice-add #'load-theme :after #'doom*load-theme-hooks)
;; ;;
;; Line numbers ;; Line numbers
@ -417,13 +438,6 @@ character that looks like a space that `whitespace-mode' won't affect.")
;; Theme & font ;; Theme & font
;; ;;
(defun doom|init-theme ()
"Set the theme and load the font, in that order."
(when doom-theme
(load-theme doom-theme t))
(add-hook 'after-make-frame-functions #'doom|init-theme-in-frame)
(run-hooks 'doom-init-theme-hook))
(defun doom|init-fonts (&optional frame) (defun doom|init-fonts (&optional frame)
"Initialize fonts." "Initialize fonts."
(add-hook 'after-make-frame-functions #'doom|init-fonts) (add-hook 'after-make-frame-functions #'doom|init-fonts)
@ -450,6 +464,12 @@ character that looks like a space that `whitespace-mode' won't affect.")
"Unexpected error while initializing fonts: %s" "Unexpected error while initializing fonts: %s"
(error-message-string ex))))))) (error-message-string ex)))))))
(defun doom|init-theme ()
"Set the theme and load the font, in that order."
(when doom-theme
(load-theme doom-theme t))
(add-hook 'after-make-frame-functions #'doom|init-theme-in-frame))
;; Getting themes to remain consistent across GUI Emacs, terminal Emacs and ;; Getting themes to remain consistent across GUI Emacs, terminal Emacs and
;; daemon Emacs is hairy. `doom|init-theme' sorts out the initial GUI frame. ;; daemon Emacs is hairy. `doom|init-theme' sorts out the initial GUI frame.
;; Attaching `doom|init-theme-in-frame' to `after-make-frame-functions' sorts ;; Attaching `doom|init-theme-in-frame' to `after-make-frame-functions' sorts