5

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?

7

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

  • That's too bad. Do you know of some other modes that fit together better? – Emil Vikström Jun 17 '16 at 8:33
  • 2
    Yes, I updated the answer with this info. – Drew Jun 17 '16 at 13:29

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.