1

我将多行文本粘贴到 Emacs 中,它会自动插入。但是,要撤消它,您必须按C-/(或M-x undo⏎</kbd>) repeatedly, undoing one line at a time. Is it normal?

如何使用单个撤消粘贴操作C-/

4

5 回答 5

3

在终端中运行 Emacs 时,粘贴确实进入了终端,而不是 Emacs。Emacs 从终端一一接收密钥。

有一些解决方法,但没有一个像撤消一样简单:例如,粘贴到*scratch*,然后从那里 kill-n-yank。或者,在粘贴之前,按C-space。然后您只需按 即可撤消C-w

于 2012-11-14T11:02:12.367 回答
2

实际上,我使用了一些自定义 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))
    )
)
于 2012-11-14T12:59:12.877 回答
1

如果您在 Mac OS 终端上运行 Emacs,此解决方案可能会有所帮助:https ://stackoverflow.com/a/3963229/114833

于 2012-11-14T13:31:16.103 回答
1

嗯...如果自上次命令以来的时间很短,我将建议使用pre-command-hook删除最后一次的。undo-boundary但是我看到运行pre-command-hook添加了撤消边界,所以这不是一个选项。您可能希望M-x report-emacs-bug,要求使这样的事情成为可能(甚至默认提供)。

于 2012-11-14T14:48:02.167 回答
0

您可以将其(global-set-key [f5] 'undo);放入您的 emacs 配置文件,即.emacs,然后 F5 命令将帮助您撤消最后的操作,包括粘贴。实际上,除了 F5 之外,您还可以设置任何您喜欢的键。

于 2012-11-14T10:40:58.207 回答