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 11:34:42 +0300 Message-ID: <834k0qwa8t.fsf@gnu.org> References: <0916306f-7e89-426d-5b05-631e5b8fa522@mailbox.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30184"; 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 10:37:26 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 1o0J63-0007aq-4m for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 12 Jun 2022 10:37:23 +0200 Original-Received: from localhost ([::1]:55560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o0J61-0002wo-CZ for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 12 Jun 2022 04:37:21 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45786) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0J3j-0002tY-Mn for help-gnu-emacs@gnu.org; Sun, 12 Jun 2022 04:34:59 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:43240) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0J3j-0002fg-DP for help-gnu-emacs@gnu.org; Sun, 12 Jun 2022 04:34:59 -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=vYxsLuqIWDQMlfgBWjvtrAMFwpTFCaqVYGNQyuu1YFs=; b=TtyBXjz//IcL tl80Ud7Lk5QthchzVOWctlNYNOucseknRm6UNpUdPK87n5CGEiXaRLPmRKzFKALUAxU24CNYn15vS iM1MOEGuWmN+Rtndxf9oBaRpE9Uk8k+KDkJDj+POpz7HZ21qAoDrz1tWSX8pDOMGWmvP4Y/elrRwQ bIt+YUYODQ5mygfPFZKsAIIakPMruKSURxzW0lbH4vB3seEhF2h6jB1OGN65B+vIgBSKCqVpNGJJX SitRA2Z2BPUhUuz/rXMQl1A+l0iwln2nlHFfcXxkhb7Whi8ud2t+vb0ALXvba1QT0fWFfIcIM8Mw5 rp6X3bOiP6jTbJPItTy6Ag==; Original-Received: from [87.69.77.57] (port=3786 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 1o0J3i-0004qz-BK for help-gnu-emacs@gnu.org; Sun, 12 Jun 2022 04:34:58 -0400 In-Reply-To: <0916306f-7e89-426d-5b05-631e5b8fa522@mailbox.org> (message from suzee on Sun, 12 Jun 2022 10:24:30 +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:137729 Archived-At: > 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: > > 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 #) > set-face-attribute(org-block-background # 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.