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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.