2

I have a problem with the magit-item-highlight in different themes. With monokai, zenburn, etc., the item highlight is a background, and does not interfere with green and red diff faces. However, with the default theme, it inherits the face from secondary-selection and overrides the red and green colouring of diffs. The interim solution would be just to customise this to empty face, but how can I actually fix it?

bad good

5
  • I just grepped the current source code for the library magit and didn't see that particular face -- so perhaps the maintainer changed it already (in which case, you may wish to consider upgrading magit).
    – lawlist
    Apr 28, 2015 at 6:49
  • I have the 1.4.0 release; I know there's work happening on a new version, do you have that installed?
    – sooheon
    Apr 28, 2015 at 8:23
  • The website repository of magit reflects a newer version than the one you are using. If you are reluctant to upgrade, you may wish to consider modifying the source code of that particular face -- look for (defface magit-item-highlight . . . If you are uncomfortable modifying source, you may wish to consider using (set-face-attribute . . . . If those files are byte-compiled and you choose to modify the source code directly, then you will need to re-byte-compile them. There are some Github issues previously posted regarding that face, so the maintainer may have already fixed it . . . .
    – lawlist
    Apr 29, 2015 at 5:35
  • Out of curiosity, what is the theme used in the second screenshot ?
    – nha
    Jul 24, 2015 at 13:57
  • It is monokai-theme on melpa.
    – sooheon
    Aug 15, 2015 at 4:25

2 Answers 2

0

The highlighting is applied to the whole line, thus if the highlight face has a background, it will override all other backgrounds. The other themes only work because they use the face's foreground attribute instead of the background like the default face does.

An easy fix would be to change the diff faces such that they represent adds and removals by using a foreground color instead of a background color.

So instead of this:

enter image description here

You get this:

enter image description here

and thus the green still shows when highlighted:

enter image description here

You can use this do customize the faces appropriately:

(custom-set-faces  
 '(diff-added ((t (:foreground "#149914" :background nil :inherit nil))))
 '(diff-removed ((t (:foreground "#991414" :background nil :inherit nil)))))

the magit diff faces inherit from the core diff faces, so I just modified those. If you want to change how magit displays diffs but not the rest of emacs, modify the magit-diff-add and magit-diff-del faces instead.

3

Update: 2.1.0 has been released.

In 1.4.*/master the face is named magit-item-highlight. In 2.1.*/next it is named magit-section-highlight, because that's what these ui elements are called everywhere else too.

When using 1.4.* diffstats lose their appearance when they are highlighted because a face is used which overrides not only the background color but also the foreground color. The reason that doesn't happen for certain other sections is that we explicitly hack around the issue by using overlays for things that should be unaffected by the highlighting.

To fix that you could change the option magit-item-highlight-face to another face which does not set the foreground color. Or you could make magit-item-highlight inherit from another face which does not set the foreground. You cannot just set magit-item-highlights foreground to "none", because there is no such value - that's a limitation in Emacs.

The reason there are many issue related to the section highlighting is that there are diverging opinions one "how it should be" and "this is the worst possible thing you could do". It took a while implementing something that allows everyone to configuring it the way they want. And that will be released as 2.1.0.

You should either update to the next branch now, or just live with diffstats losing their foreground colors when highlighted - that seems like a very minor issue.

2
  • Customizing magit-item-highlight-face will not fix the issue when using the default theme. OP's picture doesn't show it, but the default theme does NOT use a foreground to color diffs it uses a background. If OP wants a colored foreground when highlighted, then they need to specify the foreground for the diff-added and diff-removed faces. May 11, 2015 at 17:04
  • That's not a very good default then :-) I think I have changed it on the next branch.
    – tarsius
    May 11, 2015 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.