2

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

6
  • 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, 2018 at 13:54
  • How about defface? Virtually every library I can think of define a few faces ...
    – lawlist
    May 28, 2018 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. May 29, 2018 at 7:28
  • No, not a whole face; I want a named color that I can use in 'set background-color'. May 29, 2018 at 7:29
  • 1
    I would really like to know how to do something like in the original question, even if it’s hack-y. I’m hoping to be able to define new colors so I can use them in things like when selecting colors in customize, have them seen by rainbow-mode, etc. @Drew Mar 26, 2019 at 4:17

1 Answer 1

1

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")
))
;;
(set-background-color
 (cdr
  (assoc (nth 0 (split-string (system-name) "\\."))
         colors-for-machines)))

(edited for names to protect the guilty :-)

Thanks to all who contributed.

1
  • Just curious -- any reason you went with (nth 0 ...) instead of (car ...)? Apr 26, 2019 at 15:06

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.