From 9a7c7e0673c12319b91511efdca8943a76bb9480 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Tue, 16 Nov 2021 21:38:33 -0800 Subject: [PATCH] [oni-org-roam] Add any files with tasks in them to org agenda files --- oni-org-roam.el | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/oni-org-roam.el b/oni-org-roam.el index a53e422..68b6b22 100644 --- a/oni-org-roam.el +++ b/oni-org-roam.el @@ -4,7 +4,7 @@ ;; Author: Tom Willemse ;; Keywords: local -;; Version: 2021.1028.195800 +;; Version: 2021.1116.213141 ;; Package-Requires: (oni-org org-roam) ;; This program is free software; you can redistribute it and/or modify @@ -30,11 +30,29 @@ ;;; Code: (require 'org-roam) +(require 'seq) (setq org-roam-completion-everywhere t) (setq org-roam-directory (expand-file-name "~/documents/exocortex/")) (mkdir org-roam-directory t) +;;; Taken from/inspired by +;;; https://magnus.therning.org/2021-07-23-keeping-todo-items-in-org-roam-v2.html +(defun oni-org-roam--todo-node-p (node) + "Predicate to check whether or not NODE is task." + (not (null (org-roam-node-todo node)))) + +(defun oni-org-roam--todo-files () + "Get a list of all the files in the org-roam database with tasks in them." + (let ((nodes (seq-filter #'oni-org-roam--todo-node-p (org-roam-node-list)))) + (seq-uniq (seq-map #'org-roam-node-file nodes)))) + +(defun oni-org-roam-update-todo-files (&rest _) + "Set ‘org-agenda-files’ to all roam files with a task in them." + (setq org-agenda-files (seq-uniq (append org-agenda-files (oni-org-roam--todo-files))))) + +(advice-add 'org-agenda :before #'oni-org-roam-update-todo-files) + ;;;###autoload (setq org-roam-v2-ack t)