diff --git a/oni-org-roam.el b/oni-org-roam.el index 287ea62..113d686 100644 --- a/oni-org-roam.el +++ b/oni-org-roam.el @@ -4,7 +4,7 @@ ;; Author: Tom Willemse ;; Keywords: local -;; Version: 2022.0103.225707 +;; Version: 2022.0921.234248 ;; Package-Requires: (oni-org org-roam) ;; This program is free software; you can redistribute it and/or modify @@ -39,22 +39,34 @@ (mkdir org-roam-directory t) +(defun oni-org-roam-auto-toggle-roam-buffer (&optional _) + "Show the ‘org-roam-buffer' if the current buffer is part of Roam." + (if (or (string-prefix-p org-roam-directory (buffer-file-name)) + (string= (buffer-name) org-roam-buffer)) + (unless (get-buffer-window org-roam-buffer) + (org-roam-buffer-toggle)) + (when (and (get-buffer-window org-roam-buffer) + (not (window-minibuffer-p))) + (org-roam-buffer-toggle)))) + ;;; 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." - (let ((state (org-roam-node-todo node))) - (and (not (null state)) - (not (string= state "FINISHED"))))) +(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))))) (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))))) +(defun oni-org-roam--todo-node-p (node) + "Predicate to check whether or not NODE is task." + (let ((state (org-roam-node-todo node))) + (and (not (null state)) + (not (string= state "FINISHED"))))) + +(add-hook 'window-state-change-hook #'oni-org-roam-auto-toggle-roam-buffer) (advice-add 'org-agenda :before #'oni-org-roam-update-todo-files)