TransWikia.com

fill-paragraph on multiple paragraphs at once

Emacs Asked on December 11, 2021

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.

One Answer

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.

Answered by Drew on December 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP