My mouse has a horizontal scroll function, where I can tap the scroll wheel left and right to scroll horizontally. By default, it seems Emacs does nothing with that. The scroll wheel produces <mouse-6> and <mouse-7> key events, so I added this to my .emacs as a very basic way to get it to work.

(global-set-key (kbd "<mouse-6>") (lambda () (interactive) (scroll-right 6)))
(global-set-key (kbd "<mouse-7>") (lambda () (interactive) (scroll-left 6)))

This is fairly close to what I want. But the trouble is this. With vertical scrolling, Emacs always scrolls the buffer that the mouse is currently over. With my custom keys that I've just set here, horizontal scrolling happens in the active buffer, not the buffer that the mouse is over. I'd like to get the latter behavior, so that my scroll wheel consistently scrolls whichever buffer the mouse is over.

1 Answer 1


No need to handroll it yourself. This is provided out of the box in emacs 27, and it probably was available for longer:

This feature is off by default; the variable mouse-wheel-tilt-scroll turns it on, if you customize it to a non-nil value.

(setq mouse-wheel-tilt-scroll t)

Your Answer

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

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