Skip to content

Instantly share code, notes, and snippets.

@amno1
Last active November 7, 2025 15:33
Show Gist options
  • Select an option

  • Save amno1/1bf2c57033397fe876e8efd1b474e604 to your computer and use it in GitHub Desktop.

Select an option

Save amno1/1bf2c57033397fe876e8efd1b474e604 to your computer and use it in GitHub Desktop.
Show All Faces Being Used in a Buffer
;;; buffer-faces.el --- show all faces being used in a buffer -*- lexical-binding: t -*-
;; Copyright (C) 2025 Arthur Miller
;; Author: Arthur Miller <arthur.miller@live.com>
;; Keywords:
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Original idea by J. Rockway:
;; https://github.com/jrockway/elisp/blob/master/buffer-faces.el
;; Completely re-worked to work with the built-in help-mode.
;;; Code:
;;; Customize
(defgroup help nil
"This adds to built-in help-mode so we put all defcustoms in same group."
:prefix "helper-"
:group 'help)
;;;###autoload
(defun describe-buffer-faces (&optional buffer)
"Display list of font faces used in BUFFER.
If not specified, or called interactively, BUFFER defaults to `current-buffer'"
(interactive)
(let ((help-buffer (or (help-buffer) (get-buffer-create "*Help*")))
(working-buffer (or buffer (current-buffer)))
(help-buffer-under-preparation t)
(faces nil))
(help-setup-xref (list 'describe-buffer-faces working-buffer)
(called-interactively-p 'interactive))
(save-excursion
(with-current-buffer working-buffer
(goto-char (point-min))
(while (< (point) (point-max))
;; add-to-list can not use lexical var faces ????
;; (add-to-list 'faces (get-text-property (point) 'face))
(let ((face (get-text-property (point) 'face)))
(unless (member face faces)
(push face faces)))
(goto-char (next-property-change (point) nil (point-max))))))
(with-help-window help-buffer
(insert
(format "Faces found in buffer '%s':\n\n" (buffer-name working-buffer)))
(dolist (face (delete nil faces))
(help-insert-xref-button
(propertize (format " %s" face) 'face face) 'help-face face)
(insert "\n")))))
(provide 'buffer-faces)
;;; buffer-faces.el ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment