I am trying to have a simple solution to center the cursor at all times. I found that centered-cursor-mode
was too slow and found this simpler solution.
The only problem is mouse scrolling no longer works unless I disable the minor/major mode I implemented to center the cursor.
I tried to advise mwheel-scroll
to disable the mode but that was unsuccessful. I am not sure what I am doing wrong.
(define-minor-mode centered-point-mode
"Always center the cursor on the screen."
:lighter "..."
(cond (centered-point-mode (add-hook 'post-command-hook 'line-change))
(t (remove-hook 'post-command-hook 'line-change))))
(defun line-change ()
(recenter))
(define-globalized-minor-mode my-global-centered-point-mode centered-point-mode
(lambda () (centered-point-mode 1)))
(my-global-centered-point-mode 1)
(defun disable-centered
(interactive)
(centered-point-mode -1))
(advice-add 'mwheel-scroll :before (lambda () (interactive) (call-interactively 'disable-centered)))
advice-...
, as far as I can see. How about putting in exceptions forline-change
? E.g.,(unless (eq this-command 'mwheel-scroll) (recenter))
If you want multiple exceptions, use(unless (memq this-command '(mwheel-scroll foo-command bar-command baz-command)) (recenter))
In most cases,this-command
is the command of the current command loop -- however, certain hooks run afterthis-command
becomes thelast-command
even though the command loop is still the same ... but, thepost-command-hook
is early enough in time so thatthis-command
is still current.