public
Last active

List monospace fonts in Emacs

  • Download Gist
gistfile1.el
Emacs Lisp
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
;; Display all the monospace fonts available to Emacs in a dedicated buffer
 
(defun font-is-mono-p (font-family)
;; with-selected-window
(let ((wind (selected-window))
m-width l-width)
(with-current-buffer "asdf"
(set-window-buffer (selected-window) (current-buffer))
(text-scale-set 4)
(insert (propertize "l l l l l" 'face `((:family ,font-family))))
(goto-char (line-end-position))
(setq l-width (car (posn-x-y (posn-at-point))))
(newline)
(forward-line)
(insert (propertize "m m m m m" 'face `((:family ,font-family) italic)))
(goto-char (line-end-position))
(setq m-width (car (posn-x-y (posn-at-point))))
(eq l-width m-width))))
 
(defun compare-monospace-fonts ()
"Display a list of all monospace font faces."
(interactive)
(pop-to-buffer "*Monospace Fonts*")
 
(erase-buffer)
(dolist (font-family (font-family-list))
(when (font-is-mono-p font-family)
(let ((str font-family))
(newline)
(insert
(propertize (concat "The quick brown fox jumps over the lazy dog 1 l; 0 O o ("
font-family ")\n") 'face `((:family ,font-family)))
(propertize (concat "The quick brown fox jumps over the lazy dog 1 l; 0 O o ("
font-family ")\n") 'face `((:family ,font-family) italic)))))))

s/with-current-buffer "asdf"/with-current-buffer "Monospace Fonts"

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.