Elisp: Font Face
What is Face
A face is graphical attributes for displaying text, such as text color, size, font, etc.
Emacs has many faces predefined.
List Faces
To list all loaded faces, Alt+x list-faces-display
.
font-lock-mode Builtin Faces
The following are faces defined by Font Lock Mode
- font-lock-builtin-face
- font-lock-comment-delimiter-face
- font-lock-comment-face
- font-lock-constant-face
- font-lock-doc-face
- font-lock-doc-markup-face
- font-lock-function-name-face
- font-lock-keyword-face
- font-lock-negation-char-face
- font-lock-preprocessor-face
- font-lock-string-face
- font-lock-type-face
- font-lock-variable-name-face
- font-lock-warning-face
If you are creating a programing language mode, use these face as much as possible, because that will create consistent style of coloring across programing language modes.
Builtin Faces in Emacs
The following are basic faces defined by emacs.
'default
'bold
'italic
'bold-italic
'underline
'fixed-pitch
'variable-pitch
'shadow
'link
'link-visited
'highlight
'match
'isearch
'lazy-highlight
'error
'warning
'success
Show Face Documentation
describe-face
Named Face is Not Variable
🛑 WARNING:
A named face is not a variable.
defface
and
face-spec-set
do not create a new variable.
In elisp technicality, defface
does not set the
Symbol's value cell.
(boundp 'face_name)
returns nil.
A named face (such as those created by defface
) is specified by setting the face-defface-spec
property name of the
Symbol Property List
.
You can use defvar
to make a face_name symbol also a variable, but that is not necessary.
Those faces predefined from Font Lock Mode , such as font-lock-function-name-face, are both named faces and variables.
Check is Face or is Variable
facep
- Return true is its a face.
boundp
- Return true is its a variable.
;; example of user defined face (defface my-great-face '((t :foreground "red")) "my face" ) ;; check if a symbol is a variable. that is, value cell is not void (boundp 'my-great-face) ; nil ;; check if a symbol is a face (facep 'my-great-face) ; non-nil ;; get the value of 'face-defface-spec from symbol's plist (get 'my-great-face 'face-defface-spec ) ; ((t :foreground "red" :weight bold)) ;; now make it a variable. (you shouldn't do this) (defvar my-great-face nil "my face too") (boundp 'my-great-face) ; t
See also: Elisp: Symbol