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-?

5
  • What happens if you add a second argument t to the eval call? i.e. make it ... %(eval item-string t) ....
    – NickD
    Jun 23 at 1:18
  • When I add t to the eval call, I get the same capture: * %![Error: (void-variable item-string)].
    – jmrasband
    Jun 23 at 2: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 at 7: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 at 7: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.
    – jmrasband
    Jun 24 at 13:31

1 Answer 1

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")))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.