How can I use elisp to search for headlines that return true against a predicate function? In particular, I already have an elisp function within-intervalp which checks whether a number num is within the range specified by property :INTERVAL: (at point). So for example if I have

* Parent
** Child1
:INTERVAL: [2,3]
*** Subchild1
:INTERVAL: [2,4]
** Child2
:INTERVAL: [5,7]
** Child3
:INTERVAL: [7,9]

and I run (within-intervalp 2.5), I'd like to see Child1 and Subchild1 pop up in a search. Is this possible?

1 Answer 1


You can use org-element-map to collect headlines that meet some criteria.

Something like this:

 (org-element-map (org-element-parse-buffer) 'headline
         (lambda (hl)
           (goto-char (org-element-property :begin hl))
           (when (within-intervalp 2.5)

should return a list of headlines meeting your criteria. You can then map over the list to return candidates for ivy/helm or some other selection engine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.