0

I am a Vim user and i recently decided to try Emacs Spacemacs, i have a problem setting up custom highlighting, i set some lines like the following in my .spacemacs (i guess it's the same problem in your .emacs):
(set-face-background 'font-lock-comment-face nil) The idea is to always disable the background highlighting of "commented areas" but it has a problem, it works fine when starting Emacs but changing the theme resets it (the new theme overwrites it).
There is the same problem in Vim which is easily fixed by loading the custom colors after a theme has been loaded :
autocmd ColorScheme * call LoadMyCustomHighlighting() How do you translate that in elisp?

Note: I found what seems to be a similar question here but it don't understand it (elisp noob), i would want some actual working code with a basic explanation.

0

As discussed in the other question there are no hooks for this in load-theme. Neither is there in enable-theme, the function for enabling themes, which would be the right point to do this. The easiest solution is to add advice (code that is latched onto another function in some way).

(advice-add 'enable-theme :after #'aj/apply-face-definitions)

(defun aj/apply-face-definitions (&optional theme)
  "Do face definition stuff after loading theme."
  (set-face-attribute 'font-lock-comment-face nil :background nil))

set-face-attribute is used instead of set-face-background which “mostly provide compatibility with old versions of Emacs” according to the elisp manual.

  • Thanks a lot, however to complete the answer it is worth noting that it doesn't work when starting emacs, only when changing theme, so i added my customizations to a function that is called first in my .spacemacs at startup and then again every time i change theme. Sadly i don't have enough reputation to upvote you :( – ft_error Apr 27 '18 at 13:55
  • Are you sure that doesn’t depend on the load order. If themes are first enabled before this advice is added to enable-theme. I don’t use Spacemacs so I don’t know exactly in what order it does its initialization. In my standard Emacs init-file it works if I load my themes after this code. – Anders Johansson May 2 '18 at 19:11

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.