summaryrefslogtreecommitdiff
path: root/lisp/sort.el
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1995-02-15 22:21:25 +0000
committerRichard M. Stallman <rms@gnu.org>1995-02-15 22:21:25 +0000
commitd6a5558f16bfb1b67603b3b97938200050a03dda (patch)
treea68df453e54e015ce2750a68f9235bbf51a8eed5 /lisp/sort.el
parent8e1c19d5d939a7e809c24c4b7d9fb6ca8b5a1e47 (diff)
downloademacs-d6a5558f16bfb1b67603b3b97938200050a03dda.tar.gz
(sort-regexp-fields-next-record): New subroutine.
If the first search does not advance point and finds an empty match, skip one char and search again. (sort-regexp-fields): Use that subroutine. Bind sort-regexp-fields-regexp, for sort-regexp-fields-next-record. (sort-regexp-fields-regexp): Declared. (sort-regexp-record-end): Declared.
Diffstat (limited to 'lisp/sort.el')
-rw-r--r--lisp/sort.el29
1 files changed, 23 insertions, 6 deletions
diff --git a/lisp/sort.el b/lisp/sort.el
index 11e87a18cdf..af7eb37fa9b 100644
--- a/lisp/sort.el
+++ b/lisp/sort.el
@@ -347,6 +347,25 @@ FIELD, BEG and END. BEG and END specify region to sort."
;; even if moving backwards.
(skip-chars-backward "^ \t\n")))
+(defvar sort-regexp-fields-regexp)
+(defvar sort-regexp-record-end)
+
+;; Move to the beginning of the next match for record-regexp,
+;; and set sort-regexp-record-end to the end of that match.
+;; If the next match is empty and does not advance point,
+;; skip one character and try again.
+(defun sort-regexp-fields-next-record ()
+ (let ((oldpos (point)))
+ (and (re-search-forward sort-regexp-fields-regexp nil 'move)
+ (setq sort-regexp-record-end (match-end 0))
+ (if (= sort-regexp-record-end oldpos)
+ (progn
+ (forward-char 1)
+ (re-search-forward sort-regexp-fields-regexp nil 'move)
+ (setq sort-regexp-record-end (match-end 0)))
+ t)
+ (goto-char (match-beginning 0)))))
+
;;;###autoload
(defun sort-regexp-fields (reverse record-regexp key-regexp beg end)
"Sort the region lexicographically as specified by RECORD-REGEXP and KEY.
@@ -378,15 +397,13 @@ sRegexp specifying key within record: \nr")
(save-restriction
(narrow-to-region beg end)
(goto-char (point-min))
- (let (sort-regexp-record-end) ;isn't dynamic scoping wonderful?
- (re-search-forward record-regexp)
+ (let (sort-regexp-record-end
+ (sort-regexp-fields-regexp record-regexp))
+ (re-search-forward sort-regexp-fields-regexp)
(setq sort-regexp-record-end (point))
(goto-char (match-beginning 0))
(sort-subr reverse
- (function (lambda ()
- (and (re-search-forward record-regexp nil 'move)
- (setq sort-regexp-record-end (match-end 0))
- (goto-char (match-beginning 0)))))
+ 'sort-regexp-fields-next-record
(function (lambda ()
(goto-char sort-regexp-record-end)))
(function (lambda ()