1
0
Fork 0

[oni-org-roam] Show / hide the roam buffer when desired

This toggles the roam buffer on when a buffer that is part of org roam is
displayed, and toggles it off when I switch away.
This commit is contained in:
Tom Willemse 2022-09-21 23:43:07 -07:00
parent 4dcb5a4f6d
commit 298402f2e1

View file

@ -4,7 +4,7 @@
;; Author: Tom Willemse <tom@ryuslash.org> ;; Author: Tom Willemse <tom@ryuslash.org>
;; Keywords: local ;; Keywords: local
;; Version: 2022.0103.225707 ;; Version: 2022.0921.234248
;; 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
@ -39,22 +39,34 @@
(mkdir org-roam-directory t) (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 ;;; Taken from/inspired by
;;; https://magnus.therning.org/2021-07-23-keeping-todo-items-in-org-roam-v2.html ;;; https://magnus.therning.org/2021-07-23-keeping-todo-items-in-org-roam-v2.html
(defun oni-org-roam--todo-node-p (node) (defun oni-org-roam-update-todo-files (&rest _)
"Predicate to check whether or not NODE is task." "Set org-agenda-files to all roam files with a task in them."
(let ((state (org-roam-node-todo node))) (setq org-agenda-files (seq-uniq (append org-agenda-files (oni-org-roam--todo-files)))))
(and (not (null state))
(not (string= state "FINISHED")))))
(defun 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." "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)))) (let ((nodes (seq-filter #'oni-org-roam--todo-node-p (org-roam-node-list))))
(seq-uniq (seq-map #'org-roam-node-file nodes)))) (seq-uniq (seq-map #'org-roam-node-file nodes))))
(defun oni-org-roam-update-todo-files (&rest _) (defun oni-org-roam--todo-node-p (node)
"Set org-agenda-files to all roam files with a task in them." "Predicate to check whether or not NODE is task."
(setq org-agenda-files (seq-uniq (append org-agenda-files (oni-org-roam--todo-files))))) (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) (advice-add 'org-agenda :before #'oni-org-roam-update-todo-files)