Aquamacs24 和 Emacs-Trunk 的最新夜间版本的默认行为似乎都与我习惯的不同——即 command+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