Function: reftex-index-sort-phrases
reftex-index-sort-phrases is an interactive and byte-compiled function
defined in reftex-index.el.gz.
Signature
(reftex-index-sort-phrases &optional CHARS-FIRST)
Documentation
Sort the phrases lines in the buffer alphabetically.
Normally, this looks only at the phrases. With a prefix arg CHARS-FIRST, it first compares the macro identifying chars and then the phrases.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/reftex-index.el.gz
(defun reftex-index-sort-phrases (&optional chars-first)
"Sort the phrases lines in the buffer alphabetically.
Normally, this looks only at the phrases. With a prefix arg CHARS-FIRST,
it first compares the macro identifying chars and then the phrases."
(interactive "P")
;; Remember the current line, so that we can return
(let ((line (buffer-substring (progn (beginning-of-line) (point))
(progn (end-of-line) (point))))
beg end)
(goto-char (point-min))
;; Find first and last phrase line in buffer
(setq beg
(and (re-search-forward reftex-index-phrases-phrase-regexp12 nil t)
(match-beginning 0)))
(goto-char (point-max))
(setq end (re-search-backward reftex-index-phrases-phrase-regexp12 nil t))
(if end (setq end (progn (goto-char end) (end-of-line) (point))))
;; Take the lines, sort them and re-insert.
(if (and beg end)
(let ((reftex--chars-first chars-first))
(message "Sorting lines...")
(let* ((lines (split-string (buffer-substring beg end) "\n"))
(lines1 (sort lines #'reftex-compare-phrase-lines)))
(message "Sorting lines...done")
(let ((inhibit-quit t)) ;; make sure we do not lose lines
(delete-region beg end)
(insert (mapconcat #'identity lines1 "\n"))))
(goto-char (point-max))
(re-search-backward (concat "^" (regexp-quote line) "$") nil t))
(error "Cannot find phrases lines to sort"))))