emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Kenny Ballou <kb@devnulllabs.io>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: yantar92@gmail.com, emacs-orgmode@gnu.org
Subject: Re: [PATCH] lisp/org-capture.el: use link ID's for %K
Date: Sat, 09 Dec 2023 15:53:02 -0700	[thread overview]
Message-ID: <87zfyj7zko.fsf@devnulllabs.io> (raw)
In-Reply-To: <875y18cycg.fsf@localhost>

[-- Attachment #1: Type: text/plain, Size: 934 bytes --]


On 2023-12-08 19:01 GMT, Ihor Radchenko wrote:
> Kenny Ballou <kb@devnulllabs.io> writes:
>
>> I'm currently struggling through modifying it to work with
>> `org-store-link'.  Something, save-excursion -> org-clock-goto ->
>> org-store-link -> org-insert-link is what I'm trying for now, but that's
>> not quite working.  I'll come back to this in a few hours.
>
> The last step is unnecessary. You may just examine `org-stored-links'
> (documented in the docstring of `org-store-link') or
> `org-store-link-plist' (undocumented, but containing more info and also
> used by `org-capture-fill-template').

I ended up using `org-store-link-plist'.  For some reason that I don't
understand, the `save-excursion' -> `org-store-link' was not updating
`org-stored-links'.  Similarly, I had to use `save-window-excursion' or
the `org-clock-goto' would really break things.

If there's a better approach for getting the link, I'm all ears.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-org-capture.el-use-link-ID-s-for-K.patch --]
[-- Type: text/x-patch, Size: 2500 bytes --]

From e618508cdfbf899b93d5081aeec3eda18d5bd306 Mon Sep 17 00:00:00 2001
From: Kenny Ballou <kb@devnulllabs.io>
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 <nate@manicmind.earth>
Signed-off-by: Kenny Ballou <kb@devnulllabs.io>
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


[-- Attachment #3: Type: text/plain, Size: 12 bytes --]


-- 
-Kenny

  reply	other threads:[~2023-12-10 15:21 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-19 13:26 Org-capture %K "Link to the currently clocked task" link with id? Nathaniel W Griswold
2021-05-19 17:29 ` Nathaniel W Griswold
2021-05-24 12:25   ` Nathaniel W Griswold
2021-05-29  8:10     ` Ihor Radchenko
2023-12-07 18:53       ` [PATCH] lisp/org-capture.el: use link ID's for %K Kenny Ballou
2023-12-08 13:56         ` Ihor Radchenko
2023-12-08 18:47           ` Kenny Ballou
2023-12-08 19:01             ` Ihor Radchenko
2023-12-09 22:53               ` Kenny Ballou [this message]
2023-12-10 12:19                 ` Ihor Radchenko
2023-12-11 15:33                   ` Kenny Ballou
2023-12-11 15:46                   ` Kenny Ballou
     [not found]                   ` <20231211154357.23020-1-kb@devnulllabs.io>
     [not found]                     ` <87ttoo7dna.fsf@localhost>
2023-12-11 21:21                       ` Kenny Ballou
2023-12-12  4:13                         ` [PATCH] lisp/org-capture.el: use `org-store-link' for %K values Kenny Ballou
2023-12-12  4:32                           ` Kenny Ballou
2023-12-12  4:32                             ` [PATCH] lisp/org-capture.el: use `org-store-link' for %K values Kenny Ballou
2023-12-12 12:46                               ` Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zfyj7zko.fsf@devnulllabs.io \
    --to=kb@devnulllabs.io \
    --cc=emacs-orgmode@gnu.org \
    --cc=yantar92@gmail.com \
    --cc=yantar92@posteo.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).