From 228204926d32fbfbc01919e43ac77b4f4517d029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Sun, 16 Sep 2018 19:11:07 +0100 Subject: [PATCH] Load .elc even for themes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Even when an `.elc` is preset `load-theme` would attempt to load the `.el` first, to give the opportunity to inspect the theme. However we are loading themes automatically from (M)ELPA, and loading a theme package is no more dangerous than loading a regular package. So override the search order for themes and atttempt to load the `.elc` first. This improves startup time by ~25ms with the default theme. Improved implementation by @hlissner. Signed-off-by: Edwin Török --- core/core-ui.el | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/core-ui.el b/core/core-ui.el index 90d8f3781..b172bfff0 100644 --- a/core/core-ui.el +++ b/core/core-ui.el @@ -448,6 +448,16 @@ instead). Meant for `kill-buffer-query-functions'." (powerline-reset))) (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)))) + (apply orig-fn args))) +(advice-add #'load-theme :around #'doom*prefer-compiled-theme) + (defun doom|disable-whitespace-mode-in-childframes (frame) (when (frame-parameter frame 'parent-frame) (with-selected-frame frame