0

Following this response: Org-Mode - How do I create a new file with org-capture https://stackoverflow.com/questions/11902620/org-mode-how-do-i-create-a-new-file-with-org-capture?

I am trying to make this piece of code work, but I get the error: invalid file location: nil.

(defun capture-report-date-file (path)
  (let ((name (read-string "Name: ")))
    (expand-file-name (format "%s-%s.txt"
                              (format-time-string "%Y-%m-%d")
                              name) path)))

(setq org-capture-templates   
      '(("t"
         "todo"
         entry
         (file (capture-report-date-file  "~/path/path/name"))
         "* TODO")))

1 Answer 1

1

The code is outdated. Since version 9.1 org-capture-templates no longer accepts S-expressions as file names, so you have to turn:

(capture-report-date-file  "~/path/path/name")

into

(lambda () (capture-report-date-file  "~/path/path/name"))
13
  • Interesting! I knew something was amiss, thanks. I tried it and get the following error:ebugger entered--Lisp error: (error "Invalid capture target specification: (lambda nil ...") signal(error ("Invalid capture target specification: (lambda nil ...")) error("Invalid capture target specification: %S" (lambda nil (capture-report-date-file "~/path/path/name"))) (let ((target val)) (error "Invalid capture target specification: %S" target)) Feb 9, 2021 at 16:30
  • Do you also see this with emacs -Q?
    – jagrg
    Feb 10, 2021 at 0:16
  • It gives me this error: org-capture-expand-file: Symbol’s value as variable is void: capture-report-date-file. When I make the function (interactive), I run M-x capture-report-date-file, and returns: funcall-interactively: Wrong number of arguments: ((t) (path) (interactive) (let ((name (read-string "Name: "))) (expand-file-name (format "%s-%s.txt" (format-time-string "%Y-%m-%d") name) path))), 0. I'm clueless! Feb 10, 2021 at 7:44
  • emacs -Q won't load your init file so you will have to paste the code above to your scratch buffer and evaluate) both capture-report-date-file and org-capture-templates manually, usually by pressing C-x C-e. Once that's done press M-x org-capture and follow the prompt. The second error is expected.
    – jagrg
    Feb 10, 2021 at 9:50
  • Yes, that is what I did. I copied it into the scratch buffer and evaluated it. The error is after doing M-x org-capture and pressing the "t". Feb 10, 2021 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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