1
votes

I'm trying to create an Org mode capture template that writes each entry to a time-based filename.

First, there is a helper function that works in the scratch buffer:

;; Example input: (capture-date-based-file "~/path/to/logs/" "log")
;; Expected output: "~/path/to/logs/2017-11-27-monday-log.org"
(defun capture-date-based-file (path entry-type)
  "Create a date-based file name based on the given type."
  (downcase (concat path (format-time-string "%Y-%m-%d-%A-") entry-type ".org")))

Then, it's used in the capture templates list:

(setq org-capture-templates
      '(("l" "Log" entry (file+headline ,(capture-date-based-file "~/path/to/logs/" "log"))
         "* %?\n%U\n" :clock-in t :clock-resume t) ))

I get an error: Symbol's function definition is void: \,

It's difficult to find an answer in Google, because of the comma character. I've looked over the docs, and I'm not sure what I'm doing wrong.

1
What does backtick mean in LISP?: stackoverflow.com/questions/30150186/… - lawlist

1 Answers

3
votes

The comma suggests that you're wanting to evaluate the call to capture-date-based-file, but the surrounding form is quoted rather than backquoted, so that won't work.

i.e. these are two quite different things:

'(foo ,(bar) baz)
`(foo ,(bar) baz)

See C-hig (elisp)Backquote RET

In a backquoted form, the comma causes the form which follows to be evaluated immediately, and the result of that evaluation is then substituted into the backquoted form. In a quoted form, ,(bar) simply remains as a literal ,(bar).

The reason for the specific error you saw is that the lisp reader produces the following:

ELISP> (read ",(bar)")
(\, (bar))

Therefore any attempt to evaluate ,(bar) is actually calling the non-existent function \,

(One of the less-obvious errors you'll encounter, FWIW.)

In your scenario I presume that org pulls that particular form out of the template structure and evaluates it. M-x toggle-debug-on-error would most likely show you exactly where and when this happens.