Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to undo fill-paragraph in emacs?

I have a text file that is pretty long. Any easy way to "undo" a M-q (fill-paragraph) on a file that was written and saved a while ago?

For example, I want to change this:

They're coming to take me away, ha-haaa!!
They're coming to take me away, ho-ho, hee-hee, ha-haaa

To the funny farm. Where life is beautiful all the time and I'll
be happy to see those nice young men in their clean white
coats and they're coming to take me away, ha-haaa!!!!!

To this:

They're coming to take me away, ha-haaa!! They're coming to take me away, ho-ho, hee-hee, ha-haaa

To the funny farm. Where life is beautiful all the time and I'll be happy to see those nice young men in their clean white coats and they're coming to take me away, ha-haaa!!!!!

like image 523
Upgradingdave Avatar asked Mar 18 '10 16:03

Upgradingdave


People also ask

What is fill paragraph?

The command M-q ( fill-paragraph ) fills the current paragraph. It redistributes the line breaks within the paragraph, and deletes any excess space and tab characters occurring within the paragraph, in such a way that the lines end up fitting within a certain maximum width.

How do I set fill columns in Emacs?

The easiest way to set fill-column is to use the command C-x f ( set-fill-column ). With a numeric argument, it uses that as the new fill column. With just C-u as argument, it sets fill-column to the current horizontal position of point.


4 Answers

Use the following from my .emacs:

(defun unfill-paragraph ()
  (interactive)
  (let ((fill-column (point-max)))
    (fill-paragraph nil)))

(defun unfill-region ()
  (interactive)
  (let ((fill-column (point-max)))
    (fill-region (region-beginning) (region-end) nil)))

I can't take credit, I googled this years ago.

like image 88
Doug Harris Avatar answered Sep 29 '22 08:09

Doug Harris


You can set fill-columnn to a really large number, and fill.

C-u 10000 C-x f M-x fill-individual-paragraphs

Or you can use a little custom function:

(defun refill-paragraphs-to-be-one-line ()
  "fill individual paragraphs with large fill column"
  (interactive)
  (let ((fill-column 100000))
    (fill-individual-paragraphs (point-min) (point-max))))
like image 38
Trey Jackson Avatar answered Sep 29 '22 06:09

Trey Jackson


When I asked for help on M-Q (as opposed to M-q) in emacs 24.4.1, I got this:

M-Q (translated from <escape> Q) runs the command unfill-paragraph, which is an
interactive Lisp function in `init-util.el'.

It is bound to M-Q.

(unfill-paragraph &optional REGION)

Takes a multi-line paragraph and makes it into a single line of text.
like image 24
mpersico Avatar answered Sep 29 '22 06:09

mpersico


C-x f 100000 M-q

This fills exactly one paragraph.

Explanation:

  1. C-x f Number: Set a large number (100 000) of characters for the column.
  2. M-q: Invoke the fill-paragraph command. (Alternative for multiple paragraphs: M-x fill-individual-paragraphs)

Afterwards, don't forget to revert the column width back to the previous value (here: 78).

C-x f 78
like image 33
untill Avatar answered Sep 29 '22 06:09

untill