【发布时间】:2012-11-14 10:37:28
【问题描述】:
我将多行文本粘贴到 Emacs 中,它会自动插入。但是,要撤消它,您必须反复按 C-/(或 M-x undo⏎),撤消一次一行。正常吗?
如何使用单个 C-/ 撤消粘贴操作?
【问题讨论】:
-
您是在终端中运行 emacs,还是作为 X 应用程序运行?
-
@choroba,它只发生在终端中,GUI版本很好。
我将多行文本粘贴到 Emacs 中,它会自动插入。但是,要撤消它,您必须反复按 C-/(或 M-x undo⏎),撤消一次一行。正常吗?
如何使用单个 C-/ 撤消粘贴操作?
【问题讨论】:
当在终端中运行 Emacs 时,粘贴会真正进入终端,而不是 Emacs。 Emacs 从终端一一接收密钥。
有一些解决方法,但没有一个像撤消一样简单:例如,粘贴到 *scratch*,然后从那里 kill-n-yank。或者,在粘贴之前,按 C-space。然后您只需按 C-w 即可撤消。
【讨论】:
C-space 解决方案虽然聪明但不起作用,但我明白你的意思。谢谢!
我实际上有一些自定义的 elisp 我使用它撤消自上次保存点以来的所有修改。如果您经常保存(我这样做),这将提供一个很好的逻辑撤消能力。假设您在粘贴块之前保存了缓冲区,这将删除整个粘贴。 (注意,它可以跨多个保存点工作,这意味着您可以在撤消历史记录中一次撤消一个保存点)。
(defun undo-last-modification ()
"Undo all changes since last save point in the buffer."
(interactive)
(let* ((repeat-undo (eq last-command 'undo))
(cur-undo-list (if repeat-undo pending-undo-list buffer-undo-list))
(head (car-safe cur-undo-list))
(tail (cdr-safe cur-undo-list))
(found-next-mod nil)
(num-undos 0))
;; when in the midst of undoing, the first nil gets chopped off the list,
;; so add one if the list doesn't start with nil
(if head (setq num-undos (1+ num-undos)))
;; search for next save point in the undo list
(while (not found-next-mod)
(if (not head)
(setq num-undos (1+ num-undos))
(if (and (listp head) (eq (car-safe head) t))
(setq found-next-mod t)))
(if tail
(progn
(setq head (car-safe tail))
(setq tail (cdr-safe tail)))
;; end of list
(setq found-next-mod t))
)
(if (> num-undos 0)
(undo num-undos))
)
)
【讨论】:
如果您在 Mac OS 终端上运行 Emacs,此解决方案可能会有所帮助:https://stackoverflow.com/a/3963229/114833
【讨论】:
pbcopy 和 pbpaste!酷!
嗯...我正要建议使用 pre-command-hook 来删除最后一个 undo-boundary 如果自上次命令以来的时间很短。但是我看到在运行pre-command-hook 之后添加了撤消边界,所以这不是一个选项。您可能想M-x report-emacs-bug,要求使这样的事情成为可能(甚至默认提供)。
【讨论】:
你可以把这个(global-set-key [f5] 'undo);放到你的emacs配置文件中,即.emacs,然后F5命令会帮你撤消最后的操作,包括粘贴。其实,除了F5,你可以随意设置键。
【讨论】: