Quick Emacs Tip: Scale fonts in a buffer

Aug 12, 2009

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.

Posted by | Categories: programming | Tagged: |

2 Responses so far | Have Your Say!

  1. Anonymous
    December 3rd, 2009 at 10:17 pm #

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

    Thanks for including my article in the list, Ali! :D 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! ;)

  2. Anonymous
    December 24th, 2009 at 2:50 am #

    congrats!

Leave a Feedback

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>