Function: unfill-paragraph
unfill-paragraph is an interactive and byte-compiled function defined
in fill.el.gz.
Signature
(unfill-paragraph ARG &optional BEG END)
Documentation
Join lines of this paragraph and fix up whitespace at joins.
Interactively, if the region is active, join lines of each paragraph in the region. A numeric prefix argument means join the lines of the following ARG paragraphs. In this case an active region is ignored.
With an active region and no prefix argument this is roughly the same as
delete-indentation with that active region, except that this command
only joins lines within paragraphs, preserving the paragraphs
themselves.
When called from Lisp, ARG is the number of following paragraphs to join lines within, or if ARG is nil, optional arguments BEG and END non-nil means to join the lines of each paragraph in the region delimited by BEG and END.
Probably introduced at or before Emacs version 31.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/fill.el.gz
(defun unfill-paragraph (arg &optional beg end)
"Join lines of this paragraph and fix up whitespace at joins.
Interactively, if the region is active, join lines of each paragraph in
the region. A numeric prefix argument means join the lines of the
following ARG paragraphs. In this case an active region is ignored.
With an active region and no prefix argument this is roughly the same as
`delete-indentation' with that active region, except that this command
only joins lines within paragraphs, preserving the paragraphs
themselves.
When called from Lisp, ARG is the number of following paragraphs to join
lines within, or if ARG is nil, optional arguments BEG and END non-nil
means to join the lines of each paragraph in the region delimited by BEG
and END."
(interactive "P\nR")
(when (or arg (not beg))
(let ((arg (prefix-numeric-value arg)))
(when (zerop arg)
(user-error "Invalid numeric argument to `unfill-paragraph'"))
(save-excursion
(fill-forward-paragraph 1)
(fill-forward-paragraph -1)
(setq beg (point))
(fill-forward-paragraph arg)
(setq end (point)))))
;; FIXME: It would be better to use
;;
;; (let ((fill-column (* (max 2 tab-width) (point-max))))
;; (fill-region beg end))
;;
;; multiplying by at least 2 to account for any wide characters in the
;; region to be filled and by at least `tab-width' to account for any
;; tab characters in the region to be filled. Then we can easily
;; prove that filling the region will actually unfill it.
;; However, `fill-region' fails if `fill-column' is not a fixnum.
(let ((fill-column most-positive-fixnum))
(fill-region beg end)))