67 lines
3.2 KiB
Org Mode
67 lines
3.2 KiB
Org Mode
:PROPERTIES:
|
|
:ID: cce/navigate-note
|
|
:ROAM_REFS: https://ag91.github.io/blog/2021/03/12/find-org-roam-notes-via-their-relations/
|
|
:ROAM_ALIASES: "Navigate notes by relations" "Navigate notes by links"
|
|
:END:
|
|
#+TITLE: Find Org Roam notes via their relations - Where parallels cross
|
|
#+filetags: :Archive:CCE:
|
|
#+AUTO_TANGLE: t
|
|
|
|
#+ARCOLOGY_KEY: cce/navigate-notes
|
|
#+ARCOLOGY_ALLOW_CRAWL: t
|
|
|
|
[[id:d17a9ccf-0bfe-426e-85b3-d15771d3ee03][Archive]]
|
|
|
|
#+BEGIN_QUOTE
|
|
Are you an [[id:cce/org-roam][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.
|
|
#+END_QUOTE
|
|
|
|
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 [[id:cce/cce][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 [[id:6b306fe3-fbc4-4ba7-bfcb-089c0564f9c3][Topic Files]].
|
|
|
|
Great for finding [[id:09fa0674-ad3b-43c5-8d7c-6b532346a772][open threads]], perhaps, especially once we're doing headings.
|
|
|
|
#+ARROYO_EMACS_MODULE: navigate-note
|
|
#+ARROYO_MODULE_WANTS: cce/org-roam.org
|
|
#+begin_src emacs-lisp :tangle navigate-note.el
|
|
(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
|
|
:join nodes :as sources :on (= source sources:id)
|
|
:join nodes :as dests :on (= dest dests:id)
|
|
:where (= source $s1) :or (= dest $s1)])
|
|
;; pop out the one that isn't the node passed in:
|
|
(--map
|
|
(--first (not (equal it (org-roam-node-id node)))
|
|
it))
|
|
(-map #'org-roam-node-from-id)
|
|
(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."
|
|
(interactive "P")
|
|
(let* ((choices (or choices
|
|
(when arg (cce/org-roam-db--links-to (org-roam-node-at-point)))
|
|
(org-roam-node-list)))
|
|
(next-node (org-roam-node-read nil (apply-partially #'-contains? choices) nil t)))
|
|
(if (and node next-node
|
|
(string= (org-roam-node-id node)
|
|
(org-roam-node-id next-node)))
|
|
(org-roam-node-visit node)
|
|
(cce/org-roam-navigate-note nil next-node
|
|
(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))
|
|
|
|
(with-eval-after-load 'org-roam
|
|
(bind-keys :map org-roam-prefix-map
|
|
("n" . cce/org-roam-navigate-note)))
|
|
|
|
(provide 'cce/navigate-note)
|
|
#+end_src
|