Quick Emacs Tip: Scale fonts in a buffer

Emacs23 includes default keybindings for scaling fonts up or down:

C-x C-+ — scale the current buffer’s face/font up C-x C-+ — scale the current buffer’s face/font down

This is good as far as it goes, but I’d really like something a little easier. So I’ve added the following to my .emacs file:

(global-set-key [(control mouse-4)] (lambda () (interactive)                                        (text-scale-increase 1)))  (global-set-key [(control mouse-5)] (lambda () (interactive)                                        (text-scale-decrease 1)))

Now, if I hold down the control key and scroll the mouse wheel, the font will get larger or smaller. Some other applications (e.g. Firefox) use “Control +” and “Control -” to do something similar along with “Control 0” to return to the default size. You could set these keybindings in Emacs without losing too much (unless you’re used to C-- and C-0 as prefixes, in which case, you still have C-M-- and C-M-0):

(global-set-key [(control ?+)] (lambda () (interactive)                                        (text-scale-increase 1)))  (global-set-key [(control ?-)] (lambda () (interactive)                                        (text-scale-decrease 1)))  (global-set-key [(control ?0)] (lambda () (interactive)                                        (text-scale-increase 0)))

None of this will permanently affect the size of the font, so for the next buffer you open or the next time you start Emacs, you’ll have the same size font you started with. If you want to change the default font size, use M-x customize-face RET default RET instead.

2 thoughts on “Quick Emacs Tip: Scale fonts in a buffer”

  1. Сауна в Мурманске

    Thanks for including my article in the list, Ali! 😀 Like you say, hopefully it’ll be useful to people thinking about purcashing Thesis; make sure you keep checking back for future posts! Also, the Blogussion post is awesome! Seriously, that site seems to get better and better every time I visit! 😉

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.