gpt4 book ai didi

emacs - 在 emacs 中上下移动行/区域

转载 作者:行者123 更新时间:2023-12-03 05:15:23 25 4
gpt4 key购买 nike

在 emacs 中向上或向下移动选定区域或行(如果没有选择)的最简单方法是什么?我正在寻找与 Eclipse 中相同的功能(仅限于 M-up、M-down)。

最佳答案

更新:从 Marmalade 或 MELPA 安装 move-text 软件包获取以下代码。

这是我使用的方法,它适用于区域和单独的线路:

(defun move-text-internal (arg)
(cond
((and mark-active transient-mark-mode)
(if (> (point) (mark))
(exchange-point-and-mark))
(let ((column (current-column))
(text (delete-and-extract-region (point) (mark))))
(forward-line arg)
(move-to-column column t)
(set-mark (point))
(insert text)
(exchange-point-and-mark)
(setq deactivate-mark nil)))
(t
(let ((column (current-column)))
(beginning-of-line)
(when (or (> arg 0) (not (bobp)))
(forward-line)
(when (or (< arg 0) (not (eobp)))
(transpose-lines arg)
(when (and (eval-when-compile
'(and (>= emacs-major-version 24)
(>= emacs-minor-version 3)))
(< arg 0))
(forward-line -1)))
(forward-line -1))
(move-to-column column t)))))

(defun move-text-down (arg)
"Move region (transient-mark-mode active) or current line
arg lines down."
(interactive "*p")
(move-text-internal arg))

(defun move-text-up (arg)
"Move region (transient-mark-mode active) or current line
arg lines up."
(interactive "*p")
(move-text-internal (- arg)))


(global-set-key [M-S-up] 'move-text-up)
(global-set-key [M-S-down] 'move-text-down)

关于emacs - 在 emacs 中上下移动行/区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2423834/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com