The first way is the most simple: First, set your fill-column variable to some huge number greater than the probable maximum number of characters in a single paragraph, like 10,000. Then select the whole document and invoke ``fill-individual-paragraphs.'' Remember, to set your fill-paragraph variable the key binding is C-x f. So to set it to 10,000 you'd hit C-u 10000 C-x f.
The second way is easier, but may only work if you're working on Linux or Unix, which has the following tool available. Simply highlight the area or the whole document, and type M-1 M-| fmt -w2000 This pipes the text to the GNU fmt (``format'') command with a paragraph width of 2000 characters. If you can remember the keystroke, this is the most elegant way to do it.11
If you're going to use this command frequently it may make sense to define it as a macro and bind a keystroke to it so you can evoke this function with a single keystroke (see section 8.1 for more info on macros and section 8.2 for more info on binding keys). This is the code you would add to your .emacs file:
(defun fix-screwed-up-paragraphs(beg end) (interactive "r") (shell-command-on-region beg end "fmt -w2000" nil t))