Apply Font in emacsclient

emacs   elisp   index

I set the default font in my Emacs config as follows:

(set-frame-font "Source Code Pro 11" nil t)

However it was not applied when Emacs was ran in client-server mode. Emacsclient behaved weird with tiny text.

To apply in emacsclient as well, it seems another change needs to be done as well.

(add-to-list 'default-frame-alist '(font . "Source Code Pro 11"))

As the font has to be set twice, I wanted to set a variable, which led to an interesting dive into Emacs Lisp.

(defvar my-font)
(setq my-font "Source Code Pro 11")

(set-frame-font my-font nil t)
(add-to-list 'default-frame-alist `(font . ,my-font))

The “backquote” concept took a while to discover. Initially, used the more general form (cons 'font my-font) until I discovered this shortcut.

So, in this particular case, we do not want to evaluate font, but we do want my-font, thus we cannot put a quote for the whole cons. What the backquote allows, is to evaluate any symbol that has a comma in front.