[Top][All Lists]

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

Re: Problem with defining a background color by variable

From: suzee
Subject: Re: Problem with defining a background color by variable
Date: Sun, 12 Jun 2022 10:58:35 +0200

> What is mycolor's value?  When is that value being set, relative to
> the time the above defface is processed by Emacs?

It's set right before the defface command and its value is #0000e6 (checked with message outputs). My code looks like this:

    (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?

reply via email to

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