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.

  • 1
    It is not a great idea, though not strictly forbidden, to cross-post the same question to both StackOverflow, tag emacs 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: stackoverflow.com/questions/20275596/…
    – 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. Jul 22 '15 at 2:03

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

(defun highlight-visual-line ()
    (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.

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.