Created
October 5, 2011 07:24
-
-
Save hitode909/1263852 to your computer and use it in GitHub Desktop.
dial-scroll.el
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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