6

I use hl-line-mode and I really like the built-in misterioso theme. However, the way that lines are highlighted with this theme cancels out syntax highlighting or any other properties of the highlighted lines, as can be seen in this screenshot. enter image description here

How can I keep the highlighting the same color, but avoid covering up the face properties of the highlighted text? I would be willing to compromise and change the color if necessary, but that doesn't seem to be the issue. I have tried changing the color, but still get the same effect. I have also tried this solution, but only succeeded in getting rid of highlighting altogether.

This question seems to be the same or similar to mine, but I am honestly not sure if it is the same. I tried the solution suggested there but couldn't get it to work. Rather than having a discussion in the comments of that question, I thought I would ask a new one, but my feelings will not be hurt if this gets marked as duplicate.

  • I don't think the question you link to is a duplicate because it deals with the overriding of the background, while you're dealing with the overriding of the foreground. – PythonNut Feb 27 '16 at 5:49
  • @PythonNut: Seems like the same question to me, whether it is foreground or background. I'd say you should consider adding your answer to that question (swapping foreground & background) and this one should be closed as a duplicate. But this one might be expressed more clearly - not sure what's more kosher in such a case. – Drew Feb 27 '16 at 7:20
  • Possible duplicate of hl-line-mode hide background, how to avoid this? – Drew Feb 27 '16 at 7:20
5

Basically, the hl-line face is defining a :foreground property, which is overriding the other foreground colors in your theme.

misterioso defines hl-line in terms of highlight using inheritance, and because of an awkward issue (which I asked about here), it's not possible AFAIK to directly inherit from a face, and override one of the properties to be unset.

So instead, you'll need something like this:

(set-face-attribute 'hl-line nil
                    :inherit nil
                    :background (face-background 'highlight))

This may not be as clean as a hypothetical solution that could preserve the inheritance, but it works.


As noted by Stefan, another solution would be to remove the foreground from the highlight face, which would fix this issue for other types of highlights as well.

(set-face-foreground 'highlight nil)
  • A better solution is probably to change the highlight face to not specify any foreground. – Stefan Feb 27 '16 at 14:40
  • Both of these solutions don't seem to be working when running emacs in X (GUI) mode, but work nice in -nw. – Artem Pelenitsyn May 4 '18 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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