Eli Zaretskii writes: > That's a beginning, thanks. But it needs more work, IMO: > > . the cons cell case hints on a possible return value of STARTKEYFUN, > AFAIU, but the text doesn't say so > . the case of STARTKEYFUN being nil is another use case for what > PREDICATE must cope with, and the text should say so > . the text about ENDKEYFUN should also be augmented, IMO > . the description of PREDICATE should reference this text in some > useful way I must admit I found the doc sufficient for all of these. Actually, reading the implementation might be simpler than describing it: #+begin_src emacs-lisp (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)))))) #+end_src What the doc is missing to mention is the `catch' - `sort-regexp-fields' uses this feature for example. Here is an attempt (not including the `catch' feature), anyway: