Skip to content

Instantly share code, notes, and snippets.

@equwal equwal/fonts.el
Last active Feb 19, 2020

What would you like to do?
Selecting and trying out different fonts in Emacs.
;;; TL;DR
(set-face-attribute 'default nil :family "Hack");Must be the FULL name (search-fonts "Hack") for it.
(set-face-attribute 'default nil :height (* 13 10));13pt
;;; Also see:
;;; to easily compare lots of fonts.
;;; The purpose of this Gist is to help you select a font you like by trying it out in Emacs.
;;; Here is my custom Hack font:
;;; If you don't have the fonts, you can try:
;;; - Your package manager
;;; - nerd fonts
;;; - note that "installing" a font often just means putting fonts files in
;;; the right place on the disk. For Gentoo ~/.local/share/fonts
;;; How to select a (programming) font:
;;; - "Hints" on the characters: 1 is not l, 0 is not O, etc.
;;; - Monospaced fonts only!
;;; - Modern enough to be used at large sizes without anti-aliasing. (try 14pt).
;;; - No weird oddities like angled quotes or weird 0 indicators. "
;;; - Good punctuation choices: !@#$%^&*[]();:'"/?.,<>`+_-
;;; - here is my custom Hack font:
;;; To use this comment block, try each font by evaluating the
;;; experssion with C-x C-e, then look at the specimen. Also try executing
;;; search-fonts to see if you installed it correctly at all.
;;; 10Oo$.,'"`()[]/{}@%&
;;; When decided, make a set-face-attribute like the at the top of the page.
(search-fonts "Hack") ;Look at your *Messages*
(set-if-found 13 "Hack"))
;;; To have a list of fonts where the first one is chosen that is found:
;; These are specially designed for programming.
(set-if-found 14 "Inconsolata") ;Good.
(set-if-found 14 "InconsolataGo") ;Straight quotes. "
(set-if-found 13 "Hack NF") ; Nerd Fonts is a good source.
(set-if-found 13 "Hack Nerd Font Mono") ; Curvy ells and programmer hints.
;; These two have ligatures, which I don't know if I like. Seems distracting.
;; Also, it is a pain to setup ligatures in Emacs.
(set-if-found 14 "Iosevka")
(set-if-found 14 "Fura")
(set-if-found 14 "FuraCode") ;; Ligatures (break emacs with it).
(set-if-found 14 "FuraMono Nerd Font Mono") ;; Ligature free.
;; All these borrow from the vanilla DejaVu to an extent.
(set-if-found 14 "DejaVu Nerd Font Mono") ;Good.
;; Ligatures for programming things are nice to look at, but I think it incurs a
;; mental overhead penalty when they confuse things. Also, emacs does not
;; support them well.
;; ONLY use monospaced fonts for programming!
(set-if-found 'dont "Serif") ;Bad.
(set-if-found 'no "ComicSans")) ;No.
;;; other font suggestions:
;;; Inconsolata is nice,
;;; but angled quotes are no-go. The author wrote an "experimental" InconsolataGo
;;; font, with straight quotes:
;;; and it is contained on
(defmacro comment (&rest no-eval) nil)
(defun set-font (font &optional points)
(when (member font (font-family-list))
(set-face-attribute 'default nil :family font)
(set-face-attribute 'default nil :height (* points 10))
(defun pprintfonts (fonts)
(dolist (f fonts)
(message "%s" f))
(defun search-fonts (font)
(interactive "sFonty Name: ")
(remove-if #'null
(cl-loop for f in (font-family-list)
collect (when (search font f)
(defun set-if-found (points font)
"Set the font. Use a C-u prefix arg for the point size."
(interactive "P\\nsFonty Name: ")
(let ((font-matches (search-fonts font)))
(and font-matches
(set-font (car font-matches) points)
;;; Special thanks to <dale> and <wasamasa> for their feedback on the Freenode #emacs channel.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.