emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Anand Deopurkar <anandrdeopurkar@gmail.com>
To: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: [PATCH] lisp/org-capture.el: Restore org-store-link-plist
Date: Fri, 17 May 2024 21:38:32 +1000	[thread overview]
Message-ID: <87jzjsllc7.fsf@gmail.com> (raw)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: 0001-lisp-org-capture.el-Restore-org-store-link-plist.patch --]
[-- Type: text/x-patch, Size: 2048 bytes --]

From 8f603b721ddd7edf1e622a39dc80f4b74a5b5198 Mon Sep 17 00:00:00 2001
From: Anand Deopurkar <anandrdeopurkar@gmail.com>
Date: Fri, 17 May 2024 20:39:51 +1000
Subject: [PATCH] lisp/org-capture.el: Restore org-store-link-plist

* org-capture.el (org-capture-fill-template): Restore original
`org-store-link-plist' after calling `org-store-link'.

To replace a %K escape (link to currently clocked task),
`org-capture-fill-template' calls `org-store-link'.  This call has the
side-effect of replacing the contents of `org-store-link-plist'.  As a
result, expected template expansions using the original
`org-store-link-plist' do not happen.

For example, suppose `org-capture' is called from a message buffer with the
template "%:subject %:from" while the clock is running.  Then
%:subject and %:from are not substituted because of the behaviour
above.  If the clock is not running, there is no problem.

Current fix restores `org-store-link-plist' to its original value
after `org-capture-fill-template' calls `org-store-link'.

TINYCHANGE
---
 lisp/org-capture.el | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index da14f45c0..9d8f855ef 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -1675,9 +1675,12 @@ Expansion occurs in a temporary Org mode buffer."
 		  (org-no-properties org-clock-heading)
 		""))
 	 (v-K (if (marker-buffer org-clock-marker)
-                  (org-with-point-at org-clock-marker
-                    (org-store-link nil nil))
-		""))
+                  (let ((original-link-plist org-store-link-plist)
+                        (clocked-task-link (org-with-point-at org-clock-marker
+                                             (org-store-link nil nil))))
+                    (setq org-store-link-plist original-link-plist)
+                    clocked-task-link)
+	        ""))
 	 (v-f (or (org-capture-get :original-file-nondirectory) ""))
 	 (v-F (or (org-capture-get :original-file) ""))
 	 (org-capture--clipboards
-- 
2.44.0



             reply	other threads:[~2024-05-17 11:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-17 11:38 Anand Deopurkar [this message]
2024-05-18 10:56 ` [PATCH] lisp/org-capture.el: Restore org-store-link-plist 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=87jzjsllc7.fsf@gmail.com \
    --to=anandrdeopurkar@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /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).