4.6 KiB
Dynamic and fast agenda
(provide 'cce/dynamic-fast-agenda)
This is a clever use of the org-roam APIs and database to automatically populate the Org-mode Agendas file list, and has some really neat ideas which I'll integrate in to the CCE I think. I have been thinking that my Projects file isn't scaling so well since I can't represent project hierarchies or relationships very cleanly in the limited hierarchy I've limited myself to. This will have to be part of larger thinking, but I can implement most of this right now.
Without migrating out of Projects, I have
(length org-agenda-files)} {{{results(=22=)}}
org-element
search and update
I might turn this off.
There is some really sharp code in here to use the roam:Org Element API to search for TODO
headlines and add a Project
tag to the ROAM_TAGS
org-roam metadata keyword:
(defun +org-notes-project-p ()
"Return non-nil if current buffer has any todo entry.
TODO entries marked as done are ignored, meaning the this
function returns nil if current buffer contains only completed
tasks."
(seq-find
(lambda (type)
(eq type 'todo))
(org-element-map
(org-element-parse-buffer 'headline)
'headline
(lambda (h)
(org-element-property :todo-type h)))))
(add-hook 'before-save-hook #'+org-notes-project-update-tag)
(defun +org-notes-project-update-tag ()
"Update PROJECT tag in the current buffer."
(save-excursion
(goto-char (point-min))
(when (and (not (active-minibuffer-window))
(+org-notes-buffer-p))
(if (+org-notes-project-p)
(org-roam-tag-add '("Project"))
(org-roam-tag-remove '("Project"))))))
(defun +org-notes-buffer-p ()
"Return non-nil if the currently visited buffer is a note."
(and buffer-file-name
(string-prefix-p
(expand-file-name (file-name-as-directory org-roam-directory))
(file-name-directory buffer-file-name))))
DONE Evaluate turning this off.
SCHEDULED: <2021-03-08 Mon>
- Note taken on [2021-04-06 Tue 17:24]
i think this works pretty well, now that i have it working… - State "DONE" from "NEXT" [2021-04-06 Tue 17:24]
I'm not sure I want this on by default, but it seems nice and great to have documented lying around.
org-agenda-list
updating
a query against the org-roam tags
table is unfortunately un-normalized. I want to add Agendize
roam tag to it as well, and since it's non-normal and I think unsorted in the DB i need to be careful about it. Finally, remove files tagged Icebox
. it basically works though:
(defun cce/org-roam-files-with-tags (&optional tags)
"Return a list of note files containing Project tag."
(let ((tags (or tags '("Project" "Agendize"))))
(->> (org-roam-db-query
[:select file :from nodes
:join tags :on (= node_id id)
:where (in tag $v1)]
(apply #'vector tags))
(delete-dups)
(-map #'car))))
and an advice function to update the DB before showing the agenda:
(defun cce/agenda-files-update (&rest _)
"Update the value of `org-agenda-files'."
(setq org-agenda-files (cce/org-roam-files-with-tags)))
(advice-add 'org-agenda :before #'cce/agenda-files-update)
Tasks
DONE extend this to include Journal tasks! Programming CCE
- State "DONE" from "NEXT" [2021-03-01 Mon 22:33]
- Note taken on [2021-03-01 Mon 16:52]
those should have a ROAM_TAG anyways…….