0

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
:PROPERTIES:
:INTERVAL: [2,3]
:END:
*** Subchild1
:PROPERTIES:
:INTERVAL: [2,4]
:END:
** Child2
:PROPERTIES:
:INTERVAL: [5,7]
:END:
** Child3
:PROPERTIES:
:INTERVAL: [7,9]
:END:

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

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)
         hl)))

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 that you have read and understand our privacy policy and code of conduct.

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