9

I use (global-hl-line-mode 1) in order to highlight the current line. This changes the text colours of the highlighted line. Is it possible to highlight while keeping the current syntax highlighting colours (so changing only the background)?

Drew
  • 77,472
  • 10
  • 114
  • 243
Nisba
  • 905
  • 8
  • 19

3 Answers3

8

Just for reference, try

(set-face-attribute 'hl-line nil :inherit nil :background "gray6")
Yadoo86
  • 81
  • 1
  • 1
5

This is the case by default for me: hl-line-mode by default uses a face which only specifies a background color. That face is hl-line which by default just inherits from highlight. So maybe the problem is simply your that highlight face specifies both a background and a foreground color. I recommend you M-x customize-face and either change your highlight face or your hl-line face so as to keep its foreground color unspecified.

Stefan
  • 26,404
  • 3
  • 48
  • 85
5

This works for me, with this in my .emacs. See how the syntax colours are nicely preserved? (thx Yadoo86)

;; highlight line with the cursor, preserving the colours.
(set-face-attribute 'hl-line nil :inherit nil :background "gray80")
(global-hl-line-mode 1)

enter image description here

ohainaut
  • 51
  • 1
  • 1