Subject: bug#65896: 30.0.50; folding text with text properties prevents background from extending past the newline

From: StrawberryTea <[email-masked]>
Date: Sat, 30 Sep 2023 17:55:27 -0500

Basically, I want to be able to do this in Org mode:
<https://pasteboard.co/E17ioBts7HTl.png>

So I want a way to extend the heading background even when the heading is
folded. Currently this works when there are no nested headings:

(advice-add #’org-fold-core-region :around #’cae-org-fold-region-a)
(defun cae-org-fold-region-a (oldfun from to flag &optional spec-or-alias)
  (let ((shift-fold-p (and (eq to (point-max)) (not (eq from to)) flag)))
    (when shift-fold-p
      (setq to (1- to)))
    (funcall oldfun from to flag spec-or-alias)
    (remove-overlays from (1+ to) ’cae-org-fold-heading t)
    (when flag
      (let ((o (make-overlay to (1+ to) nil ’front-advance)))
        (overlay-put o ’evaporate t)
        (overlay-put o ’cae-org-fold-heading t)
        (overlay-put o ’face (save-excursion (goto-char from) (face-at-point)))
        (when shift-fold-p
          (overlay-put o ’display “\n”))))))

Basically, when the text is folded, it uses the face of the first visible
newline after the fold to determine the background.

The elisp approach is to maintain overlays at the end of each folded region and
it becomes complicated with nested headings. I was thinking that instead, we
could have the extend property (or an extra option on :extend) be used within
the line to colorize the background of the newline at the end.

Eli Zaretskii <[email-masked]> writes:

>> From: StrawberryTea <[email-masked]>
>> Cc: Kévin Le Gouguec <[email-masked]>, Eli
>>  Zaretskii
>>  <[email-masked]>, [email-masked], Ihor Radchenko
>>  <[email-masked]>
>> Date: Fri, 29 Sep 2023 14:07:17 -0500
>>
>> Basically, it’s always possible to overlay the newline after a fold or shorten
>> the fold by one character and overlay a newline for the last character then set
>> a face and extend property for that newline.
>
> Sorry, I don’t think I follow.  Could you please show some example of
> this, perhaps with “ASCII art”?  What do you mean by “overlay the
> newline”, and what is “the fold” in this context?
>
>> What I think could be an alternative to adding all these overlays is a change on
>> the display engine side so that the extend property on a character extends its
>> face background regardless of whether it’s a newline character.
>
> That is a non-starter, since there’s no text in that part.  We don’t
> show any parts of the text area with any face unless that part is “in
> the middle of text”, and the part after EOB isn’t.