help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with defining a background color by variable


From: Eli Zaretskii
Subject: Re: Problem with defining a background color by variable
Date: Sun, 12 Jun 2022 12:16:00 +0300

> Date: Sun, 12 Jun 2022 10:58:35 +0200
> From: suzee <vronk+cllbrtn.mcs@mailbox.org>
> 
>      (require 'color)
>      (defvar mycolor (color-lighten-name "navy" 20))
> 
>      (message "My Color value: %s" mycolor)
>      (message "My Color Type: %s" (type-of mycolor))
>      (message "My Color is of string type: %s" (stringp mycolor))
> 
>      (defface org-block-background
>        '((t (:background mycolor)))
>        "Face used for the source block background.")
> 
>      (require 'org)
> 
> 
>  >> What can I do to make it work or to achieve my goal in a different way?
>  >
>  > My suggestion is to use set-face-background instead.  defface is
>  > effective only once, when the face is being defined.  Thereafter you
>  > can use set-face-background to change the background color.
> 
> Ah awesome!  The following does in fact work:
> 
>      (set-face-attribute 'org-block-background mycolor)
> 
> And it's nice that it allows to change it at any moment.  (I only found 
> set-face-attribute by googling and couldn't make it work.)
> 
> Thanks a lot! :)
> 
> I'd be happy to understand the error message though to gain some 
> knowledge about elisp.  Any idea about that?

I think it's because of the quoting: the entire list is quoted, so the
value of mycolor is not evaluated.  You need to use a smarter quoting,
something like

   `((t (:background ,mycolor)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]