0

In my .emacs file I have the following:

(setq default_font "Office Code Pro D")
(when (member default_font (font-family-list))
  (set-face-attribute 'default nil
                      :family default_font
                      :font default_font))

After startup, if I evaluation the (when... function, my font family is set properly, but it is not set correctly when this file is sourced on startup.

After startup, if I check the value of default_font it is (correctly) Office Code Pro D, however, it does not set the font for my Emacs session unless I evaluate that part specifically.

Is there a reason why this does not get set in startup?

(Typically I run Emacs daemon on boot and this does not work).

2

With a quick check with Emacs 24.4 when you have just an Emacs daemon running font-family-list is nil so your code does nothing at that point. You'd need to add your function to a hook that runs after you have a GUI window, for example after-make-frame-hook.

Alternatively, why not set the default font using Customize? There's a Set Default Font in the options menu by default which (after Save options, also in the options menu) sets the default font in your init file using custom-set-faces.

| improve this answer | |
  • Great find. I do not like to set the font using Customize on principle. I like to know where I am setting my own variables. Additionally, the font I am using is custom so it may not be installed on all systems, idk if Custom allows a hook to check for that. – Startec May 30 '18 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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