-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfontify-face.el
80 lines (62 loc) · 2.61 KB
/
fontify-face.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
;;; fontify-face.el --- Fontify symbols representing faces with that face. -*- lexical-binding: t -*-
;; Copyright (C) 2018 Matúš Goljer
;; Author: Matúš Goljer <[email protected]>
;; Maintainer: Matúš Goljer <[email protected]>
;; Version: 1.0.0
;; Created: 10th April 2018
;; URL: https://github.com/Fuco1/fontify-face
;; Package-requires: ((emacs "24"))
;; Keywords: faces
;; 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:
;; Fontify symbols representing faces with that face.
;; See https://github.com/Fuco1/fontify-face
;;; Code:
(defgroup fontify-face ()
"fontify-face minor mode."
:group 'editing
:prefix "fontify-face-")
(defcustom fontify-face-mode-lighter " FF"
"Mode line lighter for the `fontify-face-mode'."
:type '(radio
(const :tag "Emoji (💡)" " 💡")
(const :tag "Ascii (FF)" " FF")
(string :tag "String"))
:group 'fontify-face)
(defun fontify-face-colorize-matched-face ()
"Return face for fontifying the last match.
The face used to fontify the region is the text of the matched
region if it represents a face, no face is returned."
(let ((match (match-string 0)))
(when (facep match) match)))
(defun fontify-face-find-next-symbol (limit)
"Find the next symbol up until LIMIT."
(re-search-forward
(rx symbol-start
(1+ (or (syntax symbol) (syntax word)))
symbol-end)
limit t))
(defconst fontify-face-keywords
`((fontify-face-find-next-symbol 0 (funcall 'fontify-face-colorize-matched-face)))
"Keywords used for highlighting faces.
Note: instead of using constants we use functions which are not
expected to change very much. This is to make toggling the
display somewhat reliable during updates.")
;;;###autoload
(define-minor-mode fontify-face-mode
"Fontify symbols representing faces with that face."
:lighter fontify-face-mode-lighter
(if fontify-face-mode
(font-lock-add-keywords nil fontify-face-keywords)
(font-lock-remove-keywords nil fontify-face-keywords)))
(provide 'fontify-face)
;;; fontify-face.el ends here