[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: Eli Zaretskii
Subject: Re: Problem with defining a background color by variable
Date: Sun, 12 Jun 2022 11:34:42 +0300

> Date: Sun, 12 Jun 2022 10:24:30 +0200
> From: suzee <>
> I want to change the background color of code (and other) blocks in 
> org-mode as proposed here:
> I use emacs with a theme (gruvbox) and when I literally use the proposed 
> code
>      (defface org-block-background
>        '((t (:background "#FFFFEA")))
>        "Face used for the source block background.")
> it does work. But I want to use a color, which is derived (made darker 
> or lighter) from another color by an emacs lisp function, so basically I 
> want something like this:
>      (defvar mycolor (color-lighten-name "navy" 20))
>      (defface org-block-background
>        '((t (:background mycolor)))
>        "Face used for the source block background.")
> However, when I try this, I get the following error when debugging:
>      Debugger entered--Lisp error: (wrong-type-argument stringp mycolor)
>        internal-set-lisp-face-attribute(org-block-background :background 
> mycolor #<frame emacs@Machine 0x11e7c30>)
>        set-face-attribute(org-block-background #<frame emacs@Machine 
> 0x11e7c30> :background mycolor)
>        [...]
> Does someone know why it fails? Is it not possible to use a variable for 
> the color there?

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

> 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.

reply via email to

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