1

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.

R891
  • 2,550
  • 4
  • 18
  • 30
  • **What does backtick mean in LISP?**: https://stackoverflow.com/questions/30150186/what-does-backtick-mean-in-lisp – lawlist Nov 28 '17 at 00:51

1 Answers1

3

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.

phils
  • 71,335
  • 11
  • 153
  • 198
  • Thanks, I've added more code to my question. It starts with a `'` (quote) character. If I use a backtick or remove the comma, I get an error (`Wrong type argument: stringp, nil`), but it doesn't tell me where the error is. I'm too new to fully understand what is going on, even after reading the doc pages a few times. – R891 Nov 27 '17 at 22:33
  • 1
    Oh -- according to `C-h v org-capture-templates` you are missing a parameter. It specifies `(file+headline "path/to/file" "node headline")` and you are only supplying a single parameter (the return value of the call to `capture-date-based-file`) which will be the `"path/to/file"` parameter. You are not supplying the `"node headline"` parameter. – phils Nov 28 '17 at 03:31
  • 1
    If you fix that then, based on the updated code, I would expect that changing the `'` to a `\`` would have the desired effect, and that removing the comma (instead of backquoting) may or may not work. If it *does* work, and if you want the date to potentially vary whenever `org-capture-templates` is used, then removing the comma would be the way to go. – phils Nov 28 '17 at 03:37
  • Thanks. Between what you wrote and [this](https://emacs.stackexchange.com/a/17899) I have it just about working. For some reason it downcases another part of the path which shouldn't be downcased, but I think I can figure that out. – R891 Nov 29 '17 at 02:10