Emacs: how to trigger scroll when cursor is n-lines from top/bottom of screen?

I think scroll-margin will help -- look for it in the Emacs docs on Textual Scrolling.

Put this in your .emacs:

(setq scroll-margin 4)