0

I'm trying to set the default font for my Emacs based on a variable (so I can use a different font on a different machine):

(setq fontspec (concat ck-font-name "-" (number-to-string ck-font-size)))
(set-default-font fontspec)
(set-fontset-font "fontset-default" nil
                  (font-spec :size ck-font-size :name ck-font-name))
(add-to-list 'default-frame-alist '(font . fontspec))

This basically works but the last line throws a warning:

frame-notice-user-settings: Invalid font: fontspec

I know what the problem is (fontspec seems to not be defined when the list gets evaluated), but I don't know how to fix this; my elisp-fu is not good enough.

Can somebody explain me or give me a pointer where I can read how to fix this?

Drew
  • 75,699
  • 9
  • 109
  • 225
ckruse
  • 457
  • 3
  • 12
  • 2
    Possible duplicate of [How to evaluate the variables before adding them to a list?](https://emacs.stackexchange.com/questions/7481/how-to-evaluate-the-variables-before-adding-them-to-a-list) – Drew Mar 16 '18 at 17:45

1 Answers1

2

Ok, I just found out about backquoting:

(add-to-list 'default-frame-alist `(font . ,fontspec))

This quotes the (font . part and evaluates the fontspec. Nice!

ckruse
  • 457
  • 3
  • 12