Commit a08caf95 authored by Richard M. Stallman's avatar Richard M. Stallman
Browse files

*** empty log message ***

parent f8db4c01
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
"General text sorting routine to divide buffer into records and sort them. "General text sorting routine to divide buffer into records and sort them.
Arguments are REVERSE NEXTRECFUN ENDRECFUN &optional STARTKEYFUN ENDKEYFUN. Arguments are REVERSE NEXTRECFUN ENDRECFUN &optional STARTKEYFUN ENDKEYFUN.
We consider this portion of the buffer to be divided into disjoint pieces We divide the accessible portion of the buffer into disjoint pieces
called sort records. A portion of each sort record (perhaps all of it) called sort records. A portion of each sort record (perhaps all of it)
is designated as the sort key. The records are rearranged in the buffer is designated as the sort key. The records are rearranged in the buffer
in order by their sort keys. The records may or may not be contiguous. in order by their sort keys. The records may or may not be contiguous.
...@@ -50,22 +50,24 @@ It should move point to the end of the record. ...@@ -50,22 +50,24 @@ It should move point to the end of the record.
STARTKEYFUN may moves from the start of the record to the start of the key. STARTKEYFUN may moves from the start of the record to the start of the key.
It may return either return a non-nil value to be used as the key, or It may return either return a non-nil value to be used as the key, or
else the key will be the substring between the values of point after else the key is the substring between the values of point after
STARTKEYFUN and ENDKEYFUN are called. If STARTKEYFUN is nil, the key STARTKEYFUN and ENDKEYFUN are called. If STARTKEYFUN is nil, the key
starts at the beginning of the record. starts at the beginning of the record.
ENDKEYFUN moves from the start of the sort key to the end of the sort key. ENDKEYFUN moves from the start of the sort key to the end of the sort key.
ENDKEYFUN may be nil if STARTKEYFUN returns a value or if it would be the ENDKEYFUN may be nil if STARTKEYFUN returns a value or if it would be the
same as ENDRECFUN." same as ENDRECFUN."
;; Heuristically try to avoid messages if sorting a small amt of text.
(let ((messages (> (- (point-max) (point-min)) 50000)))
(save-excursion (save-excursion
(message "Finding sort keys...") (if messages (message "Finding sort keys..."))
(let* ((sort-lists (sort-build-lists nextrecfun endrecfun (let* ((sort-lists (sort-build-lists nextrecfun endrecfun
startkeyfun endkeyfun)) startkeyfun endkeyfun))
(old (reverse sort-lists))) (old (reverse sort-lists)))
(if (null sort-lists) (if (null sort-lists)
() ()
(or reverse (setq sort-lists (nreverse sort-lists))) (or reverse (setq sort-lists (nreverse sort-lists)))
(message "Sorting records...") (if messages (message "Sorting records..."))
(setq sort-lists (setq sort-lists
(if (fboundp 'sortcar) (if (fboundp 'sortcar)
(sortcar sort-lists (sortcar sort-lists
...@@ -90,9 +92,9 @@ same as ENDRECFUN." ...@@ -90,9 +92,9 @@ same as ENDRECFUN."
(lambda (a b) (lambda (a b)
(string< (car a) (car b))))))))) (string< (car a) (car b)))))))))
(if reverse (setq sort-lists (nreverse sort-lists))) (if reverse (setq sort-lists (nreverse sort-lists)))
(message "Reordering buffer...") (if messages (message "Reordering buffer..."))
(sort-reorder-buffer sort-lists old))) (sort-reorder-buffer sort-lists old)))
(message "Reordering buffer... Done")) (if messages (message "Reordering buffer... Done"))))
nil) nil)
;; Parse buffer into records using the arguments as Lisp expressions; ;; Parse buffer into records using the arguments as Lisp expressions;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment