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

Just like


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. :-)

  • 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? Feb 21 at 9: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 2 at 7:33

1 Answer 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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