From e618508cdfbf899b93d5081aeec3eda18d5bd306 Mon Sep 17 00:00:00 2001 From: Kenny Ballou Date: Thu, 7 Dec 2023 10:29:46 -0700 Subject: [PATCH] lisp/org-capture.el: use link ID's for %K * org-capture.el (org-capture-fill-template): fill %K values using org ID's if `org-id-link-to-org-use-id' is non-nil. * doc/ORG-NEWS: (Template variable expansion %K) Document new behavior. Reported-by: Nathaniel W Griswold Signed-off-by: Kenny Ballou Link: https://list.orgmode.org/EF459D47-FCA4-4A18-AFC7-3E62159F186C@manicmind.earth/ TINYCHANGE --- etc/ORG-NEWS | 8 ++++++++ lisp/org-capture.el | 16 +++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 59c45b2aa..924ce43cc 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -539,6 +539,14 @@ Currently implemented options are: tasks this technically violates the iCalendar spec, but some iCalendar programs support this usage. +*** Capture template expansion now supports ID links +:PROPERTIES: +:ID: 6f1f4f77-2b16-4a4d-8c84-fb7ba5ddf1e5 +:END: + +The capture template expansion element `%K' now creates links using +the `ID' property of the currently clocked task if +`org-id-link-to-use-org-id' is non-nil. ** New features *** =ob-plantuml.el=: Support tikz file format output diff --git a/lisp/org-capture.el b/lisp/org-capture.el index e482f667f..5bb65de53 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -1675,11 +1675,17 @@ Expansion occurs in a temporary Org mode buffer." (org-no-properties org-clock-heading) "")) (v-K (if (marker-buffer org-clock-marker) - (org-link-make-string - (format "%s::*%s" - (buffer-file-name (marker-buffer org-clock-marker)) - v-k) - v-k) + (if (and (org-clock-is-active) org-id-link-to-org-use-id) + (save-window-excursion + (org-clock-goto) + (org-store-link nil) + (let ((link (plist-get org-store-link-plist :link))) + (org-link-make-string link v-k))) + (org-link-make-string + (format "%s::*%s" + (buffer-file-name (marker-buffer org-clock-marker)) + v-k) + v-k)) "")) (v-f (or (org-capture-get :original-file-nondirectory) "")) (v-F (or (org-capture-get :original-file) "")) base-commit: 282c0fb6d1d2e6289a5b535a7ee9888f845b760b -- 2.41.0