Mercurial > emacs
comparison lisp/sort.el @ 258:1e0bc00dca7a
*** empty log message ***
author | Jim Blandy <jimb@redhat.com> |
---|---|
date | Thu, 09 May 1991 21:50:55 +0000 |
parents | 4d8caa5e2cba |
children | 4cd7543be581 |
comparison
equal
deleted
inserted
replaced
257:e5ba2ba35226 | 258:1e0bc00dca7a |
---|---|
167 ;; Get rid of the separator " ". | 167 ;; Get rid of the separator " ". |
168 (goto-char (point-max)) | 168 (goto-char (point-max)) |
169 (narrow-to-region min (1+ (point))) | 169 (narrow-to-region min (1+ (point))) |
170 (delete-region (point) (1+ (point))))) | 170 (delete-region (point) (1+ (point))))) |
171 | 171 |
172 ;;;###autoload | |
172 (defun sort-lines (reverse beg end) | 173 (defun sort-lines (reverse beg end) |
173 "Sort lines in region alphabetically; argument means descending order. | 174 "Sort lines in region alphabetically; argument means descending order. |
174 Called from a program, there are three arguments: | 175 Called from a program, there are three arguments: |
175 REVERSE (non-nil means reverse order), BEG and END (region to sort)." | 176 REVERSE (non-nil means reverse order), BEG and END (region to sort)." |
176 (interactive "P\nr") | 177 (interactive "P\nr") |
178 (save-restriction | 179 (save-restriction |
179 (narrow-to-region beg end) | 180 (narrow-to-region beg end) |
180 (goto-char (point-min)) | 181 (goto-char (point-min)) |
181 (sort-subr reverse 'forward-line 'end-of-line)))) | 182 (sort-subr reverse 'forward-line 'end-of-line)))) |
182 | 183 |
184 ;;;###autoload | |
183 (defun sort-paragraphs (reverse beg end) | 185 (defun sort-paragraphs (reverse beg end) |
184 "Sort paragraphs in region alphabetically; argument means descending order. | 186 "Sort paragraphs in region alphabetically; argument means descending order. |
185 Called from a program, there are three arguments: | 187 Called from a program, there are three arguments: |
186 REVERSE (non-nil means reverse order), BEG and END (region to sort)." | 188 REVERSE (non-nil means reverse order), BEG and END (region to sort)." |
187 (interactive "P\nr") | 189 (interactive "P\nr") |
191 (goto-char (point-min)) | 193 (goto-char (point-min)) |
192 (sort-subr reverse | 194 (sort-subr reverse |
193 (function (lambda () (skip-chars-forward "\n \t\f"))) | 195 (function (lambda () (skip-chars-forward "\n \t\f"))) |
194 'forward-paragraph)))) | 196 'forward-paragraph)))) |
195 | 197 |
198 ;;;###autoload | |
196 (defun sort-pages (reverse beg end) | 199 (defun sort-pages (reverse beg end) |
197 "Sort pages in region alphabetically; argument means descending order. | 200 "Sort pages in region alphabetically; argument means descending order. |
198 Called from a program, there are three arguments: | 201 Called from a program, there are three arguments: |
199 REVERSE (non-nil means reverse order), BEG and END (region to sort)." | 202 REVERSE (non-nil means reverse order), BEG and END (region to sort)." |
200 (interactive "P\nr") | 203 (interactive "P\nr") |
217 (modify-syntax-entry ?\t " " table) | 220 (modify-syntax-entry ?\t " " table) |
218 (modify-syntax-entry ?\n " " table) | 221 (modify-syntax-entry ?\n " " table) |
219 (modify-syntax-entry ?\. "_" table) ; for floating pt. numbers. -wsr | 222 (modify-syntax-entry ?\. "_" table) ; for floating pt. numbers. -wsr |
220 (setq sort-fields-syntax-table table))) | 223 (setq sort-fields-syntax-table table))) |
221 | 224 |
225 ;;;###autoload | |
222 (defun sort-numeric-fields (field beg end) | 226 (defun sort-numeric-fields (field beg end) |
223 "Sort lines in region numerically by the ARGth field of each line. | 227 "Sort lines in region numerically by the ARGth field of each line. |
224 Fields are separated by whitespace and numbered from 1 up. | 228 Fields are separated by whitespace and numbered from 1 up. |
225 Specified field must contain a number in each line of the region. | 229 Specified field must contain a number in each line of the region. |
226 With a negative arg, sorts by the ARGth field counted from the right. | 230 With a negative arg, sorts by the ARGth field counted from the right. |
258 (re-search-forward | 262 (re-search-forward |
259 "[+-]?[0-9]*\.?[0-9]*\\([eE][+-]?[0-9]+\\)?") | 263 "[+-]?[0-9]*\.?[0-9]*\\([eE][+-]?[0-9]+\\)?") |
260 (point)))))) | 264 (point)))))) |
261 nil)) | 265 nil)) |
262 | 266 |
267 ;;;###autoload | |
263 (defun sort-fields (field beg end) | 268 (defun sort-fields (field beg end) |
264 "Sort lines in region lexicographically by the ARGth field of each line. | 269 "Sort lines in region lexicographically by the ARGth field of each line. |
265 Fields are separated by whitespace and numbered from 1 up. | 270 Fields are separated by whitespace and numbered from 1 up. |
266 With a negative arg, sorts by the ARGth field counted from the right. | 271 With a negative arg, sorts by the ARGth field counted from the right. |
267 Called from a program, there are three arguments: | 272 Called from a program, there are three arguments: |
301 (error "Line has too few fields: %s" | 306 (error "Line has too few fields: %s" |
302 (buffer-substring bol eol))) | 307 (buffer-substring bol eol))) |
303 (skip-chars-forward " \t"))) | 308 (skip-chars-forward " \t"))) |
304 | 309 |
305 | 310 |
311 ;;;###autoload | |
306 (defun sort-regexp-fields (reverse record-regexp key-regexp beg end) | 312 (defun sort-regexp-fields (reverse record-regexp key-regexp beg end) |
307 "Sort the region lexicographically as specifed by RECORD-REGEXP and KEY. | 313 "Sort the region lexicographically as specifed by RECORD-REGEXP and KEY. |
308 RECORD-REGEXP specifies the textual units which should be sorted. | 314 RECORD-REGEXP specifies the textual units which should be sorted. |
309 For example, to sort lines RECORD-REGEXP would be \"^.*$\" | 315 For example, to sort lines RECORD-REGEXP would be \"^.*$\" |
310 KEY specifies the part of each record (ie each match for RECORD-REGEXP) | 316 KEY specifies the part of each record (ie each match for RECORD-REGEXP) |
362 (error (throw 'key nil))))))))))) | 368 (error (throw 'key nil))))))))))) |
363 | 369 |
364 | 370 |
365 (defvar sort-columns-subprocess t) | 371 (defvar sort-columns-subprocess t) |
366 | 372 |
373 ;;;###autoload | |
367 (defun sort-columns (reverse &optional beg end) | 374 (defun sort-columns (reverse &optional beg end) |
368 "Sort lines in region alphabetically by a certain range of columns. | 375 "Sort lines in region alphabetically by a certain range of columns. |
369 For the purpose of this command, the region includes | 376 For the purpose of this command, the region includes |
370 the entire line that point is in and the entire line the mark is in. | 377 the entire line that point is in and the entire line the mark is in. |
371 The column positions of point and mark bound the range of columns to sort on. | 378 The column positions of point and mark bound the range of columns to sort on. |
404 (goto-char beg1) | 411 (goto-char beg1) |
405 (sort-subr reverse 'forward-line 'end-of-line | 412 (sort-subr reverse 'forward-line 'end-of-line |
406 (function (lambda () (move-to-column col-start) nil)) | 413 (function (lambda () (move-to-column col-start) nil)) |
407 (function (lambda () (move-to-column col-end) nil))))))))) | 414 (function (lambda () (move-to-column col-end) nil))))))))) |
408 | 415 |
416 ;;;###autoload | |
409 (defun reverse-region (beg end) | 417 (defun reverse-region (beg end) |
410 "Reverse the order of lines in a region. | 418 "Reverse the order of lines in a region. |
411 From a program takes two point or marker arguments, BEG and END." | 419 From a program takes two point or marker arguments, BEG and END." |
412 (interactive "r") | 420 (interactive "r") |
413 (if (> beg end) | 421 (if (> beg end) |