magit/magit — pull request #1380 by tarsius (2014-05-26 16:33:05+00:00)
Title: highlight hunks without overriding semantic background colors

Generally speaking, highlighting the current section using the
background color means that any text in that section which also sets
a background color different from that of `default` loses its special
appearance. For things like ref names we work around this by using
overlays.

But we didn't do that for added, removed, and context lines in diffs,
even though the default values of the respective faces did only set the
background color but not the foreground color. This was fixed by some
third-party color themes by using the foreground color instead
of the background color to differentiate lines in diffs.

This commit makes such kludges unnecessary. It is still possible to do
it the old way, but it is not recommended, because doing so makes it
much harder to come up with faces for hunk refinement which both look
good and are sufficiently visible. (Using bold is not a good option;
it`s easy to overlook, and for whitespace it doesn`t have any effect at
all.)

So hunks are now treated as a special case when highlighting; instead of
`magit-section-highlight` the new faces `magit-hunk-heading-highlight`,
`magit-diff-added-highlight`, `magit-diff-removed-highlight`, and
`magit-diff-context-highlight` are used.

Furthermore we don't use overlays to apply these faces but the face text
property. Doing it this way avoids problems with `diff-refine-hunk`.
If we did use overlays these overlays would in some cases override the
refinement overlays.

----

Unfortunately this means that existing themes and user customizations break. I hope that be the time `next` is merged into `master` most popular themes have been adjusted. Early adopters can help with that by adjusting their favorite theme now. I recommend you don't submit your changes just yet, as I might some other adjustments to faces before the merge happens. I have already adjusted the zenburn theme. There are two variants: https://github.com/tarsius/zenburn-emacs/tree/magit-next and https://github.com/tarsius/zenburn-emacs/tree/magit-next-oldschool. The later shows how to make a theme again look as it used to; doing that is not recommended. Treat the "light default theme" as reference implementation:

(set-face-attribute 'default nil :background "gray90")
(set-face-attribute 'default nil :foreground "gray15")

I think that looks pretty good. The "dark default theme" is a bit ugly:

(set-face-attribute 'default nil :background "gray15")
(set-face-attribute 'default nil :foreground "gray80")