5

我希望PgUpandPgDn键只是向上或向下移动显示文件的内容,但光标(在 Emacs Lingo 中的)应该保持在原位(在屏幕上)。不幸的是,默认的 Emacs 行为是不同的。默认行为很难描述,但如果你按下PgDn后跟PgUp你不会结束你之前的位置(!)。

这不是一个新问题,在 EmacsWiki 中有一个很好的解决方案,称为sfp -page-up 和 sfp-page- down

(defun sfp-page-up ()
  (interactive)
  (setq this-command 'previous-line)
  (previous-line
   (- (window-text-height)
      next-screen-context-lines)))

但是,与cua模式结合使用时存在一个问题,该模式提供(除其他外)移位选择(按下Shift和光标移动键,如PgDn开始突出显示选定区域):

cua-mode不识别重新定义的PgUp/PgDn键,即它们不开始选择。解决方法是先按or键,然后按PgUp/继续PgDn

我怎样才能cua-mode很好地玩耍sfp-page-up/down

4

2 回答 2

3

如果您添加^到函数规范的开头(interactive "...")(在双引号内),它们将支持 Emacs 23.1 及更高版本中的移位选择。

于 2010-12-23T02:44:20.727 回答
2

如果我设置主页键 (...) 然后 shift+home 不会gnu.emacs.help上以 cua 模式选择文本,我在线程中找到了解决方案的另一半:

要参与 的移位选择cua-mode,函数(在我的例子中sfp-page-xxx)必须将 symbol 属性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 回答