diff options
author | Lars Ingebrigtsen <larsi@gnus.org> | 2022-02-03 20:33:58 +0100 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2022-02-03 20:33:58 +0100 |
commit | 2ded5938753a2fac94e5aebce2e97fc5b4d91076 (patch) | |
tree | 591ad647fd45ef7e570fd8aad497fbf7f5a42581 /lisp | |
parent | e3516ec28f9a3fc81bffcf2d64a0d9e883a0ff26 (diff) | |
download | emacs-2ded5938753a2fac94e5aebce2e97fc5b4d91076.tar.gz emacs-2ded5938753a2fac94e5aebce2e97fc5b4d91076.tar.bz2 emacs-2ded5938753a2fac94e5aebce2e97fc5b4d91076.zip |
Make sort-numeric-fields resilient towards blank lines
* lisp/sort.el (sort-numeric-fields): Don't signal an error on
blank lines (bug#31800).
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/sort.el | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/lisp/sort.el b/lisp/sort.el index eb8e2787d1e..90eee01caf4 100644 --- a/lisp/sort.el +++ b/lisp/sort.el @@ -286,25 +286,30 @@ FIELD, BEG and END. BEG and END specify region to sort." (interactive "p\nr") (let ;; To make `end-of-line' and etc. to ignore fields. ((inhibit-field-text-motion t)) - (sort-fields-1 field beg end - (lambda () - (sort-skip-fields field) - (let* ((case-fold-search t) - (base - (if (looking-at "\\(0x\\)[0-9a-f]\\|\\(0\\)[0-7]") - (cond ((match-beginning 1) - (goto-char (match-end 1)) - 16) - ((match-beginning 2) - (goto-char (match-end 2)) - 8) - (t nil))))) - (string-to-number (buffer-substring (point) - (save-excursion - (forward-sexp 1) - (point))) - (or base sort-numeric-base)))) - nil))) + (sort-fields-1 + field beg end + (lambda () + ;; Don't try to parse blank lines (they'll be + ;; sorted at the start). + (if (looking-at "[\t ]*$") + 0 + (sort-skip-fields field) + (let* ((case-fold-search t) + (base + (if (looking-at "\\(0x\\)[0-9a-f]\\|\\(0\\)[0-7]") + (cond ((match-beginning 1) + (goto-char (match-end 1)) + 16) + ((match-beginning 2) + (goto-char (match-end 2)) + 8) + (t nil))))) + (string-to-number (buffer-substring (point) + (save-excursion + (forward-sexp 1) + (point))) + (or base sort-numeric-base))))) + nil))) ;;;;;###autoload ;;(defun sort-float-fields (field beg end) |