summaryrefslogtreecommitdiff
path: root/lisp/sort.el
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1993-07-23 04:44:06 +0000
committerRichard M. Stallman <rms@gnu.org>1993-07-23 04:44:06 +0000
commitfd719b0c70b512b7e10ebb141ae8e7c1e52f7ff4 (patch)
tree8b06eb80a19e51e8737d1a28d714eb1e53648fce /lisp/sort.el
parent9fb3cbe3d0a2c416a6d3701e0e8cb9dd5f0706cd (diff)
downloademacs-fd719b0c70b512b7e10ebb141ae8e7c1e52f7ff4.tar.gz
(sort-skip-fields): Really implement fields as runs
of nonwhitespace chars. (sort-fields, sort-float-fields, sort-numeric-fields): Don't subtract 1 when calling sort-skip-fields.
Diffstat (limited to 'lisp/sort.el')
-rw-r--r--lisp/sort.el50
1 files changed, 34 insertions, 16 deletions
diff --git a/lisp/sort.el b/lisp/sort.el
index c0135917687..0f3272cbe5f 100644
--- a/lisp/sort.el
+++ b/lisp/sort.el
@@ -253,7 +253,7 @@ If you want to sort floating-point numbers, try `sort-float-fields'."
(interactive "p\nr")
(sort-fields-1 field beg end
(function (lambda ()
- (sort-skip-fields (1- field))
+ (sort-skip-fields field)
(string-to-number
(buffer-substring
(point)
@@ -275,7 +275,7 @@ region to sort."
(interactive "p\nr")
(sort-fields-1 field beg end
(function (lambda ()
- (sort-skip-fields (1- field))
+ (sort-skip-fields field)
(string-to-number
(buffer-substring
(point)
@@ -295,7 +295,7 @@ FIELD, BEG and END. BEG and END specify region to sort."
(interactive "p\nr")
(sort-fields-1 field beg end
(function (lambda ()
- (sort-skip-fields (1- field))
+ (sort-skip-fields field)
nil))
(function (lambda () (skip-chars-forward "^ \t\n")))))
@@ -313,21 +313,39 @@ FIELD, BEG and END. BEG and END specify region to sort."
startkeyfun endkeyfun)))
(set-syntax-table tbl))))
+;; Position at the beginning of field N on the current line,
+;; assuming point is initially at the beginning of the line.
(defun sort-skip-fields (n)
- (let ((bol (point))
- (eol (save-excursion (end-of-line 1) (point))))
- (if (> n 0) (forward-word n)
- (end-of-line)
- (forward-word (1+ n)))
- (if (or (and (>= (point) eol) (> n 0))
- ;; this is marginally wrong; if the first line of the sort
- ;; at bob has the wrong number of fields the error won't be
- ;; reported until the next short line.
- (and (< (point) bol) (< n 0)))
+ (if (> n 0)
+ ;; Skip across N - 1 fields.
+ (let ((i (1- n)))
+ (while (> i 0)
+ (skip-chars-forward " \t")
+ (skip-chars-forward "^ \t\n")
+ (setq i (1- i)))
+ (skip-chars-forward " \t")
+ (recursive-edit)
+ (if (eolp)
+ (error "Line has too few fields: %s"
+ (buffer-substring
+ (save-excursion (beginning-of-line) (point))
+ (save-excursion (end-of-line) (point))))))
+ (end-of-line)
+ ;; Skip back across - N - 1 fields.
+ (let ((i (1- (- n))))
+ (while (> i 0)
+ (skip-chars-backward " \t")
+ (skip-chars-backward "^ \t\n")
+ (setq i (1- i)))
+ (skip-chars-backward " \t"))
+ (if (bolp)
(error "Line has too few fields: %s"
- (buffer-substring bol eol)))
- (skip-chars-forward " \t")))
-
+ (buffer-substring
+ (save-excursion (beginning-of-line) (point))
+ (save-excursion (end-of-line) (point)))))
+ ;; Position at the front of the field
+ ;; even if moving backwards.
+ (skip-chars-backward "^ \t\n")))
;;;###autoload
(defun sort-regexp-fields (reverse record-regexp key-regexp beg end)