diff options
author | Lars Ingebrigtsen <larsi@gnus.org> | 2022-08-12 15:54:55 +0200 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2022-08-12 15:54:55 +0200 |
commit | 829b131e5b3ad3b077be9d31215770b251341c68 (patch) | |
tree | e27f0f2ed16dc5ceec9984f40b26a239317667a1 /lisp/faces.el | |
parent | c0d761bf7f441f8ab9792351a493dc6bd5525dc1 (diff) | |
download | emacs-829b131e5b3ad3b077be9d31215770b251341c68.tar.gz |
Clarify face-at-point doc string and add (thing-at-point 'face)
* lisp/faces.el (face-at-point): Say what this function does.
* lisp/thingatpt.el (thing-at-point-face-at-point): Add `face'
type (bug#57087).
(thing-at-point-provider-alist, thing-at-point): Mention it in the
doc strings.
Diffstat (limited to 'lisp/faces.el')
-rw-r--r-- | lisp/faces.el | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/lisp/faces.el b/lisp/faces.el index c7acbf57587..390ddbf606a 100644 --- a/lisp/faces.el +++ b/lisp/faces.el @@ -2046,18 +2046,29 @@ as backgrounds." (when msg (message "Color: `%s'" color)) color)) -(defun face-at-point (&optional thing multiple) - "Return the face of the character after point. -If it has more than one face, return the first one. -If THING is non-nil try first to get a face name from the buffer. -IF MULTIPLE is non-nil, return a list of all faces. -Return nil if there is no face." +(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 programatically; to +do that, use `get-text-property' and `get-char-property'." (let (faces) - (if thing - ;; Try to get a face name from the buffer. - (let ((face (intern-soft (thing-at-point 'symbol)))) - (if (facep face) - (push face 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)))) |