alphapapa / org-ql

A searching tool for Org-mode, including custom query languages, commands, saved searches and agenda-like views, etc.
GNU General Public License v3.0
1.35k stars 104 forks source link

Expand DSL so we can check timestamps on specific properties #438

Open Trevoke opened 1 week ago

Trevoke commented 1 week ago

OS/platform

Linux

Emacs version and provenance

29 - compiled from source

Org version and provenance

9.7.5 - from elpa

org-ql package version and provenance

0.8.6 - melpa

Description

I would love to be able to write something like this:

;; find all headings with CUSTOM_PROP where the value is a timestamp in the past
(org-ql-search (org-agenda-files)
      '(property :CUSTOM_PROP '(ts-active :to :today)))

I know I can write custom code to match presence of CUSTOM_PROP and then do precise validation but I think it would be amazing if I could do this all within org-ql's DSL!

Etc.

No response

alphapapa commented 1 week ago

That's not a bad idea. It would be somewhere more than trivial but less than difficult to implement. I don't expect to have the time to work on this myself anytime soon.

In the meantime, it wouldn't take much code to do this now. Here are a couple of examples:

(org-ql-select BUFFERS
  `(when-let ((ts (property :CUSTOM_PROP)))
     (ts< (ts-parse-org ts) ,(ts-fill (ts-parse "2024-07-01")))))

;; With a custom predicate:

(org-ql-defpred property-ts< (property greater-ts)
  "Docstring."
  :body (when-let ((ts-value (org-entry-get nil property)))
          (ts< (ts-parse-org ts-value) greater-ts)))

(org-ql-select BUFFERS
  `(property-ts< :CUSTOM_PROP ,(ts-fill (ts-parse "2024-07-01"))))