emacs page up page down

By default, the page up and page down keys in Emacs move the screen up and down, not the point. As a result, if the screen is already at the bottom of the buffer, page down does nothing.

I don’t know about you, but this annoys me. Even if the screen is at the bottom of the buffer, I want page down to move the point to the bottom of the buffer if it’s not already there. So, I set out to make page up and page down move the point up and down a page. The screen should also scroll to follow it, if necessary, but that should be a side effect.

I first looked at pager.el. It’s close – it moves the point, not the screen – but it still errors if the screen is already at the end of the buffer.

I next looked at pc-selection-mode, which comes with Emacs (in pc-mode.el). It binds page down and page up to scroll-down-nomark and scroll-up-nomark, which do what I want, but they also disable the mark. Argh!

So, I stole the code and hacked it to leave the mark alone. I ended up with this elisp, which makes page up and page down behave exactly the way I want:

;; Page down/up move the point, not the screen.
;; In practice, this means that they can move the
;; point to the beginning or end of the buffer.
(global-set-key [next]
  (lambda () (interactive)
    (condition-case nil (scroll-up)
      (end-of-buffer (goto-char (point-max))))))

(global-set-key [prior]
  (lambda () (interactive)
    (condition-case nil (scroll-down)
      (beginning-of-buffer (goto-char (point-min))))))

7 thoughts on “emacs page up page down

  1. I found this note interesting.

    I came from Windows land and had accepted Emacs behavior on face-value when I arrived.

    The documentation you link to does say this about pc-selection-mode:

    “However, using Shift together with the ‘move keys’ activates the region over which they move.”

    Seems there should be a way to customize scroll-down-mark and scroll-up-mark rather than redefining the keys.

  2. Thanks! I switched to Emacs from Jed (an Emacs clone) that had some quirks, this being one of the ones I liked!

  3. Thanks a billion ! this save me a lot of time hacking around …

  4. Cool. Looks like (setq scroll-error-top-bottom t) does some of this but it will still give an error if you try from the end of buffer.

  5. for emacs >= 24.1, use
    (setq-default scroll-error-top-bottom t)

Leave a Reply

Your email address will not be published. Required fields are marked *