Skip to content

Instantly share code, notes, and snippets.

@hanabokuro
Last active December 23, 2015 12:18
Show Gist options
  • Save hanabokuro/6633972 to your computer and use it in GitHub Desktop.
Save hanabokuro/6633972 to your computer and use it in GitHub Desktop.
(defvar accelerated-move:buffer nil)
(defvar accelerated-move:count 0)
(defvar accelerated-move:point (make-hash-table))
(defvar accelerated-move:table '(7 12 17 21 24 26 28 30))
(defun accelerated-move:previous (&optional arg try-vscroll)
(interactive "^p\np")
(accelerated-move:do 'previous-line "previous" arg try-vscroll))
(defun accelerated-move:next (&optional arg try-vscroll)
(interactive "^p\np")
(accelerated-move:do 'next-line "next" arg try-vscroll))
(defun accelerated-move:do (original name arg try-vscroll)
(if (= arg 1)
(if (and (eq (current-buffer) accelerated-move:buffer)
(eq (point) (gethash name accelerated-move:point)))
(setq arg (accelerated-move:calc_acceleration_step accelerated-move:table accelerated-move:count 1))
(progn
(setq accelerated-move:count 0)
(setq arg 1)))
(setq accelerated-move:count 0))
(funcall original arg try-vscroll)
(setq accelerated-move:buffer (current-buffer))
(puthash name (point) accelerated-move:point)
(setq accelerated-move:count (1+ accelerated-move:count)))
(global-set-key (kbd "C-p") 'accelerated-move:previous)
(global-set-key (kbd "C-n") 'accelerated-move:next)
(defun accelerated-move:calc_acceleration_step (table count step)
(cond ((null table) step)
((< count (car table)) step)
(t (accelerated-move:calc_acceleration_step (cdr table) count (1+ step)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment