From mboxrd@z Thu Jan 1 00:00:00 1970 From: Richard Lawrence Subject: Re: capture template, filename Date: Fri, 05 Sep 2014 09:53:11 -0700 Message-ID: <87oauuroug.fsf@berkeley.edu> References: <4b7mdbxt03.ln2@news.c0t0d0s0.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55420) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPwmj-0003px-58 for emacs-orgmode@gnu.org; Fri, 05 Sep 2014 12:55:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XPwmb-0002qo-M4 for emacs-orgmode@gnu.org; Fri, 05 Sep 2014 12:54:53 -0400 Received: from plane.gmane.org ([80.91.229.3]:34404) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XPwmb-0002q5-GJ for emacs-orgmode@gnu.org; Fri, 05 Sep 2014 12:54:45 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1XPwmZ-0001fR-0m for emacs-orgmode@gnu.org; Fri, 05 Sep 2014 18:54:43 +0200 Received: from c-67-169-117-151.hsd1.ca.comcast.net ([67.169.117.151]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 05 Sep 2014 18:54:43 +0200 Received: from richard.lawrence by c-67-169-117-151.hsd1.ca.comcast.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 05 Sep 2014 18:54:43 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Cc: Michael Welle Hi Michael, Michael Welle 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