views:

402

answers:

4

notepad++ allow me to increase the font size when I hold the Ctrl Key and rotate the mouse middle scroll button to forward.

In the same way, the when I hold Ctrl and rotate the mouse middle scroll button backward, the fond size reduces.

How can I get the same with Emacs?

+2  A: 

Theoretically I can give you the answer to this, but someone more skilled than me is going to have to write the lisp I'm just a little to busy atm to figure it out for myself.

If nobody responds by tomorrow I'll hit the books and figure it out.

What needs to be done: Write a function (font-big) which does this:

  1. font-default-size = font-default-size+1`

  2. Then re-evaluate all open buffers.

Then Bind the function to a key (define-key map [C-wheel-up] 'font-big)

Then do the same for (font-small).

I hope I get at least partial credits for the idea :)

AlexCombas
thanks for idea :-). looking for lisp expert to write a function
Gopalakrishnan Subramani
+3  A: 

with emacs23 you can add following lines to your .emacs.el:

(global-set-key (kbd "<C-mouse-4>") 'text-scale-decrease)
(global-set-key (kbd "<C-mouse-5>") 'text-scale-increase)
Alexey Voinov
I use emacs 23.1.5 on windows. but I could not make it working
Gopalakrishnan Subramani
Does font scaling work if you press C-x C-= or C-x C--?
Alexey Voinov
+1 Not sure what the mouse-4 and mouse-5 are, but this works perfectly for me, so thanks! (global-set-key (kbd "<C-wheel-down>") 'text-scale-decrease)(global-set-key (kbd "<C-wheel-up>") 'text-scale-increase)
harpo
+1  A: 

code for AlexCombas' answer:

(defun font-big ()
 (interactive)
 (set-face-attribute 'default nil :height 
  (+ (face-attribute 'default :height) 10)))

(defun font-small ()
 (interactive)
 (set-face-attribute 'default nil :height 
  (- (face-attribute 'default :height) 10)))

(global-set-key (kbd "<C-wheel-down>") 'font-small)
(global-set-key (kbd "<C-wheel-up>") 'font-big)

Edit: for a min and a max use

(defun font-big ()
 (interactive)
 (set-face-attribute 'default nil :height 
  (min 720
   (+ (face-attribute 'default :height) 10))))

(defun font-small ()
 (interactive)
 (set-face-attribute 'default nil :height 
  (max 80
   (- (face-attribute 'default :height) 10))))
cobbal
this works. anyway where I can limit the font size to 72 maximum and 8 minimum?
Gopalakrishnan Subramani
+1  A: 

Try this:

(global-set-key (kbd "<C-mouse-4>") (lambda () (interactive) (text-scale-decrease 1)))
(global-set-key (kbd "<C-mouse-5>") (lambda () (interactive) (text-scale-increase 1)))
Nathan