feat: add doom-emoji-font

This parallels doom-symbol-font for emoji. In the process, refactor
symbol and emoji font setup to take advantage of these parallels.
This commit is contained in:
Liam Hupfer 2023-09-24 21:28:13 -05:00 committed by Henrik Lissner
parent 4499ce7b0a
commit 37affa5cff
2 changed files with 19 additions and 8 deletions

View file

@ -248,6 +248,8 @@ Doom exposes a couple variables for setting fonts. They are:
- [[var:doom-variable-pitch-font]]: used for non-monospace fonts (e.g. when using - [[var:doom-variable-pitch-font]]: used for non-monospace fonts (e.g. when using
variable-pitch-mode or mixed-pitch-mode). Popular for text modes, like Org or variable-pitch-mode or mixed-pitch-mode). Popular for text modes, like Org or
Markdown. Markdown.
- [[var:doom-emoji-font]]: used for rendering emoji. Only needed if you want to use
a font other than your operating systems default.
- [[var:doom-symbol-font]]: used for rendering symbols. - [[var:doom-symbol-font]]: used for rendering symbols.
- [[var:doom-serif-font]]: the sans-serif font to use wherever the [[face:fixed-pitch-serif]] - [[var:doom-serif-font]]: the sans-serif font to use wherever the [[face:fixed-pitch-serif]]
face is used. face is used.

View file

@ -46,6 +46,14 @@ font to that size. It's rarely a good idea to do so!")
(define-obsolete-variable-alias 'doom-unicode-font 'doom-symbol-font "3.0.0") (define-obsolete-variable-alias 'doom-unicode-font 'doom-symbol-font "3.0.0")
(defvar doom-emoji-font nil
"Fallback font for emoji.
Must be a `font-spec', a font object, an XFT font string, or an XLFD string. See
`doom-font' for examples.
WARNING: if you specify a size for this font it will hard-lock any usage of this
font to that size. It's rarely a good idea to do so!")
(defvar doom-emoji-fallback-font-families (defvar doom-emoji-fallback-font-families
'("Apple Color Emoji" '("Apple Color Emoji"
"Segoe UI Emoji" "Segoe UI Emoji"
@ -525,15 +533,16 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original
(custom-push-theme 'theme-face face 'user 'set new-specs) (custom-push-theme 'theme-face face 'user 'set new-specs)
(put face 'face-modified nil)))) (put face 'face-modified nil))))
(when (fboundp 'set-fontset-font) (when (fboundp 'set-fontset-font)
(let ((fn (doom-rpartial #'member (font-family-list)))) (let* ((fn (doom-rpartial #'member (font-family-list)))
(when-let (font (cl-find-if fn doom-symbol-fallback-font-families)) (symbol-font (or doom-symbol-font
(cl-find-if fn doom-symbol-fallback-font-families)))
(emoji-font (or doom-emoji-font
(cl-find-if fn doom-emoji-fallback-font-families))))
(when symbol-font
(dolist (script '(symbol mathematical)) (dolist (script '(symbol mathematical))
(set-fontset-font t script font))) (set-fontset-font t script symbol-font)))
(when-let (font (cl-find-if fn doom-emoji-fallback-font-families)) (when emoji-font
(set-fontset-font t 'emoji font))) (set-fontset-font t 'emoji emoji-font)))
(when doom-symbol-font
(dolist (script '(symbol mathematical))
(set-fontset-font t script doom-symbol-font)))
;; Nerd Fonts use these Private Use Areas ;; Nerd Fonts use these Private Use Areas
(dolist (range '((#xe000 . #xf8ff) (#xf0000 . #xfffff))) (dolist (range '((#xe000 . #xf8ff) (#xf0000 . #xfffff)))
(set-fontset-font t range "Symbols Nerd Font Mono"))) (set-fontset-font t range "Symbols Nerd Font Mono")))