From b5ccc3294ec7942fa6a7eb041208b2b28c23ecd6 Mon Sep 17 00:00:00 2001 From: Adam Porter Date: Thu, 25 Jul 2019 07:51:28 -0500 Subject: [PATCH] Fix: (--select) Don't iterate over every heading with preamble Oops, using "when" instead of "while" did outline-next-heading even when re-search-forward found no more matches. That unnecessarily slowed down some searches, negating almost all of the gains. --- org-ql.el | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/org-ql.el b/org-ql.el index 2abeaa3..bb6e726 100644 --- a/org-ql.el +++ b/org-ql.el @@ -404,10 +404,11 @@ If NARROW is non-nil, buffer will not be widened." (goto-char (point-min)) (when (org-before-first-heading-p) (outline-next-heading)) - (cond (preamble-re (cl-loop when (and (when (re-search-forward preamble-re nil t) - (outline-back-to-heading 'invisible-ok) - t) - (funcall predicate)) + ;; `cl-loop' makes this double-while much clearer than the expanded form. + (cond (preamble-re (cl-loop while (and (when (re-search-forward preamble-re nil t) + (outline-back-to-heading 'invisible-ok) + t) + (funcall predicate)) collect (funcall action) while (outline-next-heading))) (t (cl-loop when (funcall predicate)