Skip to content

Instantly share code, notes, and snippets.

@jgarvin
Created October 16, 2017 15:56
Show Gist options
  • Save jgarvin/70d747a9ee9b4b0b5683035d9080643d to your computer and use it in GitHub Desktop.
Save jgarvin/70d747a9ee9b4b0b5683035d9080643d to your computer and use it in GitHub Desktop.
(defun mouse-button-pressed-p ()
"Return non-nil if last event is a mouse-button down event."
(run-hooks 'mouse-leave-buffer-hook)
(and (consp last-input-event)
(string-match-p "down-mouse-" (format "%s" (car last-input-event)))))
(defun etc-maybe-recenter ()
(unless (or
;; don't interfere with erc scroll-to-bottom
(derived-mode-p 'erc-mode 'term-mode 'shell-mode 'eshell-mode)
(not (eq (get-buffer-window (current-buffer) t) (selected-window)))
(equal (window-point) (point-max))
;; (region-active-p) ;; old way
(mouse-button-pressed-p) ;; new way
)
(recenter)))
(defvar etc-recenter-timer nil)
(progn
(when etc-recenter-timer
(cancel-timer etc-recenter-timer))
(setq etc-recenter-timer nil)
(setq etc-recenter-timer (run-with-idle-timer 0.25 t #'etc-maybe-recenter)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment