Subject: Re: bug#42184: 27.0.91; org-fontify-whole-heading-line does not work in emacs 27

From: Kévin Le Gouguec <[email-masked]>
Date: Sun, 05 Jul 2020 18:02:04 +0200

Eli Zaretskii <[email-masked]> writes:

>> The only faces I added were org-level-[3-8], because I don't see why
>> different heading levels should not work with
>> org-fontify-whole-heading-line.
>
> The original code only affects certain heading levels, it doesn't
> affect all of them.

By "the original code", you mean this part in
org-set-font-lock-defaults, right?

> 	   `(,(if org-fontify-whole-heading-line
> 		  "^\\(\\**\\)\\(\\* \\)\\(.*\n?\\)"
> 		"^\\(\\**\\)\\(\\* \\)\\(.*\\)")

That seems to apply to all heading levels to me?  Group 1 captures all
but the last stars, group 2 the last star, and group 3 the heading text?

>                                                             Which is
> another aspect of your proposed patch I'd like to change: it seems to
> cause these faces be extended unconditionally, not just under these
> optional variables.  Or did I miss something?

IIUC, org-fontify-whole-heading-line (which predates :extend t) is Org's
way of letting users "opt in" to face extension, by applying the
org-level-* face to the final newline *iff* this user option is set.

Adding :extend t to the face definition thus will not cause the
backgrounds to extend unconditionally: as long as the user option is
unset, the final newline will not be fontified.

>> AFAICT, this is the simplest way to fix org-fontify-whole-heading-line
>> and org-fontify-whole-block-delimiter-line for Emacs ≥27.  These user
>> options work under the assumption that simply fontifying the final
>> newline is enough to extend attributes past EOL.
>
> Nevertheless, I would like to see the :extend attribute applied only
> under the above options; there's the set-face-extend function for
> doing that.

OK.  That's more or less what I had in mind when I went into my
"long-term fix" ideas.

Note that Org tries to support older Emacs versions.  AFAICT, with my
patch, (1) org-fontify-whole-heading-line is fixed for Emacs 27, (2) no
further modification is needed for Emacs ≤26.

I can try to cook up a patch based on set-face-extend instead, with all
the fboundp fun that entails to prevent byte-compiler warnings with
older Emacs versions.  I'm not sure where the calls to set-face-extend
should be inserted; when setting up the major mode?

At this point, I should probably wait for Org maintainers to chime in…