diff --git a/oni-org-roam.el b/oni-org-roam.el index d3cc1b5..261d1c9 100644 --- a/oni-org-roam.el +++ b/oni-org-roam.el @@ -4,7 +4,7 @@ ;; Author: Tom Willemse ;; Keywords: local -;; Version: 2022.1122.231427 +;; Version: 2023.0325.115622 ;; Package-Requires: (oni-org org-roam) ;; This program is free software; you can redistribute it and/or modify @@ -66,6 +66,27 @@ (and (not (null state)) (not (string= state "FINISHED"))))) +(defun oni-org-roam--books-to-read () + (seq-filter (lambda (item) + (string= (map-elt (car item) "STATUS") "toread")) + (org-roam-db-query [:select [nodes:properties nodes:file nodes:title] + :from nodes + :left-join tags + :on (= tags:node-id nodes:id) + :where (like tag (quote "%\"book\"%"))]))) + +(defun oni-org-roam-list-books-to-read () + (interactive) + (let ((buffer (get-buffer-create "*books-to-read*"))) + (with-current-buffer buffer + (erase-buffer) + (mapc (lambda (item) (insert (caddr item) "\n")) (oni-org-roam--books-to-read))) + (switch-to-buffer buffer))) + +(defun oni-org-roam-random-book-to-read () + (interactive) + (find-file (cadr (seq-random-elt (oni-org-roam--books-to-read))))) + (add-to-list 'display-buffer-alist `(,(rx string-start "*org-roam*" string-end) display-buffer-in-side-window