emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Looking for a sample function to find a location for org-capture
@ 2010-08-12  1:30 Charles Cave
  2010-08-12 10:06 ` Carsten Dominik
  2010-08-12 14:37 ` Bastien
  0 siblings, 2 replies; 5+ messages in thread
From: Charles Cave @ 2010-08-12  1:30 UTC (permalink / raw)
  To: emacs-orgmode

I'm exploring the many features of org-capture and I see the
documentation about a function for finding the location for refiling.

I would like to see some sample code on how to do this.

At the moment I am using a date tree to file my TODO items and
notes. (I am writing an article about this and will publish soon)

Let's say I had a headline structure for weeks of the year and I would
like a function to add an item to the heading corresponding to the week
of the year. Today (12th Aug) we are in Week 32. 

What would the function be to file under the appropriate heading:

* 2010
** 2010-Week-28
** 2010-Week-29
** 2010-Week-30
** 2010-Week-31
** 2010-Week-32
** 2010-Week-33

Could the function create the heading if it didnt exist . just like 
org-capture handles creation of new brances on a date tree?


Charles

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Looking for a sample function to find a location for org-capture
  2010-08-12  1:30 Looking for a sample function to find a location for org-capture Charles Cave
@ 2010-08-12 10:06 ` Carsten Dominik
  2010-08-12 11:42   ` Nick Dokos
  2010-08-12 14:37 ` Bastien
  1 sibling, 1 reply; 5+ messages in thread
From: Carsten Dominik @ 2010-08-12 10:06 UTC (permalink / raw)
  To: Charles Cave; +Cc: emacs-orgmode


On Aug 12, 2010, at 3:30 AM, Charles Cave wrote:

> I'm exploring the many features of org-capture and I see the
> documentation about a function for finding the location for refiling.

What exactly are you referring to?

>
> I would like to see some sample code on how to do this.
>
> At the moment I am using a date tree to file my TODO items and
> notes. (I am writing an article about this and will publish soon)
>
> Let's say I had a headline structure for weeks of the year and I would
> like a function to add an item to the heading corresponding to the  
> week
> of the year. Today (12th Aug) we are in Week 32.
>
> What would the function be to file under the appropriate heading:
>
> * 2010
> ** 2010-Week-28
> ** 2010-Week-29
> ** 2010-Week-30
> ** 2010-Week-31
> ** 2010-Week-32
> ** 2010-Week-33
>
> Could the function create the heading if it didnt exist . just like
> org-capture handles creation of new brances on a date tree?

Well, the datetree is a special library that does create the
headings for a date tree.  If you want a different structure
(weeks instead of months), code for this would have to be written, and
I guess org-capture would have to be extended to call this code.
But I am not sure if I understand what you are asking.

- Carsten

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Looking for a sample function to find a location for org-capture
  2010-08-12 10:06 ` Carsten Dominik
@ 2010-08-12 11:42   ` Nick Dokos
  0 siblings, 0 replies; 5+ messages in thread
From: Nick Dokos @ 2010-08-12 11:42 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: nicholas.dokos, emacs-orgmode, Charles Cave

Carsten Dominik <carsten.dominik@gmail.com> wrote:

> 
> On Aug 12, 2010, at 3:30 AM, Charles Cave wrote:
> 
> > I'm exploring the many features of org-capture and I see the
> > documentation about a function for finding the location for refiling.
> 
> What exactly are you referring to?
> 
> >
> > I would like to see some sample code on how to do this.
> >
> > At the moment I am using a date tree to file my TODO items and
> > notes. (I am writing an article about this and will publish soon)
> >
> > Let's say I had a headline structure for weeks of the year and I would
> > like a function to add an item to the heading corresponding to the
> > week
> > of the year. Today (12th Aug) we are in Week 32.
> >
> > What would the function be to file under the appropriate heading:
> >
> > * 2010
> > ** 2010-Week-28
> > ** 2010-Week-29
> > ** 2010-Week-30
> > ** 2010-Week-31
> > ** 2010-Week-32
> > ** 2010-Week-33
> >
> > Could the function create the heading if it didnt exist . just like
> > org-capture handles creation of new brances on a date tree?
> 
> Well, the datetree is a special library that does create the
> headings for a date tree.  If you want a different structure
> (weeks instead of months), code for this would have to be written, and
> I guess org-capture would have to be extended to call this code.
> But I am not sure if I understand what you are asking.
> 

I think Charles is referring to the following in org-capture-templates's
doc string:

,----
|              (file+function "path/to/file" function-finding-location)
|                  A function to find the right location in the file
| 
|              ...
| 
|              (function function-finding-location)
|                 Most general way, write your own function to find both
|                 file and location
`----

I tried using the first (in a very simple minded way) but it was late last
night, I was tired and I couldn't get it to work in five minures, so I gave
up:

(WARNING: DOES NOT WORK)
,----
| (setq org-capture-templates
| '(...
|   ("X" "Experimental function for Charles Cave" entry (file+function "~/lib/org/charles.org" cc-date-tree) "* DONE %?
|   %U %a" :prepend t)
|   ...
|   ))
| 
| (defun cc-date-tree ()
|   (let ((year 2010)
|         (weeknum 32))
|     (format "%4d-Week-%2d" year weeknum)))
`----
(WARNING: DOES NOT WORK)

So maybe I have it completely wrong, maybe this is close, but at this
point I just don't know.

Also, I saw in the doc string the following:

,----
|              (file+datetree "path/to/file")
|                  Will create a heading in a date tree
`----

which might do exactly what Charles wants in this case, without having
to write a function? But I have no idea how datetrees work, so this
too might be off.

Thanks,
Nick

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Looking for a sample function to find a location for org-capture
  2010-08-12  1:30 Looking for a sample function to find a location for org-capture Charles Cave
  2010-08-12 10:06 ` Carsten Dominik
@ 2010-08-12 14:37 ` Bastien
  2010-08-12 23:11   ` Charles Cave
  1 sibling, 1 reply; 5+ messages in thread
From: Bastien @ 2010-08-12 14:37 UTC (permalink / raw)
  To: Charles Cave; +Cc: emacs-orgmode

Charles Cave <charles_cave@optusnet.com.au> writes:

> I'm exploring the many features of org-capture and I see the
> documentation about a function for finding the location for refiling.

Let's say you have this capture template:

,----
| (setq org-capture-templates
|   '(("w" "WP TEST" entry (function bzg-find-location)
|      "* TODO Put this after abcde\n\n" :prepend t)))
`----

And this finding function:

,----
| (defun bzg-find-location ()
|   "Example: find my bzg.org file and the abcde string in the current buffer"
|   (find-file "~/org/bzg.org")
|   (goto-char (point-min))
|   (re-search-forward "abcde" nil t)
|   (newline 2))
`----

Capturing with "w" will put the entry after the "abcde" string in
bzg.org.

HTH,

-- 
 Bastien

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Looking for a sample function to find a location for org-capture
  2010-08-12 14:37 ` Bastien
@ 2010-08-12 23:11   ` Charles Cave
  0 siblings, 0 replies; 5+ messages in thread
From: Charles Cave @ 2010-08-12 23:11 UTC (permalink / raw)
  To: emacs-orgmode

> Bastien <bastien.guerry <at> wikimedia.fr> writes:

Thanks for the clarification.  My original question referred to
refiling when I meant capturing. Sorry about the confusion.

Now I understand the purpose of the function. It should leave the
cursor (point) at the location where the capture input should
be written.

As for modifying the date tree I will look at the date-tree code
and see if I understand it.

Thanks,
Charles

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-08-12 23:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-12  1:30 Looking for a sample function to find a location for org-capture Charles Cave
2010-08-12 10:06 ` Carsten Dominik
2010-08-12 11:42   ` Nick Dokos
2010-08-12 14:37 ` Bastien
2010-08-12 23:11   ` Charles Cave

Code repositories for project(s) associated with this 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).