Skip to content

Instantly share code, notes, and snippets.

@hitode909
Created October 5, 2011 07:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hitode909/1263852 to your computer and use it in GitHub Desktop.
Save hitode909/1263852 to your computer and use it in GitHub Desktop.
dial-scroll.el
(defun dial-scroll ()
(interactive)
(lexical-let ((last_rad 0.0))
(run-with-timer 0.05 0.05
(lambda ()
(let ((current_x (car (cdr (mouse-position))))
(current_y (cdr (cdr (mouse-position)))))
(let ((diff_x (float (- current_x (/ (window-width) 2))))
(diff_y (float (- current_y (/ (window-height) 2)))))
(let ((rad (atan (/ diff_y diff_x))))
(let ((rad (if (> 0.0 diff_x) rad (+ rad pi))))
(let ((diff (- rad last_rad)))
(let ((diff (if (< diff (* -1 pi)) (+ diff (* 2 pi)) diff)))
(let ((diff (if (> diff pi) (- diff (* 2 pi)) diff)))
(setq last_rad rad)
(when (< 0 diff)
(scroll-up 1))
(when (> 0 diff)
(scroll-down 1))
)))))))))))
(provide 'dial-scroll)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment