/[emacs]/emacs/lisp/sort.el
ViewVC logotype

Diff of /emacs/lisp/sort.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.41 by monnier, Fri Apr 12 03:42:56 2002 UTC revision 1.41.2.1 by miles, Fri Apr 4 06:20:11 2003 UTC
# Line 1  Line 1 
1  ;;; sort.el --- commands to sort text in an Emacs buffer  ;;; sort.el --- commands to sort text in an Emacs buffer
2    
3  ;; Copyright (C) 1986, 1987, 1994, 1995 Free Software Foundation, Inc.  ;; Copyright (C) 1986, 1987, 1994, 1995, 2003 Free Software Foundation, Inc.
4    
5  ;; Author: Howie Kaye  ;; Author: Howie Kaye
6  ;; Maintainer: FSF  ;; Maintainer: FSF
# Line 42  Line 42 
42  ;;;###autoload  ;;;###autoload
43  (defun sort-subr (reverse nextrecfun endrecfun &optional startkeyfun endkeyfun)  (defun sort-subr (reverse nextrecfun endrecfun &optional startkeyfun endkeyfun)
44    "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.  
45    
46  We divide the accessible portion of the buffer into disjoint pieces  We divide the accessible portion of the buffer into disjoint pieces
47  called sort records.  A portion of each sort record (perhaps all of  called sort records.  A portion of each sort record (perhaps all of
# Line 97  same as ENDRECFUN." Line 96  same as ENDRECFUN."
96                                     ((consp (car (car sort-lists)))                                     ((consp (car (car sort-lists)))
97                                      (function                                      (function
98                                       (lambda (a b)                                       (lambda (a b)
99                                         (> 0 (compare-buffer-substrings                                         (> 0 (compare-buffer-substrings
100                                               nil (car a) (cdr a)                                               nil (car a) (cdr a)
101                                               nil (car b) (cdr b))))))                                               nil (car b) (cdr b))))))
102                                     (t                                     (t
# Line 108  same as ENDRECFUN." Line 107  same as ENDRECFUN."
107                                ((consp (car (car sort-lists)))                                ((consp (car (car sort-lists)))
108                                 (function                                 (function
109                                  (lambda (a b)                                  (lambda (a b)
110                                    (> 0 (compare-buffer-substrings                                    (> 0 (compare-buffer-substrings
111                                          nil (car (car a)) (cdr (car a))                                          nil (car (car a)) (cdr (car a))
112                                          nil (car (car b)) (cdr (car b)))))))                                          nil (car (car b)) (cdr (car b)))))))
113                                (t                                (t
# Line 193  same as ENDRECFUN." Line 192  same as ENDRECFUN."
192        (set-buffer old-buffer)        (set-buffer old-buffer)
193        (let ((inhibit-quit t))        (let ((inhibit-quit t))
194          ;; Make sure insertions done for reordering          ;; Make sure insertions done for reordering
195          ;; do not go after any markers at the end of the sorted region,          ;; saves any markers at the end of the sorted region,
196          ;; by inserting a space to separate them.          ;; by leaving the last character of the region.
197          (goto-char max)          (delete-region min (1- max))
198          (insert-before-markers " ")          ;; Now replace the one remaining old character with the sorted text.
199          ;; Delete the original copy of the text.          (goto-char (point-min))
         (delete-region min max)  
         ;; Now replace the separator " " with the sorted text.  
         (goto-char (point-max))  
200          (insert-buffer-substring temp-buffer)          (insert-buffer-substring temp-buffer)
201          (delete-region min (1+ min))))))          (delete-region max (1+ max))))))
202    
203  ;;;###autoload  ;;;###autoload
204  (defun sort-lines (reverse beg end)  (defun sort-lines (reverse beg end)
205    "Sort lines in region alphabetically; argument means descending order.    "Sort lines in region alphabetically; argument means descending order.
206  Called from a program, there are three arguments:  Called from a program, there are three arguments:
207  REVERSE (non-nil means reverse order), BEG and END (region to sort).  REVERSE (non-nil means reverse order), BEG and END (region to sort).
# Line 429  For example: to sort lines in the region Line 425  For example: to sort lines in the region
425    ;; using negative prefix arg to mean "reverse" is now inconsistent with    ;; using negative prefix arg to mean "reverse" is now inconsistent with
426    ;; other sort-.*fields functions but then again this was before, since it    ;; other sort-.*fields functions but then again this was before, since it
427    ;; didn't use the magnitude of the arg to specify anything.    ;; didn't use the magnitude of the arg to specify anything.
428    (interactive "P\nsRegexp specifying records to sort:    (interactive "P\nsRegexp specifying records to sort:
429  sRegexp specifying key within record: \nr")  sRegexp specifying key within record: \nr")
430    (cond ((or (equal key-regexp "") (equal key-regexp "\\&"))    (cond ((or (equal key-regexp "") (equal key-regexp "\\&"))
431           (setq key-regexp 0))           (setq key-regexp 0))
# Line 441  sRegexp specifying key within record: \n Line 437  sRegexp specifying key within record: \n
437        (goto-char (point-min))        (goto-char (point-min))
438        (let (sort-regexp-record-end        (let (sort-regexp-record-end
439              (sort-regexp-fields-regexp record-regexp))              (sort-regexp-fields-regexp record-regexp))
440          (re-search-forward sort-regexp-fields-regexp)          (re-search-forward sort-regexp-fields-regexp nil t)
441          (setq sort-regexp-record-end (point))          (setq sort-regexp-record-end (point))
442          (goto-char (match-beginning 0))          (goto-char (match-beginning 0))
443          (sort-subr reverse          (sort-subr reverse

Legend:
Removed from v.1.41  
changed lines
  Added in v.1.41.2.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26