I use Emacs mostly to write R using ESS. I like a large font to reduce eye strain so the last line of my .emacs file is:

(set-default-font "Inconsolata-20")

If I open a file of R code, this appears as one would expect. However, additional frames opened with C-x 5 2 have a tiny font. Typically this happens when I eval the buffer and want to look at the resulting ESS/R session in a separate frame.

I assume there is something overiding the default font, but cannot find what it might be. Strangely, sometimes the default font is respected, but I cannot reproduce.

How can I force all new frames to honor the default font?

Tiny text in ESS window

up vote 5 down vote accepted

set-default-font by default sets the font for current frame only from the documentation C-hfset-default-fontRET (emphasis mine)

(set-default-font FONT &optional KEEP-SIZE FRAMES)

This function is obsolete since 23.1; use `set-frame-font' instead.

Set the default font to FONT. When called interactively, prompt for the name of a font, and use that font on the selected frame. When called from Lisp, FONT should be a font name (a string), a font object, font entity, or font spec.

If KEEP-SIZE is nil, keep the number of frame lines and columns fixed. If KEEP-SIZE is non-nil (or with a prefix argument), try to keep the current frame size fixed (in pixels) by adjusting the number of lines and columns.

If FRAMES is nil, apply the font to the selected frame only. If FRAMES is non-nil, it should be a list of frames to act upon, or t meaning all existing graphical frames. Also, if FRAMES is non-nil, alter the user's Customization settings as though the font-related attributes of the `default' face had been "set in this session", so that the font is applied to future frames.

So the solution is to do

(set-default-font "Inconsolata-20" nil t)

Also please note that this function is obsolete since emacs 23.1. Use set-frame-font instead, the API is same

Additional methods for setting font

For sake of completeness I am mentioning additional methods for setting default font

Customizing default-frame-alist, mentioned by @Drew

(add-to-list 'default-frame-alist '(font . "Inconsolata-20"))

Customizing the default face, mentioned by @wasamasa, by doing something like the following

(set-face-font 'default "Inconsolata-20")

Alternately you can use the customize interface, mentioned by @VitoshKa, M-xcustomize-faceRETdefaultRET.

  • 1
    There is no need to do this change to Customize at every start. It's better to customize the default face instead to have the desired font family. – wasamasa Sep 4 '15 at 10:38
  • Thank you for the comment. Can you expand on this please? – SlowLearner Sep 4 '15 at 11:23
  • @SlowLearner, I guess @wasamasa meant M-x customize-face RET default RET – VitoshKa Sep 4 '15 at 14:41
  • Or customize default-frame-alist to use the font parameter value you want. – Drew Sep 4 '15 at 14:49
  • @wasamasa I am not sure I understand why it is better to customize the default face. My understanding is that both methods are equivalent since set-frame-default internally customizes the default face. Anyways I have updated the answer to mention alternative ways to set the font – Iqbal Ansari Sep 4 '15 at 16:25

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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