2

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
       '(("x"
     "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 '19 at 16:35
  • Does this answer your question? How to evaluate the variables before adding them to a list? – Drew Jan 8 at 5:10
6

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.

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

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

| improve this answer | |

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.