2

The description of defface in (info "(elisp) Defining Faces") says that the name of a face should not end in -face. But most faces declared in font-lock.el do use the suffix -face. How does this fit together?

1

There are exceptions. ;-)

Some may be vestiges. In the Olden Days it was common to have both a variable for the face and the face itself, and the variable, or both, had a name that ended in -face.

Some are not just vestiges, at least for the variables. One reason to have a variable is to be able to bind it, to temporarily change which face is used. This is not common.

In the case of font-lock faces, there is this comment (from @Stefan Monnier) in the code (font-lock.el), which explains things:

;; Originally these variable values were face names such as `bold' etc.
;; Now we create our own faces, but we keep these variables for compatibility
;; and they give users another mechanism for changing face appearance.
;; We now allow a FACENAME in `font-lock-keywords' to be any expression that
;; returns a face.  So the easiest thing is to continue using these variables,
;; rather than sometimes evalling FACENAME and sometimes not.  sm.

;; Note that in new code, in the vast majority of cases there is no
;; 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.
(defvar font-lock-comment-face      'font-lock-comment-face
  "Face name to use for comments.")
| improve this answer | |
  • 1
    Maybe, it is good to know that faces are actually managed in face-... properties of a symbol (face-defface-spec, face-override-spec, customized-face, saved-face). That makes is possible to use one symbol for a variable and a face simultaneously. Last time I read the manual in that respect it was a bit vague. One got the wrong impression that faces are a separate primitive type. – Tobias Apr 19 at 7:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.