I'm using one of the pre-defined custom themes that come bundled with Spacemacs (zenburn).
How can I modify specific portions of the theme, for example just change the font color used for comments ?
I'm using one of the pre-defined custom themes that come bundled with Spacemacs (zenburn).
How can I modify specific portions of the theme, for example just change the font color used for comments ?
I favor using custom-theme-set-faces
to redefine how the theme displays a particular face, e.g.,
(custom-theme-set-faces
'zenburn
'(font-lock-comment-face ((t (:foreground "#DFAF8F"))))
'(font-lock-comment-delimiter-face ((t (:foreground "#DFAF8F")))))
For the specific case of zenburn
, the theme itself defines various colors and a macro in which those are bound to variable names, so you can write the above as:
(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))))))
In spacemacs, install the layer theming
, see https://github.com/syl20bnr/spacemacs/tree/master/layers/%2Bthemes/theming
For example, I have the following snipped in the dotspacemacs/user-init
of my .spacemacs
to adjust the background and linenumber color of the gruvbox and the solarized-light theme:
(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)
)
))
I added advice to the load-theme function to override certain faces - that way you can continue to use load-theme as normal to select a theme and it'll apply the overrides automatically.
(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))))
))
It works, and it would be nice to have as part of the interface, but it's probably simplest to just make a function for each theme that you use and call custom-theme-set-faces after loading it -
(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)
It might be easier for you to just use SPC SPC custom-theme-visit-theme
, find gruvbox
, make your edits there and then just place (load-file "~/.emacs.d/gruvbox-theme.el")
in your dotspacemacs/user-config
function.
Example of what I did to edit spacemacs-dark
, removing a couple of bolds I don't like:
;; 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))))
)
)