unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: suzee <vronk+cllbrtn.mcs@mailbox.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Problem with defining a background color by variable
Date: Sun, 12 Jun 2022 10:58:35 +0200	[thread overview]
Message-ID: <6fd8ba0d-7393-19c9-5fb8-137cfccb6119@mailbox.org> (raw)
In-Reply-To: <834k0qwa8t.fsf@gnu.org>

 > 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	other threads:[~2022-06-12  8:58 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
2022-06-12  8:58   ` suzee [this message]
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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=6fd8ba0d-7393-19c9-5fb8-137cfccb6119@mailbox.org \
    --to=vronk+cllbrtn.mcs@mailbox.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).