next up previous contents
Next: Transposing Letters/Words/Lines Up: Formatting Your Text Previous: Word wrap   Contents

Reformatting Hard Wrapped Documents

If you have a document that has already been hard-wrapped, getting rid of all those newline characters and going back to soft wrapping is not quite intuitive either. One place where you'll run into this is reformatting plain text email for use in another program. Before you can do much with the text you need to get rid of the carriage return at the end of each line. There are two easy ways to do this.

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))


next up previous contents
Next: Transposing Letters/Words/Lines Up: Formatting Your Text Previous: Word wrap   Contents
Randall Wood 2011-03-31