When you define a face, you can supply a face spec, which is a condition under which the attributes should be used. This allows Emacs to pick different face attributes in different contexts. For example, if you have one light and one dark frame open at the same time, or if you have a GUI emacs runnning and connect to it using a terminal.
The face spec can contain a lot of conditions, one of them is background
, whose values an be light
and dark
. Others are somewhat obsolete like class
which could be color
, grayscale
, and mono
(even though if feels like it wasn't that long ago when, as a student, I was running Emacs on monochrome workstations).
You can use a face spec both with defface
and with custom-theme-set-faces
.
For example:
(defface my-test-face
'((((background light))
:foreground "red")
(((background dark))
:foreground "blue")
(t :weight bold))
"My test face.")
I would recommend you to define your own theme that could contain all your face definitions.
A side note: face definitions like this can be used by packages like e2ansi to determine what the face would have looked in other displays than the current.