1
0
Fork 0

[oni-org-roam] Add command to pick a random book from toread list

This commit is contained in:
Tom Willemse 2023-03-25 21:40:39 -07:00
parent 94a7eeef18
commit 3a3460b0d7

View file

@ -4,7 +4,7 @@
;; Author: Tom Willemse <tom@ryuslash.org> ;; Author: Tom Willemse <tom@ryuslash.org>
;; Keywords: local ;; Keywords: local
;; Version: 2022.1122.231427 ;; Version: 2023.0325.115622
;; Package-Requires: (oni-org org-roam) ;; Package-Requires: (oni-org org-roam)
;; This program is free software; you can redistribute it and/or modify ;; This program is free software; you can redistribute it and/or modify
@ -66,6 +66,27 @@
(and (not (null state)) (and (not (null state))
(not (string= state "FINISHED"))))) (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 (add-to-list 'display-buffer-alist
`(,(rx string-start "*org-roam*" string-end) `(,(rx string-start "*org-roam*" string-end)
display-buffer-in-side-window display-buffer-in-side-window