Fix inconsistencies in fonts across frames #399

Also, minor refactor for doom|init-theme.
This commit is contained in:
Henrik Lissner 2018-02-02 16:56:34 -05:00
parent bae2287d51
commit e71f28601a
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -436,46 +436,52 @@ character that looks like a space that `whitespace-mode' won't affect.")
(defun doom|init-theme (&optional frame) (defun doom|init-theme (&optional frame)
"Set the theme and load the font, in that order." "Set the theme and load the font, in that order."
(with-selected-frame (or frame (selected-frame)) (with-selected-frame (or frame (selected-frame))
(when doom-theme (when (and (not (daemonp)) (symbolp doom-theme))
(load-theme doom-theme t)) (load-theme doom-theme t))
(condition-case-unless-debug ex (add-hook 'after-make-frame-functions #'doom|init-theme-in-daemon)
(when (display-graphic-p) (run-hooks 'doom-init-theme-hook)))
(when (fontp doom-font)
(set-frame-font doom-font nil (if frame (list frame) t)) (defun doom|init-fonts (&optional frame)
(set-face-attribute 'fixed-pitch frame :font doom-font)) "Initialize fonts."
;; Fallback to `doom-unicode-font' for Unicode characters (add-hook 'after-make-frame-functions #'doom|init-fonts)
(when (fontp doom-unicode-font) (if (not frame)
(set-fontset-font t 'unicode doom-unicode-font frame)) (when (fontp doom-font)
;; ...and for variable-pitch-mode: (map-put default-frame-alist 'font (font-xlfd-name doom-font)))
(when (fontp doom-variable-pitch-font) (when (display-graphic-p)
(set-face-attribute 'variable-pitch frame :font doom-variable-pitch-font))) (or frame (setq frame (selected-frame)))
('error (condition-case-unless-debug ex
(if (string-prefix-p "Font not available: " (error-message-string ex)) (progn
(lwarn 'doom-ui :warning (when (fontp doom-font)
"Could not find the '%s' font on your system, falling back to system font" (set-face-attribute 'fixed-pitch frame :font doom-font))
(font-get (caddr ex) :family)) ;; Fallback to `doom-unicode-font' for Unicode characters
(lwarn 'doom-ui :error (when (fontp doom-unicode-font)
"Unexpected error while initializing fonts: %s" (set-fontset-font t 'unicode doom-unicode-font frame))
(error-message-string ex))))) ;; ...and for variable-pitch-mode:
(run-hooks 'doom-init-theme-hook) (when (fontp doom-variable-pitch-font)
(when frame (set-face-attribute 'variable-pitch frame :font doom-variable-pitch-font)))
(remove-hook 'after-make-frame-functions #'doom|init-theme)))) ('error
(if (string-prefix-p "Font not available: " (error-message-string ex))
(lwarn 'doom-ui :warning
"Could not find the '%s' font on your system, falling back to system font"
(font-get (caddr ex) :family))
(lwarn 'doom-ui :error
"Unexpected error while initializing fonts: %s"
(error-message-string ex))))))))
;; 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. Running `doom|init-theme' sorts out the initial GUI ;; daemon Emacs is hairy. `doom|init-theme' sorts out the initial GUI frame.
;; frame. ;; Attaching that hook to `after-make-frame-functions' sorts out daemon and
;; emacsclient frames.
;; ;;
;; `doom|init-theme-in-frame' sorts out daemon and emacsclient frames by ;; There will still be issues with simultaneous gui and terminal (emacsclient)
;; reloading the theme in those frame. However, if you open simultaneous ;; frames, however. There's always `doom//reload-theme' if you need it!
;; terminal and gui frames with emacsclient, you will get issues! There's always (defun doom|init-theme-in-daemon (frame)
;; `doom//reload-theme' if you need it.
(defun doom|reload-ui-in-daemon (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 (or (daemonp) (not (display-graphic-p)))
(doom|init-theme frame))) (doom|init-theme frame)
(remove-hook 'after-make-frame-functions #'doom|init-theme-in-daemon)))
(add-hook 'doom-init-ui-hook #'doom|init-theme) (add-hook! 'doom-init-ui-hook #'(doom|init-theme doom|init-fonts))
(add-hook 'after-make-frame-functions #'doom|reload-ui-in-daemon)
;; ;;