>> AFAIU `fill-forward-paragraph-function` should take care of such issues.
>> If it doesn't, maybe there's a bug in the way we use it or the way Org
>> defines it (where "it" is `fill-forward-paragraph-function`).
>
> With
> * Heading<point>
> SCHEDULED: <...>
>
> fill-forward-paragraph will move point to
>
> * 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.

>>> 2. A source block
>>>
>>> #+begin_src emacs-lisp
>>>   (if t
>>>      (message "Hello!")
>>>    (error "This should not happen!"))
>>> #+end_src
>>>
>>> When filling the source block, Org expedites part of the process to
>>> emacs-lisp-mode - something fill/unfill-paragraph has no idea about.
>>
>> Expedites part of the process ... of what exactly?
>> I think I'm missing some details to understand what is the issue.
>
> 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.

> 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.

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

> Also, fill-region-as-paragraph-function can be ignored when
> `use-hard-newlines' is non-nil. I think we discussed this aspect though.

Yup.  🙁


=== Stefan


Reply via email to