From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: jan.synacek@posteo.org Newsgroups: gmane.emacs.help Subject: Using face names as FACESPEC in font-lock-keywords does not work Date: Wed, 22 Jun 2022 08:33:49 +0000 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10797"; 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 Wed Jun 22 21:26:50 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 1o4602-0002dR-GZ for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 22 Jun 2022 21:26:50 +0200 Original-Received: from localhost ([::1]:54386 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4601-0000Bl-Jn for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 22 Jun 2022 15:26:49 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46866) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3voF-0000cs-Jy for help-gnu-emacs@gnu.org; Wed, 22 Jun 2022 04:33:59 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:48289) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3voD-0000EI-1O for help-gnu-emacs@gnu.org; Wed, 22 Jun 2022 04:33:59 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id D6CD9240108 for ; Wed, 22 Jun 2022 10:33:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.org; s=2017; t=1655886829; bh=bSmjozcGE+tXUfG5JOnK0zTufdef6+Wzry4ktkt9biM=; h=Date:From:To:Subject:From; b=XFY8063mYIDcUFM8yJQxlwjzCC8QeboelbxDAdfgslMPxYfBHs0JZOda9cNy46NtQ VkciKHazvLM2wTNn/BXRtxziKK0AjHVWQxCIUb4AyEbYpsw/5WD9BV4+CZoqPKkZHr GbYda/taoYJUHOGSskVT4viuj9NUd4U2nZ1QpCPmRJoQme7uJzisrBWx6NVF08iwMc QijNv0GFucKXe4WMAtgFI9u30MwVnQqShFFUWYj6irOnIJa1qlzolmz8tVW4H+ZLok q1uwjMX8elXMAIyEB5s08VWxJVJRVd32TYMPIT5jr+d9eOyA/cHYk5s/3GTDplUVRi G5vMCz0s9frRA== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4LSc9T2X2Hz9rxB for ; Wed, 22 Jun 2022 10:33:49 +0200 (CEST) Received-SPF: pass client-ip=185.67.36.66; envelope-from=jan.synacek@posteo.org; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Wed, 22 Jun 2022 15:11:48 -0400 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:137994 Archived-At: Hello! I have the following piece of code that is supposed to add highlighting=20 for CPP-like conditionals in my mode: (setq-local font-lock-defaults (let* ((cpp-rx (rx line-start "#" (or "if" "ifdef" "else" "elif"=20 "endif") word-boundary)) (keywords `((,cpp-rx . xref-file-header)))) (list keywords))) This piece of code does not work and does not use the 'xref-file-header'=20 face. In the Elisp manual (24.6.2 Search-based Fontification) it says: " -- Variable: font-lock-keywords ... =2E.. Each element of =E2=80=98font-lock-keywords=E2=80=99 should have one of the= se forms: =2E.. =E2=80=98(MATCHER . FACESPEC)=E2=80=99 In this kind of element, FACESPEC is an expression whose value specifies the face to use for highlighting. In the simplest case, FACESPEC is a Lisp variable (a symbol) whose value is a face name. =2E.. " I find the language here quite confusing. 'xref-file-header' is a symbol=20 that evaluates to itself, which also happens to be the face name, and is=20 technically an expression. But apparently, that's not enough, as it=20 seems that the symbol itself has to have a value cell in this particular=20 case. Also, in 40.12.2 Defining Faces, it says: " People are sometimes tempted to create a variable whose value is a face name. In the vast majority of cases, this is not necessary; the usual procedure is to define a face with =E2=80=98defface=E2=80=99, and the= n use its name directly. " This piece of documentation doesn't really help, too. It seems that my=20 case is exactly the minority case where it's actually needed. Using=20 faces like 'font-lock-string-face' works, because they are defined=20 exactly as the documentation says is not necessary. And evaluating=20 "(defvar xref-file-header 'xref-file-header)" fixes the highlighting,=20 too. So my question is: Am I doing something wrong? Or does this case=20 (setting font-lock-keywords) really require a variable which holds the face name instead of using the face=20 name directly? In any case, I think that the documentation deserves a bit of=20 sharpening. Regards, Jan Syn=C3=A1=C4=8Dek