Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
904 views
in Technique[技术] by (71.8m points)

emacs - org-mode capture : dynamic file name

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: %?

  %i

  From: %a"
     :empty-lines 1)
;; ..
))

Thanks for any assistance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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] %?
   SCHEDULED: <%<%Y-%m-%d %a>>
  [%<%Y-%m-%d %a>]
  %a")
   ("T" "Travel" entry (file+datetree+prompt "~/Documents/org/travel.org")
    "* %?
  :PROPERTIES:
  :LOCATION:
  :END:
  %t
  %a")
   ("j" "Journal Note" entry (
               file+olp+datetree
               ,(concat
                 org-journal-dir
                 (format-time-string "journal-%m-%d.org")))
   "* Event: %?
 %i
  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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...