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?

Erik
  • 153
  • 9

2 Answers2

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.

Fran Burstall
  • 3,855
  • 11
  • 18
  • Many thanks! How come (concat (file-name-directory buffer-file-name) "notes.org") is not accapted as a function? – Erik Jun 21 '18 at 07: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!

Joel Reymont
  • 101
  • 1
  • In that case the question becomes a duplicate of https://emacs.stackexchange.com/q/7481/105. – Drew Jan 08 '20 at 05:13