6

I want to highlight the current symbol under the cursor as well as the current line, but with different background colors.

Combining highlight-symbol-mode and hl-line-mode only highlights the entire line with the hl-line-mode color.

I have hl-line+ installed and have tried reducing the hl-line-overlay-priority option but that does not seem to work. The entire line still get the same background color.

Are there any other modes or settings I can set to make this work?

Drew
  • 75,699
  • 9
  • 109
  • 225
Emil Vikström
  • 223
  • 1
  • 6

1 Answers1

8

highlight-symbol-mode uses text properties, not an overlay.

hl-line-mode uses an overlay, not text properties.

Overlays always take precedence over text properties, no matter how low the overlay priority is.

So without some coding or code tweaking, I don't see a solution.


However, if you use the Highlight library (highlight.el) then the solution is simple.

Just use command hlt-highlight-symbol. It is bound by default to C-x X h s.

(All of the commands in this library are bound in keymap hlt-map, which is bound by default to prefix key C-x X. If you don't find C-x X convenient, you can bind the keymap to another key. Or if you want to use only some of the commands in the library, you can of course bind those individually to keys.)

Here is a screenshot, showing symbol nb highlighted and hl-line mode turned on. I use hl-line+.el, but that shouldn't matter here. I did nothing special -- no tweaking of overlay priorities etc. I just loaded highlight.el and hl-line+.el, turned on hl-line-mode, and used hlt-highlight-symbol.

enter image description here

Drew
  • 75,699
  • 9
  • 109
  • 225