<span class="mw-page-title-namespace">Blog</span><span class="mw-page-title-separator">:</span><span class="mw-page-title-main">Hacks/Collapsing paragraph into single-lines with Emacs</span>
Fabrice P. Lauss𝕪s ombifying Web

If you have a text like this:

He told Bill that humanity deserved to die horribly, since it had
behaved so cruelly and wastefully on a planet so sweet. "We're all
Heliogabalus, Bill," he would say. This was the name of a Roman
emperor who had a sculptor make a hollow, life-size iron bull with a
door on it. The door could be locked from the outside. The bull's
mouth was open. That was the only other opening to the outside.

Heliogabalus would have a human being put into the bull through the
door, and the door would be locked. Any sounds the human being made in
there would come out of the mouth of the bull. Heliogabalus would have
guests in for a nice party, with plenty of food and wine and beautiful
women and pretty boys–and Heliogabalus would have a servant light
kindling. The kindling was under dry firewood—which was under the
bull.

and would like it in a single line, like this:

He told Bill that humanity deserved to die horribly, since it had behaved so cruelly and wastefully on a planet so sweet. "We're all Heliogabalus, Bill," he would say. This was the name of a Roman emperor who had a sculptor make a hollow, life-size iron bull with a door on it. The door could be locked from the outside. The bull's mouth was open. That was the only other opening to the outside.

Heliogabalus would have a human being put into the bull through the door, and the door would be locked. Any sounds the human being made in there would come out of the mouth of the bull. Heliogabalus would have guests in for a nice party, with plenty of food and wine and beautiful women and pretty boys–and Heliogabalus would have a servant light kindling. The kindling was under dry firewood—which was under the bull.

(this is from Breakfast of Champions), you can Ctrl+^ through it with Emacs, but this is tedious for large chunks of text.

You can otherwise

M-x set-variable RET fill-column RET 999999 RET

and the M-q (i.e., M-x fill-paragraph) will do that. But I actually like M-q to break single lines into indented paragraphs.

A better option is to define new functions:

(defun join-paragraph ()
  "Join all lines in the current paragraph into a single line."
  (interactive)
  (save-excursion
    (let ((fill-column 999999))
      (fill-paragraph nil))))

(defun join-all-paragraphs-in-buffer ()
  "Join all lines in each paragraph of the buffer, preserving empty lines."
  (interactive)
  (save-excursion
    (let ((fill-column 999999))
      (fill-region (point-min) (point-max)))))

and bind them to keys:

(global-set-key (kbd "C-c M-q") 'join-paragraph)
(global-set-key (kbd "C-c M-Q") 'join-all-paragraphs-in-buffer)

so that C-c M-q fills a single-paragraph into a single line, while C-c M-Q processes the full buffer.

One may need such functionalities to avoid unwanted or broken indentation in text processed by a renderer (e.g., web forms).