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.

Drew
  • 75,699
  • 9
  • 109
  • 225
aepound
  • 273
  • 1
  • 2
  • 8
  • 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 Mar 31 '15 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](http://stackoverflow.com/questions/294664/how-to-set-the-font-size-in-emacs). – Dan Apr 01 '15 at 00: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 Apr 01 '15 at 02:05
  • @Drew: agreed. OP: are you looking to set the font size or zoom? – Dan Apr 01 '15 at 03:07
  • possible duplicate of [Transiently adjust text size in mode line and minibuffer?](http://emacs.stackexchange.com/questions/7583/transiently-adjust-text-size-in-mode-line-and-minibuffer) – Kaushal Modi Apr 01 '15 at 03:31
  • @Dan, I'm more asking which is the better way go? At the moment I use the zooming functionality but am tiring of doing it so much. Are there advantages/disadvantages to either? – aepound Apr 01 '15 at 13:40
  • @kaushalmodi, The point is to _not_ do it interactively or transiently. – aepound Apr 01 '15 at 14:09
  • @aepound In that case, as Drew mentioned, you can set the default font size. In [my solution](http://emacs.stackexchange.com/a/7584/115) to the referenced emacs.SE question in my above comment, I keep both options available: set the default font size and be able to **globally** vary the font size. – Kaushal Modi Apr 01 '15 at 14:21
  • 1
    My answer would be: In that case, see the [**Emacs Wiki page**](http://www.emacswiki.org/emacs/SetFonts) 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 Apr 01 '15 at 15:28
  • My non-answer would be: try using a nice big external display in portrait mode. I wouldn't use anything else for coding. – Phil Hudson Nov 25 '18 at 15:37

4 Answers4

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

xandfury
  • 645
  • 7
  • 15
  • 1
    Thanks, this should be _the_ only recommended answer, here, on the wiki page, on the Aquamacs home page! – agam Feb 28 '18 at 18:00
  • 4
    How do you make this permanent? – smonff Jun 21 '19 at 07: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 Feb 01 '23 at 18:45
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
Drew
  • 75,699
  • 9
  • 109
  • 225
  • 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 Apr 01 '15 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 Apr 01 '15 at 15:39
4

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.

Phil Hudson
  • 1,651
  • 10
  • 13