Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inverse of M-q, an unfill-paragraph-function

Tags:

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.

like image 428
Calaf Avatar asked Jul 15 '11 13:07

Calaf


2 Answers

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.

like image 93
sanityinc Avatar answered Oct 04 '22 22:10

sanityinc


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.

like image 20
David Röthlisberger Avatar answered Oct 04 '22 22:10

David Röthlisberger