emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Re: capture template, filename
       [not found] <4b7mdbxt03.ln2@news.c0t0d0s0.de>
@ 2014-09-05 16:53 ` Richard Lawrence
  0 siblings, 0 replies; only message in thread
From: Richard Lawrence @ 2014-09-05 16:53 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Michael Welle

Hi Michael,

Michael Welle <mwe012008@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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-09-05 16:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <4b7mdbxt03.ln2@news.c0t0d0s0.de>
2014-09-05 16:53 ` capture template, filename Richard Lawrence

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).