[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:
parent
4dcb5a4f6d
commit
298402f2e1
1 changed files with 21 additions and 9 deletions
|
@ -4,7 +4,7 @@
|
|||
|
||||
;; Author: Tom Willemse <tom@ryuslash.org>
|
||||
;; 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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue