Clinton Winant
Clinton Winant

Reputation: 734

Setting default emacs font for initial and new frame

This or a similar question has been asked so many times that there exist tens of answers, but seemingly little consensus, so I will risk the wrath of the monitors and ask my own version:

I am using emacs 26.1 on Debian bullseye. I have acquired a 4k monitor, on which the default emacs fonts appear way too large. Reading many of the related answers on this site, I have found that adding the line

(set-face-attribute 'default (selected-frame) :height 60)

to my .emacs file results in a font size of 6 pts in the initial Emacs frame, which is great. The problem arises when I try to open a new frame with C-x 5 2. The new frame opens with a font size of 11. That can be changed through Options ->set default font and reducing from 11 to 6. However it would be much easier if the new frame opened with the correct font size (6).

Any suggestions?

Upvotes: 5

Views: 4424

Answers (2)

Rorschach
Rorschach

Reputation: 32446

In my init, I have the following to hook into after-make-frame-functions where I setup fonts (taken from somewhere online, surely),

(defun my-frame-init ()
  ;; eg.
  (set-face-attribute 'mode-line nil
                      :font "NanumGothicCoding-14"
                      :weight 'normal))

(if (daemonp)
    (add-hook 'after-make-frame-functions
              (lambda (frame)
                (select-frame frame)
                (my-frame-init)))
  (my-frame-init))

Upvotes: 1

Drew
Drew

Reputation: 30708

  1. You can use set-face-attribute for face default, but use nil or t, not (selected-frame) as the value of argument FRAME:

    (set-face-attribute 'default nil :height 60)
    

    C-h f set-face-attribute tells you:

set-face-attribute is a compiled Lisp function in faces.el.

(set-face-attribute FACE FRAME &rest ARGS)

Set attributes of FACE on FRAME from ARGS.

This function overrides the face attributes specified by FACE’s face spec. It is mostly intended for internal use only.

If FRAME is nil, set the attributes for all existing frames, as well as the default for new frames. If FRAME is t, change the default for new frames only.

...

  1. Or you can customize option default-frame-alist, to provide the frame parameter values you want. That affects all new frames (ordinary ones, at least). M-x customize-option default-frame-alist.

    You can set frame parameter font - e.g.:

    "-*-Lucida Console-normal-r-*-*-12-*-*-*-c-*-iso8859-1"
    

Upvotes: 4

Related Questions