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 ?

  • 2
    Are you sure you mean color theme and not custom theme? If you are not using the 3rd-party color-theme.el then you probably mean custom theme. In that case, please edit your question accordingly. See Color and Custom Themes.
    – Drew
    Oct 16 '15 at 21:45

I favor using custom-theme-set-faces to redefine how the theme displays a particular face, e.g.,

 '(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:

   `(font-lock-comment-face ((t (:foreground ,zenburn-orange))))
   `(font-lock-comment-delimiter-face ((t (:foreground ,zenburn-orange))))))
  • where are you supposed to write this piece of code ? in .spacemacs ? Sep 26 '16 at 2:32
  • 2
    No idea, sorry; I don't use Spacemacs. In principle though, all you need to do is cause the code to be evaluated sometime after the zenburn theme has been loaded. Sep 26 '16 at 15:43
  • Note: as of Emacs 27, you have to set custom--inhibit-theme-enable to nil for this to work emacs.stackexchange.com/a/52804/12381 Oct 16 '20 at 14:49

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
       (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)
     (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 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 ()
  (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))))


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
      ((func "#d75fd7")
       (keyword "#4f97d7")
       (type "#ce537a"))

     `(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))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.