all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Problem with defining a background color by variable
Date: Sun, 12 Jun 2022 11:34:42 +0300	[thread overview]
Message-ID: <834k0qwa8t.fsf@gnu.org> (raw)
In-Reply-To: <0916306f-7e89-426d-5b05-631e5b8fa522@mailbox.org> (message from suzee on Sun, 12 Jun 2022 10:24:30 +0200)

> Date: Sun, 12 Jun 2022 10:24:30 +0200
> From: suzee <vronk+cllbrtn.mcs@mailbox.org>
> 
> I want to change the background color of code (and other) blocks in 
> org-mode as proposed here:
> 
> https://orgmode.org/worg/org-contrib/babel/examples/fontify-src-code-blocks.html#org4218fd0
> 
> 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	other threads:[~2022-06-12  8:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-12  8:24 Problem with defining a background color by variable suzee
2022-06-12  8:34 ` Eli Zaretskii [this message]
2022-06-12  8:58   ` suzee
2022-06-12  9:16     ` Eli Zaretskii
2022-06-12  9:41       ` suzee

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=834k0qwa8t.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.