Refactor font initialization

+ Add doom-serif-font variable
+ Update docstrings of all doom-*font variables to mention that they all
  support font-specs, font objects, XFT strings and XLFD strings.
+ Set doom-font if the user hasn't, ensuring that other functions know
  what the current, default font is set to (fixes doom-big-font-mode not
  switching back to normal when disabled).
This commit is contained in:
Henrik Lissner 2018-09-28 20:45:20 -04:00
parent 1785adb068
commit 6da307d30e

View File

@ -6,7 +6,10 @@
This is changed when `load-theme' is used as well.") This is changed when `load-theme' is used as well.")
(defvar doom-font nil (defvar doom-font nil
"The default font to use. Expects either a `font-spec' or a XFT font string. "The default font to use.
Expects either a `font-spec', font object, an XFT font string or an XLFD font
string.
This affects the `default' and `fixed-pitch' faces. This affects the `default' and `fixed-pitch' faces.
@ -19,13 +22,31 @@ Examples:
`font-spec' or a XFT font string. See `doom-font' for examples.") `font-spec' or a XFT font string. See `doom-font' for examples.")
(defvar doom-variable-pitch-font nil (defvar doom-variable-pitch-font nil
"The font to use for variable-pitch text. Expects either a `font-spec' "The font to use for variable-pitch text.
or a XFT font string. See `doom-font' for examples.")
Expects either a `font-spec', font object, a XFT font string or XLFD string. See
`doom-font' for examples.
It is recommended you don't set specify a font-size, as to inherit `doom-font's
size.")
(defvar doom-serif-font nil
"The default font to use for the `fixed-pitch-serif' face.
Expects either a `font-spec', font object, a XFT font string or XLFD string. See
`doom-font' for examples.
It is recommended you don't set specify a font-size, as to inherit `doom-font's
size.")
(defvar doom-unicode-font nil (defvar doom-unicode-font nil
"Fallback font for unicode glyphs. Is ignored if :feature unicode is active. "Fallback font for unicode glyphs. Is ignored if :feature unicode is active.
Expects either a `font-spec' or a XFT font string. See `doom-font' for
examples.") Expects either a `font-spec', font object, a XFT font string or XLFD string. See
`doom-font' for examples.
It is recommended you don't set specify a font-size, as to inherit `doom-font's
size.")
;; ;;
@ -318,17 +339,21 @@ frame's window-system, the theme will be reloaded.")
"Initialize fonts." "Initialize fonts."
(condition-case e (condition-case e
(progn (progn
(when doom-font (cond (doom-font
(add-to-list ;; We avoid `set-frame-font' for performance reasons.
'default-frame-alist ;; Manipulating `default-frame-alist' is effective enough.
(cons 'font (add-to-list
(cond ((stringp doom-font) doom-font) 'default-frame-alist
((fontp doom-font) (font-xlfd-name doom-font)) (cons 'font
((signal 'wrong-type-argument (list '(fontp stringp) doom-font))))))) (cond ((stringp doom-font) doom-font)
(when (fontp doom-variable-pitch-font) ((fontp doom-font) (font-xlfd-name doom-font))
(set-face-attribute 'variable-pitch t ((signal 'wrong-type-argument (list '(fontp stringp) doom-font)))))))
:width 'normal :weight 'normal :slant 'normal ((display-graphic-p)
:font doom-variable-pitch-font)) (setq doom-font (face-attribute 'default :font))))
(when doom-serif-font
(set-face-attribute 'fixed-pitch-serif t :font doom-serif-font))
(when doom-variable-pitch-font
(set-face-attribute 'variable-pitch t :font doom-variable-pitch-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 nil doom-unicode-font nil 'append))) (set-fontset-font t nil doom-unicode-font nil 'append)))