Subject: bug#71469: font-lock does not apply standard faces and their descendants

From: Stefan Kangas <[email-masked]>
Date: Fri, 4 Oct 2024 18:39:06 -0700

Stefan Monnier <[email-masked]> writes:

>>> 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).
>
> No face defines a variable.
>
> Some faces (mostly font-lock faces) have an associated variable whose
> content is "the face name" (which is also the variable's name), but it's
> not a result of the face itself.  It's a separate explicit definition of
> a variable with the same name as the face.
>
> And I agree that it would be simpler if we didn't have those, but
> they've been with us since `font-lock.el` in Emacs-19, so it's not easy
> to get rid of them.

We have occasionally declared things obsolete with the understanding
that they'll be deleted much later than the normal "10 years, give or
take".  See the comment in `interactive-p', for example.

The patch below gives me 64 warnings in our tree.  I'm not sure if it's
worth installing or not.

diff --git a/lisp/font-lock.el b/lisp/font-lock.el
index 7b077a826bf..7787af43bc9 100644
--- a/lisp/font-lock.el
+++ b/lisp/font-lock.el
@@ -316,46 +316,74 @@ font-lock-verbose
 ;; need to create variables that specify face names.  Simply using
 ;; faces directly is enough.  Font-lock is not a template to be
 ;; followed in this area.
+(make-obsolete-variable 'font-lock-comment-face
+                        "use 'font-lock-comment-face instead." "31.1")
 (defvar font-lock-comment-face		'font-lock-comment-face
   "Face name to use for comments.")

+(make-obsolete-variable 'font-lock-comment-delimiter-face
+                        "use 'font-lock-comment-delimiter-face
instead." "31.1")
 (defvar font-lock-comment-delimiter-face 'font-lock-comment-delimiter-face
   "Face name to use for comment delimiters.")

+(make-obsolete-variable 'font-lock-string-face
+                        "use 'font-lock-string-face instead." "31.1")
 (defvar font-lock-string-face		'font-lock-string-face
   "Face name to use for strings.")

+(make-obsolete-variable 'font-lock-doc-face
+                        "use 'font-lock-doc-face instead." "31.1")
 (defvar font-lock-doc-face		'font-lock-doc-face
   "Face name to use for documentation.")

+(make-obsolete-variable 'font-lock-doc-markup-face
+                        "use 'font-lock-doc-markup-face instead." "31.1")
 (defvar font-lock-doc-markup-face       'font-lock-doc-markup-face
   "Face name to use for documentation mark-up.")

+(make-obsolete-variable 'font-lock-keyword-face
+                        "use 'font-lock-keyword-face instead." "31.1")
 (defvar font-lock-keyword-face		'font-lock-keyword-face
   "Face name to use for keywords.")

+(make-obsolete-variable 'font-lock-builtin-face
+                        "use 'font-lock-builtin-face instead." "31.1")
 (defvar font-lock-builtin-face		'font-lock-builtin-face
   "Face name to use for builtins.")

+(make-obsolete-variable 'font-lock-function-name-face
+                        "use 'font-lock-function-name-face instead." "31.1")
 (defvar font-lock-function-name-face	'font-lock-function-name-face
   "Face name to use for function names.")

+(make-obsolete-variable 'font-lock-variable-name-face
+                        "use 'font-lock-variable-name-face instead." "31.1")
 (defvar font-lock-variable-name-face	'font-lock-variable-name-face
   "Face name to use for variable names.")

+(make-obsolete-variable 'font-lock-type-face
+                        "use 'font-lock-type-face instead." "31.1")
 (defvar font-lock-type-face		'font-lock-type-face
   "Face name to use for type and class names.")

+(make-obsolete-variable 'font-lock-constant-face
+                        "use 'font-lock-constant-face instead." "31.1")
 (defvar font-lock-constant-face		'font-lock-constant-face
   "Face name to use for constant and label names.")

+(make-obsolete-variable 'font-lock-warning-face
+                        "use 'font-lock-warning-face instead." "31.1")
 (defvar font-lock-warning-face		'font-lock-warning-face
   "Face name to use for things that should stand out.")

+(make-obsolete-variable 'font-lock-negation-char-face
+                        "use 'font-lock-negation-char-face instead." "31.1")
 (defvar font-lock-negation-char-face	'font-lock-negation-char-face
   "Face name to use for easy to overlook negation.
 This can be an \"!\" or the \"n\" in \"ifndef\".")

+(make-obsolete-variable 'font-lock-preprocessor-face
+                        "use 'font-lock-preprocessor-face instead." "31.1")
 (defvar font-lock-preprocessor-face	'font-lock-preprocessor-face
   "Face name to use for preprocessor directives.")