From 81394cf733bff09cc0362b49baa897e5991ed1ec Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 31 Dec 2018 15:18:45 -0500 Subject: [PATCH] Only prefer compiled theme on startup ...But not on doom/reload-theme or post-init load-theme calls. --- core/autoload/ui.el | 4 +++- core/core-ui.el | 22 +++++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/core/autoload/ui.el b/core/autoload/ui.el index 168a5fa8f..2b6ee3f52 100644 --- a/core/autoload/ui.el +++ b/core/autoload/ui.el @@ -88,7 +88,9 @@ See `display-line-numbers' for what these values mean." (let ((theme (or (car-safe custom-enabled-themes) doom-theme))) (when theme (mapc #'disable-theme custom-enabled-themes)) - (doom|init-theme) + (when (and doom-theme (not (memq doom-theme custom-enabled-themes))) + (let (doom--prefer-theme-elc) + (load-theme doom-theme t))) (doom|init-fonts))) ;;;###autoload diff --git a/core/core-ui.el b/core/core-ui.el index 7c5595028..9eca1a770 100644 --- a/core/core-ui.el +++ b/core/core-ui.el @@ -53,6 +53,10 @@ size.") (defvar doom-init-ui-hook nil "List of hooks to run when the UI has been initialized.") +(defvar doom--prefer-theme-elc nil + "If non-nil, `load-theme' will prefer the compiled theme (unlike its default +behavior). Do not set this directly, this is let-bound in `doom|init-theme'.") + (setq-default ansi-color-for-comint-mode t bidi-display-reordering nil ; disable bidirectional text for tiny performance boost @@ -360,7 +364,8 @@ frame's window-system, the theme will be reloaded.") (defun doom|init-theme () "Set the theme and load the font, in that order." (when (and doom-theme (not (memq doom-theme custom-enabled-themes))) - (load-theme doom-theme t))) + (let ((doom--prefer-theme-elc t)) + (load-theme doom-theme t)))) ;; Getting themes to remain consistent across GUI Emacs, terminal Emacs and ;; daemon Emacs is hairy. `doom|init-theme' sorts out the initial GUI frame. @@ -477,12 +482,15 @@ instead). Meant for `kill-buffer-query-functions'." (advice-add #'load-theme :around #'doom*disable-old-themes-first) (defun doom*prefer-compiled-theme (orig-fn &rest args) - "Make `load-theme' prioritize the byte-compiled theme (if it exists) for a -moderate boost in startup (or theme switch) time." - (cl-letf* ((old-locate-file (symbol-function 'locate-file)) - ((symbol-function 'locate-file) - (lambda (filename path &optional _suffixes predicate) - (funcall old-locate-file filename path '("c" "") predicate)))) + "Make `load-theme' prioritize the byte-compiled theme for a moderate boost in +startup (or theme switch) time, so long as `doom--prefer-theme-elc' is non-nil." + (if (or (null after-init-time) + doom--prefer-theme-elc) + (cl-letf* ((old-locate-file (symbol-function 'locate-file)) + ((symbol-function 'locate-file) + (lambda (filename path &optional _suffixes predicate) + (funcall old-locate-file filename path '("c" "") predicate)))) + (apply orig-fn args)) (apply orig-fn args))) (advice-add #'load-theme :around #'doom*prefer-compiled-theme)