- (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 ((floatp (car (car sort-lists)))
- 'f<)
- ((numberp (car (car sort-lists)))
- '<)
- ((consp (car (car sort-lists)))
- 'buffer-substring-lessp)
- (t
- 'string<)))
+ ;; 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)))
+ (function
+ (lambda (a b)
+ (> 0 (compare-buffer-substrings
+ nil (car a) (cdr a)
+ nil (car b) (cdr b))))))
+ (t
+ 'string<)))