Search code examples
emacsfontsemacs-faces

Get font face under cursor in Emacs


I've been developing my own custom color theme, and it'd be really useful if I could get a list of font-faces affecting the text under the cursor.

Something like Textmate's show current scope command.

That would save me the trouble of doing M-x customize-face and looking through available options, guessing at which one affects the current word I'm on.

Any ideas?


Solution

  • You can define what-face with this code:

    (defun what-face (pos)
      (interactive "d")
      (let ((face (or (get-char-property (pos) 'read-face-name)
                      (get-char-property (pos) 'face))))
        (if face (message "Face: %s" face) (message "No face at %d" pos))))
    

    After that,

    M-x what-face
    

    will print the face found at the current point.

    (Thanks to thedz for pointing out that what-face wasn’t built in.)