I'd like the PgUp and PgDn keys to just move the contents of the shown file upwards or downwards, but the cursor (point in Emacs Lingo) should stay where it is (on the screen). Unfortunately the default Emacs behaviour is different. The default behaviour is difficult to describe, but if you press PgDn followed by PgUp you don't end up where you were before (!).
This is not a new problem and there exists a nice solution called sfp-page-up and sfp-page-down in the EmacsWiki.
(defun sfp-page-up ()
(interactive)
(setq this-command 'previous-line)
(previous-line
(- (window-text-height)
next-screen-context-lines)))
There is one problem, however, in combination with cua-mode, which provides (among others) shift-selection (pressing Shift and a Cursor movement key like ← or PgDn starts highlighting a selected area):
cua-mode
doesn't recognise the redefined PgUp/PgDn keys, i.e. they don't start a selection. The workaround is to press first the ↑ or ↓ key and then continue with PgUp/PgDn.
How can I make cua-mode
play nicely with sfp-page-up/down
?
I found the other half of the solution in the thread if I set home key (...) then shift+home does not select text in cua-mode on gnu.emacs.help:
To participate in the shift selection of
cua-mode
, a function (in my casesfp-page-xxx
) must have the symbol propertyCUA
set tomove
:(For the first half of the solution see JSON's answer).
So here is my complete solution: