The functionality of clever-scroll-up and clever-scroll-down is simply that, instead of scrolling only when you are at the top or bottom line of the screen, scrolling occurs when you are in the top third or bottom third of the screen. More specifically, if you are in the top third of the screen and move your cursor up, the screen will scroll down; and, if you are in the bottom half of your screen and scroll down, the screen will scroll up. It's simple, but I think if you try it you will find that, compared to the usual scrolling behaviour, it is a much more convenient way to control screen scrolling while browsing and editing files. I would be interested to hear if others find this as beneficial as I do.
Here is the Emacs code. Simply add it to your .emacs file to
enable stress free scrolling. I think it should work with pretty much
any Emacs setup although the appropriate key binding commands
may vary.
;; Clever scrolling commands
;; by Brandon Bennett, University of Leeds
(defun clever-scroll-down ()
(interactive)
(previous-line 1)
(setq winstart (window-start))
(if (and ( > winstart 1)
( > ( / (screen-height)
(+ 1 (count-lines winstart (point))))
3 )
)
(scroll-down 1) ) )
(defun clever-scroll-up ()
(interactive)
(next-line 1)
(if (and (> (buffer-size) (window-end))
( > (* 3 (+ 1 (count-lines (window-start) (point))))
(* 2 (screen-height))
)
)
(scroll-up 1) ) )
;; Now bind to your up and down arrow buttons
(global-set-key [up] 'clever-scroll-down)
(global-set-key [down] 'clever-scroll-up)
More Tips?
Sorry, there is just the one tip on this page so far. I will probably
put some more up if I get time, especially if I get positive comments
about the clever scrolling. My .emacs file is certainly very
large (a boast that only a true geek could make), so probably there is
some other stuff in it that people might find useful.