How I configured OS-specific fonts in Emacs
Collected in emacs
Here is the Elisp snippet:
(let ((font-value (cond
((eq system-type 'gnu/linux)
"Source Code Pro-12:weight=medium")
((eq system-type 'darwin)
"Source Code Pro-17:weight=medium"))))
(add-to-list 'default-frame-alist `(font . ,font-value)))
Things I learned while creating this snippet:
-
system-type
variable in Elisp identifies the operating system. -
A quote
'
does not evaluate the entire quoted expression, but a backquote`
allows evaluation of sub-expressions marked with a comma,
, inside the quoted expression. Hence,`(font . ,font-value)
, wherefont-value
is evaluated to the font value it got in its let binding, before the parent expression is quoted. -
The syntax to configure font properties. When I last tried Emacs more than 5 years ago (or more), I was stumped by a plethora of solutions on the internet to specify font properties, none of which had worked. Part of why I had abandoned Emacs back then. This time, I was able to figure it out, thanks to the official doc that describes the syntax to specify a font.
I am sure there is a better way, but I have only recently started tinkering with Emacs and ELisp. I mean I still nest a sexp by manually adding parentheses before and after the sexp, like a caveman!
Written by Jayesh Bhoot