From 7309cee4131f2abf91b2eb73d63cae58002d5dda Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Sat, 6 Jul 2024 13:47:29 +0200 Subject: [PATCH] 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. --- site-lisp/db-org.el | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/site-lisp/db-org.el b/site-lisp/db-org.el index 84f7fd3..9ecd495 100644 --- a/site-lisp/db-org.el +++ b/site-lisp/db-org.el @@ -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)))