7

I am trying to use concat from within an org-capture template. But I keep getting an "Invalid template" error, so something's not right. Here is my code:

(setq org-capture-templates
    '(("j" "Journal" entry (file+datetree "~/org/journal.org")
      (concat "* " (format-time-string "%H:%M") " %^{Title}\n\n%?"))))

Any ideas?

Drew
  • 75,699
  • 9
  • 109
  • 225
Adam
  • 1,857
  • 11
  • 32
  • 4
    Possible duplicate of [How to evaluate the variables before adding them to a list?](https://emacs.stackexchange.com/questions/7481/how-to-evaluate-the-variables-before-adding-them-to-a-list) – Drew Feb 11 '18 at 17:34

2 Answers2

11

Okay, figured it out! Because the template was quoted '(("j"... the concat expression was not being evaluated. What I needed to do was use backquote and then insert a , before the concat statement to allow this part to evaluate:

(setq org-capture-templates
    `(("j" "Journal" entry (file+datetree "~/org/journal.org")
      ,(concat "* " (format-time-string "%H:%M") " %^{Title}\n\n%?"))))
Adam
  • 1,857
  • 11
  • 32
1

If you use concat, it seems to not update the timestamp for each entry. You can use the built in template expansion for time to make it use the current time when you capture, rather than the time the configuration file was read.

(setq org-capture-templates
    '(("j" "Journal" entry (file+datetree "~/org/journal.org")
      "* %<%H:%M> %^{Title}\n\n%?")))