Skip to content

Commit

Permalink
update: set Sarasa Mono SC as the default font;
Browse files Browse the repository at this point in the history
fix: can NOT use C-s on Windows 11
  • Loading branch information
cabins committed Jan 22, 2024
1 parent 9418365 commit 089552a
Showing 1 changed file with 3 additions and 40 deletions.
43 changes: 3 additions & 40 deletions init.el
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,8 @@

(defvar cabins-os-win (memq system-type '(ms-dos windows-nt cygwin)))
(defvar cabins-os-mac (eq system-type 'darwin))
(defvar cabins-fonts-default '("Cascadia Code PL" "Courier Prime" "Jetbrains Mono" "Roboto Mono" "Menlo" "Consolas"))
(defvar cabins-fonts-unicode '("Segoe UI Symbol" "Symbola" "Symbol"))
(defvar cabins-fonts-emoji '("Apple Color Emoji" "Segoe UI Emoji" "Noto Color Emoji" "Noto Emoji"))
(defvar cabins-fonts-cjk '("WeRead Font" "KaiTi" "STKaiTi" "WenQuanYi Micro Hei"))

;;;###autoload
(defun cabins-find-font (custom-fonts default-fonts)
"Get the first installed font from CUSTOM-FONTS and DEFAULT-FONTS."

(catch 'font
(dolist (f (append custom-fonts default-fonts))
(when (find-font (font-spec :family f))
(throw 'font f)))))

;;;###autoload
(defun cabins-font-setup (&rest args)
"Setup fonts from ARGS, The accepted args are :default :unicode :emoji :cjk."

(interactive)
(when (display-graphic-p)
(let ((f-def (cabins-find-font (plist-get args :default) cabins-fonts-default))
(f-uni (cabins-find-font (plist-get args :unicode) cabins-fonts-unicode))
(f-emo (cabins-find-font (plist-get args :emoji) cabins-fonts-emoji))
(f-cjk (cabins-find-font (plist-get args :cjk) cabins-fonts-cjk)))
(set-face-attribute 'default nil :family f-def)
(setq face-font-rescale-alist `((,f-cjk . 1.2)))
(dolist (pair `((unicode . ,f-uni)
(emoji . ,f-emo)
(kana . ,f-cjk)
(han . ,f-cjk)
(bopomofo . ,f-cjk)
(cjk-misc . ,f-cjk)))
(set-fontset-font t (car pair) (font-spec :family (cdr pair)) nil 'prepend)))))

(add-hook 'after-init-hook #'cabins-font-setup)
(when (daemonp)
(add-hook 'after-make-frame-functions
(lambda (frame)
(with-selected-frame frame (cabins-font-setup)))))
(when (find-font (font-spec :family "Sarasa Mono SC"))
(set-face-attribute 'default nil :family "Sarasa Mono SC"))

;; packages
(add-to-list 'load-path (concat user-emacs-directory "lisp"))
Expand Down Expand Up @@ -199,7 +162,7 @@
;; solve the Chinese paste issue
;; let Emacs auto-guess the selection coding according to the Windows/system settings
(prefer-coding-system 'utf-8)
(setq locale-coding-system 'utf-8)
;; (setq locale-coding-system 'utf-8)
(unless cabins-os-win
(set-selection-coding-system 'utf-8))

Expand Down

0 comments on commit 089552a

Please sign in to comment.