Search for template also in superordinate headings

This allows to jump to templates also in the case that the template contains subtree itself.
This commit is contained in:
Daniel Borchmann 2025-05-29 11:06:50 +02:00
parent 61b3964224
commit adb22bbc1c
No known key found for this signature in database
GPG Key ID: 50EA937BF472ADD1

View File

@ -1414,7 +1414,7 @@ Org Babel source blocks and dependent tables."
(defun db/org--find-template () (defun db/org--find-template ()
"Return marker to template item associated with item at point. "Return marker to template item associated with item at point.
Return NIL if no template is associated with item at point. Return nil if no template is associated with item at point.
See `db/org-insert-checklist' for how this template item is See `db/org-insert-checklist' for how this template item is
determined." determined."
@ -1422,7 +1422,7 @@ determined."
(let (template-marker) (let (template-marker)
;; Check for TEMPLATE_ID property ;; Check for TEMPLATE_ID property
(when-let ((template-id (org-entry-get (point) "TEMPLATE_ID"))) (when-let ((template-id (org-entry-get (point) "TEMPLATE_ID" :inherit)))
(setq template-marker (org-id-find template-id :get-marker)) (setq template-marker (org-id-find template-id :get-marker))
(unless template-marker (unless template-marker
(warn "TEMPLATE_ID is set, but could not be resolved: %s" (warn "TEMPLATE_ID is set, but could not be resolved: %s"
@ -1452,62 +1452,60 @@ determined."
(defun db/org-insert-checklist (arg) (defun db/org-insert-checklist (arg)
"Insert checklist for Org Mode item at point. "Insert checklist for Org Mode item at point.
Checklists are inserted before the first child, if existent, or Checklists are inserted before the first child, if existent, or at the
at the end of the subtree. end of the subtree.
After inserting a checklist, add the property After inserting a checklist, add the property CHECKLIST_INSERTED_P with
CHECKLIST_INSERTED_P with value t to item at point. Checklists value t to item at point. Checklists are not inserted if this property
are not inserted if this property with this value is already with this value is already present, to avoid double insertions of
present, to avoid double insertions of checklists. checklists.
The checklist consists of a listing of concurrent date entries, The checklist consists of a listing of concurrent date entries, relevant
relevant backlinks of the current item and its parents (without backlinks of the current item and its parents (without archives) as well
archives) as well as a template. as a template.
Concurrent date entries are all Org items tagged with DATE and Concurrent date entries are all Org items tagged with DATE and posessing
posessing an active time range that encloses today. an active time range that encloses today.
Relevant backlinks are Org items and are determined as follows: Relevant backlinks are Org items and are determined as follows:
- for an Org item to be considered as backlink item, it must - for an Org item to be considered as backlink item, it must reference
reference the item at point directly, or one of its parents, the item at point directly, or one of its parents, via an Org link
via an Org link using the id: link type (also see the using the id: link type (also see the `db/org-backlinks' dynamic
`db/org-backlinks' dynamic block); block);
- the backlink item must not be done, must not be tagged locally - the backlink item must not be done, must not be tagged locally with
with TEMPLATE and must not be tagged with HOLD nor TEMPLATE and must not be tagged with HOLD nor SOMEWHEN (neither
SOMEWHEN (neither locally nor inherited); locally nor inherited);
- the backlink item must not be scheduled in the future; - the backlink item must not be scheduled in the future;
- the backlink item must be contained in a file in the variables - the backlink item must be contained in a file in the variables
`org-agenda-files' or `org-agenda-text-search-extra-files', but `org-agenda-files' or `org-agenda-text-search-extra-files', but not in
not in an archive file (i.e., archives are excluded from the an archive file (i.e., archives are excluded from the search);
search);
- the backlink item must not have the CHECKLIST_NO_BACKLINK - the backlink item must not have the CHECKLIST_NO_BACKLINK property set
property set to nil (with inheritance not being considered, to nil (with inheritance not being considered, i.e., the property must
i.e., the property must be set directly at the item to exclude be set directly at the item to exclude it as backlink).
it as backlink).
The depth to which backlinks to parents are considered can be The depth to which backlinks to parents are considered can be configured
configured via the CHECKLIST_BACKLINK_DEPTH property at the item via the CHECKLIST_BACKLINK_DEPTH property at the item at point. This
at point. This property is looked up only at the current item, property is looked up only at the current item, i.e., again no
i.e., again no inheritance is considered. If this property is inheritance is considered. If this property is not set, the depth to
not set, the depth to which backlinks to parents is considered is which backlinks to parents is considered is unlimited by default (i.e.,
unlimited by default (i.e., nil). nil).
After the table of backlinks, a template is inserted. This After the table of backlinks, a template is inserted. This templates is
templates is usually a checklist copied from another Org item usually a checklist copied from another Org item tagged with :TEMPLATE:.
tagged with :TEMPLATE:. The item to copy the template from is The item to copy the template from is determined by the TEMPLATE_ID
determined by the TEMPLATE_ID property, which must be an ID property, which must be an ID referencing the proper template item. If
referencing the proper template item. If that property is not that property is not set (either directly or via inheritance), search
set, search for the topmost sibling of the current item is for the topmost sibling of the current item is conducted to see whether
conducted to see whether its headline is matching its headline is matching \"^Template.*\"; if so, its body is used as
\"^Template.*\"; if so, its body is used as template. template.
When ARG is given, jump to the current template instead of When ARG is given, jump to the current template instead of inserting the
inserting the checklist." checklist."
(interactive "P") (interactive "P")
(when (derived-mode-p 'org-agenda-mode) (when (derived-mode-p 'org-agenda-mode)