emacs: How to return to last position after scroll/page up/down?

(setq scroll-preserve-screen-position t)

With this setting, if you page up and down, the cursor returns to its original line. It also retains its original column in Emacs version 23 or newer.

You may or may not prefer

(setq scroll-preserve-screen-position 'always)

which always preserves the cursor's screen position when scrolling, rather than preserving the cursor position in the buffer if the original position is still visible.


What I've found to work well is using goto-last-change.el, which pops you back to the location where you last made an edit. I like the binding:

(require 'goto-last-change) ;; download this package and install in load-path
(global-set-key (kbd "C-x C-\\") 'goto-last-change)