I am able to scroll using navigation buttons and external mouse on a Mac with this code that keeps the cursor at a specific line at all times. I am using this code since it is much faster than centered-cursor-mode.

The only problem I am facing is when using the macbook mouse which is mapped to "mac-mwheel-scroll". When using it, the buffer stalls and the cursor doesn't move at all. Any help to figure a solution out is appreciated.

(defcustom centered-point-position 0.35
  "Percentage of screen where `centered-point-mode' keeps point."
  :type 'float)

(setq centered-point--preserve-pos nil)

(define-minor-mode centered-point-mode
  "Keep the cursor at `centered-point-position' in the window"
  :lighter " centerpoint"
  (cond (centered-point-mode (add-hook 'post-command-hook 'center-point nil t)
                             (setq centered-point--preserve-pos
                             (setq-local scroll-preserve-screen-position 'all))
        (t (remove-hook 'post-command-hook 'center-point t)
           (setq-local scroll-preserve-screen-position

(defun center-point ()
  "Move point to the line at `centered-point-position'."
  (when (eq (current-buffer) (window-buffer))
    (let ((recenter-positions (list centered-point-position)))

(defun centered-point-mode-on ()
  (centered-point-mode 1))

(define-globalized-minor-mode global-centered-point-mode centered-point-mode
  • Based on this comment, try turning off mac-mouse-wheel-mode. Otherwise, I think just rebinding the scroll events to the regular mwheel-scroll would probably do the job. – jirassimok Jan 13 '20 at 19:37
  • Disabling mac-mouse-wheel-mode as the comment recommended disabled even the external mouse, which is not the desired outcome. – SFbay007 Jan 13 '20 at 21:48

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.