1

I am struggling to setup an org-capture template which captures the current projects name from where it is called.

Just like

‘%f’

File visited by current buffer when org-capture was called.

I am looking for

Project visited by current buffer when org-capture was called.

In fact, I want to end with something like

("r" "Project todo" entry (file+headline notes.org "Tasks")
             "* TODO %? :%p:" :prepend t)

Where %p inserts the current project name.

I am using project.el at the moment.

Thanks. :-)

grszkthfr
  • 80
  • 6
  • 2
    Assuming that `project.el` has a function to provide the current project name, you could fold that into the template with the `%(sexp)` placeholder? – Fran Burstall Feb 21 '22 at 09:22
  • Any idea, how I can extend the target (and not the template) with the function? I.e. how to get the project as a subtree with something like `(file+function org-default-notes-file gkh/project-current-name)` working? – grszkthfr May 02 '22 at 07:33

1 Answers1

1

Thanks for the pointer @Fran Burstall. :-)

I was able to get the desired behavior with a custom funtion:

(defun gkh/project-current-name ()
"Get the name of the current project by returning the project name for DIR."
(if (string-match "/\\([^/]+\\)/\\'" (project-root (project-current t)))
    (match-string 1 (project-root (project-current t)))
  (project-root (project-current t))))

(based on from consult--project-root)

And a template of the form:

("r" "Project todo" entry (file+headline notes.org "Tasks")
         "* TODO %? :%(gkh/project-current-name):" :prepend t)

Best Jonas

grszkthfr
  • 80
  • 6