Accessing and Modifying Nodes
The node interface is cleanly defined using cl-defstruct. The primary method to access nodes is org-roam-node-at-point and org-roam-node-read:
Function: org-roam-node-at-point &optional assert
Return the node at point. If ASSERT, throw an error if there is no node at point.
Function: org-roam-node-read &optional initial-input filter-fn sort-fn require-match
Read and return an ‘org-roam-node’. INITIAL-INPUT is the initial minibuffer prompt value. FILTER-FN is a function to filter out nodes: it takes a single argument (an org-roam-node), and when nil is returned the node will be filtered out. SORT-FN is a function to sort nodes. See org-roam-node-read-sort-by-file-mtime for an example sort function. If REQUIRE-MATCH, the minibuffer prompt will require a match.
Once you obtain the node, you can use the accessors for the node, e.g. org-roam-node-id or org-roam-node-todo.
It is possible to define (or override existing) properties on nodes. This is simply done using a cl-defmethod on the org-roam-node struct:
(cl-defmethod org-roam-node-namespace ((node org-roam-node))
"Return the namespace for NODE.
The namespace is the final directory of the file for the node."
(file-name-nondirectory
(directory-file-name
(file-name-directory (org-roam-node-file node)))))The snippet above defines a new property namespace on org-roam-node, which making it available for use in capture templates.