0

I'm new to emacs and I'm trying to figure out some theme behavior that is confusing me. I'm trying to figure out why the second call doesn't take effect in this theme. Note that this is obviously a contrived, reduced case:

(deftheme test-theme
  "testing override behavior")

(custom-theme-set-faces
 'test-theme
 `(default ((t (:foreground "#ff0000"))))
 )

(custom-theme-set-faces
 'test-theme
 `(default ((t (:foreground "#00ff00"))))
 )

(provide-theme 'test-theme)

With this theme, I would've imagined that the second call to custom-theme-set-faces would take effect so that the default foreground would be green, but it's red instead (the first call). I load it in my init.el with (load-theme 'testing t).

What I find weird is that if I then go to the buffer for the theme and eval-buffer, it does seem to take effect, with the text being green. It seems like at emacs startup with load-theme it doesn't work, perhaps it doesn't allow redefining the same spec or something. Even afterward doing M-x load-theme on it has the same unintended effect. Only if I go to the buffer of the theme and M-x eval-buffer does it take effect.

Merging the calls into one has the same effect. It doesn't work, the text is red not green:

(deftheme test-theme
  "testing override behavior")

(custom-theme-set-faces
 'test-theme
 `(default ((t (:foreground "#ff0000"))))
 `(default ((t (:foreground "#00ff00"))))
 )

(provide-theme 'testing)

I've tried looking at the code for this and other related functions as well as documentation but I can't seem to figure out what causes this, or what is going on.

Another thing which I imagine is similar to the fact that eval-buffer makes it work is that if I put the same custom-theme-set-faces call in my init.el, it works as intended, that is, the default font face shows up green:

(custom-theme-set-faces
 'test-theme
 `(default ((t (:foreground "#ff0000"))))
 `(default ((t (:foreground "#00ff00"))))
 )

So I think it has something to do with the way that theme files are loaded or something. Does anyone have any ideas?

EDIT: If in ielm I do (get 'test-theme 'theme-settings) I see the duplicate entries. The weird thing is that if I then enter a combined call as in the last code example, it only shows a single entry: the last one, as I would expect.

EDIT 2: I think this stems from the fact that custom-theme-set-faces and load-theme both use different ways of 'enabling' a face spec.

1 Answer 1

0

It is indeed due to the way that load-theme works, which is unlike the way custom-theme-set-faces works. I worked around this by creating a macro for the theme I use to make it usable with custom-theme-set-faces.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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