82 lines
3.4 KiB
Org Mode
82 lines
3.4 KiB
Org Mode
#+TITLE: Font Configuration
|
|
|
|
* set default fonts
|
|
#+begin_src emacs-lisp
|
|
(let ((default-family "Roboto Mono")
|
|
(variable-family "Inter"))
|
|
(custom-set-faces
|
|
;; set default font
|
|
`(default ((t (:inherit nil :extend nil :stipple nil
|
|
:inverse-video nil :box nil
|
|
:strike-through nil :overline nil :underline nil
|
|
:slant normal :weight normal
|
|
:height 100 :width normal
|
|
:family ,default-family))))
|
|
`(fixed-pitch ((t (:family ,default-family))))
|
|
`(fixed-pitch-serif ((t (:family ,default-family))))
|
|
`(variable-pitch ((t (:inherit default :weight regular :family ,variable-family))))))
|
|
#+end_src
|
|
|
|
* Font setter function
|
|
#+begin_src emacs-lisp
|
|
(defun set-face-attr-family (face font-families &optional attributes)
|
|
"Set FACE's font family to the first available font family from FONT-FAMILIES list,
|
|
and apply other ATTRIBUTES specified in the plist."
|
|
|
|
(when attributes
|
|
(while attributes
|
|
(let ((attr (pop attributes))
|
|
(value (pop attributes)))
|
|
(set-face-attribute face nil attr value))))
|
|
|
|
(let ((available-font (seq-find (lambda (font)
|
|
(find-font (font-spec :family font)))
|
|
font-families)))
|
|
(when available-font
|
|
;; Set the font family
|
|
(set-face-attribute face nil :family available-font)
|
|
;; Apply other attributes from the plist
|
|
|
|
(message "Set %s face to use font family: %s with attributes: %s"
|
|
face available-font attributes))))
|
|
|
|
#+end_src
|
|
|
|
* Set face family and attributes
|
|
#+begin_src emacs-lisp
|
|
(set-face-attr-family 'default
|
|
'("Roboto Mono" "Source Code Pro" "Fira Code" "Noto Sans Mono" "Cascadia Code" "SF Pro Mono" "fixed")
|
|
'(:inherit nil :extend nil :stipple nil
|
|
:inverse-video nil :box nil
|
|
:strike-through nil :overline nil :underline nil
|
|
:slant normal :weight normal
|
|
:height 100 :width normal))
|
|
(set-face-attr-family 'variable-pitch
|
|
'("Inter" "Cantarell" "Fira Sans" "Noto Sans" "Segoe UI" "SF Pro Display")
|
|
'(:inherit default :weight regular))
|
|
|
|
(set-face-attribute 'fixed-pitch nil :family (face-attribute 'default :family))
|
|
(set-face-attribute 'fixed-pitch-serif nil :family (face-attribute 'default :family))
|
|
|
|
(set-face-attribute 'fringe nil :background (face-background 'default))
|
|
(set-face-attribute 'line-number nil :background (face-background 'default))
|
|
(set-face-attribute 'line-number nil :foreground (face-foreground 'shadow))
|
|
#+end_src
|
|
|
|
* Chinese Font
|
|
#+begin_src emacs-lisp
|
|
;; (dolist (charset '(kana han symbol cjk-misc bopomofo))
|
|
;; (set-fontset-font (frame-parameter nil 'font)
|
|
;; charset (font-spec :family "Noto Sans Mono CJK TC Regular"
|
|
;; :size 10)))
|
|
#+end_src
|
|
|
|
* Font finder function
|
|
#+begin_src emacs-lisp
|
|
;; (defun find-available-font-family (font-families)
|
|
;; "Return the first available font family from FONT-FAMILIES list, or nil if none is found."
|
|
;; (seq-find (lambda (font)
|
|
;; (find-font (font-spec :family font)))
|
|
;; font-families))
|
|
#+end_src
|