add predicate for checking DONE state changes

This commit is contained in:
Anh T Nguyen 2021-08-20 23:50:38 +07:00
parent 94f9e6f303
commit 277218ee88

View file

@ -60,6 +60,11 @@
Like `org-clock-line-re', but matches the timestamp range in a Like `org-clock-line-re', but matches the timestamp range in a
match group.") match group.")
(defconst org-ql-log-done-regexp
(rx bol "- State \"DONE\"" (1+ blank) "from \"WAITING\"" (1+ blank) (group (1+ not-newline)))
;; TODO: Remove hardcoded states, i.e DONE & WAITING
"Regular expression matching state changes")
(defconst org-ql-planning-regexp (defconst org-ql-planning-regexp
(rx bol (0+ blank) (or "CLOSED" "DEADLINE" "SCHEDULED") ":" (1+ blank) (group (1+ not-newline))) (rx bol (0+ blank) (or "CLOSED" "DEADLINE" "SCHEDULED") ":" (1+ blank) (group (1+ not-newline)))
"Regular expression matching Org \"planning\" lines. "Regular expression matching Org \"planning\" lines.
@ -1969,6 +1974,24 @@ ignored."
:body :body
(org-ql--predicate-ts :from from :to to :regexp org-ql-clock-regexp :match-group 1)) (org-ql--predicate-ts :from from :to to :regexp org-ql-clock-regexp :match-group 1))
(org-ql-defpred log-done (&key from to _on)
"Return non-nil if current entry contains DONE state change in given period."
:normalizers ((`(,predicate-names ,(and num-days (pred numberp)))
;; (clocked) and (closed) implicitly look into the past.
(let* ((from-day (* -1 num-days))
(rest (list :from from-day)))
(org-ql--normalize-from-to-on
`(log-done :from ,from))))
(`(,predicate-names . ,rest)
(org-ql--normalize-from-to-on
`(log-done :from ,from :to ,to))))
:preambles ((`(,predicate-names ,(pred numberp))
(list :regexp org-ql-log-done-regexp :query t))
(`(,predicate-names)
(list :regexp org-ql-log-done-regexp :query t)))
:body
(org-ql--predicate-ts :from from :to to :regexp org-ql-log-done-regexp :match-group 1))
(org-ql-defpred closed (&key from to _on) (org-ql-defpred closed (&key from to _on)
;; MAYBE: Use the new org-ql-regexps? ;; MAYBE: Use the new org-ql-regexps?
"Return non-nil if current entry was closed in given period. "Return non-nil if current entry was closed in given period.