Org-roam and code integration

Has anyone ever thought about using Org-roam and integrating it tightly with coding tasks? What I’m thinking about is being able to capture notes while navigating through a codebase and then later being able to jump from the note directly to the specific place in code.

Similar to org-noter, which allows you to take notes while reading a pdf, and then sync them, making it possible to either find the relevant text in the pdf related to the note or jump from a specific page in the document to the relevant note (if there’s one).

Maybe you can get a bit crazy. Imagine being able to create an “Org skeleton” document that goes through some project and creates a bunch of headings for each module/namespace, and maybe even sub-headings for each function/procedure, adding hyperlinks to the module/namespace the function gets imported from. Then you can use org-roam-ui to inspect the structure of the project. Would that be really cool?

Maybe even some GitHub/GitLab/Codeberg integration, where you can find all related issues and pull requests and navigate to them if needed? Directly from your notes.

I use my package Org-remark.

The latest lets you have an annotation for a line. In the image above, the “(*)” in the main buffer (“ren.el”) denotes that the line has a annotation. The annotations are saved as an Org file shown on the left.

I don’t integrate the annotation file with Org-roam, but you can. It uses a normal Org files. You can add ID to the headline or the file and save it in your org-roam-directory.

1 Like

That’s interesting!

If an annotation file is in (one of) your org-roam data folder(s), how does the code know where to find the annotation?

A function that looks for the annotation file. The package comes with a default and you can define your own.

1 Like

Sweet! In your .emacs config do you have code that overrides that default with something that calls org-roam-node-find? And if so do you mind sharing that?

@JeffBrown , I don’t and I don’t need to override the default.
The default function does this and is good for me:

the default function is
‘org-remark-notes-file-name-function’.  It returns a file name
like this: "FILE-notes.org" by adding "-notes.org" as a
suffix to the file name without the extension.

I hope it’s straightforward to store notes file(s) in org-roam-directory.

Let’s say you have directories like this.

~/
├── src
│   └── my-code.el
├── org-roam-directory
│   ├── 2022-01-22T112233_notes-about-stuff.org
.    .

You can add annotations to my-code.el and store the notes file under org-roam-directory by setting user option org-remark-notes-file-name like this:

(setopt org-remark-notes-file-name (expand-file-name "notes.org" org-roam-directory))

Alternatively, you can set a function to the user option if you wish to be more flexible, like these examples:

(setopt org-remark-notes-file-name (lambda ()
                                     ;; return an absolute file name for the current-buffer
                                     ))

(setopt org-remark-notes-file-name #'my-function)

There is nothing that automatically adds an ID to the file or headline – you can manually do this so that org-roam stores the file/headline in the cache…