Function: sort-paragraphs

sort-paragraphs is an autoloaded, interactive and byte-compiled function defined in sort.el.gz.

Signature

(sort-paragraphs REVERSE BEG END)

Documentation

Sort paragraphs in region alphabetically; argument means descending order.

Called from a program, there are three arguments: REVERSE (non-nil means reverse order), BEG and END (region to sort). The variable sort-fold-case determines whether alphabetic case affects the sort order.

View in manual

Probably introduced at or before Emacs version 18.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/sort.el.gz
;;;###autoload
(defun sort-paragraphs (reverse beg end)
  "Sort paragraphs in region alphabetically; argument means descending order.
Called from a program, there are three arguments:
REVERSE (non-nil means reverse order), BEG and END (region to sort).
The variable `sort-fold-case' determines whether alphabetic case affects
the sort order."
  (interactive "P\nr")
  (save-excursion
    (save-restriction
      (narrow-to-region beg end)
      (goto-char (point-min))
      (sort-subr reverse
		 (lambda ()
		   (while (and (not (eobp)) (looking-at paragraph-separate))
		     (forward-line 1)))
		 (lambda ()
                   (forward-paragraph)
                   ;; If the buffer doesn't end with a newline, add a
                   ;; newline to avoid having paragraphs being
                   ;; concatenated after sorting.
                   (when (and (eobp)
                              (not (bolp)))
                     (insert "\n")))))))