C-x s用于diff
显示更改。我该如何使用ediff
?
问问题
468 次
2 回答
3
我可以看到几种方法来做到这一点。第一种是save-some-buffers-action-alist
用修改后的代码替换变量,这样更直接。第二个是建议save-some-buffers
和重新定义这些操作调用的函数,但这有点棘手。
我尝试了两种方式,我认为这是最好的选择:
;; Use ediff instead of diff in `save-some-buffers'
(eval-after-load "files"
'(progn
(setcdr (assq ?d save-some-buffers-action-alist)
`(,(lambda (buf)
(if (null (buffer-file-name buf))
(message "Not applicable: no file")
(add-hook 'ediff-after-quit-hook-internal
'my-save-some-buffers-with-ediff-quit t)
(save-excursion
(set-buffer buf)
(let ((enable-recursive-minibuffers t))
(ediff-current-file)
(recursive-edit))))
;; Return nil to ask about BUF again.
nil)
,(purecopy "view changes in this buffer")))
(defun my-save-some-buffers-with-ediff-quit ()
"Remove ourselves from the ediff quit hook, and
return to the save-some-buffers minibuffer prompt."
(remove-hook 'ediff-after-quit-hook-internal
'my-save-some-buffers-with-ediff-quit)
(exit-recursive-edit))))
我使用建议的尝试是有缺陷的(它破坏了C-r也调用的行为view-buffer
,这导致我重新考虑为此目的使用建议),但是 FWIW:
(defadvice save-some-buffers (around my-save-some-buffers-with-ediff)
"Use ediff instead of diff."
(require 'cl)
(flet ((view-buffer (&rest) nil)
(diff-buffer-with-file
(buf)
(add-hook 'ediff-after-quit-hook-internal
'my-save-some-buffers-with-ediff-quit t)
(save-excursion
(set-buffer buf)
(ediff-current-file))))
(let ((enable-recursive-minibuffers t))
ad-do-it)))
(ad-activate 'save-some-buffers)
(defun my-save-some-buffers-with-ediff-quit ()
"Remove ourselves from the ediff quit hook, and
return to the save-some-buffers minibuffer prompt."
(remove-hook 'ediff-after-quit-hook-internal
'my-save-some-buffers-with-ediff-quit)
(exit-recursive-edit))
于 2011-02-04T13:32:49.593 回答
1
文档说,该变量diff-command
是可定制的。但是,请记住它指向外部程序,而不是 elisp 函数。 ediff
是 ediff.el 中的一个 elisp 函数。您可能必须将 diff.el 编辑为(require 'ediff)
,然后在 diff.el 中到处调整,以确保您没有破坏其他任何内容。
于 2011-02-04T09:31:33.470 回答