2

I often cut and paste non "filled" text into text files (mostly in org-mode). I then have to go line by line and call fill-paragraph or org-fill-paragraph in org-mode to clean up the text. I was wondering if there's a way to apply this operation to multiple paragraphs at once maybe in a region. For example, if we have the following paragraphs in org-mode with fill-column set to 20:

- This is the first paragraph.
- This is the second paragraph.

I'd like to mark both with a region, and then have them transform into:

- This is the first
  paragraph.
- This is the second
  paragraph.

It seems that fill-region is suppose to do this. I've tried calling it with various parameter combinations but it just condenses that entire region as one paragraph:

- This is the first
paragraph. - This
is the second
paragraph.
Drew
  • 75,699
  • 9
  • 109
  • 225
oneself
  • 289
  • 1
  • 10
  • 2
    This sounds like `fill-forward-paragraph-function` is not being set up correctly by org-mode. You should take this up with the org-mode developers. – rpluim Jul 23 '20 at 12:24
  • This works for me in org-mode 9.3 with emacs option -Q. Pasting long line text in list items into a new org-mode buffer and `C-x h M-q`. – Heikki Jul 24 '20 at 09:30
  • How can I fix `fill-forward-paragraph-function`? – oneself Jul 25 '20 at 14:05
  • Works fine for me: Org mode version 9.5.3 (release_9.5.3-526-g548632). Try with emacs -q? – NickD Jul 12 '22 at 20:24

1 Answers1

0

Dunno about Org mode, but in normal circumstances those two lines are not considered paragraphs, because they are separated only by a single newline character (C-j).

However, if you separate them by a blank line (i.e., another newline char), then M-x fill-region does what you expect:

- This is the first paragraph.

- This is the second paragraph.

becomes (assuming fill-column is 20):

- This is the first
  paragraph.

- This is the second
  paragraph.

See the Emacs manual, node Paragaphs, and the Elisp manual, node Standard Regexps. See, in particular, option paragraph-separate.

Drew
  • 75,699
  • 9
  • 109
  • 225
  • 1
    org-mode sets paragraph-separate correctly so that they are considered as separate paragraphs. It's just that it doesn't do the right thing with `fill-forward-paragraph-function` – rpluim Jul 23 '20 at 16:34