EmacsWiki: Face (original) (raw)

A face provides text with various visible properties, such as color and font.

We need a clear description of the relation between fonts and faces. – DrewAdams

Finding the Face at Point

You can use ` C-u C-x =’ to find out which faces are applied to the text at point (under the cursor).

Alternatively, you can use ‘M-x describe-face RET’. The faces used are listed as the default value for completion.

If you use Icicles, then ‘describe-face’ shows the face-name candidates in buffer ‘*Completions*’ using their own faces – WYSIWYG. (Screenshot) – DrewAdams

Use ‘M-x describe-text-properties RET’ to learn all faces being used at point: faces for overlays at point (as in flyspell incorrect words), face which in turn is a list of faces (as in org mode tags). – JisangYoo

Faces and Emacs Lisp

A symbol can be used as a face, if it has the face property. Check it out by evaluating the following:

(apropos "font-lock-comment-face")

This will show you that the symbol font-lock-comment-face has a variable value. You can examine the value and read the DocString by clicking on “Variable”. The value is the symbol font-lock-comment-face – it stores its own “name” or “pointer”!

Therefore, you can use font-lock-comment-face as a variable. It will evaluate to the symbol with the same name. And the symbol is a valid face because it has the face property.

Check the output of apropos again. If you click on “Face” you will be put in a customization buffer where you can edit the value of the font “spec”. The spec is a data structure specifying how text should look.

The above description is confusing. A face need not have a variable associated with it. In fact, nowadays, faces are typically not associated with variables. Font-lock faces are an exception in this regard. – DrewAdams

Is it possible to add the ‘invisible’ property to a face? I want to be able to hide/show regions defined by a face so font-lock can take care of the work for me. – PatrickAnderson

No, because ‘face’ and ‘invisible’ are different text properties. The ‘face’ property can have a value such as ‘bold’, and the ‘invisible’ porperty can have a value such as ‘t’. But there is no face that makes text invisible. Adding such a face was discussed on emacs-devel. You can emulate such a thing though with some elisp. See the EmacsManual (` C-h i RET g (emacs)faces RET’) – AlexSchroeder

Is it possible to undefine a face, using something like ` makunbound’? I’d like to experiment with different calls to defface, but only the first one takes effect. – EthanGlasserCamp

It probably is possible, but I don’t know how. You can look in library faces.el, but you might also need to check some C code. Dunno.

But what you describe needing is not really to undefine a face in the sense of ‘makunbound’ (so that ‘facep’ will return ‘nil’) but simply to either (a) redefine it or (b) set all of its attributes to ‘undefined’.

For (a), you can just put the cursor inside a given ‘defface’ definition for the face and then hit ‘C-M-x’ to put that definition into effect. This is just like using ‘C-M-x’ on a ‘defun’.

For (b), you can use ‘set-face-attribute’ or you can just do either of these, where ‘the-face’ is the face for which you want to reset all the attributes to ‘unspecified’:

M-: (face-spec-reset-face 'the-face) M-: (modify-face 'the-face)

DrewAdams

No, I actually do want it to be undefined, because defface won’t take effect if the face already exists. (This is true even in emacs version 23.1.50 from emacs-snapshot.) Checking the C code was a good idea, and it looks like I should be able to remove the face from face-new-frame-defaults, but if I do that, I get into a weird undefined state where the face is in the frame-face-alist and I still can’t define a new face. Oh well, I guess I’ll just defface a bunch of new faces until I get to a definition I like, and then restart emacs and only use that one. – EthanGlasserCamp

Why do you say that the ‘defface’ won’t take effect? Did you try it? If you put the cursor inside a ‘defface’ expression and hit ‘C-M-x’ then the ‘defface’ does take effect anew. You can see this easily by changing some setting in the ‘defface’ and doing it again. This will not work with old versions of Emacs (e.g. Emacs 20), but it works starting at least with Emacs 22. You can see this mentioned in node ‘Lisp Eval’ of the Emacs manual: Lisp Eval. It says this:

Typing C-M-x on a defface expression reinitializes the face according to the defface specification.

DrewAdams

For those who want to undefine a face in order to replace the face’s original defface spec with one’s own defface spec, they may achieve similar effects without undefining the face by either 1. going to the Customize interface for the face and clicking on ‘State’ then on ‘For All Kinds of Displays’ and start customizing, or 2. customizing the face so that it simply inherits from a new face which is defined with a defface form in the init file. --JisangYoo


CategoryGlossary