diff options
| author | Gerd Moellmann | 2000-01-28 12:47:38 +0000 |
|---|---|---|
| committer | Gerd Moellmann | 2000-01-28 12:47:38 +0000 |
| commit | 5d6dd9631751565b4f6037d35bd93d4c2739338b (patch) | |
| tree | 3021004f3c9c04ee6f33957fc13b7ecbfb298324 | |
| parent | 3b43c01c60b4baf73c5d1813715e62e89dcdc544 (diff) | |
| download | emacs-5d6dd9631751565b4f6037d35bd93d4c2739338b.tar.gz emacs-5d6dd9631751565b4f6037d35bd93d4c2739338b.zip | |
(sort-numeric-base): New option.
(sort-numeric-fields): If number starts with `0' or `0[xX[',
interpret it as octal or hexadecimal. Use sort-numeric-base
as default base.
| -rw-r--r-- | lisp/sort.el | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/lisp/sort.el b/lisp/sort.el index 886d77eb40c..dc1cc453e22 100644 --- a/lisp/sort.el +++ b/lisp/sort.el | |||
| @@ -258,26 +258,40 @@ the sort order." | |||
| 258 | (modify-syntax-entry ?\. "_" table) ; for floating pt. numbers. -wsr | 258 | (modify-syntax-entry ?\. "_" table) ; for floating pt. numbers. -wsr |
| 259 | (setq sort-fields-syntax-table table))) | 259 | (setq sort-fields-syntax-table table))) |
| 260 | 260 | ||
| 261 | (defcustom sort-numeric-base 10 | ||
| 262 | "*The default base used by `sort-numeric-fields'." | ||
| 263 | :group 'sort | ||
| 264 | :type 'integer) | ||
| 265 | |||
| 261 | ;;;###autoload | 266 | ;;;###autoload |
| 262 | (defun sort-numeric-fields (field beg end) | 267 | (defun sort-numeric-fields (field beg end) |
| 263 | "Sort lines in region numerically by the ARGth field of each line. | 268 | "Sort lines in region numerically by the ARGth field of each line. |
| 264 | Fields are separated by whitespace and numbered from 1 up. | 269 | Fields are separated by whitespace and numbered from 1 up. |
| 265 | Specified field must contain a number in each line of the region. | 270 | Specified field must contain a number in each line of the region, |
| 271 | which may begin with \"0x\" or \"0\" for hexadecimal and octal values. | ||
| 272 | Otherwise, the number is interpreted according to sort-numeric-base. | ||
| 266 | With a negative arg, sorts by the ARGth field counted from the right. | 273 | With a negative arg, sorts by the ARGth field counted from the right. |
| 267 | Called from a program, there are three arguments: | 274 | Called from a program, there are three arguments: |
| 268 | FIELD, BEG and END. BEG and END specify region to sort." | 275 | FIELD, BEG and END. BEG and END specify region to sort." |
| 269 | (interactive "p\nr") | 276 | (interactive "p\nr") |
| 270 | (sort-fields-1 field beg end | 277 | (sort-fields-1 field beg end |
| 271 | (function (lambda () | 278 | (lambda () |
| 272 | (sort-skip-fields field) | 279 | (sort-skip-fields field) |
| 273 | (string-to-number | 280 | (let* ((case-fold-search t) |
| 274 | (buffer-substring | 281 | (base |
| 275 | (point) | 282 | (if (looking-at "\\(0x\\)[0-9a-f]\\|\\(0\\)[0-7]") |
| 276 | (save-excursion | 283 | (cond ((match-beginning 1) |
| 277 | ;; This is just wrong! Even without floats... | 284 | (goto-char (match-end 1)) |
| 278 | ;; (skip-chars-forward "[0-9]") | 285 | 16) |
| 279 | (forward-sexp 1) | 286 | ((match-beginning 2) |
| 280 | (point)))))) | 287 | (goto-char (match-end 2)) |
| 288 | 8) | ||
| 289 | (t nil))))) | ||
| 290 | (string-to-number (buffer-substring (point) | ||
| 291 | (save-excursion | ||
| 292 | (forward-sexp 1) | ||
| 293 | (point))) | ||
| 294 | (or base sort-numeric-base)))) | ||
| 281 | nil)) | 295 | nil)) |
| 282 | 296 | ||
| 283 | ;;;;;###autoload | 297 | ;;;;;###autoload |