From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.help Subject: Re: Problem with defining a background color by variable Date: Sun, 12 Jun 2022 12:16:00 +0300 Message-ID: <83zgiiutrj.fsf@gnu.org> References: <0916306f-7e89-426d-5b05-631e5b8fa522@mailbox.org> <834k0qwa8t.fsf@gnu.org> <6fd8ba0d-7393-19c9-5fb8-137cfccb6119@mailbox.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19106"; mail-complaints-to="usenet@ciao.gmane.io" To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jun 12 11:18:53 2022 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o0JkC-0004qZ-NH for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 12 Jun 2022 11:18:52 +0200 Original-Received: from localhost ([::1]:51602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o0JkB-0007lf-JB for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 12 Jun 2022 05:18:51 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49320) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0Jhh-0007l4-Gr for help-gnu-emacs@gnu.org; Sun, 12 Jun 2022 05:16:18 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:43746) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0Jhg-0008NU-W0 for help-gnu-emacs@gnu.org; Sun, 12 Jun 2022 05:16:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=d0gqpzcf2wpOYvUcTcMB1VpNMxmT6fefJCrpl/GZRv0=; b=L+pJzgWo6rV2 eKhQOaMujDTTTnv6dhhansXgDYN6iJAFLJbL3rzw545aELicyfgiuARpZm6uyDp+aDsLECES+HA7k M3pDLGPPRpwOt7ciMjWY+3tUaWD8mcN9cEtjYmkmZyClUXrF/JoBXX+ic9nPqrXi4cm5PN9KjntyA WtnecKE3mQ9E0pAV47q4pLVOuZJpTvvE85uM6vgWDTvLqPJTi3NHJPMX9+9bxSQms85VPe7YnqpNB ZuUTsGZQ/8byMJk9nswylVAWNAIpy1apx1DgyBMF7mGYiD1TrOJerdrvel6K0dRV68ynLoHZDP+A/ 5/hpxoDHFC3zBdsTWHw1hA==; Original-Received: from [87.69.77.57] (port=2441 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0Jhg-0001d3-7u for help-gnu-emacs@gnu.org; Sun, 12 Jun 2022 05:16:16 -0400 In-Reply-To: <6fd8ba0d-7393-19c9-5fb8-137cfccb6119@mailbox.org> (message from suzee on Sun, 12 Jun 2022 10:58:35 +0200) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:137737 Archived-At: > Date: Sun, 12 Jun 2022 10:58:35 +0200 > From: suzee > > (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)))