Stefan Monnier <[email protected]> writes:

>> But earlier you said that
>>
>> "it's the responsibility of the caller to make sure the region is indeed a 
>> fillable paragraph"
>>
>> Either these two statements contradict each other or I am missing something.
>
> By "make sure the region is indeed a fillable paragraph" I meant that
> it's the responsibility of the callers to make sure that *they* consider
> it as a fillable paragraph.

But the fill-paragraph-function has no idea about assumptions made by
the callers. It needs to operate with its own assumption about paragraph
syntax. So, if the region it is called on happens to contradict that
syntax, it cannot get anything other than - "ok, the caller wants to
treat the whole region as a single paragraph".

But in Org mode, it is simply impossible to treat certain regions as
single paragraph. I cannot "fill" something like

Normal text.
#+begin_src emacs-lisp
"Elisp code"
#+end_src

So, the only sane behavior will be filling as much as possible, but
leaving paragraph + code block as a sequence of two separate elements.

However, then, the caller may be confused, especially if it expects the
end result to be a single paragraph inside the requested region.

>>> What behavior would you find more intuitive?
>>> IOW, how would you change its behavior to make it more intuitive?
>> Given that I do not quite understand the intended API and behavior, I
>> have no clue what would be more intuitive. I just don't understand the
>> current design well enough.
>
> I don't know how else to describe it... OK, here's another try.
> The basic behavior of `fill-region-as-paragraph` is roughly:
>
>     (subst-char-in-region BEG END ?\n ?\s)
>     (goto-char BEG)
>     (while (progn (forward-char fill-column)
>                   (< (point) END))
>       (insert "\n"))
>
> Except it makes sure to insert the space only at appropriate places,
> counts columns instead of chars, takes care of `fill-prefix`, compacts
> sequences of whitespace into a single space, etc...
>
> Does that make sense?

So, in other words, it only joins the paragraphs on blank lines that are
either empty or only contain spaces (no tabs!). Page breaks and tabs
will remain separators and we may end up with multiple paragraph after
filling region "as paragraph".

Honestly, sounds like a bug reproducer.

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