emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Richard Lawrence <richard.lawrence@berkeley.edu>
To: emacs-orgmode@gnu.org
Cc: Michael Welle <mwe012008@gmx.net>
Subject: Re: capture template, filename
Date: Fri, 05 Sep 2014 09:53:11 -0700	[thread overview]
Message-ID: <87oauuroug.fsf@berkeley.edu> (raw)
In-Reply-To: 4b7mdbxt03.ln2@news.c0t0d0s0.de

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

           reply	other threads:[~2014-09-05 16:55 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <4b7mdbxt03.ln2@news.c0t0d0s0.de>]

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=87oauuroug.fsf@berkeley.edu \
    --to=richard.lawrence@berkeley.edu \
    --cc=emacs-orgmode@gnu.org \
    --cc=mwe012008@gmx.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).