Hi Michael, Michael Welle <mwe012...@gmx.net> writes:
> I have a capture template like this: > > ("j" "Journal" plain > (file (capture-report-data-file "~/org")) > "%^{Heading}\n#tags %^{Tags}\nmeta-creation_date: %(format-time-string > \"%m/%d/%Y %H:%M:%S\")\n\n%?") > > In capture-report-data-file I want to calculate the filename for the org > file. The filename should be constructed with information from the > heading's value. If I understand correctly, you are trying to choose the file in which to save the captured data dynamically, at capture time, based on the value of the headline...right? I think you will not be able to do this by setting a target in org-capture-templates, as you are trying to do. The reason is that the target for the capture is expanded and determined before any data is captured. (If you can calculate the filename without using the heading value, you could use (function ...) or (file+function ...) rather than (file ...) in org-capture-templates to set the target location.) I think what you probably want to do is *refile* the captured entry to the desired location after the template is filled out. I think you can do this from one of the org-capture-{prepare,before,after}-finalize hooks -- probably org-capture-prepare-finalize-hook. You could there add something like (lambda () (org-back-to-heading) (let ((target (get-target-from-heading))) (org-refile nil nil target)) where get-target-from-heading should return a refile location based on the heading. I'm not sure about all the arguments to org-refile (particularly the second, `default-buffer'). Also if you have other capture templates where you don't want to dynamically refile based on the heading, you need to insert a test in there to only do the refile in the cases you want. I should say this is not tested and you may need to play around with some things to get it to work for you. Someone else may have better advice. But I hope that points you in the right direction! Best, Richard