2

I want to have a single line in a long-word wrapped line highlighted. The default setting of hl-line seems to highlight the whole wrapped line as shown below.

enter image description here

Which setting do I have to change to highlight only the line in which the cursor is located in a longer wrapped line? In the screenshot this would be the first line of the text.

Drew
  • 75,699
  • 9
  • 109
  • 225
  • 1
    It is not a great idea, though not strictly forbidden, to cross-post the same question to both [StackOverflow, tag emacs](http://stackoverflow.com/q/31541907/729907) and this site. Since you have already gotten answers there, consider deleting your question here. – Drew Jul 21 '15 at 16:31
  • There is a prior thread on stackoverflow.com that already contains an answer to this question: http://stackoverflow.com/questions/20275596/how-to-use-hl-line-mode-to-highlight-just-one-1-line-when-visual-line-mode-is – lawlist Jul 21 '15 at 20:33
  • Sorry, for double posting. Was my first question asked ever, and I did not find the answer on stackoverflow. Thank you for your answers. – user3607807 Jul 22 '15 at 02:03

1 Answers1

3

I've had this in my init.el for a while:

(defun highlight-visual-line ()
  (save-excursion
    (cons (progn (beginning-of-visual-line) (point))
          (progn (end-of-visual-line) (point)))))

(setq hl-line-range-function 'highlight-visual-line)

This is assuming you use (global-hl-line-mode 1) to achieve that highlighting. I probably posted this as an answer either in this forum, or in SO section for Emacs questions, but cannot find it at the moment.

wvxvw
  • 11,222
  • 2
  • 30
  • 55