My goal is to get org-capture to store captured notes in a local "notes.org" file located in the same directory as the current working buffer.

I set the template like so:

(setq org-capture-templates
     "local notes" entry (file+headline (concat ,(file-name-directory buffer-file-name) "notes.org") "Copied regions")
     "* %^{Title} %U \n %i")

Alas, when invoking the template i get Invalid file location: nil.

How should this be done?

  • I successfully used this syntax for several years under Emacs 24 and 25, but it fails under Emacs 26. Evidently the restriction to a function noted below was introduced with this version of Emacs.
    – Liam
    Dec 27, 2019 at 16:35
  • Does this answer your question? How to evaluate the variables before adding them to a list?
    – Drew
    Jan 8, 2020 at 5:10
  • If you want to use defun then advice-add will give you the answer
    – yuskam
    May 6, 2021 at 14:14

2 Answers 2


As the docs say, you can supply a function (with no arguments) to set the file here. Thus:

(setq org-capture-templates
   '(("x"  "local notes" entry 
     (file+headline (lambda () (concat (file-name-directory buffer-file-name) "notes.org")) "Copied regions")
       "* %^{Title} %U \n %i")

does the job.

  • Many thanks! How come (concat (file-name-directory buffer-file-name) "notes.org") is not accapted as a function?
    – Erik
    Jun 21, 2018 at 7:46
  • Because it isn't a function! Functions are either pre-defined using defun or on the fly with lambda. Jun 21, 2018 at 18:09

Change the leading apostrophe to a backquote on the template list. It will work then, no lambda needed!


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.