6

I've seen this:

How to type a dynamic file entry for org capture

but cannot get it to work; I get "Invalid file location: nil". Has something changed in org-mode or in Emacs itself to stop this from working? Otherwise: suggestions for how to debug what has gone wrong?

What I'm really trying to get working is what is described on this page:

http://www.howardism.org/Technical/Emacs/journaling-org.html

The capture template I'm interested in is the "Journal Note" one all the way at the bottom of the page:

(setq org-capture-templates '(
;; ...
("j" "Journal Note"
     entry (file (get-journal-file-today))
     "* Event: %?\n\n  %i\n\n  From: %a"
     :empty-lines 1)
;; ..
))

Thanks for any assistance.

Drew
  • 29,895
  • 7
  • 74
  • 104
Jeff Templon
  • 161
  • 8
  • 1
    Someone started a discussion on reddit linking to this post, maybe that helps, didn't read it through: https://www.reddit.com/r/emacs/comments/7m6nwo/file_orgcapture_item_under_existing_heading_if_it/ – Hubisan Oct 08 '19 at 11:30

2 Answers2

10

Figured it out ... it is using a backquote instead of a normal quote for the entire capture template block! I missed this because all of the answers I saw had only a single capture template with a backquote in front of it; I tried doing that but this doesn't work if the template is "one of" ...

So here is a snippet a bit richer than those I found; I hope it helps someone else.

(setq org-capture-templates
  `(("t" "TODO" entry (file+datetree "~/Documents/org/tasks.org"  "Tasks")
     "* TODO [#C] %?\n   SCHEDULED: <%<%Y-%m-%d %a>>\n  [%<%Y-%m-%d %a>]\n  %a")
   ("T" "Travel" entry (file+datetree+prompt "~/Documents/org/travel.org")
    "* %?\n  :PROPERTIES:\n  :LOCATION:\n  :END:\n  %t\n  %a")
   ("j" "Journal Note" entry (
               file+olp+datetree
               ,(concat
                 org-journal-dir
                 (format-time-string "journal-%m-%d.org")))
   "* Event: %?\n %i\n  From: %a")
   )
  )

The keys are the backquote ` at the start of the capture template def block, and the comma , before (concat ... ) on the function being called.

Jeff Templon
  • 161
  • 8
6

It seems like something has changed between Org-mode 8.2.10 and 9.1.9 specifically in the way Org handles template elements. Whereas in earlier version of Org the second value in the pair (file ...) could be a function that Org would evaluate, now it seems only a string (file path) is valid here.

The fix is to use the backquote list form, and explicitly state that the function needs evaluating using the comma:

(setq org-capture-templates `(
    ;; ...
    ("j" "Journal Note"
         entry (file ,(get-journal-file-today))
         "* Event: %?\n\n  %i\n\n  From: %a"
         :empty-lines 1)
    ;; ..
    ))
  • Thanks for replying, Mark. I already found something that worked, but this answer will surely help somebody else facing the same problem. – Jeff Templon Sep 07 '18 at 12:35
  • 1
    It's worth noting that the `get-journal-file-today` function is executed straight away, and not when the template has been selected, so it's not useful for doing anything interactive or time-based. – John Hamelink Jun 18 '20 at 00:29