Emacs font sizing with Ctrl key and mouse scroll

前端 未结 5 1767
庸人自扰
庸人自扰 2020-12-31 06:17

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 ho

相关标签:
5条回答
  • 2020-12-31 06:40

    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))))
    
    0 讨论(0)
  • 2020-12-31 06:42

    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

    0 讨论(0)
  • 2020-12-31 06:50

    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)
    
    0 讨论(0)
  • 2020-12-31 06:53

    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)))
    
    0 讨论(0)
  • 2020-12-31 07:02

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

    0 讨论(0)
提交回复
热议问题