aboutsummaryrefslogtreecommitdiffstats
path: root/oni-org-roam.el
diff options
context:
space:
mode:
authorGravatar Tom Willemse2022-09-21 23:43:07 -0700
committerGravatar Tom Willemse2022-09-21 23:43:07 -0700
commit298402f2e13dc32c0cda332b4d6bf825068c993d (patch)
treed5d959027609fc2810cc4192e9438089beca1fd7 /oni-org-roam.el
parent4dcb5a4f6d64e8a23b709124940547ffc8e01620 (diff)
downloademacs-config-298402f2e13dc32c0cda332b4d6bf825068c993d.tar.gz
emacs-config-298402f2e13dc32c0cda332b4d6bf825068c993d.zip
[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.
Diffstat (limited to 'oni-org-roam.el')
-rw-r--r--oni-org-roam.el30
1 files changed, 21 insertions, 9 deletions
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 <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)