Reputation: 1982
The function delete-indentation, usually bound to (M-^), joins the current line to the next one and deletes any indentation.
How do I apply this function to a whole region to join multiple lines in a region? Or is there another way to achieve the desired result?
Thanks
Upvotes: 3
Views: 120
Reputation: 17422
Try unfill-paragraph
, taken from the Emacs wiki.
;;; An unfill-paragraph that works in lisp modes
(defun unfill-paragraph (&optional region)
"Takes a multi-line paragraph and makes it into a single line of text."
(interactive (progn (barf-if-buffer-read-only) '(t)))
(let ((fill-column (point-max))
(emacs-lisp-docstring-fill-column t))
(fill-paragraph nil region)))
If you're willing to give up the prefix argument of the standard M-^, you could bind the following function to that keyboard shortcut like so:
(defun join-line-or-unfill-paragraph (&optional unfill)
(interactive "P")
(if unfill (unfill-paragraph) (delete-indentation)))
(global-set-key (kbd "M-^") 'join-line-or-unfill-paragraph)
This way, whenever you type C-u before M-^ the full paragraph will be joined.
Upvotes: 4