From mboxrd@z Thu Jan 1 00:00:00 1970 From: Aankhen Subject: Re: Define capture template with dynamic id target Date: Sat, 11 Jun 2011 13:36:27 +0530 Message-ID: References: <4df10e5c.4b6edc0a.1d4f.1a14@mx.google.com> <87aadqjlq8.wl%dmaus@ictsoc.de> <4df23d66.814de50a.09ad.7325@mx.google.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([140.186.70.92]:57942) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QVJDV-0002Kj-58 for emacs-orgmode@gnu.org; Sat, 11 Jun 2011 04:06:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QVJDT-0000nq-Rp for emacs-orgmode@gnu.org; Sat, 11 Jun 2011 04:06:49 -0400 Received: from mail-vw0-f41.google.com ([209.85.212.41]:36737) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QVJDT-0000nm-Pb for emacs-orgmode@gnu.org; Sat, 11 Jun 2011 04:06:47 -0400 Received: by vws4 with SMTP id 4so3544064vws.0 for ; Sat, 11 Jun 2011 01:06:47 -0700 (PDT) In-Reply-To: <4df23d66.814de50a.09ad.7325@mx.google.com> 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: Darlan Cavalcante Moreira , David Maus , Org mailing list Hi Darlan, On Fri, Jun 10, 2011 at 21:20, Darlan Cavalcante Moreira wrote: > Thanks David, > > I tried to follow your suggestion, but I found two problems (maybe becaus= e > I know little about lisp). > > For instance, suppose I have a test.org file with the follow content > --8<---------------cut here---------------start------------->8--- > * 2011 > =C2=A0Every headline has an ID, but I have omitted here for brevity > *** May > ***** Sub-headline > =C2=A0 =C2=A0 =C2=A0bla bla bla > *** June > ***** Sub-headline > =C2=A0 =C2=A0 =C2=A0bla bla bla > --8<---------------cut here---------------end--------------->8--- > > I want the capture process to add an entry to the Sub-headline of June. I= f > I just use the file+headline and specify "Sub-headline" then it will add = to > the Sub-headline in May. That's why I tried using IDs in the first > place. Also, every month I create a new month headline with the > Sub-headline and the capture process should add an entry to that > instead. That is the reason I wanted to get the ID from a function, inste= ad > of just writing it in the capture template. > > > As far as I understand if I use the file+function target then the functio= n > must return the headline name, but how can I say that I want the > Sub-headline of June and not of May? [first problem] > > I found an org-id-find function that returns something like > "(filename . characterPosition)". Therefore, If there is a way to specify= a > position where org should start looking for the headline then I could use > that to go to the correct Sub-headline. > > > Also, the file+headline target will add the entry as a child of the > specified headline, but file+function seems to add the entry as a sibling > of the headline returned by the function. [second problem] Is this intend= ed > behaviour or is it a bug? > [snip] Looking at the code, the function doesn=E2=80=99t need to return anything; = it just needs to place point where you want the new headline to appear. Therefore, you can use =E2=80=98org-find-olp=E2=80=99 to locate the entry: ,----[ C-h f org-find-olp RET ] | org-find-olp is a compiled Lisp function in `org.el'. | | (org-find-olp PATH &optional THIS-BUFFER) | | Return a marker pointing to the entry at outline path OLP. | If anything goes wrong, throw an error. | You can wrap this call to catch the error like this: | | (condition-case msg | (org-mobile-locate-entry (match-string 4)) | (error (nth 1 msg))) | | The return value will then be either a string with the error message, | or a marker if everything is OK. | | If THIS-BUFFER is set, the outline path does not contain a file, | only headings. `---- So the code would look something like this: ,---- | (org-find-olp '("2011" "May" "Sub-headline") t) `---- Aankhen