【问题标题】:Emacs: Is there a better PgDn/PgUp behaviour with cua-mode?Emacs:cua 模式是否有更好的 PgDn/PgUp 行为?
【发布时间】:2011-05-29 15:50:37
【问题描述】:

我希望 PgUpPgDn 键只是向上或向下移动显示文件的内容,但光标(point 在 Emacs Lingo 中)应该留在原处(在屏幕上)。不幸的是,默认的 Emacs 行为是不同的。默认行为很难描述,但如果您按 PgDn 后按 PgUp,您最终不会回到之前的位置 (!)。

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

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

然而,与cua-mode 结合使用时存在一个问题,它提供(除其他外)移位选择(按 Shift 和光标移动键,如 ← kbd> 或 PgDn 开始突出显示选定区域):

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

如何让cua-modesfp-page-up/down 配合得很好?

【问题讨论】:

    标签: emacs keyboard-shortcuts cua cua-mode


    【解决方案1】:

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

    【讨论】:

    • 我将函数更改为(defun sfp-page-down (arg) (interactive "^p") ...,但仍然无法开始选择。我应该将 cua-mode 修补到 remap sfp-page-up 而不是 remap scroll-up 吗?顺便说一句:哪个是正确的,"^p""^P"
    • 感谢您的提示,解决方案成功了一半。当我禁用cua-mode 时,班次选择现在确实适用于sfp-page-xx。但是启用cua-mode 后仍然无法正常工作。
    【解决方案2】:

    我在gnu.emacs.help上的线程if I set home key (...) then shift+home does not select text in cua-mode中找到了解决方案的另一半:

    要参与cua-mode的移位选择,函数(在我的例子中是sfp-page-xxx)必须将符号属性CUA设置为move

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

    (对于解决方案的前半部分,请参阅JSON's answer)。

    所以这是我的完整解决方案:

    (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-11-28
      • 1970-01-01
      • 2016-06-26
      • 1970-01-01
      • 1970-01-01
      • 2012-11-26
      • 1970-01-01
      • 1970-01-01
      • 2010-09-09
      相关资源
      最近更新 更多