Subject: bug#78561: [PATCH] Add semantic linefeed support for paragraph filling

From: Eli Zaretskii <[email-masked]>
Date: Mon, 16 Jun 2025 13:51:55 +0300

> From: Roi Martin <[email-masked]>
> Cc: [email-masked], [email-masked]
> Date: Mon, 16 Jun 2025 12:14:46 +0200
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> >> Then, what's better?  Should we remove the following paragraph from the
> >> doc string of `fill-paragraph-semlf'?
> >> 
> >>   You can use this function as the value of ‘fill-paragraph-function’, so
> >>   ‘fill-paragraph’ and other filling commands will use it.
> >> 
> >> Or should we return t in `fill-paragraph-semlf'?
> >
> > I don't know.  Is returning fill-prefix useful in some important cases?
> 
> That's hard to say until we decide how to "wire" the semantic-linefeed
> functions with the generic functions already provided by fill.el.  For
> instance, coming back to some of the comments done by Stefan,
> 
> - How do we fill the paragraphs within the active region?  Should we add
>   a new `fill-region-function' variable and provide a
>   `fill-region-semlf' function?  Should we have a way to tell fill.el to
>   use a custom `fill-region-as-paragraph' function?
> - How do we change how major modes fill a paragraph or a region?  For
>   instance, in the case of org-mode, how do we combine org-mode's
>   fill-paragraph logic with semantic linefeeds?  Should the major mode
>   be in charge of providing this feature leveraging the existing
>   semantic-linefeed functions?  Should the user change a set of hooks?
>   What if the major mode already sets this hooks?

The active region case should be supported, IMO.  As for other modes,
what modes could usefully make use of this kind of region-filling?
Org mode might be the only one, but in that case it's something for
Org developers to chime in; I added Ihor to the discussion.

> Besides that, `fill-paragraph-semlf' calls `fill-forward-paragraph'
> internally, so it already takes into account what the major mode defines
> as paragraph.  And, `fill-region-as-paragraph-semlf' calls
> `fill-region-as-paragraph' internally, so if we add a hook to customize
> this function, it would take that into account.

Right.

> I guess the safest call for now is to provide `fill-paragraph-semlf' and
> `fill-region-as-paragraph-semlf' as commands that users or major modes
> can call directly.

That's what we currently do, right?

> What do you think?  Sorry, but I'm still wrapping my head around all the
> nuances of the filling code and how major modes make use of it.

I'd love to hear Stefan and Ihor to chime in and express their views.