I use the monokai theme by default in my Emacs configurations. But sometimes I use other themes too, particularly light themes like leuven if the light in the room is more suitable for that. But I don't like the face that monokai uses for org-block
(the background exactly), thus I want to override it.
My first attempt was this (I use use-package
):
(use-package monokai-theme
:ensure t
:config
(custom-theme-set-faces
'monokai
'(org-block ((t (:foreground "#F8F8F0" :background "#171717"))))))
And works perfectly fine at the start, but if I switch to another theme and then go back to monokai the org-block
face is the default one of the theme again, ignoring my customization. The same happens if I try to wrap that in a (with-eval-after-load "monokai-theme" ... )
function (as in How to change face in particular theme locally?).
So, I tried another approach, using a hook that I use to reset my smart-mode-line theme every time that I change the theme. The entire solution is this:
(use-package monokai-theme
:ensure t
:config
(progn
(defvar after-load-theme-hook nil
"Hook run after a color theme is loaded using `load-theme'.")
(defadvice load-theme (after run-after-load-theme-hook activate)
"Run `after-load-theme-hook'."
(run-hooks 'after-load-theme-hook))
(defun customize-monokai ()
"customize monokai theme"
(custom-theme-set-faces
'monokai
'(org-block ((t (:foreground "#F8F8F0" :background "#171717"))))))
(add-hook 'after-load-theme-hook 'customize-monokai)))
And this works, now every time that I change themes and go back to monokai my custom face is applied as expected. But this also is not a perfect solution because it has side effects, like to switch to a light theme like leuven and have the org-block
background in a dark grey instead of the theme default. If you reload the leuven theme again, then seems to apply the theme default and ignore my customization. But this is not a desirable solution, and in the other hand, in a light theme like leuven is easy to see that something went wrong, but it could not be that easier in another dark themes.
I have looked for another solutions but either didn't work, or are generic solutions (for all the themes, not a particular one) or seems too cumbersome.
Is there a properly way to persistently overwrite a face only for a particular theme?
M-x byte-compile-file
when you are finished modifyingmonokai-theme.el
.