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-
?
t
to theeval
call? i.e. make it... %(eval item-string t) ...
.t
to theeval
call, I get the same capture:* %![Error: (void-variable item-string)]
.(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!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.(("i" "inbox" plain ,(format "* %s %%?" item-string) :if-new (file "Inbox.org")))
as the template fixed the problem. Note that I needed to remove theeval
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.