# Agenda view from nearby notes

**URL:** <https://org-roam.discourse.group/t/agenda-view-from-nearby-notes/371>\
**Category:** How To\
**Created:** [June 14, 2020, 7:46am UTC](https://org-roam.discourse.group/t/agenda-view-from-nearby-notes/371 "2020-06-14T07:46:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![timquelch](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@timquelch](https://org-roam.discourse.group/u/timquelch)\
**Post date:** [June 14, 2020, 7:46am UTC](https://org-roam.discourse.group/t/agenda-view-from-nearby-notes/371/1 "2020-06-14T07:46:46Z")

</div>

I often leave TODOs in my notes if I need to complete a train of thought or elaborate on something. I’ve been trying to implement an agenda view which picks up TODOs from not only the current note, but ones that are closely linked to it.

The minimum (not) working example I came up with was adding an custom agenda view which rebinds the `org-agenda-files` list:

```
(setq org-agenda-custom-commands
  '(("e" "todos in nearby notes"
     ((todo "" ((org-agenda-files
                 (org-roam-db--links-with-max-distance
                  buffer-file-name
                  3))))))))

```

Basically the `org-roam-db--links-with-max-distance` call gets a list of all files that are within 3 links of the file in the current buffer. This doesn’t seem to work because by the time the let binding is evaluated, `buffer-file-name` evaluates to nil because the agenda buffer is already created.

The other option I (and @zaeph) considered were just a wrapper around the agenda view. My version of this was

```
(defun tq/agenda-nearby-notes ()
  (interactive)
  (let ((org-agenda-files (org-roam-db--links-with-max-distance
                           buffer-file-name
                           3)))
    (org-todo-list)))

```

and @zaeph’s

```
 (defun zp/org-roam-agenda ()
  (interactive)
  (let ((org-agenda-custom-commands
         `(("e" "todos in nearby notes"
            ((todo "" ((org-agenda-files
                        ',(org-roam-db--links-with-max-distance
                          (buffer-file-name)
                          3)))))))))
    (org-agenda nil "e")))

```

Disadvantages of wrappers are that It can’t be launched from my the default `org-agenda` dispatcher, but it does give a bit more flexibility in functionality.

Has anyone implemented anything similar to this or has a better version they use?

---

<div class="post-metadata">

**Author:** ![timquelch](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@timquelch](https://org-roam.discourse.group/u/timquelch)\
**Post date:** [June 26, 2020, 6:56am UTC](https://org-roam.discourse.group/t/agenda-view-from-nearby-notes/371/2 "2020-06-26T06:56:38Z")

</div>

I finally got back to this. This is what I settled on. I can provide a prefix argument to configure how far I want it to search for TODOs

```
(defun tq/org-agenda-nearby-notes (&optional distance)
  (interactive "P")
  (let ((org-agenda-files (org-roam-db--links-with-max-distance
                           buffer-file-name (or distance 3)))
        (org-agenda-custom-commands '(("e" "" ((alltodo ""))))))
    (org-agenda nil "e")))
```
