comparison lisp/prim/sort.el @ 76:c0c698873ce1 r20-0b33

Import from CVS: tag r20-0b33
author cvs
date Mon, 13 Aug 2007 09:05:10 +0200
parents b9518feda344
children
comparison
equal deleted inserted replaced
75:a4e0195b387b 76:c0c698873ce1
46 buffer in order by their sort keys. The records may or may not be 46 buffer in order by their sort keys. The records may or may not be
47 contiguous. 47 contiguous.
48 48
49 Usually the records are rearranged in order of ascending sort key. 49 Usually the records are rearranged in order of ascending sort key.
50 If REVERSE is non-nil, they are rearranged in order of descending sort key. 50 If REVERSE is non-nil, they are rearranged in order of descending sort key.
51 The variable `sort-fold-case' determines whether alphabetic case affects
52 the sort order.
51 53
52 The next four arguments are functions to be called to move point 54 The next four arguments are functions to be called to move point
53 across a sort record. They will be called many times from within sort-subr. 55 across a sort record. They will be called many times from within sort-subr.
54 56
55 NEXTRECFUN is called with point at the end of the previous record. 57 NEXTRECFUN is called with point at the end of the previous record.
192 194
193 ;;;###autoload 195 ;;;###autoload
194 (defun sort-lines (reverse beg end) 196 (defun sort-lines (reverse beg end)
195 "Sort lines in region alphabetically; argument means descending order. 197 "Sort lines in region alphabetically; argument means descending order.
196 Called from a program, there are three arguments: 198 Called from a program, there are three arguments:
197 REVERSE (non-nil means reverse order), BEG and END (region to sort)." 199 REVERSE (non-nil means reverse order), BEG and END (region to sort).
200 The variable `sort-fold-case' determines whether alphabetic case affects
201 the sort order."
198 (interactive "P\nr") 202 (interactive "P\nr")
199 (save-excursion 203 (save-excursion
200 (save-restriction 204 (save-restriction
201 (narrow-to-region beg end) 205 (narrow-to-region beg end)
202 (goto-char (point-min)) 206 (goto-char (point-min))
204 208
205 ;;;###autoload 209 ;;;###autoload
206 (defun sort-paragraphs (reverse beg end) 210 (defun sort-paragraphs (reverse beg end)
207 "Sort paragraphs in region alphabetically; argument means descending order. 211 "Sort paragraphs in region alphabetically; argument means descending order.
208 Called from a program, there are three arguments: 212 Called from a program, there are three arguments:
209 REVERSE (non-nil means reverse order), BEG and END (region to sort)." 213 REVERSE (non-nil means reverse order), BEG and END (region to sort).
214 The variable `sort-fold-case' determines whether alphabetic case affects
215 the sort order."
210 (interactive "P\nr") 216 (interactive "P\nr")
211 (save-excursion 217 (save-excursion
212 (save-restriction 218 (save-restriction
213 (narrow-to-region beg end) 219 (narrow-to-region beg end)
214 (goto-char (point-min)) 220 (goto-char (point-min))
221 227
222 ;;;###autoload 228 ;;;###autoload
223 (defun sort-pages (reverse beg end) 229 (defun sort-pages (reverse beg end)
224 "Sort pages in region alphabetically; argument means descending order. 230 "Sort pages in region alphabetically; argument means descending order.
225 Called from a program, there are three arguments: 231 Called from a program, there are three arguments:
226 REVERSE (non-nil means reverse order), BEG and END (region to sort)." 232 REVERSE (non-nil means reverse order), BEG and END (region to sort).
233 The variable `sort-fold-case' determines whether alphabetic case affects
234 the sort order."
227 (interactive "P\nr") 235 (interactive "P\nr")
228 (save-excursion 236 (save-excursion
229 (save-restriction 237 (save-restriction
230 (narrow-to-region beg end) 238 (narrow-to-region beg end)
231 (goto-char (point-min)) 239 (goto-char (point-min))
252 Fields are separated by whitespace and numbered from 1 up. 260 Fields are separated by whitespace and numbered from 1 up.
253 Specified field must contain a number in each line of the region. 261 Specified field must contain a number in each line of the region.
254 With a negative arg, sorts by the ARGth field counted from the right. 262 With a negative arg, sorts by the ARGth field counted from the right.
255 Called from a program, there are three arguments: 263 Called from a program, there are three arguments:
256 FIELD, BEG and END. BEG and END specify region to sort. 264 FIELD, BEG and END. BEG and END specify region to sort.
265 The variable `sort-fold-case' determines whether alphabetic case affects
266 the sort order.
257 If you want to sort floating-point numbers, try `sort-float-fields'." 267 If you want to sort floating-point numbers, try `sort-float-fields'."
258 (interactive "p\nr") 268 (interactive "p\nr")
259 (sort-fields-1 field beg end 269 (sort-fields-1 field beg end
260 (function (lambda () 270 (function (lambda ()
261 (sort-skip-fields field) 271 (sort-skip-fields field)
384 Otherwise, it is a regular-expression for which to search within the record. 394 Otherwise, it is a regular-expression for which to search within the record.
385 If a match for KEY is not found within a record then that record is ignored. 395 If a match for KEY is not found within a record then that record is ignored.
386 396
387 With a negative prefix arg sorts in reverse order. 397 With a negative prefix arg sorts in reverse order.
388 398
399 The variable `sort-fold-case' determines whether alphabetic case affects
400 the sort order.
401
389 For example: to sort lines in the region by the first word on each line 402 For example: to sort lines in the region by the first word on each line
390 starting with the letter \"f\", 403 starting with the letter \"f\",
391 RECORD-REGEXP would be \"^.*$\" and KEY would be \"\\\\=\\<f\\\\w*\\\\>\"" 404 RECORD-REGEXP would be \"^.*$\" and KEY would be \"\\\\=\\<f\\\\w*\\\\>\""
392 ;; using negative prefix arg to mean "reverse" is now inconsistent with 405 ;; using negative prefix arg to mean "reverse" is now inconsistent with
393 ;; other sort-.*fields functions but then again this was before, since it 406 ;; other sort-.*fields functions but then again this was before, since it
418 ((re-search-forward 431 ((re-search-forward
419 key-regexp sort-regexp-record-end t) 432 key-regexp sort-regexp-record-end t)
420 (setq n 0)) 433 (setq n 0))
421 (t (throw 'key nil))) 434 (t (throw 'key nil)))
422 (condition-case () 435 (condition-case ()
423 (if (fboundp 'buffer-substring-lessp) 436 (if (fboundp 'compare-buffer-substrings)
424 (cons (match-beginning n) 437 (cons (match-beginning n)
425 (match-end n)) 438 (match-end n))
426 (buffer-substring (match-beginning n) 439 (buffer-substring (match-beginning n)
427 (match-end n))) 440 (match-end n)))
428 ;; if there was no such register 441 ;; if there was no such register
436 "Sort lines in region alphabetically by a certain range of columns. 449 "Sort lines in region alphabetically by a certain range of columns.
437 For the purpose of this command, the region includes 450 For the purpose of this command, the region includes
438 the entire line that point is in and the entire line the mark is in. 451 the entire line that point is in and the entire line the mark is in.
439 The column positions of point and mark bound the range of columns to sort on. 452 The column positions of point and mark bound the range of columns to sort on.
440 A prefix argument means sort into reverse order. 453 A prefix argument means sort into reverse order.
454 The variable `sort-fold-case' determines whether alphabetic case affects
455 the sort order.
441 456
442 Note that `sort-columns' rejects text that contains tabs, 457 Note that `sort-columns' rejects text that contains tabs,
443 because tabs could be split across the specified columns 458 because tabs could be split across the specified columns
444 and it doesn't know how to handle that. Also, when possible, 459 and it doesn't know how to handle that. Also, when possible,
445 it uses the `sort' utility program, which doesn't understand tabs. 460 it uses the `sort' utility program, which doesn't understand tabs.