WIP: Add more keys

This commit is contained in:
Adam Porter 2021-08-31 03:07:50 -05:00
parent ab91209e2c
commit 7540e81f09

View file

@ -141,6 +141,34 @@ Returns in format \"%Y-%m-%d\"."
(org-element-property :closed element)) (org-element-property :closed element))
"Planned")) "Planned"))
(taxy-org-ql-view-define-key category ()
"Return ELEMENT's category."
(org-with-point-at (org-element-property :org-hd-marker element)
(org-get-category)))
(defun taxy-org-ql--latest-timestamp-in (regexp element)
"Return the latest timestamp matching REGEXP in ELEMENT.
Searches in ELEMENT's buffer."
(org-with-point-at (org-element-property :org-hd-marker element)
(let* ((limit (org-entry-end-position))
(tss (cl-loop for next-ts =
(when (re-search-forward regexp limit t)
(ts-parse-org (match-string 1)))
while next-ts
collect next-ts)))
(when tss
(car (sort tss #'ts>))))))
(taxy-org-ql-view-define-key ts-year ()
"Return the year of ELEMENT's latest timestamp."
(when-let ((latest-ts (taxy-org-ql--latest-timestamp-in org-element--timestamp-regexp element)))
(ts-format "%Y" latest-ts)))
(taxy-org-ql-view-define-key ts-month ()
"Return the month of ELEMENT's latest timestamp."
(when-let ((latest-ts (taxy-org-ql--latest-timestamp-in org-element--timestamp-regexp element)))
(ts-format "%Y-%m (%B)" latest-ts)))
(taxy-org-ql-view-define-key deadline (&rest args) (taxy-org-ql-view-define-key deadline (&rest args)
"Return whether ELEMENT has a deadline according to ARGS." "Return whether ELEMENT has a deadline according to ARGS."
(when-let ((deadline-element (org-element-property :deadline element))) (when-let ((deadline-element (org-element-property :deadline element)))