I have a customization requirement (for branding purposes) to define custom colors for several backgrounds. This needs to use new color names rather than hard-wired #hex so that it can go in a shared .emacs. I don't seem to be able to find the command that will (for example) set foobar to be #314159

  • 2
    The question is not clear to me. What do you mean by a "new color" and a "new color name"? What do you mean by "set foobar"? Are you talking about using a variable whose value is a hex color string? (setq foobar "#314160") – Drew May 28 '18 at 13:54
  • How about defface? Virtually every library I can think of define a few faces ... – lawlist May 28 '18 at 17:32
  • Sorry for not being more explicit. "new color [name]" means one that is new, ie not already defined (by X or wherever Emacs gets its existing color names from). My example "set foobar" was intended to imply that there may be a command to do this, whose name I do not know (foobar is a token commonly used as a generic example in discussing computer documentation). Put another way, how do I define the name "foobar" to equate to "#314159" (or perhaps a decimal RGB triplet) so that I can use the name in a command like 'set background-color'? Maybe it is a variable I want; I don't know. – Peter Flynn May 29 '18 at 7:28
  • No, not a whole face; I want a named color that I can use in 'set background-color'. – Peter Flynn May 29 '18 at 7:29
  • Your setq example does the job, thank you. I was expecting that it would need something a lot more complex, and also that dereferencing it in a (set-background-color ...) command would require some kind of signal or flag character. – Peter Flynn May 29 '18 at 7:39

The requirement was for a different background color for each remote host logged into. This snippet is now at the end of the shared .emacs on each host:

(setq colors-for-machines
("adam" . "seashell")
("eve" . "lavender blush")
("lucifer" . "lavender")
("cherub" . "linen")
("moly" . "alice blue")
("athame" . "mint cream")
("aziraphael" . "alice blue")
  (assoc (nth 0 (split-string (system-name) "\\."))

(edited for names to protect the guilty :-)

Thanks to all who contributed.

| improve this answer | |
  • Just curious -- any reason you went with (nth 0 ...) instead of (car ...)? – cyberbisson Apr 26 '19 at 15:06

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.