In a list of files I have org tasks with the property E such that each E is marked with an interval range.

* Some task1
:E: [E1, E3]

* Some task2
:E: [E4, E7]

...and so forth.

Question: How can I search through files and obtain an agenda view of all tasks that intersect within a range min to max?

So for example (search files 3 7) should display tasks that have, i,e., [E2, E4], [E4, E5] or [E6, E8] but not display tasks have [E1, E2] or [E8, E9].

1 Answer 1


First collect the range of all entries that have an :E: property, and then check which of those intersect with the MIN to MAX range (see cl-intersection). Finally, create a regular expression of all entries matched, passing it to the org-search-view function.

(defun get-range (min max)
  (cl-loop for range from min to max
           collect range))

(defun search (files min max)
  (let (regexp
        (org-agenda-files files))
     (lambda ()
       (when-let* ((el (org-element-at-point))
                   (e (org-element-property :E el))
                   (range (replace-regexp-in-string "[^[:digit:] ]" "" e))
                   (range (mapcar 'string-to-number (split-string range " ")))
                   (range (get-range (cl-first range) (cl-second range)))
                   (line (regexp-quote e)))
         (when (and (cl-intersection range (get-range min max))
                    (not (member line lines)))
           (push line lines)
           (setq regexp (mapconcat #'identity lines "\\|")))))
     nil 'agenda)
    (unless (null lines)
      (org-search-view nil (concat "{" regexp "}")))))

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.