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

From: Juri Linkov <[email-masked]>
Date: Mon, 16 Jun 2025 19:36:01 +0300

>> I tried to add to .dir-locals.el:
>>
>>   ((org-mode . ((fill-paragraph-function . fill-paragraph-semlf))))
>>
>> and it works nicely.
>
> That's interesting.  If I create an org-mode buffer and set
> `fill-paragraph-function' with:
>
>   (setq-local fill-paragraph-function #'fill-paragraph-semlf)
>
> Invoking `org-fill-paragraph' (bound to 'M-q') does not fill the
> paragraph using semantic linefeeds.  However, `fill-paragraph' does.
>
> I'll have to dig more into it.

Sorry, I added the following line to my config long ago,
and forgot about it:

  ;; Revert 'M-q' hijacked by org-mode:
  (define-key org-mode-map (vector 'remap 'fill-paragraph) nil)

>> With one exception that it fails on the active region.
>>
>> But we could add a new variable, e.g. 'fill-region-function'
>> that will be possible to customize to 'fill-region-as-paragraph-semlf'.
>
> Check these sub-threads,
>
> https://lists.gnu.org/archive/html/bug-gnu-emacs/2025-05/msg01088.html
> https://lists.gnu.org/archive/html/bug-gnu-emacs/2025-06/msg00920.html
>
> Maybe it is time to move the discussion to emacs-devel?

Probably better to create a new feature request on bug-gnu-emacs.

>> Although it's strange that 'fill-region-as-paragraph-semlf'
>> doesn't keep empty lines between paragraphs like 'fill-region' does.
>
> `fill-region-as-paragraph-semlf' is analogous to
> `fill-region-as-paragraph', so it removes any paragraph breaks in the
> region and extra newlines at the end, and fills lines within the region.

Then maybe we need another function `fill-region-semlf'.
I see that you already mentioned it earlier.

Another variant is to add a new argument `region' to `fill-paragraph-semlf'.
But the problem is that `fill-paragraph' doesn't forward its argument 
`region' to `fill-paragraph-function', i.e. there is

  (funcall function justify)

instead of

  (funcall function justify region)