如何在 Emacs diff 模式下配置突出显示?

发布于 2024-09-30 15:08:14 字数 325 浏览 3 评论 0原文

我在 Emacs 中使用 mercurial.el 模式。当我运行 vc-diff 时,我可以看到差异,但是与源代码不同,它没有很好地突出显示:

Emacs vc-diff

阅读这样的差异是很困难的。如何配置 Emacs,

  1. 以使用不同颜色突出显示 -+ 行? (例如红色和蓝色)
  2. 以突出显示单词差异(就像 BitBucket 和 GitHub 所做的那样)

I use mercurial.el mode with Emacs. When I run vc-diff, I can see the diff, but, unlike the source code, it is not nicely highlighted:

Emacs vc-diff

Reading such diffs is difficult. How do I configure Emacs,

  1. to highlight - and + lines with different colors? (red and blue, for example)
  2. to highlight word difference (like BitBucket and GitHub do)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

难以启齿的温柔 2024-10-07 15:08:14

尝试使用 Mx ediff-revision,它会执行 ediff 而不仅仅是常规的 diff。这将为您提供单词差异和并排(或顶部/底部)显示。查看 ediff 手册

Emacs wiki 还有许多用于常规 diff 文件的模式(就像您正在查看的那样) - 检查出来

要仅更改当前使用的 diff-mode 中的颜色,您可以执行以下操作:

(defun update-diff-colors ()
  "update the colors for diff faces"
  (set-face-attribute 'diff-added nil
                      :foreground "white" :background "blue")
  (set-face-attribute 'diff-removed nil
                      :foreground "white" :background "red3")
  (set-face-attribute 'diff-changed nil
                      :foreground "white" :background "purple"))
(eval-after-load "diff-mode"
  '(update-diff-colors))

Try using M-x ediff-revision, which does an ediff instead of just a regular diff. That will give you word-differences and a side-by-side (or top/bottom) display. Check out the ediff manual.

The Emacs wiki also has a number of modes for just regular diff files (like what you're looking at) - check it out.

To just change the colors in the diff-mode which you're currently using, you can do something like:

(defun update-diff-colors ()
  "update the colors for diff faces"
  (set-face-attribute 'diff-added nil
                      :foreground "white" :background "blue")
  (set-face-attribute 'diff-removed nil
                      :foreground "white" :background "red3")
  (set-face-attribute 'diff-changed nil
                      :foreground "white" :background "purple"))
(eval-after-load "diff-mode"
  '(update-diff-colors))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文