0

I would like to define an function using org-roam's capture system. However, I want to create a new function, not use the variable org-roam-capture-templates and the related function org-roam-capture.

I want to create a function that takes a string as an argument so that I can use it in the captured text. In this case, I want to be able to specificy a string (e.g. "TODO", "DONE", or other states) that is added to the beginning of the captured item.

This is my attempt so far:

(defun org-roam-capture-inbox-test (item-string)
    (interactive)
    (org-roam-capture- :node (org-roam-node-create)
                       :templates '(("i" "inbox" plain "* %(eval item-string) %?"
                                     :if-new (file "Inbox.org")))))

Evaluating this function creates this capture item: * %![Error: (void-variable item-string)]. Unless I'm mistaken, this means that item-string is out of scope when it is called in org-roam-capture-.

Why is item-string out of scope in this case? How can I pass it to org-roam-capture-?

Fran Burstall
  • 3,665
  • 10
  • 18
jrasband
  • 73
  • 6
  • What happens if you add a second argument `t` to the `eval` call? i.e. make it `... %(eval item-string t) ...`. – NickD Jun 23 '22 at 01:18
  • When I add `t` to the `eval` call, I get the same capture: `* %![Error: (void-variable item-string)]`. – jrasband Jun 23 '22 at 02:31
  • @NickD No, Nick. The `(eval item-string)` is within a string. So you would you have to replace the quoted list by something like `(("i" "inbox" plain ,(format "* %%(eval %s) %%?" item-string) :if-new (file "Inbox.org")). Note the backquote instead of the quote! – Tobias Jun 23 '22 at 07:10
  • Yes, I know - the thing is that `org-capture` will parse the `%(eval ...)` form eventually and it will evaluate it. But the evaluation environment will be far removed from the definition environment: I was wondering if there would be any connection. If the OP is right, there does not seem to be any - so, yes, it's just another backquoting problem. – NickD Jun 23 '22 at 07:25
  • Using the backquote and `(("i" "inbox" plain ,(format "* %s %%?" item-string) :if-new (file "Inbox.org")))` as the template fixed the problem. Note that I needed to remove the `eval` from the solution. If @Tobias wants the reputation for the solution, you can write it up and I'll mark it as correct. Otherwise, I'll write up and post your solution. – jrasband Jun 24 '22 at 13:31

1 Answers1

0

As @Tobias suggested, this is partially a backquote problem. This is the solution:

(defun org-roam-capture-inbox-test (item-string)
    (interactive)
    (org-roam-capture- :node (org-roam-node-create)
                       :templates `(("i" "inbox" plain ,(format "* %s %%?" item-string) :if-new (file "Inbox.org")))))
jrasband
  • 73
  • 6