Skip to content

Instantly share code, notes, and snippets.

@SirensOfTitan
Created July 15, 2021 17:35
Show Gist options
  • Save SirensOfTitan/75204ccffc5227baaa131c203066bcf1 to your computer and use it in GitHub Desktop.
Save SirensOfTitan/75204ccffc5227baaa131c203066bcf1 to your computer and use it in GitHub Desktop.
random-excluding-dailies
(defun sirensoftitan/org-roam-node-random (&optional other-window)
"Find a random Org-roam node not in the daily notes collection.
With prefix argument OTHER-WINDOW, visit the node in another
window instead."
(interactive current-prefix-arg)
(if (not org-roam-dailies-directory)
(org-roam-node-random other-window)
(let* ((expanded-dir (expand-file-name org-roam-dailies-directory))
(where-pred (concat expanded-dir "%"))
(results (org-roam-db-query [:select [id file pos] :from nodes :where (not-like file $s1)] where-pred))
(random-row (seq-random-elt results)))
(org-roam-node-visit (org-roam-node-create :id (nth 0 random-row)
:file (nth 1 random-row)
:point (nth 2 random-row))
other-window))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment