4

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?

Drew
  • 29,895
  • 7
  • 74
  • 104
Clinton Winant
  • 704
  • 10
  • 19
  • Possible duplicate of [How do I get my cocoa emacs on Mac OS X to load my .emacs visual customizations for new windows (any document opened after the first)?](https://stackoverflow.com/questions/1909593/how-do-i-get-my-cocoa-emacs-on-mac-os-x-to-load-my-emacs-visual-customizations) – Rorschach Oct 14 '19 at 18:49

2 Answers2

3
  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"
    
Drew
  • 29,895
  • 7
  • 74
  • 104
  • Thanks so much. The first part of your solution, replacing (selected-frame) by nil works like a charm. Emacs wouldn't let me enter 'M-x customize-option default-frame-alist' as a single entry, it insists on a '-' after the word option. I tried entering 'M-x customize-option' followed by 'default-frame-alist', but that only gives a help item. – Clinton Winant Oct 14 '19 at 19:04
  • Yes, I meant `M-x customize-option RET` followed by `default-frame-alist RET`. That should open Customize for that user option. – Drew Oct 14 '19 at 19:17
  • after 'default-frame-list RET' I see an interactive page that has live buttons for 'Search', Revert...', 'Apply', Apply and Save', 'INS' and 'State'. How would I use those to set 'font' to the value you suggested? It may well be that I just don't know eneough to ask a cogent question?? I have accepted your answer, Thanks once more forr the very helpful answers – Clinton Winant Oct 14 '19 at 19:30
  • 1
    Click `INS`, which means "insert". Then you'll see places to enter the name of a frame `Parameter` and its `Value`. Enter `font` for the `Parameter`. Enter a string font name (with the enclosing `"` chars) for the `Value`. Each time you define a parameter to include you get a new `INS` button to let you insert another one. And you get a `DEL` button to delete the one you inserted. – Drew Oct 14 '19 at 22:43
  • 1
    You should see this at the top of the Customize buffer: **For help using this buffer, see [Easy Customization](https://www.gnu.org/software/emacs/manual/html_node/emacs/Easy-Customization.html) in the Emacs manual.** Follow that link to "Ask Emacs" - even better than asking here. ;-) – Drew Oct 14 '19 at 22:47
0

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))
Rorschach
  • 31,301
  • 5
  • 78
  • 129
  • I have added the code you supplied verbatim to my .emacs file and restarted. Sadly `C-x 5 2` still starts a large frame with a large font. Not sure what you mean by 'taken from somewhere on line, surely' Could you supply example? – Clinton Winant Oct 14 '19 at 18:50
  • added an example line from my frame config -- by "taken from online" I just meant I'm sure I got this solution online somewher – Rorschach Oct 14 '19 at 18:54