GNU bug report logs - #71469
font-lock does not apply standard faces and their descendants

Previous Next

Package: emacs;

Reported by: Konstantin Kharlamov <Hi-Angel <at> yandex.ru>

Date: Mon, 10 Jun 2024 12:33:02 UTC

Severity: normal

Fixed in version 31.1

Done: Stefan Kangas <stefankangas <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


Message #8 received at 71469 <at> debbugs.gnu.org (full text, mbox):

From: Konstantin Kharlamov <Hi-Angel <at> yandex.ru>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 71469 <at> debbugs.gnu.org
Subject: [PATCH] Re: bug#71469: font-lock does not apply standard faces and
 their descendants
Date: Mon, 10 Jun 2024 16:41:53 +0300
[Message part 1 (text/plain, inline)]
On Mon, 2024-06-10 at 15:55 +0300, Eli Zaretskii wrote:
> tags 71469 notabug
> thanks
> 
> > From: Konstantin Kharlamov <Hi-Angel <at> yandex.ru>
> > Date: Mon, 10 Jun 2024 14:59:37 +0300
> > 
> >      (defface test-face
> >        '((t (:inherit bold)))
> >        "Test face.")
> > 
> >      (define-derived-mode my-mode fundamental-mode "My Mode"
> >        "A minimal mode that highlights 'hello world' text."
> >        (font-lock-add-keywords nil '(("hello world" 0 test-face)))
> 
> From the ELisp manual:
> 
>    Each element of ‘font-lock-keywords’ should have one of these
> forms:
>    [...]
>   ‘(MATCHER . FACESPEC)’
>        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.
>       
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> IOW, there's a difference between a symbol of a variable whose value
> is a face name, and that face name itself.
> 
> This works for me:
> 
>   (defface test-face
>     '((t (:inherit bold)))
>     "Test face.")
>   (defvar test-face 'test-face
>     "Face name to use for My Mode.")
> 
>   (define-derived-mode my-mode fundamental-mode "My Mode"
>     "A minimal mode that highlights 'hello world' text."
>     (font-lock-add-keywords nil '(("hello world" 0 test-face)))
>     (font-lock-flush))
>   (add-to-list 'auto-mode-alist (cons "test.txt" 'my-mode))
>   (provide 'my-mode)

Ooh, I see, thank you! So using e.g. a `'test-face` also makes it work.

I'm wondering if it would be okay to mention such nuance in the
"standard faces" documentation, such as with the attached patch? I
think it would be really helpful, because the nuance of how it works is
not obvious at all (it would be much easier if none of the faces such
as font-lock-keyword-face, would be defining a variable). I've spent
for about an hour on this trying in different ways to make it work, and
I also think it wasn't the first time I stumbled upon this. Having the
"standard faces" mention that interaction nuance I think could be
helpful for people in the future.
[1.patch (text/x-patch, attachment)]

This bug report was last modified 151 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.