Skip to main content
2 of 2
Fixed typographical error.
lawlist
  • 19.5k
  • 5
  • 42
  • 125

When doc-view-mode is enabled, mwheel-scroll-up-function is set locally to be doc-view-scroll-up-or-next-page; and, mwheel-scroll-down-function is set locally to be doc-view-scroll-down-or-previous-page. The preferred behavior sought by the original poster in the question above is that the mouse-wheel activate doc-view-next-page and doc-view-previous-page when focus is in another unrelated buffer window, and the mouse is hovering over the doc-view-mode buffer window. The code set out below resolves that issue. Although the original poster tried binding doc-view-next-page to wheel-down and doc-view-previous-page to wheel-up, that is not correct and this is why the original poster received the error message that was cited above.

The behavior of doc-view-scroll-up-or-next-page and doc-view-scroll-down-or-previous-page is slightly different than doc-view-next-page and doc-view-previous-page. Ultimately, this is a matter of personal preference and the issue was simply how to implement that preference.

(defun doc-view-mouse-turn-page ()
  (when (boundp 'mwheel-scroll-up-function)
    (setq-local mwheel-scroll-up-function #'doc-view-next-page))
  (when (boundp 'mwheel-scroll-down-function)
    (setq-local mwheel-scroll-down-function #'doc-view-previous-page)))

(add-hook 'doc-view-mode-hook 'doc-view-mouse-turn-page)
lawlist
  • 19.5k
  • 5
  • 42
  • 125