Is there an inverse for M-q, some kind of unfill-paragraph-function
?
If I have undo data, then it's of course easy. What I am asking for is instead the ability to merge lines in a paragraph into a single long line, right after I have just read the file from disk. This would make it possible to then paste the text into a form (a web form and the like) that is expecting a single linebreak for each paragraph.
In the past I have turned off auto-fill
, created a macro to delete an EOL and move to the next line, and applied it repeatedly, but this is getting tiring.
Here's the answer. In short:
(defun unfill-paragraph ()
"Replace newline chars in current paragraph by single spaces.
This command does the reverse of `fill-paragraph'."
(interactive)
(let ((fill-column 90002000))
(fill-paragraph nil)))
(defun unfill-region (start end)
"Replace newline chars in region by single spaces.
This command does the reverse of `fill-region'."
(interactive "r")
(let ((fill-column 90002000))
(fill-region start end)))
Update: I've packaged this up here and it can be installed from Marmalade or Melpa.
See also M-^ (delete-indentation).
It joins the current line to the previous line, so if you start with point at the last line of the paragraph you can keep pressing M-^ until all the lines are joined up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With