Apparently the correct way to set the default font is the following:

 '(default ((t (:family "Raize" :foundry "raster" :slant normal
                :weight normal :height 120 :width normal)))))

But it's not portable, that means I cannot copy and paste on a different init.el on another computer if I don't check the existence of the correct font before.

A solution is to use a conditional. I already modified my emacs configuration to be environment sensitive, but I cannot solve this issue, I mean I did not manage how to correctly extract the statement from the (custom-set-faces ...) block to use within a (setq ...), for instance. Or, as alternative, I wonder if I can use an if() in this case.

Any clue?

2 Answers 2


Are you expecting to also use the Customize interface (UI)? If so then any top-level use of custom-set-faces in your init file (or custom-file) will be overwritten by Customize.

If you just want some code to do what you describe then something like this should do it:

    (custom-set-faces '(default ((t (:family "Raize" :foundry "raster" :slant normal
                                :weight normal :height 120 :width normal)))))
  (custom-set-faces '(default ((t YYYYYYYYYYYYYYYY)))))

But don't factor out the custom-set-faces and place it at top level in your init file, if you also use the Customize UI.

  • Well, using a form like if () custom-set () then custom-set () brings to a huge code duplication, doesn't it?
    – Daniele
    Commented Oct 4, 2017 at 16:03
  • You can factor out any parts that are duplicated, if you want. (You don't show the two face definitions...) Just don't put custom-set-faces at the top level in your init file, if you also use the Customize UI.
    – Drew
    Commented Oct 4, 2017 at 18:16

Thank you, at the end I preferred this solution:

(when (member "Raize" (font-family-list))
  (add-to-list 'initial-frame-alist '(font . "Raize"))
  (add-to-list 'default-frame-alist '(font . "Raize")))

in a secondary file. It's more compatible with my legacy configuration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.