Refactor theme/font initialization

Addressed #489
This commit is contained in:
Henrik Lissner 2018-03-30 00:08:25 -04:00
parent 673b723977
commit 13bffc54bd
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -467,21 +467,23 @@ character that looks like a space that `whitespace-mode' won't affect.")
;; Theme & font ;; Theme & font
;; ;;
(defun doom|init-fonts (&optional frame) (defvar doom-last-window-system window-system
"The `window-system' of the last frame. If this doesn't match the current
frame's window-system, the theme will be reloaded.")
(defun doom|init-fonts ()
"Initialize fonts." "Initialize fonts."
(when (fontp doom-font)
(map-put default-frame-alist 'font (font-xlfd-name doom-font)))
(or frame (setq frame (selected-frame)))
(condition-case-unless-debug ex (condition-case-unless-debug ex
(progn (progn
(when (fontp doom-font) (when (fontp doom-font)
(set-face-attribute 'fixed-pitch frame :font doom-font)) (map-put default-frame-alist 'font (font-xlfd-name doom-font))
(set-face-attribute 'fixed-pitch nil :font doom-font))
;; Fallback to `doom-unicode-font' for Unicode characters ;; Fallback to `doom-unicode-font' for Unicode characters
(when (fontp doom-unicode-font) (when (fontp doom-unicode-font)
(set-fontset-font t 'unicode doom-unicode-font frame)) (set-fontset-font t 'unicode doom-unicode-font nil))
;; ...and for variable-pitch-mode: ;; ...and for variable-pitch-mode:
(when (fontp doom-variable-pitch-font) (when (fontp doom-variable-pitch-font)
(set-face-attribute 'variable-pitch frame :font doom-variable-pitch-font))) (set-face-attribute 'variable-pitch nil :font doom-variable-pitch-font)))
('error ('error
(if (string-prefix-p "Font not available: " (error-message-string ex)) (if (string-prefix-p "Font not available: " (error-message-string ex))
(lwarn 'doom-ui :warning (lwarn 'doom-ui :warning
@ -494,8 +496,7 @@ character that looks like a space that `whitespace-mode' won't affect.")
(defun doom|init-theme () (defun doom|init-theme ()
"Set the theme and load the font, in that order." "Set the theme and load the font, in that order."
(when doom-theme (when doom-theme
(load-theme doom-theme t)) (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.
@ -506,11 +507,18 @@ character that looks like a space that `whitespace-mode' won't affect.")
;; frames, however. There's always `doom//reload-theme' if you need it! ;; frames, however. There's always `doom//reload-theme' if you need it!
(defun doom|init-theme-in-frame (frame) (defun doom|init-theme-in-frame (frame)
"Reloads the theme in new daemon or tty frames." "Reloads the theme in new daemon or tty frames."
(when (or (daemonp) (not (display-graphic-p))) (when (and (framep frame)
(not (eq doom-last-window-system (display-graphic-p frame))))
(with-selected-frame frame (with-selected-frame frame
(doom|init-theme)))) (doom|init-theme))
(setq doom-last-window-system (display-graphic-p frame))))
(add-hook! 'doom-init-ui-hook #'(doom|init-theme doom|init-fonts)) ;; fonts
(add-hook 'doom-init-ui-hook #'doom|init-fonts)
;; themes
(add-hook 'after-make-frame-functions #'doom|init-theme-in-frame)
(unless (daemonp)
(add-hook 'doom-init-ui-hook #'doom|init-theme))
;; ;;