Aquamacs24和Emacs-Trunk的最新夜间版本的默认行为似乎与我习惯的功能不同 - 即命令+ shift + right或command + shift + left跳转到开头或结尾没有选择区域的视线。相反,有必要通过移动shift + left或shift + right或Ctrl + SPC来激活标记然后转到视线的结尾或开始来设置标记。换句话说,这是一个两步骤的方法,需要合并为一次性。
以下代码几乎可以完成我正在寻找的内容,但我希望如果我改变主意并释放shift键并移动箭头键,我会选择自动取消。当前编写代码的方式使选择模式保持活动状态,除非我使用Ctrl + g。
,否则不会取消任何人都可以建议修改我的代码或另一种方法来实现所需的行为吗?
(defun beginning-of-visual-line (&optional n)
"Move point to the beginning of the current line.
If `word-wrap' is nil, we move to the beginning of the buffer
line (as in `beginning-of-line'); otherwise, point is moved to
the beginning of the visual line."
(interactive)
(if word-wrap
(progn
(if (and n (/= n 1))
(vertical-motion (1- n))
(vertical-motion 0))
(skip-read-only-prompt))
(beginning-of-line n)))
(defun end-of-visual-line (&optional n)
"Move point to the end of the current line.
If `word-wrap' is nil, we move to the end of the line (as in
`beginning-of-line'); otherwise, point is moved to the end of the
visual line."
(interactive)
(if word-wrap
(unless (eobp)
(progn
(if (and n (/= n 1))
(vertical-motion (1- n))
(vertical-motion 1))
(skip-chars-backward " \r\n" (- (point) 1))))
(end-of-line n)))
(defun command-shift-right ()
""
(interactive) ;; this is a command (i.e. can be interactively used)
(when (not (region-active-p)) ;; if the region is not active...
(push-mark (point) t t)) ;; ... set the mark and activate it
(end-of-visual-line)) ;; move point defined
(defun command-shift-left ()
""
(interactive) ;; this is a command (i.e. can be interactively used)
(when (not (region-active-p)) ;; if the region is not active...
(push-mark (point) t t)) ;; ... set the mark and activate it
(beginning-of-visual-line)) ;; move point defined
答案 0 :(得分:2)
Emacs内置了对shift-select-mode
的支持:只需在您的功能中使用(interactive "^")
,他们会在轮班触发时选择。