Emacs font sizing with Ctrl key and mouse scroll

2019-02-08 12:31发布

问题:

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?

回答1:

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


回答2:

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)


回答3:

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



回答4:

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


回答5:

Zoom Frame is what you want. I do exactly what you describe all the time. After loading zoom-frm.el, add some bindings such as these:

    (global-set-key [S-mouse-1]   'zoom-in)
    (global-set-key [C-S-mouse-1] 'zoom-out)
    (global-set-key (vector (list 'control mouse-wheel-down-event)) 'zoom-in)
    (global-set-key (vector (list 'control mouse-wheel-up-event))   'zoom-out)

See also: http://www.emacswiki.org/emacs/SetFonts#ChangingFontSize