Unfilling regions in Emacs

March 3, 2010

I have the habit of hitting M-q every 5 seconds or so when working with text in emacs. This key combination is bound to "fill-paragraph" and inserts line breaks into the current paragraph to keep the line width to approximately 80 characters.

If you're cutting and pasting the text into an email message or website form though, this is often not what you want. The way round this is to "unfill" the current paragraph or region. The following commands will help:

(defun unfill-paragraph ()
  (interactive)
  (let ((fill-column (point-max)))
    (fill-paragraph nil)))

(defun unfill-region (start end)
  (interactive "r")
  (let ((fill-column (point-max)))
    (fill-region start end nil)))

But now you have lines in your emacs buffer that wrap in an unusable way. Longlines-mode to the rescue (M-x longlines-mode). Longlines mode uses "soft newlines" which will not show up when yanked or saved to disk.

I've recently added my emacs config to github. Feel free to have a poke around and let me know what other emacs tricks I am missing!

Discuss

blog comments powered by Disqus

Share