reddit / emacs

org-roam: Show only file nodes when inserting a node?

pragmat1c1 · 2022-06-13 10:41
Coming from Roam Research to org-roam, I miss the conceptual distinction between `page references` and `block references`. In org-roam, whenever I'd like to insert a link to a node via `C-c n i`, I am offered a long list of nodes that represent files AND links to outline items that I have linked to. So when I try to link to a document called `Emacs`, I see a very long list of nodes mentioning Emacs, amongh which there's also my entry `Emacs`. My current workaround is to enter `^Emacs` in the node search field (`^` is a regular expression denoting beginning of line), but that maybe there's a more elegant solution?
bespokey · 2022-06-13 11:09
I think org-roam uses completing-read which can be customized using completion-styles, or, if you're using a completion framework such as Vertico, use the package's completion style customizatuon variables. Reference: https://www.gnu.org/software/emacs/manual/html_node/emacs/Completion-Styles.html
organic-bookworm · 2022-06-13 18:07
Just skimmed through the code. You could wrap [`org-roam-node-insert`](https://github.com/org-roam/org-roam/blob/b63ff2a7bbd888128939b8ae88c3f62c0d529945/org-roam-node.el#L665) or advice [`org-roam-node-read`](https://github.com/org-roam/org-roam/blob/b63ff2a7bbd888128939b8ae88c3f62c0d529945/org-roam-node.el#L510) to use a custom `filter-fn`. (defun my/org-roam-node-file-p (node) (= (org-roam-node-level node) 0)) (org-roam-node-read nil #'my/org-roam-node-file-p)
pragmat1c1 · 2022-06-13 19:11
>org-roam-node-insert Excellent! Thank you very much!