Function: sort-build-lists
sort-build-lists is a byte-compiled function defined in sort.el.gz.
Signature
(sort-build-lists NEXTRECFUN ENDRECFUN STARTKEYFUN ENDKEYFUN)
Source Code
;; Defined in /usr/src/emacs/lisp/sort.el.gz
;; Parse buffer into records using the arguments as Lisp expressions;
;; return a list of records. Each record looks like (KEY STARTPOS . ENDPOS)
;; where KEY is the sort key (a number or string),
;; and STARTPOS and ENDPOS are the bounds of this record in the buffer.
;; The records appear in the list lastmost first!
(defun sort-build-lists (nextrecfun endrecfun startkeyfun endkeyfun)
(let ((sort-lists ())
(start-rec nil)
done key)
;; Loop over sort records.
;(goto-char (point-min)) -- it is the caller's responsibility to
;arrange this if necessary
(while (not (eobp))
(setq start-rec (point)) ;save record start
(setq done nil)
;; Get key value, or move to start of key.
(setq key (catch 'key
(or (and startkeyfun (funcall startkeyfun))
;; If key was not returned as value,
;; move to end of key and get key from the buffer.
(let ((start (point)))
(funcall (or endkeyfun
(prog1 endrecfun (setq done t))))
(cons start (point))))))
;; Move to end of this record (start of next one, or end of buffer).
(cond ((prog1 done (setq done nil)))
(endrecfun (funcall endrecfun))
(nextrecfun (funcall nextrecfun) (setq done t)))
(if key (push
;; consing optimization in case in which key is same as record.
(if (and (consp key)
(equal (car key) start-rec)
(equal (cdr key) (point)))
(cons key key)
(cons key (cons start-rec (point))))
sort-lists))
(and (not done) nextrecfun (funcall nextrecfun)))
sort-lists))