Skip to content

Instantly share code, notes, and snippets.

@emres
Last active April 30, 2019 13:06
Show Gist options
  • Save emres/c23de947a4a89d6bafa8d7d89973cb2d to your computer and use it in GitHub Desktop.
Save emres/c23de947a4a89d6bafa8d7d89973cb2d to your computer and use it in GitHub Desktop.
Sample the mono spaced fonts in Emacs, printing the same line in different mono fonts
(defun font-is-mono-p (font-name)
(string-match "-mono-" font-name))
(defun compare-monospace-fonts ()
"Display a list of all monospace font faces. Tested on MS Windows 10."
(interactive)
(pop-to-buffer "*Monospace Fonts*")
(erase-buffer)
(dolist (font-name (x-list-fonts "*"))
(if (and (font-is-mono-p font-name)
(ignore-errors (font-spec :name font-name)))
(progn
(newline)
(insert
(propertize (concat "1 l; 0 O o [ < = > ] " font-name ")\n")
'font-lock-face `((:family ,(format "%s" (font-get (font-spec :name font-name) :family)))
(:font (font-spec :name font-name)))))))))
;; See the following for more details
;; https://emacs.stackexchange.com/a/50215/8887
;; and also see the following on a recent GNU/Linux or similar system:
;; /usr/share/doc/fontconfig/fontconfig-user.html
;; for the explanation of spacing=100
;; also see the following UNIX StackExchange answer:
;; https://unix.stackexchange.com/a/363368/13105
(defun compare-monospace-font-families ()
"Display a list of all monospace font faces. Tested on GNU/Linux."
(interactive)
(pop-to-buffer "*Monospace Fonts*")
(erase-buffer)
(dolist (font-name (seq-filter (lambda (font)
(when-let ((info (font-info font)))
(string-match-p "spacing=100" (aref info 1))))
(font-family-list)))
(insert
(propertize (concat "1 l; 0 O o [ < = > ] " font-name ")\n")
'font-lock-face `((:family
,(format "%s" (font-get (font-spec :name font-name) :family))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment