Wednesday, May 27, 2009

Remove Line Breaks in Paragraphs in Emacs

Include the following in your .emacs, or somewhere else:
(defun remove-line-breaks ()
"Remove line endings in a paragraph."
(interactive)
(let ((fill-column 90002000))
(fill-paragraph nil)))

(defun remove-all-line-breaks ()
"Remove all single line-breaks in a document"
(interactive)
(while (not (= (point) (buffer-end 1)))
(remove-line-breaks)
(next-line 1)))

Then position your cursor at the top of a stretch of paragraphs that need to have line breaks removed, and do:
M-x remove-all-line-breaks RET
It will remove all line breaks between there and the end of the buffer.