Add property to exclude individual Org items as checklist backlinks

Use case: do not add a workload report (which usually contains links to all
current tasks) when inserting checklist backlinks; they do not carry any
information and are thus not relevant.
This commit is contained in:
Daniel - 2023-01-13 19:32:03 +01:00
parent fc4d6b7767
commit d699fc8450
Signed by: dbo
GPG Key ID: 784AA8DF0CCDF625
1 changed files with 39 additions and 14 deletions

View File

@ -888,22 +888,46 @@ determined."
(defun db/org-insert-checklist () (defun db/org-insert-checklist ()
"Insert checklist for Org Mode item at point. "Insert checklist for Org Mode item at point.
The checklist consists of a listing of all backlinks to the The checklist consists of a listing of relevant backlinks of the
current item and its parents (without archives) as well as a current item and its parents (without archives) as well as a
template. template.
The depth to which backlinks to parents are considered can be Relevant backlinks are Org items and are determined as follows:
configured via the CHECKLIST_BACKLINK_DEPTH property. This
property is looked up only at the current item, i.e., no
inheritance is considered. If this property is not set, the
depth to which backlinks to parents is considered is unlimited by
default (i.e., nil).
The template is determined by the TEMPLATE_ID property, which - for an Org item to be considered as backlink item, it must
must be an ID referencing the proper template item. If that reference the item at point directly, or one of its parents,
property is not set, search for the topmost sibling of the via an Org link using the id: link type (also see the
current item and see whether its headline is matching `db/org-backlinks' dynamic block);
\"^Template.*\"; if so, use its body as template."
- the backlink item must not be done and must not be tagged with
TEMPLATE;
- the backlink item must not be scheduled in the future;
- the backlink item must be contained in a file from
`org-agenda-files' or `org-agenda-text-search-extra-files', but
not in an archive file (i.e., archives are excluded from the search)
- the backlink item must not have the CHECKLIST_NO_BACKLINK
property set to nil (with inheritance not being considered,
i.e., the property must be set directly at the item to exclude
it as backlink).
The depth to which backlinks to parents are considered can be
configured via the CHECKLIST_BACKLINK_DEPTH property at the item
at point. This property is looked up only at the current item,
i.e., again no inheritance is considered. If this property is
not set, the depth to which backlinks to parents is considered is
unlimited by default (i.e., nil).
After the table of backlinks, a template is inserted. This
templates is usually a checklist copied from another Org item
tagged with :TEMPLATE:. The item to copy the template from is
determined by the TEMPLATE_ID property, which must be an ID
referencing the proper template item. If that property is not
set, search for the topmost sibling of the current item is
conducted to see whether its headline is matching
\"^Template.*\"; if so, its body is used as template."
(interactive) (interactive)
(unless (derived-mode-p 'org-mode) (unless (derived-mode-p 'org-mode)
@ -915,7 +939,7 @@ current item and see whether its headline is matching
number-of-backlinks number-of-backlinks
point-before-backlinks) point-before-backlinks)
(insert (format "\nBacklinks (not DONE, no TEMPLATE, %s, no archives, not scheduled in the future):\n\n" (insert (format "\nRelevant backlinks (%s):\n\n"
(if parent-depth (if parent-depth
(format "parent-depth %d" parent-depth) (format "parent-depth %d" parent-depth)
"all parents"))) "all parents")))
@ -929,7 +953,8 @@ current item and see whether its headline is matching
:org-ql-match '(and :org-ql-match '(and
(not (done)) (not (done))
(not (ltags "TEMPLATE")) (not (ltags "TEMPLATE"))
(not (scheduled :from 1))) (not (scheduled :from 1))
(not (property "CHECKLIST_NO_BACKLINK" "t" :inherit nil)))
:parent-depth (--when-let (org-entry-get (point) "CHECKLIST_BACKLINK_DEPTH" nil) :parent-depth (--when-let (org-entry-get (point) "CHECKLIST_BACKLINK_DEPTH" nil)
(string-to-number it)) (string-to-number it))
:archive nil))) :archive nil)))