是否有任何编辑器/IDE 在我编辑文件时提供差异的实时 View (可能使用 diff
)。理想的设置是,当我打开一个文件以这种差异模式进行编辑时,该文件缓冲在两个独立的 Pane 中(但并排放置),这样当我编辑一个 Pane 的内容时,两个 Pane 的差异对我来说突出显示。
最佳答案
似乎没有现有的 Emacs 模式可以完全满足您的要求,但粗略的谷歌搜索发现 this和 this 。
从第二个开始(具有稍微固定的格式):
(defun diff-buffer-against-file (context)
"diff the current [edited] buffer and the file of the same name"
(interactive "P")
(let (($file buffer-file-name)
($tempFile "/tmp/emacs.diff")
($tempBuffer "emacs.diff"))
(delete-other-windows)
(push-mark (point) t)
(generate-new-buffer $tempFile)
(copy-to-buffer $tempBuffer (point-min) (point-max))
(set-buffer $tempBuffer)
(write-file $tempFile)
(shell-command (concat (if context "diff -c " "diff ") $file " " $tempFile))
(kill-buffer $tempFile)
(pop-mark)))
(global-set-key "\C-cd" 'diff-buffer-against-file)
该操作看起来有点过于激烈,无法绑定(bind)到 change hook ,但如果您喜欢这类事情,就没有什么可以阻止您这样做。
编辑: Stefan 指出 diff-buffer-with-file
存在,并且具有您正在寻找的行为(它需要一个缓冲区,并且 diff
s 该缓冲区及其文件,在未聚焦的临时缓冲区中显示输出),因此您甚至不需要定义上述内容。我确实尝试过,但天真
(defun diff-current (start end len) (diff-buffer-with-file (current-buffer)))
(add-hook 'after-change-functions 'diff-current)
编辑起来太不符合我的口味了。您可能需要遵循 Stefan 的建议并使用超时,而不是在每次更改时立即进行比较。
关于vim - 任何支持或可能被黑客攻击以支持在编辑时实时查看差异的编辑器/IDE?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15979232/