Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increase/decrease font size in an emacs frame (not just buffer)

Tags:

emacs

Using C-x C-+ and C-x C-- (text-scale-adjust) is very convenient to increase/decrease the font size in one buffer. This is nice to reduce head bumping when a few people work together in front of the same monitor.

Is there a way to increase (and later decrease) the font size in one frame (or all frames simultaneously)? I am wondering if there is a way faster than 1- retyping C-x C-+ in each new buffer, 2- Calling M-x x-select-font and using the mouse to choose, and 3- running elisp code in the scratch buffer.

Update:

If you are interested in satisfying not just 1-3 above but also:

4- Keep the size (and position) of the frame still.

Then look at this question.

like image 985
Calaf Avatar asked Jul 11 '14 20:07

Calaf


People also ask

How do I increase font size in idle?

On the top menu, choose Options , then Configure IDLE . The Fonts/Tabs tab will be displayed. There is a Size button. Click on it and select a bigger size than the default of 10.

How do I change font size in Spacemacs?

Another way is to use the key sequence "SPC z x" and then press "+/=" key to increase font size or "-" key to decrease font size. Other options are shown on the which-key menu.


2 Answers

See the Emacs Wiki page about frame zooming.

It tells you about several ways to do this, including commands from libraries zoom-frm.el, doremi-frm.el, and frame-cmds.el.

In particular, the single command zoom-in/out lets you zoom either a frame or a buffer in or out. (The former: zooming a frame, is what you requested.)

like image 82
Drew Avatar answered Sep 22 '22 20:09

Drew


Based on @Jordon Biondo's answer, this is an alternative solution that solves the collateral effect of changing the frame's size by using set-frame-font with the argument KEEP-SIZE equals to t.

;; Resize the whole frame, and not only a window
;; Adapted from https://stackoverflow.com/a/24714383/5103881
(defun acg/zoom-frame (&optional amt frame)
  "Increaze FRAME font size by amount AMT. Defaults to selected
frame if FRAME is nil, and to 1 if AMT is nil."
  (interactive "p")
  (let* ((frame (or frame (selected-frame)))
         (font (face-attribute 'default :font frame))
         (size (font-get font :size))
         (amt (or amt 1))
         (new-size (+ size amt)))
    (set-frame-font (font-spec :size new-size) t `(,frame))
    (message "Frame's font new size: %d" new-size)))

(defun acg/zoom-frame-out (&optional amt frame)
  "Call `acg/zoom-frame' with negative argument."
  (interactive "p")
  (acg/zoom-frame (- (or amt 1)) frame))

(global-set-key (kbd "C-x C-=") 'acg/zoom-frame)
(global-set-key (kbd "C-x C--") 'acg/zoom-frame-out)
(global-set-key (kbd "<C-down-mouse-4>") 'acg/zoom-frame)
(global-set-key (kbd "<C-down-mouse-5>") 'acg/zoom-frame-out)
like image 34
Arthur Colombini Gusmão Avatar answered Sep 21 '22 20:09

Arthur Colombini Gusmão