The Complete Computing Environment

Jump to Missing Org Roam Nodes


Invoking jump-to-missing-node picks a random org-roam link which is of the [[roam:Some Text]] form, i.e. a stub, so that you can fill in missing parts of your graph. This paired with help:org-roam-refile is a helpful way to flesh out your Knowledge Base.

(defun one-random (list)
  (elt list
       (random (length list))))

(defun one-missing-node ()
  (let* ((from-db (org-roam-db-query [:select [source dest] :from links :where (= type "roam")])) 
         (dest-names (-map #'cadr from-db))
         (as-alist (--map (cons (cadr it) (car it)) from-db))
         (eln (one-random dest-names))) 
    (assoc eln as-alist #'equal)))

(defun jump-to-missing-node ()
  (pcase-let* ((`(,text . ,source-id) (one-missing-node))
               (node (org-roam-node-from-id source-id)))
    (org-roam-node-open node)
    (goto-char (point-min))
    (search-forward (format "[[roam:%s]]" text))

(provide 'cce/missing-org-roam)