From 80eeca1e44cc2ff6817aa33bd7894b56f065beae Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Mon, 13 Dec 2021 21:32:05 +0100 Subject: [PATCH] Add simple function to find template via special property This allows both a more fine-grained and more flexible control over where templates can be located and which templates are suppoed to be used for the item at point. This function could also be bound to a custom key binding to make it easier to invoke. --- site-lisp/db-org.el | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/site-lisp/db-org.el b/site-lisp/db-org.el index 6de110f..f16b85b 100644 --- a/site-lisp/db-org.el +++ b/site-lisp/db-org.el @@ -588,6 +588,20 @@ drawers, will be copied to point." (db/org-copy-body-from-item-to-point template-pom))) +(defun db/org-copy-template-from-id () + "Copy template given by current value of TEMPLATE_ID property to point. +The TEMPLATE_ID property must be an ID property of another item +from which the contents is supposed to be copied to point." + (interactive) + (let ((template-id (org-entry-get (point) "TEMPLATE_ID")) + template-pom) + (unless template-id + (user-error "Property TEMPLATE_ID not set, cannot copy from there")) + (setq template-pom (org-id-find template-id :get-marker)) + (unless template-pom + (user-error "Cannot find item with id %s" template-id)) + (db/org-copy-body-from-item-to-point template-pom))) + (defun db/org-copy-body-from-item-to-point (pom) "Copy body from item given by POM to point.