org-mode capture : dynamic file name

前端 未结 2 863
天涯浪人
天涯浪人 2020-12-19 09:21

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

2条回答
  •  感动是毒
    2020-12-19 10:00

    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.

提交回复
热议问题