Insert active concurrent DATE entries when inserting checklist

Those DATE entries may be relevant to the item at hand.

Caveat: the query to determine active, concurrent DATE entries is not
quite right yet, two disjoint time ranges that do not include today but
cover the past and the future would also be considered as concurrent
active date.  This needs to be fixed.
This commit is contained in:
Daniel Borchmann 2024-07-06 13:47:29 +02:00
parent 94187697e6
commit 7309cee413
No known key found for this signature in database
GPG Key ID: 784AA8DF0CCDF625

View File

@ -1193,9 +1193,12 @@ CHECKLIST_INSERTED_P with value t to item at point. Checklists
are not inserted if this property with this value is already
present, to avoid double insertions of checklists.
The checklist consists of a listing of relevant backlinks of the
current item and its parents (without archives) as well as a
template.
The checklist consists of a listing of concurrent date entries,
relevant backlinks of the current item and its parents (without
archives) as well as a template.
Concurrent date entries are all Org items tagged with DATE and
posessing an active time range that encloses today.
Relevant backlinks are Org items and are determined as follows:
@ -1281,6 +1284,21 @@ inserting the checklist."
(looking-at (rx bol (* space) eol)))
(insert "\n"))
;; Insert links to concurrent DATEs, if any
(when-let ((concurrent-dates (org-ql-query :from (org-agenda-files)
:select '(cons
(org-entry-get (point) "ITEM")
(org-id-get-create))
:where '(and ; XXX: this is not quite right yet
(tags "DATE")
(not (done))
(ts-active :from today)
(ts-active :to today)))))
(insert "Concurrent DATEs:\n")
(dolist (date concurrent-dates)
(insert "- " (org-link-make-string (cdr date) (car date)) "\n"))
(insert "\n"))
;; Insert relevant backlinks, when available.
(let ((parent-depth (--when-let (org-entry-get (point) "CHECKLIST_BACKLINK_DEPTH" nil)
(string-to-number it)))