5

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?

4

2 に答える 2

3

^関数の仕様の先頭(二重引用符内)に追加する(interactive "...")と、Emacs23.1以降でシフト選択がサポートされます。

于 2010-12-23T02:44:20.727 に答える
2

ホームキーを設定すると (...)、 gnu.emacs.helpの cua-modeでshift+home がテキストを選択しない場合、スレッドで解決策の残りの半分を見つけました:

のシフト選択に参加するにはcua-mode、関数 (私の場合sfp-page-xxxは ) のシンボル プロパティCUAを に設定する必要がありmoveます。

(put 'sfp-page-up 'CUA 'move)

(ソリューションの前半については、JSON の回答を参照してください)。

だからここに私の完全な解決策があります:

(defun sfp-page-down (&optional arg)
  (interactive "^P")
  (setq this-command 'next-line)
  (next-line
   (- (window-text-height)
      next-screen-context-lines)))
(put 'sfp-page-down 'isearch-scroll t)
(put 'sfp-page-down 'CUA 'move)

(defun sfp-page-up (&optional arg)
  (interactive "^P")
  (setq this-command 'previous-line)
  (previous-line
   (- (window-text-height)
      next-screen-context-lines)))
(put 'sfp-page-up 'isearch-scroll t)
(put 'sfp-page-up 'CUA 'move)
于 2010-12-24T12:42:51.287 に答える