reddit / emacs

Org capture template %a link ONLY when I'm capturing from an email

EnoughUnit5 · 2022-02-16 19:54
I hope one of you fine folk can help. I'm trying to set up mu4e and integrate it with my org-mode based GTD system. I already have org capture templates set up to make next action entries. What I want to do now, is make the next action entry have a link to the email that the action is about (i.e. the one I was reading when I invoked the capture template)... but if I invoke the capture template from someplace other than an email, I don't want there to be a link in it. So if I'm in an email, I want `C-c c a w` to open this template: ("aw" "Work Related" entry (file+headline "~/mygtd.org" "Work") "* TODO %? %a %u \n\n ") But if I'm someplace other than an email, I want the same key combination `C-c c a w` to open this template: ("aw" "Work Related" entry (file+headline "~/mygtd.org" "Work") "* TODO %? %u \n\n ") Which is exactly the same, except it has no `%a` in it. How would I do that?
EnoughUnit5 · 2022-02-16 20:03
Actually, I think I may have solved my problem with a rather practical workaround. While an automation would be REALLY nice, I think this will work: While reading the email, store the link with `C-c l`. Then do `C-c c a w` to open the capture template. Then put the link in manually with `C-c C-l`. It's a little more keyboard work, but should be pretty fast in practice.
oantolin · 2022-02-16 20:32
An even more practical workaround is to just use two different bindings for the two templates.
rguy84 · 2022-02-16 21:19
Have you seen https://orgmode.org/manual/Templates-in-contexts.html?
0lMon · 2022-02-16 21:22
Hej Hej, Just some quick and dirty example how you can do this: (defun my-org-capture-shananiganz (&rest args) (if (string= (buffer-name) "NAME OF EMAIL BUFFER") (setq org-capture-templates '(("aw" "Work Related" entry (file+headline "~/mygtd.org" "Work") "* TODO %? %a %u \n\n "))) (setq org-capture-templates '(("aw" "Work Related" entry (file+headline "~/mygtd.org" "Work") "* TODO %? %u \n\n "))))) (advice-add 'org-capture :before 'my-org-capture-shananiganz) Hope this helps. It should give you the rough structure. Cheers, OlMon
nv-elisp · 2022-02-16 21:38
Came in here to post this solution, /u/EnoughUnit5. [doct makes managing these easier, too] (https://www.github.com/progfolio/doct#contexts)
EnoughUnit5 · 2022-02-17 08:58
I did see this, yes. Maybe it was just late at night but I didn't manage to connect the dots. How does it help?
EnoughUnit5 · 2022-02-17 08:59
Thanks! doct looks interesting, if only to make my .emacs file a little easier to read. Right now my capture template setup is rather hard on the eyes.
EnoughUnit5 · 2022-02-17 09:08
Yeah, I thought of that - unfortunately my capture template setup is already near the limit of practicality, so I don't want to add more if I can avoid it. It's not just adding one extra, it's adding about 4 different ones: One for each context where I am likely to want to link an email in the TODO.
rguy84 · 2022-02-17 13:22
From the page > To control whether a capture template should be accessible from a specific context, you can customize org-capture-templates-contexts. Let’s say, for example, that you have a capture template “p” for storing Gnus emails containing patches. So you could only make that capture only available when called via a message.