2009-03-13 Zoom

Here’s what I use to “zoom” text in an Emacs window:

(global-set-key (kbd "M-+") 'text-scale-adjust)
(global-set-key (kbd "M--") 'text-scale-adjust)
(global-set-key (kbd "M-0") 'text-scale-adjust)

Apparently this is part of Emacs 23.

​#Emacs

Comments

(Please contact me if you want to remove your comment.)

The blog entry started out by asking for an Emacs zoom library. I decided to replace what I had with one of the answers from the comments below. For reference, my original quick and dirty solution has been copied here:

;; zoom
(defconst default-font-size (face-attribute 'default :height) "Default font size.")
(defconst current-font-size (face-attribute 'default :height) "Current font size.")

(global-set-key (kbd "M-+")
		(lambda ()
		  (interactive)
		  (setq current-font-size (truncate (* 1.2 current-font-size)))
		  (set-face-attribute 'default nil :height current-font-size)))

(global-set-key (kbd "M--")
		(lambda ()
		  (interactive)
		  (setq current-font-size (truncate (* 0.8 current-font-size)))
		  (set-face-attribute 'default nil :height current-font-size)))

(global-set-key (kbd "M-0")
		(lambda ()
		  (interactive)
		  (setq current-font-size default-font-size)
		  (set-face-attribute 'default nil :height current-font-size)))

I found that using (set-face-attribute ’default nil :height 1.1) resultet in an error on my Emacs from CVS. I’m building a new one as I type to try and verify this still bombs. Unfortunately Emacs will reduce the frame size as the frame starts to exceed your screen size, and forget about the old value, so that the frame will end up much smaller if you do a sequence of zoom ins followed by a sequence of zoom outs.

– Alex

---

M-x text-scale-increase, and text-scale-decrease. These are the functions called from the appearance menu (Shift+left click).

– Damien Cassou 2009-03-13 11:49 UTC

Damien Cassou

---

Hehe that’s what I get for disabling the menus! Thanks.

– Alex Schroeder 2009-03-13 12:00 UTC

Alex Schroeder

---

C-x C-+, C-x C– and C-x C-0 would be default bindings in 23 for increase, decrease, default (all bound to `text-scale-adjust’)

– Anonymous 2009-03-13 14:02 UTC

---

This is awesome. Thanks!

– Alex Schroeder 2009-03-13 14:09 UTC

Alex Schroeder

---

How handy!

I almost always only use the click-menus by accident, so didn’t recall any such thing. Much prefer your bindings, Alex.

– OtherMichael 2009-03-13 20:39 UTC

OtherMichael