17

I find myself consistently zooming out (C-x C--) in every buffer that I am using in order to see more lines of code that I'm working on.

Is there a way to set the zoom level in my .emacs, not interactively? Or should I look into setting the fontsize? I've been using the zoom, because it's been the easiest/quickest solution, but I'd rather find a more permanent solution. Are there disadvantages or advantages to using one versus the other? I am unclear on the differences.

10
  • 1
    How about?: (face-remap-add-relative 'default '((:height 300))) to blow it up; and (face-remap-add-relative 'default '((:height 120))) to shrink it? You can change the height to your liking. You can turn those into interactive functions and map them to your favorite keyboard shortcuts. To try them out, paste them into your *Scratch* buffer and place the cursor at the end of a code snippet and type C-x C-e
    – lawlist
    Commented Mar 31, 2015 at 23:45
  • 3
    If you're zooming out in virtually every buffer you use, why not just set the font size to be smaller? See this S.O. thread on exactly that issue.
    – Dan
    Commented Apr 1, 2015 at 0:26
  • @Dan: If the question is not about zooming, but is, in fact, about how to set the default font size, then it should perhaps be closed as a duplicate of the question you cite. It sounds like the OP is maybe unsure what s?he wants in this regard: set the font size or zoom.
    – Drew
    Commented Apr 1, 2015 at 2:05
  • @Drew: agreed. OP: are you looking to set the font size or zoom?
    – Dan
    Commented Apr 1, 2015 at 3:07
  • 1
    My answer would be: In that case, see the Emacs Wiki page I cited in my answer. It covers everything about setting fonts and font sizes, both interactively (e.g. zooming) and in init files (setting defaults). It is the place to start (and probably the place to end).
    – Drew
    Commented Apr 1, 2015 at 15:28

4 Answers 4

12

Yes. What you want is to zoom (the font size for) a frame, regardless of which buffers are displayed there.

See library zoom-frm.el, and these descriptions of zooming a frame and zooming a buffer.

See, in particular, command zoom-in/out, which does both. It is bound by default to the keys normally bound to just buffer zooming: C-x C-+, C-x C--, C-x C-0, and C-x C-=. You can also bind commands zoom-in and zoom-out to mouse-wheel rotations. Using C-u with any of these commands toggles between frame zooming and buffer zooming.

Besides interactively zooming frames or buffers, you can of course set the default font size you want for all frames.

The same Emacs-Wiki page has more info about setting fonts and font sizes.


Update after you decided that you want to set the default font size

The answer is in the last line I wrote above: See section Globally Change the Default Font on the Emacs Wiki Set Fonts page. It tells you how to set the default font. (It also tells you how to zoom font sizes interactively.)

Here is that information in a nutshell - put this in your init file:

(add-to-list 'default-frame-alist '(font . FONT ))
(set-face-attribute 'default t :font FONT )

But do read the entire section of that page, as it tells you more, including how to set the default font using .Xresources and the Emacs daemon. An example of a line suitable for ~/.Xresources for setting the default font size is:

Emacs.default.attributeHeight: 94
2
  • I read in the documentation that the zoom-frm.el had the ability to save the customizations, although it seems a bit confusing. (I haven't done much with the customize interface, preferring to set things in the init file, instead) I will give it a try.
    – aepound
    Commented Apr 1, 2015 at 14:12
  • Yes, the commentary of file zoom-frm.el tells you how to save font-change customizations, including how to do so without using the Customize UI. FWIW, I recommend that people do use Customize, but that use a separate custom-file (see that variable) instead of letting Customize write code to their init file.
    – Drew
    Commented Apr 1, 2015 at 15:39
16

If you want to use a GUI font picker with previews and all, you may use M-x menu-set-font

Emacs pick a font

3
  • 1
    Thanks, this should be the only recommended answer, here, on the wiki page, on the Aquamacs home page!
    – agam
    Commented Feb 28, 2018 at 18:00
  • 4
    How do you make this permanent?
    – smonff
    Commented Jun 21, 2019 at 7:51
  • 1
    @smonff (set-frame-font "Monospace 18") does the trick. If you look up the help for menu-set-font via C-h f you can step through the function and see this is what it ultimately calls
    – Will Ayd
    Commented Feb 1, 2023 at 18:45
5

I'm using this for zooming Emacs-wide (not just the current buffer):

;; http://blog.vivekhaldar.com/post/4809065853/dotemacs-extract-interactively-change-font-size
(defun my/zoom-in ()
  "Increase font size by 10 points"
  (interactive)
  (set-face-attribute 'default nil
                      :height
                      (+ (face-attribute 'default :height)
                         10)))

(defun my/zoom-out ()
  "Decrease font size by 10 points"
  (interactive)
  (set-face-attribute 'default nil
                      :height
                      (- (face-attribute 'default :height)
                         10)))

;; change font size, interactively
(global-set-key (kbd "C->") 'my/zoom-in)
(global-set-key (kbd "C-<") 'my/zoom-out)
0

Here's a suggestion that doesn't try to answer your question but does try to solve your problem: consider adding a second display in portrait orientation (as opposed to the normal landscape orientation). I find it essential for precisely the reason you keep zooming out: being able to see enough lines of code to get the full context of what I'm looking at and working on.

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.