This is what Jayesh Bhoot looks like, with a lopsided smile on its right, which almost closes his right eye while smiling, which strongly implies that he needs to work on his lazy left-side cheek muscles.

How I configured OS-specific fonts in Emacs

Posted on

Collected in

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:

  1. system-type variable in Elisp identifies the operating system.
  2. 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), where font-value is evaluated to the font value it got in its let binding, before the parent expression is quoted.
  3. 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!

Post author's photo Written by Jayesh Bhoot

Comments