aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1995-02-15 22:21:25 +0000
committerRichard M. Stallman1995-02-15 22:21:25 +0000
commit387f3b2189c25476d26b95ad6c095d53bacc7f54 (patch)
tree516e9122009c72952a664a7b0b3fb2bfa19cb440
parentaebd973ee347bdf21ac75e70204295ec645fe7d9 (diff)
downloademacs-387f3b2189c25476d26b95ad6c095d53bacc7f54.tar.gz
emacs-387f3b2189c25476d26b95ad6c095d53bacc7f54.zip
(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.
-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."
347 ;; even if moving backwards. 347 ;; even if moving backwards.
348 (skip-chars-backward "^ \t\n"))) 348 (skip-chars-backward "^ \t\n")))
349 349
350(defvar sort-regexp-fields-regexp)
351(defvar sort-regexp-record-end)
352
353;; Move to the beginning of the next match for record-regexp,
354;; and set sort-regexp-record-end to the end of that match.
355;; If the next match is empty and does not advance point,
356;; skip one character and try again.
357(defun sort-regexp-fields-next-record ()
358 (let ((oldpos (point)))
359 (and (re-search-forward sort-regexp-fields-regexp nil 'move)
360 (setq sort-regexp-record-end (match-end 0))
361 (if (= sort-regexp-record-end oldpos)
362 (progn
363 (forward-char 1)
364 (re-search-forward sort-regexp-fields-regexp nil 'move)
365 (setq sort-regexp-record-end (match-end 0)))
366 t)
367 (goto-char (match-beginning 0)))))
368
350;;;###autoload 369;;;###autoload
351(defun sort-regexp-fields (reverse record-regexp key-regexp beg end) 370(defun sort-regexp-fields (reverse record-regexp key-regexp beg end)
352 "Sort the region lexicographically as specified by RECORD-REGEXP and KEY. 371 "Sort the region lexicographically as specified by RECORD-REGEXP and KEY.
@@ -378,15 +397,13 @@ sRegexp specifying key within record: \nr")
378 (save-restriction 397 (save-restriction
379 (narrow-to-region beg end) 398 (narrow-to-region beg end)
380 (goto-char (point-min)) 399 (goto-char (point-min))
381 (let (sort-regexp-record-end) ;isn't dynamic scoping wonderful? 400 (let (sort-regexp-record-end
382 (re-search-forward record-regexp) 401 (sort-regexp-fields-regexp record-regexp))
402 (re-search-forward sort-regexp-fields-regexp)
383 (setq sort-regexp-record-end (point)) 403 (setq sort-regexp-record-end (point))
384 (goto-char (match-beginning 0)) 404 (goto-char (match-beginning 0))
385 (sort-subr reverse 405 (sort-subr reverse
386 (function (lambda () 406 'sort-regexp-fields-next-record
387 (and (re-search-forward record-regexp nil 'move)
388 (setq sort-regexp-record-end (match-end 0))
389 (goto-char (match-beginning 0)))))
390 (function (lambda () 407 (function (lambda ()
391 (goto-char sort-regexp-record-end))) 408 (goto-char sort-regexp-record-end)))
392 (function (lambda () 409 (function (lambda ()