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.
  • 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 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 at 9:30
  • How can I fix fill-forward-paragraph-function? – oneself Jul 25 at 14:05
1

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.

| improve this answer | |
  • 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 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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