Skip to content

Commit c5d39f9

Browse files
committed
fix(fonts): correctly set fonts with custom-theme-set-faces
1 parent 01c0dea commit c5d39f9

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

core/me-fonts.el

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ face names or script names expressed as keywords (with the \":\" prefix).
7878
7979
For example to set `default' face, use `:default', to set the `mode-line' face,
8080
use `:mode-line', and so on. The parameters for each font in these cases (ie.
81-
for face names) are used in the `set-face-attribute' function, so you can pass
82-
any key value pairs supported by `set-face-attribute' (like `:weight',
83-
`:slanted', ...). A list of supported keywords are available in the variable
84-
`+set-face-attribute-keywords'.
81+
for face names) are used in the `custom-theme-set-faces' function, so you can
82+
pass any specs (key value pairs) supported by `custom-theme-set-faces' (like
83+
`:weight', `:slant', `:foreground', ...). A list of supported keywords are
84+
available in the variable `+face-attributes'.
8585
8686
You can also setup some language-specific fonts. All scripts supported by Emacs
8787
can be found in `+known-scripts'. The keyword in this plist will be the script
@@ -109,10 +109,10 @@ scaling factor for the font in Emacs' `face-font-rescale-alist'. See the
109109
"List of available fonts on the system, initialized at startup from
110110
`font-family-list'.")
111111

112-
(defconst +set-face-attribute-keywords
112+
(defconst +face-attributes
113113
'(:family :foundry :width :height :weight :slant :foreground
114-
:background :underline :overline :strike-through :box
115-
:inverse-video :stipple :extend :font :inherit)
114+
:distant-foreground :background :underline :overline :strike-through
115+
:box :inverse-video :stipple :font :inherit :extend)
116116
"Arguments accepted by the `set-face-attribute' function.")
117117

118118
(defconst +font-spec-keywords
@@ -129,7 +129,7 @@ scaling factor for the font in Emacs' `face-font-rescale-alist'. See the
129129
(cl-intersection (+plist-keys font)
130130
(if (memq script-or-face +known-scripts)
131131
+font-spec-keywords
132-
+set-face-attribute-keywords))))))
132+
+face-attributes))))))
133133

134134
(defun +font-installed-p (font-family)
135135
"Check if FONT-FAMILY is installed on the system."
@@ -140,14 +140,17 @@ scaling factor for the font in Emacs' `face-font-rescale-alist'. See the
140140
(catch 'done
141141
(dolist (font (plist-get minemacs-fonts-plist (intern (format ":%s" script-or-face))))
142142
(let* ((spec (+font--get-valid-args script-or-face font))
143-
(prepend (and (plistp font) (plist-get font :family)))
144143
(scale (and (plistp font) (plist-get font :scale)))
145-
(family (plist-get spec :family)))
146-
(when (+font-installed-p family)
147-
(if (memq script-or-face +known-scripts)
148-
(set-fontset-font t script-or-face (apply #'font-spec spec) nil prepend)
149-
(apply #'set-face-attribute (append `(,script-or-face nil) spec)))
150-
(when scale (add-to-list 'face-font-rescale-alist (cons (plist-get spec :family) scale)))
144+
(prependp (and (plistp font) (plist-get font :family)))
145+
(family (plist-get spec :family))
146+
(scriptp (memq script-or-face +known-scripts)))
147+
(when (or (not family) (+font-installed-p family))
148+
(if scriptp
149+
(set-fontset-font t script-or-face (apply #'font-spec spec) nil prependp)
150+
(custom-theme-set-faces 'user `(,script-or-face ((t ,spec)))))
151+
(when (and scale family)
152+
(add-to-list 'face-font-rescale-alist (cons family scale)))
153+
(+log! "Settinng %s `%s' to `%s'" (if scriptp "script" "face") script-or-face spec)
151154
(throw 'done spec))))))
152155

153156
;; Inspired by: github.com/seagle0128/.emacs.d/blob/master/custom-example.el
@@ -162,7 +165,7 @@ scaling factor for the font in Emacs' `face-font-rescale-alist'. See the
162165
;; Run hooks
163166
(run-hooks 'minemacs-after-setup-fonts-hook))
164167

165-
(make-obsolete #'+set-fonts #'+setup-fonts "v3.0.0")
168+
(define-obsolete-function-alias #'+set-fonts #'+setup-fonts "v3.0.0")
166169

167170
(+add-hook! (window-setup server-after-make-frame) #'+setup-fonts)
168171

skel/config.el

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@
2222
;; You can set a list of fonts to be used, like the snippet below. The first
2323
;; font found on the system will be used:
2424
(plist-put minemacs-fonts-plist
25-
:default ;; <- applies to the `default' face usig `set-face-attribute'
25+
:default ;; <- applies to the `default' face usig `custom-theme-set-faces'
2626
'((:family "Iosevka Fixed Curly Slab" :height 130) ; <- priority 1
2727
(:family "JetBrains Mono" :height 110 :weight light) ; <- priority 2
2828
(:family "Cascadia Code" :height 120 :weight semi-light))) ; <- priority 3
2929

3030
;; To set font for arbitrary Emacs face, you need just to write the face name as
3131
;; a keyword. For example `variable-pitch' -> `:variable-pitch':
3232
(plist-put minemacs-fonts-plist
33-
:variable-pitch ;; <- applies to the `variable-pitch' face usig `set-face-attribute'
33+
:variable-pitch ;; <- applies to the `variable-pitch' face usig `custom-theme-set-faces'
3434
'("Lato"
3535
"Roboto"
3636
"Inter"
3737
"Helvetica"))
3838

3939
;; For example to set custom font for `mode-line' -> `:mode-line':
4040
(plist-put minemacs-fonts-plist
41-
:mode-line ;; <- applies to the `mode-line' face usig `set-face-attribute'
41+
:mode-line ;; <- applies to the `mode-line' face usig `custom-theme-set-faces'
4242
'((:family "Lato" :weight regular)
4343
(:family "Roboto" :weight light)))
4444

0 commit comments

Comments
 (0)