UP | HOME

▼ 本文更新于 [2025-05-21 周三 19:08]

emacs-更改配色方案

这两天将emacs的配色方案由用了接近10年的gruvbox-light-soft换到了随机切换的ef-themes

1. 随机切换主题

我挑选了几个自己看得比较顺眼的 ef-themes 主题,参考官方配置设置启动Emacs时随机切换。

(require 'modus-themes)
(require 'ef-themes)
;; (setq ef-melissa-palette-overrides
;;       '((cursor "#928374")))
;; Disable all other themes to avoid awkward blending:
(mapc #'disable-theme custom-enabled-themes)
;; Random load the theme of choice:  
(let* ((themes '(modus-operandi-tinted ef-arbutus ef-cyprus ef-day ef-eagle ef-elea-light ef-kassio ef-melissa-light ef-reverie ef-spring ef-trio-light))
       (n (random (length themes)))
       (pick (nth n themes))
       (loaded (if (null pick) (car themes) pick)))
  (when (string= "modus-operandi-tinted" loaded)
    ;; modus-theme的取色宏与ef-themes不一样,这里定义一个别名就可以不改后续代码
    (defalias 'ef-themes-with-colors 'modus-themes-with-colors))
  (load-theme loaded :no-confirm))

2. 配置全局字形设置

首先是把 org-mode 下所有的heading设置为正常字形,无行高调整;然后全局启用默认字体。我默认的字体是中英文1:2等宽的字体混合搭配(emacs-字体选择)。

(setq modus-themes-italic-constructs t
      modus-themes-bold-constructs nil)
(setq modus-themes-headings ; read the manual's entry or the doc string
      '((0 . (regular 1))
        (1 . (regular 1))
        (2 . (regular 1))
        (3 . (regular 1))
        (4 . (regular 1))
        (5 . (regular 1)) ; absence of weight means `bold'
        (6 . (regular 1))
        (7 . (regular 1))
        (t . (regular 1))))
(setq ef-themes-headings ; read the manual's entry or the doc string
      '((0 regular 1)
        (1 regular 1)
        (2 regular 1)
        (3 regular 1)
        (4 regular 1)
        (5 regular 1) ; absence of weight means `bold'
        (6 regular 1)
        (7 regular 1)
        (t regular 1)))
;; They are nil by default...
(setq ef-themes-mixed-fonts t
      ef-themes-variable-pitch-ui nil)

3. 配置自动取色

利用 ef-themes-with-colors 宏,自动化取色并设置。色彩名称可通过 ef-themes-list-colorsef-themes-list-colors-current 查看。

3.1. 自动化色彩配置

;; nano-modeline的配色
(set-face-attribute 'nano-modeline-status nil :background (ef-themes-with-colors fg-alt) :foreground (ef-themes-with-colors bg-main))
(set-face-attribute 'nano-modeline-inactive nil :background (ef-themes-with-colors bg-inactive) :foreground (ef-themes-with-colors fg-dim))
(set-face-attribute 'nano-modeline-active nil :background (ef-themes-with-colors bg-dim) :foreground (ef-themes-with-colors fg-main))
;;设置sis的状态光标颜色
(setq sis-other-cursor-color (ef-themes-with-colors cyan-faint))
;; 设置org-TODO-keywords颜色,这里注释掉仅供参考,为了正确显示粗体,手动指定了更粗的字体名称。
;; (if my-use-pc
;;       (setq org-todo-keyword-faces `(("TODO" . (:foreground ,(ef-themes-with-colors red-warmer) :family "LXGW Bright Code GB regular"))
;;                                      ("HOLD" . (:foreground ,(ef-themes-with-colors yellow-warmer) :family "LXGW Bright Code GB regular"))
;;                                      ("XXXX" . (:foreground ,(ef-themes-with-colors magenta-warmer) :family "LXGW Bright Code GB regular"))
;;                                      ("DONE" . (:foreground ,(ef-themes-with-colors green-warmer) :family "LXGW Bright Code GB regular"))
;;                                      ))
;;     (setq org-todo-keyword-faces `(("TODO" . (:foreground ,(ef-themes-with-colors red-warmer) :weight bold))
;;                                      ("HOLD" . (:foreground ,(ef-themes-with-colors yellow-warmer) :weight bold ))
;;                                      ("XXXX" . (:foreground ,(ef-themes-with-colors magenta-warmer) :weight bold ))
;;                                      ("DONE" . (:foreground ,(ef-themes-with-colors green-warmer) :weight bold ))
;;                                      )))

© Published by Emacs 31.0.50 (Org mode 9.8-pre) | RSS 评论