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

From: Roi Martin <[email-masked]>
Date: Tue, 17 Jun 2025 08:49:36 +0200

Juri Linkov <[email-masked]> writes:

>> I expect it would make more sense to introduce
>> a `fill-region-as-paragraph-function`, so `fill-region` will DTRT after
>> you set that var to `fill-region-as-paragraph-semlf`.  Instead of having
>> to reinvent/duplicate the code of `fill-region` in a new
>> `fill-region-semlf`.
>
> AFAIS, they have a significant difference: `fill-region-as-paragraph`
> merges all selected paragraphs into one paragraph, but `fill-region`
> formats each paragraph separately, keeping separators (empty lines)
> between them.

If I'm not wrong, `fill-region' calls `fill-region-as-paragraph'
internally,

  (defun fill-region (from to &optional justify nosqueeze to-eop)
    ;; ...
  	    (setq fill-pfx
  		  (fill-region-as-paragraph (point) end justify nosqueeze))
    ;; ...
      fill-pfx))

And `fill-paragraph' calls `fill-region' if Transient Mark mode is
enabled and the mark is active.

So, the idea is to define a new variable
`fill-region-as-paragraph-function' so `fill-region' uses this variable
instead of calling `fill-region-as-paragraph' directly.

Stefan, I'll send a new patch to support this.  I'll also modify
`fill-paragraph-semlf' to respect the `fill-paragraph-function' protocol
(i.e. return t).

        Roi