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: |