Stefan Monnier <[email protected]> writes:

>> * Heading
>> <point>SCHEDULED: <...>
>>
>> How does it help with the fact that filling headings just cannot work -
>> they must always be on one line?
>
> It doesn't help: it should *not* move to that place, since the `*
> Heading` is not a (fillable) paragraph, whereas `fill-forward-paragraph`
> should move to the end of a (fillable) paragraph.

Are you sure it is how it is designed to work?
I just tried a quick test making fill-forward-paragraph-function return
its argument - never fill anything.
Then, M-x fill-region inf-loops.

>> It switches to dedicated buffer using block's major mode (in this case
>> emacs-lisp-mode), calls fill-paragraph there, using major mode settings,
>> and copies the result back to Org.
>
> Still a bit too short for me to understand the issue.
> If the command is `fill-paragraph`, presumably you have no problem using
> `fill-paragraph-function` to switch to the `emacs-lisp-mode` buffer and
> call `fill-paragraph` there (or maybe you do have problems because the
> inner `fill-paragraph` doesn't tell you the bounds of its effect?).

> I'd guess for `fill-region` (and thus indirectly `unfill-paragraph`),
> you'd similar use the `fill-forward-paragraph-function` and
> `fill-region-as-paragraph` hooks to switch to the `emacs-lisp-mode`
> buffer and re-call the function there.

Kinda, but I am not sure if that's going to work well.
fill-region-as-paragraph assumes that any region can be filled into a
single paragraph. But it is not always possible in Org. For example,
imagine that the region includes code block + something else. The best
Org can do in fill-region-as-paragraph is filling the code block
separately and the rest separately. But then we risk breaking the
general filling code that will assume that filling will create a single
paragraph block. Maybe I am missing something.
(My main issue is that the concept of filling region "as paragraph" does
not quite fit within Org markup).

>> However, in Org's context, filling region as paragraph does not always
>> make sense.
>
> Not all regions make sense, indeed.  It's the responsibility of the
> caller of `fill-region-as-paragraph` to make sure the region is indeed
> "a (fillable) paragraph".  Usually this is done by calling
> `fill-forward-paragraph` to determine the bounds of the region.

Is it? The docstring says

  "Fill the region as if it were a single paragraph.

It never hints that the region SHOULD be a single paragraph.
After all, what is the point of that function if there is fill-paragraph
already. It ought to do something else.

> I'd expect that `fill-region-as-paragraph-function` is usually concerned
> with things like indentation, preserving line-prefixes, preserving
> line-suffixes, etc...

Well... the default also joins paragraphs together:

   (defun fill-region-as-paragraph-default (from to &optional justify
                                                 nosqueeze squeeze-after)
     "Fill the region as if it were a single paragraph.
   This command removes any paragraph breaks in the region and
   extra newlines at the end...

-- 
Ihor Radchenko // yantar92,
Org mode maintainer,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

Reply via email to