>> + (while (if outline-search-function >> + (funcall outline-search-function) >> + (re-search-forward outline-regexp nil t)) > > This changes the effect of the code because the new code searches for > a different regexp. Sorry, this was an attempt to unify code branches, but this change remained untested. Now fixed below. >> + (if outline-search-function >> + (funcall outline-search-function) >> + (re-search-forward >> + (concat "^\\(?:" outline-regexp "\\)") >> + nil 'move))) > > These two loops cons a new string each iteration. (So did the > original code, but if we are touching this, might as well fix that.) This is optimized as well: