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

From: Roi Martin <[email-masked]>
Date: Sun, 15 Jun 2025 11:12:49 +0200

Eli Zaretskii <[email-masked]> writes:

>> (setq-local fill-paragraph-function 'fill-paragraph-semlf)
>> 
>> or this
>> 
>> (setq-local fill-paragraph-function 'fill-region-as-paragraph-semlf)
>
> Neither, AFAIU?  Those two are commands, not fill-paragraph functions.
> They don't implement the protocol defined for fill-paragraph
> functions.

It should be possible to use `fill-paragraph-semlf' as
`fill-paragraph-function'.

It takes a JUSTIFY argument, which is required by:

  (funcall function justify)

in the specific case in `fill-paragraph' ("2. Try
fill-paragraph-function.").

  ;; 2. Try fill-paragraph-function.
  (and (not (eq fill-paragraph-function t))
            (or fill-paragraph-function
                (and (minibufferp (current-buffer))
                     (= 1 (point-min))))
            (let ((function (or fill-paragraph-function
                                ;; In the minibuffer, don't count
                                ;; the width of the prompt.
                                'fill-minibuffer-function))
                  ;; If fill-paragraph-function is set, it probably
                  ;; takes care of comments and stuff.  If not, it
                  ;; will have to set fill-paragraph-handle-comment
                  ;; back to t explicitly or return nil.
                  (fill-paragraph-handle-comment nil)
                  (fill-paragraph-function t))
              (funcall function justify)))

It also returns a non-nil value to avoid executing the following cases
in `fill-paragraph'.

Is there anything missing?

        Roi