Are you an org-roam user that takes a lot of notes and struggles finding them? I will share here a function to reach lost notes via their relations.
This is really neat: you open this and can rifle through your notes, following links until you find the document you want. So imagine, I open it here, and because this page is linked on the CCE index page (and now, vice-versa!) I can navigate from this page to CCE, and then to any other CCE module, or another CCE-related page. This is especially useful when opening Topic Files.
Great for finding open threads, perhaps, especially once we're doing headings.
defun cce/org-roam-db--links-to (&optional node)
(let* ((node (or node (org-roam-node-at-point t))))
(
(->> node
(org-roam-node-id)
(org-roam-db-query [:select [sources:id dests:id] :from links= source sources:id)
:join nodes :as sources :on (= dest dests:id)
:join nodes :as dests :on (= source $s1) :or (= dest $s1)])
:where (;; pop out the one that isn't the node passed in:
(--mapnot (equal it (org-roam-node-id node)))
(--first (
it))#'org-roam-node-from-id)
(-map append (list node)))))
(
defun cce/org-roam-navigate-note (arg &optional node choices)
("Navigate notes by link. With universal ARG tries to use only to navigate the tags of the current note.
Optionally takes a selected NOTE and filepaths CHOICES."
"P")
(interactive let* ((choices (or choices
(when arg (cce/org-roam-db--links-to (org-roam-node-at-point)))
(
(org-roam-node-list)))nil (apply-partially #'-contains? choices) nil t)))
(next-node (org-roam-node-read if (and node next-node
(string= (org-roam-node-id node)
(
(org-roam-node-id next-node)))
(org-roam-node-visit node)nil next-node
(cce/org-roam-navigate-note
(cce/org-roam-db--links-to next-node)))))
;; TODO: 2021-07 this doesn't work, needs an interactive that can take the string, org-roam-find it then navigate
; (bind-keys :map embark-buffer-map
; ("n" . #'cce/org-roam-navigate-note))
'org-roam
(with-eval-after-load
(bind-keys :map org-roam-prefix-map"n" . cce/org-roam-navigate-note)))
(
provide 'cce/navigate-note) (