Function: pages-sort-region

pages-sort-region is an interactive and byte-compiled function defined in page-ext.el.gz.

Signature

(pages-sort-region REVERSE BEG END)

Documentation

Sort pages in region alphabetically. Prefix arg means reverse order.

Called from a program, there are three arguments: REVERSE (non-nil means reverse order), BEG and END (region to sort).

Key Bindings

Aliases

sort-pages-in-region (obsolete since 27.1)

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/page-ext.el.gz
(defun pages-sort-region (reverse beg end)
  "Sort pages in region alphabetically.  Prefix arg means reverse order.

Called from a program, there are three arguments:
REVERSE (non-nil means reverse order), BEG and END (region to sort)."

  ;; This sort function handles ends of pages differently than
  ;; `sort-pages' and works better with lists of addresses and similar
  ;; files.

  (interactive "P\nr")
  (save-restriction
    (narrow-to-region beg end)
    (goto-char (point-min))
    ;;; `sort-subr' takes three arguments
    (sort-subr reverse

               ;; NEXTRECFUN is called with point at the end of the
               ;; previous record. It moves point to the start of the
               ;; next record.
               (lambda ()
                 (re-search-forward page-delimiter nil t)
                 (skip-chars-forward " \t\n"))

               ;; ENDRECFUN is called with point within the record.
               ;; It should move point to the end of the record.
               (lambda ()
                 (if (re-search-forward
                      page-delimiter
                      nil
                      t)
                     (goto-char (match-beginning 0))
                   (goto-char (point-max)))))))