12

Q: is there a way to have hl-line-mode highlight the current line only in the selected window?

When I have multiple windows showing buffers with hl-line-mode on, it is difficult to tell, at a glance, which window is current.

I have the variable cursor-in-non-selected-windows set to nil to show the cursor only in the current window, but that visual cue is swamped by the highlighted lines in the windows.

Is there a similar setting to allow me to have hl-line-mode show the highlighted line only in the current window? Even better, is there a way to give the highlighted lines a different face when they're in inactive windows (analogous to mode-line-inactive)?

PS: yes, I can look at the mode line to tell which window is active, but doing so takes my eyes away from what I'm doing and breaks my concentration.

  • It seems that if you activate hl-line-mode with global-hl-line-mode (rather than calling hl-line-mode for each buffer) then only line the selected window is highlighted. – Iqbal Ansari Aug 28 '15 at 12:06
  • @IqbalAnsari: interesting! Unfortunately, I only want to use hl-line-mode in a few buffer types (occur, mu4e, etc.). I'll dig around in the source code when I get a moment. – Dan Aug 28 '15 at 12:09
9

You can set hl-line-sticky-flag to nil

hl-line-sticky-flag is a variable defined in hl-line.el.

Non-nil means the HL-Line mode highlight appears in all windows. Otherwise Hl-Line mode will highlight only in the selected window. Setting this variable takes effect the next time you use the command hl-line-mode to turn Hl-Line mode on.

This variable has no effect in Global Highlight Line mode. For that, use global-hl-line-sticky-flag.

  • 1
    Ha! I didn't know this was an option, and ended up writing my own: emacs.stackexchange.com/a/14658/780. I guess that approach has the benefit of letting you pick a different color for inactive windows, but I'll probably switch to this much simpler solution. – glucas Aug 28 '15 at 12:56

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.