【发布时间】:2015-03-11 13:04:56
【问题描述】:
我目前选择了一个文本区域。我想杀死/拉动(或以任何其他方式格式化)除所选区域之外的整个缓冲区。有什么方法可以在 emacs 中进行反转选择并完成相同的操作吗?
【问题讨论】:
标签: emacs textselection
我目前选择了一个文本区域。我想杀死/拉动(或以任何其他方式格式化)除所选区域之外的整个缓冲区。有什么方法可以在 emacs 中进行反转选择并完成相同的操作吗?
【问题讨论】:
标签: emacs textselection
kill-region 中间的文字。mark-whole-buffer 剩下的文字。yank 中间文字。【讨论】:
kill ring 不会受到影响吗?那么第 4 步可能不会产生预期的结果。
M-y。这是一枚戒指,它可以容纳不止一个杀戮。
(defun my-copy-inverted-region-as-kill (beginning end)
"Copy to the kill ring everything except the marked region."
(interactive "r")
(let ((srcbuf (current-buffer))
(offset (point-min)))
(with-temp-buffer
(insert-buffer-substring srcbuf)
(delete-region (- beginning offset) (- end offset))
(copy-region-as-kill (point-min) (point-max)))))
【讨论】:
不能存在非连续区域。 但是,这会将相反的命令放在 C-c DEL
(global-set-key "\^C\^?" ; help edit mail files, etc.
(defun erase-buffer-except-region (beg end)
"Erase the buffer except for the region."
(interactive "r")
(when (< end beg)
(cl-rotatef beg end))
(delete-region end (point-max))
(delete-region (point-min) beg)))
【讨论】: