2

I'd like to enable changing the font size by holding down the right mouse button and using the scroll-wheel. Emacs does however treat mouse buttons as keys, so this obviously cannot be achieved directly by a straight-forward (define-key ... (kbd ...) ...) binding.

Since I also don't want to disable the standard actions performed by "click and release" of the right mouse button, I can't just bind something to <up/down-mouse-3>. Instead, I'd like to bind a command to the scroll events <mouse-4> and <mouse-5>, that detects, whether the right mouse button is being held.

Is this possible?

Related questions point to the variable track-mouse, but it doesn't seem, like that method can distinguish different mouse buttons.

1
  • You might be able to use something like the answers to this question to detect if the last pressed key was <down-mouse>, then set a variable that you can check. Something based on key-chord.el might also be useful, but that would probably require more work to figure out. An easier solution, might be to add something to the right-click context menu (like a minor mode that binds scrolling to resize).
    – jirassimok
    Apr 8, 2020 at 22:30

2 Answers 2

1

Library zoom-frm.el lets you do either of these things using the mouse wheel:

  • Zoom the buffer text size, for all windows showing a given buffer. This is called text-scaling.
  • Zoom the frame text size, for a given frame or for all frames.

It, in turn, requires these libraries:

See also Changing Font Size.

These are bindings recommended in zoom-frm.el for the mouse wheel:

(global-set-key (vector (list 'control mouse-wheel-down-event))
                'zoom-in)
(global-set-key (vector (list 'control 'meta mouse-wheel-down-event))
                'zoom-all-frames-in)
(global-set-key (vector (list 'control  mouse-wheel-up-event))
                'zoom-out)
(global-set-key (vector (list 'control 'meta mouse-wheel-up-event))
                'zoom-all-frames-out)

Perhaps you can provide similar bindings for simultaneous use of the wheel and holding mouse-3 (right button) pressed. I don't know, and I'm not really motivated to find out. Perhaps someone else here will help with that.


For buffer (not frame) zooming, you might also want to use library face-remap+.el. It lets buffer resizing also zoom the window size accordingly (horizontally, vertically, or both). That way, you can take advantage of the space freed up by resizing (text-scaling) to a smaller font.

1
  • Binding the mouse-wheel is really white easy; I have my own setup for that. The problem is mostly avoiding the use of they keyboard while scrolling through other peoples source code.
    – kdb
    Apr 8, 2020 at 20:12
1

mapping behavior similar to browser might be helpful,

  • zoom in : Ctrl + mouse-scroll-up and Ctrl + Shift + =
  • zoom out : Ctrl + mouse-scroll-down and Ctrl + -
  • zoom 1x : Ctrl + 0

these config are for the single buffer

(global-set-key [C-mouse-4] 'text-scale-increase)
(global-set-key [(control ?+)] 'text-scale-increase)
(global-set-key [C-mouse-5] 'text-scale-decrease)
(global-set-key [(control ?-)] 'text-scale-decrease)
(global-set-key (kbd "C-0") '(lambda () (interactive)
                               (text-scale-adjust
                                (- text-scale-mode-amount))
                               (text-scale-mode -1)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.