From 3a3460b0d7283a45c54330f589c52e4c441423e4 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Sat, 25 Mar 2023 21:40:39 -0700 Subject: [PATCH] [oni-org-roam] Add command to pick a random book from toread list --- oni-org-roam.el | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) 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