1

I've changed my diff-mode colours according to this article, but the character-based differences are shown in the original(?) and very bright colours, making them quite unreadable.

How do I change the colours that show the char-by-char differences on the removed/added lines?

Drew
  • 75,699
  • 9
  • 109
  • 225
forthrin
  • 451
  • 2
  • 10

2 Answers2

2

With diff-refine faces:

(defun update-diff-refine-colors ()
  "update the colors for diff faces"
  (set-face-attribute 'diff-refine-added nil
                      :foreground "white" :background "darkgreen")
  (set-face-attribute 'diff-refine-removed nil
                      :foreground "white" :background "darkred")
  (set-face-attribute 'diff-refine-changed nil
                      :foreground "white" :background "darkblue"))
(eval-after-load "diff-mode"
  '(update-diff-refine-colors))
Daniil Iaitskov
  • 205
  • 1
  • 8
djangoliv
  • 3,169
  • 16
  • 31
  • Very good! I merged them into one function. However strangely, earlier all of my diff chunks were automatically refined (char differences showed automatically). Now I have to do it manually. How do I enable it automatically? The linked article suggests a snippet to enable this, but it really did happen on my machine without any such snippet... https://emacs.stackexchange.com/questions/28271/diff-mode-refine-all-hunks-when-opening-a-diff-file – forthrin Apr 06 '18 at 13:07
  • I'm pretty sure that Emacs does'nt refine by default. You need to used a function for that. – djangoliv Apr 06 '18 at 13:24
2

There are more faces involved than the ones mentioned in the link you pointed to. The answer is to use C-u C-x = to find out what faces are involved. Those are the ones you need to customize.

Use M-x customize-face to customize the faces you are interested in. If you don't know which faces they are, put the cursor on that highlighted text and use C-u C-x =. Look near the bottom of *Help* for the face name.

From @djangoliv's answer it seems that these are the faces you need to customize: diff-refine-added, diff-refine-removed, diff-refine-changed.

So just M-x customize-face diff-refine-added and define the face as you like.

Do the same for diff-refine-removed and diff-refine-changed.

Easy, persistent, and the way Emacs wants to help you customize faces. See the Emacs manual, node Specific Customization.

Drew
  • 75,699
  • 9
  • 109
  • 225