2

I'm trying to use overlay to highlight a whole line but for some reason my overlay stops at the end of the line (past the last character) instead of the end of the physical line (just before fringe). I'm certainly missing something obvious. Using the code below, ;; Test is highlighted but I would have expected ;; Test .

;; Test

(save-excursion
  (goto-char 0)
  (let ((beg (point-at-bol))
        (end (min (point-max) (+ 1 (point-at-eol)))))
    (overlay-put (make-overlay beg end)
                 'face '(:background "#f0f0f0"))))

Update Answer given by @rpluim, I need to add a :extend t in the face definition.

3
  • point-at-eol tells you where the last character on the line is. Why would you expect it to give you the rightmost character position of the window?
    – rpluim
    Dec 18, 2020 at 13:00
  • 1
    Also I'd read about the :extend face attribute which is new in emacs-27
    – rpluim
    Dec 18, 2020 at 13:03
  • Tested it and it works. Dec 18, 2020 at 14:28

1 Answer 1

2

Starting in emacs-27 you can specify the :extend t attribute when creating the face, and the background will then extend to the right edge of the Emacs window.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.