|
(after! org |
|
;; org-mode下的中文字体(用汉字、拉丁字母等宽的更纱黑体) |
|
(pcase system-type |
|
('gnu/linux (setq should-org-use-separate-font t |
|
org-separate-font-family "Sarasa Mono SC")) |
|
(_ (setq should-org-use-separate-font nil |
|
org-separate-font-family nil))) |
|
|
|
(when should-org-use-separate-font |
|
;; 创建专门的fontset,只包含Sarasa Gothic字体 |
|
;; NOTE: 这里下面是可以直接设置字体的,像是 "-*-*-*-*-*--*-*-*-*-*-*-fontset-monospacecjkv, han:Sarasa Mono SC 18" 这样 |
|
;; 不过这么写的字号解析好像和 `font-spec' 不太一样,18号XLFD要比18号 `font-spec' 要大很多 |
|
(defconst fontset-monospace-cjkv (create-fontset-from-fontset-spec "-*-*-*-*-*--*-*-*-*-*-*-fontset-monospacecjkv")) |
|
|
|
;; 创建专门的继承自以上fontset的face |
|
(make-face 'org-default-cjkv) |
|
(setq fontset-monospace-cjkv-faces '(org-default-cjkv)) |
|
|
|
;; 配置之前创建的 fontset 和 face |
|
(defun hnosm/config-fontset-monospace-cjkv (font-size) |
|
(interactive "nFont size: ") |
|
;; Set fontset font spec |
|
(dolist (charset '(latin kana han cjk-misc bopomofo)) |
|
(set-fontset-font fontset-monospace-cjkv |
|
charset |
|
(font-spec :family org-separate-font-family :size font-size))) |
|
;; Set face to use `fontset-monospace-cjkv', we need to do this every time because for some reason, Emacs |
|
;; "caches" ASCII characters' font information and calling `set-fontset-font' only affects non-ASCII chars |
|
(dolist (face fontset-monospace-cjkv-faces) |
|
(set-face-attribute face nil |
|
;; NOTE: 不知道为什么,`:font'和`:fontset'都必须写才能正常工作 |
|
;; 前者控制ASCII字符的字体(也就相当于直接设置face的`:family'),后者控制其他汉字等字符的字体 |
|
;; NOTE: `:fontset'好像是个undocumented parameter,不过能用我也管不了那么多了 |
|
:font fontset-monospace-cjkv |
|
:fontset fontset-monospace-cjkv))) |
|
;; Default value |
|
;; TODO make this detect display DPI and scale automatically |
|
(let ((font-size (pcase (system-name) |
|
;; Insert your own device-specific logic here |
|
(_ 20)))) |
|
(hnosm/config-fontset-monospace-cjkv font-size))) |
|
|
|
(defun hnosm/org-mode-hook () |
|
;; Less distractions |
|
(display-line-numbers-mode -1) |
|
;; Disable word autocompletion - nuclear solution, too lazy to specifically remove the correct backends |
|
(company-mode -1) |
|
(+org/buffer-name-to-title) |
|
(+org/run-startblock) |
|
(when should-org-use-separate-font |
|
(setq buffer-face-mode-face 'org-default-cjkv) |
|
(buffer-face-mode))) |
|
(add-hook 'org-mode-hook 'hnosm/org-mode-hook)) |