-
Notifications
You must be signed in to change notification settings - Fork 3
/
emoji-fontset.el
108 lines (83 loc) · 3.84 KB
/
emoji-fontset.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
;;; emoji-fontset.el --- Set font face for Emoji.
;; Copyright (C) 2015 USAMI Kenta
;; Author: USAMI Kenta <tadsan@zonu.me>
;; Created: 31 May 2015
;; Keywords: emoji font config
;; This file is NOT part of GNU Emacs.
;; 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:
;; I recommend that you install the Symbola font.
;; http://users.teilar.gr/~g1951d/
;; (It should do so even in the Mac OS X. "Apple Color Emoji" is too heavy.)
;; put into your own .emacs file (init.el)
;; (emoji-fontset-enable "Symbola")
;;; Code:
(defgroup emoji-fontset nil "Set font family to display Emoji charactor"
:group 'faces)
(defcustom emoji-fontset-default-font-family "Symbola"
"Default Font Family Emoji for Emoji."
:group 'emoji-fontset
:type '(string))
(defcustom emoji-fontset-font-families
'((ns "Apple Color Emoji")
(w32 "Segoe UI Emoji"))
"Assoc list of Font Family for Emoji by `WINDOW-SYSTEM'."
:group 'emoji-fontset
:type '(repeat (cons symbol string)))
(defcustom emoji-fontset-check-version 'error
"Behavior in new version of Emacs."
:type '(radio (const :tag "Force apply fontset setting." 'force)
(const :tag "Do not apply fontset. And display message." 'message)
(const :tag "Do not apply fontset. And display error." 'error)))
(defconst emoji-fontset--codepoint
'((#x1f000 . #x1f02f) ; Mahjong Tiles
(#x1f0a0 . #x1f0ff) ; Playing Cards
(#x1f110 . #x1f19a) ; Enclosed Alphanumeric Supplement
; Regional Indicator Symbol, Enclosed Ideographic Supplement,
; Emoticons, Transport and Map Symbols, Alchemical Symbols
(#x1f1e6 . #x1f8ff)))
(defvar emoji-fontset--do-not-apply nil)
(defun emoji-fontset--font-family (font-family)
"Choose `FONT-FAMILY' for Emoji fontset by `WINDOW-SYSTEM'."
(or
font-family
(car (assoc-default window-system emoji-fontset-font-families 'eq '()))
emoji-fontset-default-font-family))
(defun emoji-fontset--set-fontset (font-family range)
"Set `FONT-FAMILY' to fontset for Emojis by `RANGE'."
(set-fontset-font
"fontset-default"
(cons (decode-char 'ucs (car range)) (decode-char 'ucs (cdr range)))
font-family))
;;;###autoload
(define-obsolete-function-alias 'emoji-fontset/turn-on 'emoji-fontset-enable "0.1.0")
;;;###autoload
(defun emoji-fontset-enable (&optional font-family)
"Be enable Emoji Font face by `FONT-FAMILY'."
(interactive "MEmoji Font Famly: ")
(when (and (stringp font-family) (< (length font-family) 1))
(setq font-family nil))
(when (and (version< "25.1" emacs-version) (equal font-family "Symbola")
(not (eq emoji-fontset-check-version 'force)))
(setq emoji-fontset--do-not-apply t)
(cond
((eq emoji-fontset-check-version 'message) (message "emoji-fontset.el is out-of-date in Emacs 25.1+"))
((eq emoji-fontset-check-version 'error) (error "emoji-fontset.el is out-of-date in Emacs 25.1+"))))
(when (and window-system (not emoji-fontset--do-not-apply))
(let ((-emoji-font-family (emoji-fontset--font-family font-family)))
(mapc (lambda (it) (emoji-fontset--set-fontset -emoji-font-family it))
emoji-fontset--codepoint)
t)))
(when (version< "25.1.1" emacs-version)
(make-obsolete 'emoji-fontset-enable nil "0.2.0"))
(provide 'emoji-fontset)
;;; emoji-fontset.el ends here