Function: face-at-point

face-at-point is a byte-compiled function defined in faces.el.gz.

Signature

(face-at-point &optional TEXT MULTIPLE)

Documentation

Return a face name from point in the current buffer.

This function is meant to be used as a conveniency function for providing defaults when prompting the user for a face name.

If TEXT is non-nil, return the text at point if it names an existing face.

Otherwise, look at the faces in effect at point as text properties or overlay properties, and return one of these face names.

IF MULTIPLE is non-nil, return a list of faces.

Return nil if there is no face at point.

This function is not meant for handling faces programmatically; to do that, use get-text-property and get-char-property.

Source Code

;; Defined in /usr/src/emacs/lisp/faces.el.gz
(defun face-at-point (&optional text multiple)
  "Return a face name from point in the current buffer.
This function is meant to be used as a conveniency function for
providing defaults when prompting the user for a face name.

If TEXT is non-nil, return the text at point if it names an
existing face.

Otherwise, look at the faces in effect at point as text
properties or overlay properties, and return one of these face
names.

IF MULTIPLE is non-nil, return a list of faces.

Return nil if there is no face at point.

This function is not meant for handling faces programmatically; to
do that, use `get-text-property' and `get-char-property'."
  (let (faces)
    (when text
      ;; Try to get a face name from the buffer.
      (when-let ((face (thing-at-point 'face)))
        (push face faces)))
    ;; Add the named faces that the `read-face-name' or `face' property uses.
    (let ((faceprop (or (get-char-property (point) 'read-face-name)
                        (get-char-property (point) 'face))))
      (cond ((facep faceprop)
             (push faceprop faces))
            ((face-list-p faceprop)
             (dolist (face faceprop)
               (if (facep face)
                   (push face faces))))))
    (if multiple
        (delete-dups (nreverse faces))
      (car (last faces)))))