0

The function org-tags-view allows you to build up semi-complex searches for tags using regexp:

(org-tags-view t "+PROP1={value}&+PROP2={[1-2]}")

However, regexp is very limited. Is there a way to search using some sort of matcher function that can, i.e., inspect an org header's properties, do some computations on them, and returns t or nil depending upon whether the computation matches in the way I specify?

  • If you have already read the advanced searching page of the org-mode manual -- orgmode.org/worg/org-tutorials/advanced-searching.html -- and if you did not find what you are looking for, then it may behoove you to create a minimal working example with a few headers with drawers (if applicable) and ask how to comb through all of the org-mode flat files defined by org-agenda-files (testing for a specified criteria) and someone can write-up a solution. – lawlist Jun 3 at 2:39
  • The org-agenda-skip-function is a custom function written to suit the needs of a user ... Here is a link to an example I wrote up a couple of years ago that looks for a date ... emacs.stackexchange.com/a/30194/2287 – lawlist Jun 3 at 3:03
0

Here's an example using org-search-view that adds the value of A and B and returns t when the sum of both numbers is equal to N. The regular expression at the end combines metadata and full text query, as explained here, but if you really want to avoid false positives you may have to use something more unique (like IDs, see (find-library "org-id.el")).

* Five
  :PROPERTIES:
  :A: 3
  :B: 2
  :END:

* Four
  :PROPERTIES:
  :A: 2
  :B: 2
  :END:
(defun n-equals-a-plus-b-p (n)
  (interactive "nNumber: ")
  (let (entries)
    (org-map-entries
     (lambda ()
       (let* ((el (org-element-at-point))
              (a (org-element-property :A el))
              (b (org-element-property :B el)))
         (when (and a b (= (+ (string-to-number a)
                              (string-to-number b))
                           n))
           (push (org-element-property :title el) entries))))
     nil 'agenda)
    (unless (null entries)
      (org-search-view nil (concat "+{^\\*\s\\("
                                   (mapconcat #'identity entries "\\|")
                                   "\\)} +{:\\(A\\|B\\):.}")))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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