Skip to content

Instantly share code, notes, and snippets.

@richlowe
Last active February 11, 2016 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richlowe/2e4fb391e4bce91b3e6e to your computer and use it in GitHub Desktop.
Save richlowe/2e4fb391e4bce91b3e6e to your computer and use it in GitHub Desktop.
(defvar emoji-font
(case window-system
(ns "Apple Color Emoji")
(w32 "Segoe UI") ;Maybe?
(x "Symbola")) ;Maybe?
"Font used to display emoji")
(defun generate-emoji-font-tables ()
"Fetch the emoji unicode data from unicode.org, and insert
the forms to specify that the emoji font be used for those
codepoints into the current buffer"
(interactive)
(let ((buf (url-retrieve-synchronously "http://www.unicode.org/Public/emoji/2.0//emoji-data.txt")))
(unless buf
(error "Couldn't fetch emoji data"))
(let ((emoji '()))
(with-current-buffer buf
(search-forward "\n\n") ;Skip headers
(while (not (eobp))
(when (looking-at "^\\([0-F]+\\)\\(\.\.\\([0-F]+\\)\\)?")
(let* ((start (string-to-number (match-string 1) 16))
(end (if (match-string 3)
(string-to-number (match-string 3) 16)
nil))
(range (if end (cons start end) start)))
(when (>= start #x1f000) ;Skip chars that aren't _really_
(add-to-list 'emoji range))))
(forward-line)))
(insert "(progn\n")
(dolist (e emoji)
(insert (format " (set-fontset-font t %s emoji-font nil 'prepend)\n"
(if (consp e)
(format "'(?\\x%x . ?\\x%x)" (car e) (cdr e))
(format "?\\x%x" e)))))
(insert ")\n"))))
;; Now M-x generate-emoji-font-tables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment