summaryrefslogtreecommitdiff
path: root/lisp/sort.el
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1992-08-18 03:12:53 +0000
committerRichard M. Stallman <rms@gnu.org>1992-08-18 03:12:53 +0000
commit2b3adbdf454d36b07bbf662bb4d598a13f918d93 (patch)
tree0c0696f4149a579238ee37d5d6c2a4952f2c95da /lisp/sort.el
parentc0e9aece1f752d624375fb57036402aaa5d9ee11 (diff)
downloademacs-2b3adbdf454d36b07bbf662bb4d598a13f918d93.tar.gz
*** empty log message ***
Diffstat (limited to 'lisp/sort.el')
-rw-r--r--lisp/sort.el78
1 files changed, 40 insertions, 38 deletions
diff --git a/lisp/sort.el b/lisp/sort.el
index b03e9947824..dd238d326e5 100644
--- a/lisp/sort.el
+++ b/lisp/sort.el
@@ -28,7 +28,7 @@
"General text sorting routine to divide buffer into records and sort them.
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)
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.
@@ -50,49 +50,51 @@ 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.
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
starts at the beginning of the record.
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
same as ENDRECFUN."
- (save-excursion
- (message "Finding sort keys...")
- (let* ((sort-lists (sort-build-lists nextrecfun endrecfun
- startkeyfun endkeyfun))
- (old (reverse sort-lists)))
- (if (null sort-lists)
- ()
- (or reverse (setq sort-lists (nreverse sort-lists)))
- (message "Sorting records...")
- (setq sort-lists
- (if (fboundp 'sortcar)
- (sortcar sort-lists
- (cond ((numberp (car (car sort-lists)))
- ;; This handles both ints and floats.
- '<)
- ((consp (car (car sort-lists)))
- 'buffer-substring-lessp)
- (t
- 'string<)))
- (sort sort-lists
- (cond ((numberp (car (car sort-lists)))
- (function
- (lambda (a b)
- (< (car a) (car b)))))
- ((consp (car (car sort-lists)))
- (function
- (lambda (a b)
- (buffer-substring-lessp (car a) (car b)))))
- (t
- (function
- (lambda (a b)
- (string< (car a) (car b)))))))))
- (if reverse (setq sort-lists (nreverse sort-lists)))
- (message "Reordering buffer...")
- (sort-reorder-buffer sort-lists old)))
- (message "Reordering buffer... Done"))
+ ;; Heuristically try to avoid messages if sorting a small amt of text.
+ (let ((messages (> (- (point-max) (point-min)) 50000)))
+ (save-excursion
+ (if messages (message "Finding sort keys..."))
+ (let* ((sort-lists (sort-build-lists nextrecfun endrecfun
+ startkeyfun endkeyfun))
+ (old (reverse sort-lists)))
+ (if (null sort-lists)
+ ()
+ (or reverse (setq sort-lists (nreverse sort-lists)))
+ (if messages (message "Sorting records..."))
+ (setq sort-lists
+ (if (fboundp 'sortcar)
+ (sortcar sort-lists
+ (cond ((numberp (car (car sort-lists)))
+ ;; This handles both ints and floats.
+ '<)
+ ((consp (car (car sort-lists)))
+ 'buffer-substring-lessp)
+ (t
+ 'string<)))
+ (sort sort-lists
+ (cond ((numberp (car (car sort-lists)))
+ (function
+ (lambda (a b)
+ (< (car a) (car b)))))
+ ((consp (car (car sort-lists)))
+ (function
+ (lambda (a b)
+ (buffer-substring-lessp (car a) (car b)))))
+ (t
+ (function
+ (lambda (a b)
+ (string< (car a) (car b)))))))))
+ (if reverse (setq sort-lists (nreverse sort-lists)))
+ (if messages (message "Reordering buffer..."))
+ (sort-reorder-buffer sort-lists old)))
+ (if messages (message "Reordering buffer... Done"))))
nil)
;; Parse buffer into records using the arguments as Lisp expressions;