3

I am beginning to use org-mode as an electronic lab notebook, which is working very well. I work on a number of different projects, each of which has its own directory. When I use org-capture, I want the task, etc., to be written to an .org file in the directory for the current project.

So if I am working in my org lab notebook for Project A and I capture a task, I want that task to go to the capture.org file in the directory for Project A, but when I capture a task from my notebook for Project B, I want the task written to capture.org in that directory instead.

It seems like I could do this with different templates, using something along these lines.

(setq org-capture-templates
'(("t" "Todo" entry (file "~/project_a/capture.org")...)
  ("u" "Todo" entry (file "~/project_b/capture.org")...)
  ("v" "Todo" entry (file "~/project_c/capture.org")...)))

The downside of this is that I have to remember or check a lot of different templates each time, making it more distracting to capture something, especially when I'm working on a lot of different projects.

An alternative would be to always insert the capture into the buffer I'm currently working on, but I'd rather not do that.

I think I could also just have a small piece of executable code at the beginning of each notebook that defines all the captures, but there must be a better way than that.

I suspect that there may be some way to do this by giving the target as a function, but I can't figure out how to do that, and I'm not sure whether it's the best way.

What would be ideal is that any capture done in ~/project_a or any of its subdirectories would go to ~/project_a/capture.org, but I can easily live with the customization applying only to the specific file (~/project_a/notebook.org) that I use as my notebooks, since I'll almost always have that open.

0

This is an imperfect solution, but good enough for my purposes (and the only one I've been able to come up with).

When you set the location of your capture file in your .emacs file, you can set a relative path, which will start from the location of the org file.

So I added this to my .emacs file.

(setq org-default-notes-file "org/capture.org")

The downside is that the relative path has to be the same for all org files. This works for me, because I'm structuring all my project directories the same way, but if someone can come up with a more flexible solution, I'd love to hear it.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.