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.
4
  • 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
    Commented Jul 23, 2020 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
    Commented Jul 24, 2020 at 9:30
  • How can I fix fill-forward-paragraph-function?
    – oneself
    Commented Jul 25, 2020 at 14:05
  • Works fine for me: Org mode version 9.5.3 (release_9.5.3-526-g548632). Try with emacs -q?
    – NickD
    Commented Jul 12, 2022 at 20:24

1 Answer 1

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.

1
  • 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
    Commented Jul 23, 2020 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.