如何更改自定义主题的部分?


21

我正在使用与Spacemacs(zenburn)捆绑在一起的预定义自定义主题之一。

如何修改主题的特定部分,例如仅更改用于注释的字体颜色?


2
您确定您是指颜色主题而不是自定义主题吗?如果您不使用第三方,color-theme.el则可能是自定义主题。在这种情况下,请相应地编辑您的问题。请参阅颜色和自定义主题
画了

Answers:


13

我喜欢使用custom-theme-set-faces重新定义主题显示特定面孔的方式,例如,

(custom-theme-set-faces
 'zenburn
 '(font-lock-comment-face ((t (:foreground "#DFAF8F"))))
 '(font-lock-comment-delimiter-face ((t (:foreground "#DFAF8F")))))

对于的特定情况zenburn,主题本身定义了各种颜色以及一个将变量绑定到变量名称的宏,因此您可以将上述内容编写为:

(zenburn-with-color-variables
  (custom-theme-set-faces
   'zenburn
   `(font-lock-comment-face ((t (:foreground ,zenburn-orange))))
   `(font-lock-comment-delimiter-face ((t (:foreground ,zenburn-orange))))))

您应该在哪里编写这段代码?在.spacemacs
ChiseledAbs

1
不知道,对不起;我不使用Spacemacs。不过,原则上,您要做的就是使zenburn主题加载后的某个时间对代码进行评估。
亚伦·哈里斯

8

在spacemacs中,安装该层theming,请参见https://github.com/syl20bnr/spacemacs/tree/master/layers/%2Bthemes/theming

例如,我将以下内容插入dotspacemacs/user-init其中.spacemacs以调整gruvbox和solarized-light主题的背景和行号颜色:

  (setq theming-modifications '(
    ;; requires the theming layer
    (gruvbox
       (default :background "#1D2021" :foreground "#fdf4c1")
       (linum :background "#000000" :foreground "#878787")
       (fringe  :background "#000000")
       (linum-relative-current-face :inherit (shadow default) :background "#3C3836" :foreground "#ff0000")
       (font-lock-comment-face :slant italic)
    )
    (solarized-light
     (linum :background "#DBCDA7" :foreground "#40371F")
       (fringe :background "#DBCDA7")
       (font-lock-comment-face :slant italic)
       )
))

4

我向load-theme函数添加了建议以覆盖某些面孔-这样您就可以继续正常使用load-theme选择主题,并且它将自动应用覆盖。

(defadvice load-theme (after theme-set-overrides activate)
  "Set override faces for different custom themes."
  (dolist (theme-settings theme-overrides)
    (let ((theme (car theme-settings))
          (faces (cadr theme-settings)))
      (if (member theme custom-enabled-themes)
          (dolist (face faces)
            (custom-theme-set-faces theme face))))))

(defcustom theme-overrides nil
  "Association list of override faces to set for different custom themes.")

(defun alist-set (alist-symbol key value)
  "Set VALUE of a KEY in ALIST-SYMBOL."
  (set alist-symbol
        (cons (list key value) (assq-delete-all key (eval alist-symbol)))))

; override some settings of the ample-flat theme
(alist-set 'theme-overrides 'ample-flat '(
                                          (default ((t (:background "gray12" :foreground "#bdbdb3"))))
                                          (mode-line ((t (:background "cornsilk4" :foreground "#222" :inherit 'variable-pitch))))
                                          (outline-2 ((t (:inherit font-lock-keyword-face)))) ; blueish
                                          (outline-3 ((t (:inherit font-lock-comment-face)))) ; brownish
                                          (outline-4 ((t (:inherit font-lock-string-face)))) ; orangeish
                                          (org-table ((t (:inherit fixed-pitch :height 0.7 :foreground "#887"))))
                                          (org-formula ((t (:inherit org-table :foreground nil))))
                                          ))

它可以正常工作,并且可以很好地包含在界面中,但为您使用的每个主题创建一个函数并在加载后调用自定义主题设置界面可能是最简单的-

(defun ample-flat ()
  (interactive)
  (mapc #'disable-theme custom-enabled-themes) ; clear any existing themes
  (load-theme 'ample-flat t)
  (custom-theme-set-faces 'ample-flat 
                          '(default ((t (:background "gray12" :foreground "#bdbdb3"))))
                          '(mode-line ((t (:background "cornsilk4" :foreground "#222" :inherit 'variable-pitch))))
                          '(outline-2 ((t (:inherit font-lock-keyword-face)))) ; blueish
                          '(outline-3 ((t (:inherit font-lock-comment-face)))) ; brownish
                          '(outline-4 ((t (:inherit font-lock-string-face)))) ; orangeish
                          '(org-table ((t (:inherit fixed-pitch :height 0.7 :foreground "#887"))))
                          '(org-formula ((t (:inherit org-table :foreground nil))))
                          ))

(ample-flat)

0

我所做的编辑示例spacemacs-dark,删除了一些我不喜欢的粗体:

  ;; on dotspacemacs/user-config:

  ;; configure spacemacs-dark theme, specifically removing bolds
  (let
      ((func "#d75fd7")
       (keyword "#4f97d7")
       (type "#ce537a"))

    (custom-theme-set-faces
     'spacemacs-dark
     `(font-lock-function-name-face ((t (:foreground ,func :inherit normal))))
     `(font-lock-keyword-face ((t (:foreground ,keyword :inherit normal))))
     `(font-lock-type-face ((t (:foreground ,type :inherit normal))))
     )
    )

0

您可能更容易使用SPC SPC custom-theme-visit-theme,查找gruvbox,在此处进行编辑,然后将其放置(load-file "~/.emacs.d/gruvbox-theme.el")dotspacemacs/user-config函数中。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.