Skip to content

Instantly share code, notes, and snippets.

@equwal
Last active September 21, 2020 21:07
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save equwal/89b1ef5ac8d4d737cfd37f66e9ba4895 to your computer and use it in GitHub Desktop.
Save equwal/89b1ef5ac8d4d737cfd37f66e9ba4895 to your computer and use it in GitHub Desktop.
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: https://github.com/alphapapa/unpackaged.el#font-compare
;;; 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: https://github.com/equwal/alt-hack0
;;; If you don't have the fonts, you can try:
;;; - Your package manager
;;; - nerd fonts https://github.com/ryanoasis/nerd-fonts/releases/
;;; - 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: https://github.com/equwal/alt-hack0
;;; 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.
;;; SPECIMEN:
;;; 10Oo$.,'"`()[]/{}@%&
;;; When decided, make a set-face-attribute like the at the top of the page.
(comment
(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:
(comment
;; 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:
;;; http://hivelogic.com/articles/top-10-programming-fonts/ Inconsolata is nice,
;;; but angled quotes are no-go. The author wrote an "experimental" InconsolataGo
;;; font, with straight quotes:
;;; https://www.levien.com/type/myfonts/inconsolata.html
;;; 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))
t))
(defun pprintfonts (fonts)
(dolist (f fonts)
(message "%s" f))
fonts)
(defun search-fonts (font)
(interactive "sFonty Name: ")
(pprintfonts
(remove-if #'null
(cl-loop for f in (font-family-list)
collect (when (search font f)
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)
font-matches)))
;;; 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