0

I have just started to use org-mode and I am tweaking an existing configuration to my needs.

In that configuration, the code is itself in an org file and the org-capture-templates is splited in a lot of individual blocks (because there are some text explanations between) like

(add-to-list 'org-capture-templates
             '("j" "Journal entry"
               entry
               (file+datetree "~/org/journal.org")
               "* %?"
               :empty-lines 1 
               ))

Given that I have defined my org-directory to "~/org" and that this path is duplicated in quite every entry definition, in case I would move the org file in say a share or a git repo, I tried to replace the file paths by a construct like

(add-to-list 'org-capture-templates
             '("j" "Journal entry"
               entry
               (file+datetree (concat org-directory "/journal.org"))
               "* %?"
               :empty-lines 1 
               ))

Unfortunately when I try to capture a journal entry I get this

org-capture-expand-file: Invalid file location: nil

while (concat org-directory "/journal.org") evaluates to the same value "~/org/journal.org". I suppose that the concat is missing some quoting, but I did no find the correct form.

Drew
  • 75,699
  • 9
  • 109
  • 225
Seki
  • 157
  • 9
  • 1
    Here is a recent [duplicate](https://emacs.stackexchange.com/questions/77091/how-to-split-org-roam-capture-templates-in-to-multiple-lines) of this question. The answer is: use `backquote` instead of `quote` in front of the entry and precede the `(concat ...` form with a comma. That will quote the rest of the entry, but it will evaluate the expression after the comma. See [Backquote](https://www.gnu.org/software/emacs/manual/html_node/elisp/Backquote.html) in the Emacs Lisp Reference manual. – NickD May 10 '23 at 01:34
  • https://emacs.stackexchange.com/tags/elisp/info – Drew May 10 '23 at 14:04
  • @NickD Maaaany thanks! I may be an Emacs user for years and a programmer for many more, I never managed to dive in functional programming/lisp and while I can manage my .emacs I am always puzzled by elisp. – Seki May 10 '23 at 14:43
  • That's fine: I hope you got your template working properly given the above hints. This question appears in many different guises and trips up a lot of people. If you search for `backquote`, you can find a bunch of different manifestations of the same underlying problem (`quote` quotes everything, so nothing gets evaluated in the quoted expression; `backquote` quotes everything *except* it allows evaluation of selected sub-expressions). After having seen a few, you get to recognize the underlying problem. – NickD May 10 '23 at 15:18
  • 1
    @NickD, yes your comment in the question linked in your previous comment totally clarified the situation, so my org capture template are working as expected. Also I copy/pasted it to my Emacs Notes related to quoting for future reference. – Seki May 15 '23 at 12:58

0 Answers0