# What is the best way to use org-roam-node-read with an arbitrary list of nodes?

**URL:** <https://org-roam.discourse.group/t/what-is-the-best-way-to-use-org-roam-node-read-with-an-arbitrary-list-of-nodes/2014>\
**Category:** How To\
**Created:** [September 7, 2021, 12:37am UTC](https://org-roam.discourse.group/t/what-is-the-best-way-to-use-org-roam-node-read-with-an-arbitrary-list-of-nodes/2014 "2021-09-07T00:37:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![arozbiz](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@arozbiz](https://org-roam.discourse.group/u/arozbiz)\
**Post date:** [September 7, 2021, 12:37am UTC](https://org-roam.discourse.group/t/what-is-the-best-way-to-use-org-roam-node-read-with-an-arbitrary-list-of-nodes/2014/1 "2021-09-07T00:37:00Z")

</div>

Let’s say I’m trying to write a function that will let me choose from all the backlinks to a particular node (and I don’t want to use the org-roam buffer, but rather the standard minibuffer `completing-read` function). I can’t just use `org-roam-node-read` with a filter function, because the list of nodes that `org-roam-node-read` is pulling from (which is given by `org-roam-node-list`) doesn’t have the relevant information. So I need to figure out the list of nodes that link to the node at point, and then somehow input them into `org-roam-node-read`, which lacks this functionality. Here is a fairly simple way I’ve figured out how to do this (the important work is done by the `cl-letf` in the first function, based on ideas I read about [here](http://endlessparentheses.com/understanding-letf-and-how-it-replaces-flet.html) and [here](https://nullprogram.com/blog/2017/10/27/)):

```auto
(defun azr/org-roam-node-read (nodes)
  "Like org-roam-node-read but takes a list of NODES."
  (cl-letf (((symbol-function 'org-roam-node-list) (lambda () nodes)))
    (org-roam-node-read)))

(defun azr/org-roam-node-read-backlinks ()
  (interactive)
  "Like org-roam-node-read but only for backlinks of node at point."
  (let ((nodes (seq-uniq (mapcar #'org-roam-backlink-source-node
    		                     (org-roam-backlinks-get (org-roam-node-at-point))))))
    (azr/org-roam-node-read nodes)))

```

This works but it feels hacky. Is there a better way?

---

<div class="post-metadata">

**Author:** ![nobiot](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/nobiot/32/159_2.png) [@nobiot](https://org-roam.discourse.group/u/nobiot)\
**Post date:** [September 7, 2021, 2:01pm UTC](https://org-roam.discourse.group/t/what-is-the-best-way-to-use-org-roam-node-read-with-an-arbitrary-list-of-nodes/2014/2 "2021-09-07T14:01:02Z")

</div>

Looks cool to me; especially the use of cl-letf.  
Otherwise you would need to copy and paste relevant part from org-roam-node-read, and adjust.

---

<div class="post-metadata">

**Author:** ![arozbiz](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@arozbiz](https://org-roam.discourse.group/u/arozbiz)\
**Post date:** [September 7, 2021, 2:19pm UTC](https://org-roam.discourse.group/t/what-is-the-best-way-to-use-org-roam-node-read-with-an-arbitrary-list-of-nodes/2014/3 "2021-09-07T14:19:30Z")

</div>

Thanks. I just learned about `cl-letf` and am a big fan, especially for deeply nested function calls.

Ideally though the org-roam API would provide a better way to do this, so that I could, for example, also change the prompt text in the minibuffer completion.

---

<div class="post-metadata">

**Author:** ![nobiot](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/nobiot/32/159_2.png) [@nobiot](https://org-roam.discourse.group/u/nobiot)\
**Post date:** [September 7, 2021, 3:01pm UTC](https://org-roam.discourse.group/t/what-is-the-best-way-to-use-org-roam-node-read-with-an-arbitrary-list-of-nodes/2014/4 "2021-09-07T15:01:20Z")

</div>

until such an API gets done, you can always write your own function using org-roam-node-read as a reference. It’s not a big function and what it is doing is rather clear (it looks a bit complicated because of the API of built-in completion functions, I guess, but it’s almost fixed syntax).

---

<div class="post-metadata">

**Author:** ![arozbiz](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@arozbiz](https://org-roam.discourse.group/u/arozbiz)\
**Post date:** [September 7, 2021, 3:18pm UTC](https://org-roam.discourse.group/t/what-is-the-best-way-to-use-org-roam-node-read-with-an-arbitrary-list-of-nodes/2014/5 "2021-09-07T15:18:41Z")

</div>

Yeah, I haven’t figured out how the completion API works. But if, as you say, the details of that don’t matter and I can just copy and paste that bit of code, `org-roam-node-read` is quite simple. I just don’t like copy-pasting code I don’t understand :-).

---

<div class="post-metadata">

**Author:** ![nobiot](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/nobiot/32/159_2.png) [@nobiot](https://org-roam.discourse.group/u/nobiot)\
**Post date:** [September 7, 2021, 4:29pm UTC](https://org-roam.discourse.group/t/what-is-the-best-way-to-use-org-roam-node-read-with-an-arbitrary-list-of-nodes/2014/6 "2021-09-07T16:29:48Z")

</div>

You don’t need to take my word for it. In addition to the built-in documentation on completing-read, I use [this part if Embark’s readme](https://github.com/oantolin/embark#telling-embark-about-commands-that-prompt-for-tabs-by-name) as a reference too. You will see it has the same form as org-roam-node-read when it uses completing-read (I vaguely remember this might be the way described in the built-in documentation, too) ;). It will soon go into C code if you try to read the source, which is for me a sign to turn around… (I don’t usually have C source as I don’t build Emacs on Windows).
