feat(emacs): move org tasks to org roam

Moves all of the tasks from Todo.org into any org-roam note file. All tasks
will then show up in the agenda and be able to be scheduled and searched just
like any other task we currently have in the Todo.org file. This is based of
the task management blog below. It will add a filetag to any file that has
tasks in it. This will then use only those files to build the org agenda so it
dose not have to search though every file in the roam database.

https://d12frosted.io/posts/2021-01-16-task-management-with-roam-vol5.html

The main difference from this blog is that it uses the `tasklist` filetag
rather than `projects` as the blogs. This makes much more sense for my use case

It also moves all the capture targets to the roam dailies so my main workspace
for the day is the daily note. This also moves the refile targets to be the old
Todo.org file. I will still be using this for the main backlog and any tasks
that don't need to be complete on that day. The current workflow I will be
using is capturing into the daily note. If I won't complete it that day, it
will either move to the next day or be refiled to be done on another day.
This commit is contained in:
Ade Attwood 2024-10-10 07:36:09 +01:00
parent b095833f8e
commit 843767fdb8

View file

@ -92,8 +92,70 @@ just in in the current buffer."
(require 'org-protocol)
(require 'org-tempo)
(defun aa/org-roam-update-tasklist-tag ()
"Add or remove the 'tasklist' filetag based on the presence of TODO items in
the current buffer. Ensure the filetag is inserted right under the title if
not present."
(when (org-roam-file-p) ; Ensure this only runs on Org-roam files
(save-excursion
(goto-char (point-min))
;; Locate the title or the first heading
(let ((has-title (re-search-forward "^#\\+title:" nil t))
(has-todo nil))
;; Check for TODOs in the file
(goto-char (point-min))
(while (re-search-forward org-todo-regexp nil t)
(setq has-todo t))
;; Determine the correct place for filetags (right below the title or
;; first heading)
(goto-char (point-min))
(when has-title
(re-search-forward "^#\\+title:.*$" nil t))
;; Insert filetags if missing
(unless (re-search-forward "^#\\+filetags:" (save-excursion (outline-next-heading) (point)) t)
;; Move under title or first heading
(end-of-line)
(insert "\n#+filetags:"))
;; Go to the filetags line and modify based on presence of TODOs
(goto-char (point-min))
(when (re-search-forward "^#\\+filetags:.*$" nil t)
(let ((tags-line (match-string 0)))
(if has-todo
(unless (string-match-p ":tasklist:" tags-line)
;; Add the tasklist tag if not present and TODOs exist
(end-of-line)
(insert " :tasklist:"))
(when (string-match-p ":tasklist:" tags-line)
;; Remove the tasklist tag if no TODOs exist
(replace-match (replace-regexp-in-string ":tasklist:" "" tags-line) nil nil nil 0)))))))))
;; Add the function to before-save-hook so it runs on every save
(add-hook 'before-save-hook 'aa/org-roam-update-tasklist-tag)
(defun aa/org-roam-tasklist-files ()
"Return a list of note files containing 'tasklist' tag."
(seq-uniq
(seq-map
#'car
(org-roam-db-query
[:select [nodes:file]
:from tags
:left-join nodes
:on (= tags:node-id nodes:id)
:where (like tag (quote "%\"tasklist\"%"))]))))
(defun aa/org-agenda-files (&rest _)
"Update the value of `org-agenda-files'."
(setq org-agenda-files
(append (aa/org-roam-tasklist-files) (list org-directory))))
(advice-add 'org-agenda :before #'aa/org-agenda-files)
(advice-add 'org-todo-list :before #'aa/org-agenda-files)
(setq org-directory "~/Org"
org-agenda-files (list org-directory)
org-todo-keywords '((sequence "TODO" "WAITING" "REVIEW" "|" "DONE" "ARCHIVED"))
org-hide-emphasis-markers t
org-agenda-window-setup 'current-window
@ -120,6 +182,17 @@ just in in the current buffer."
'(("t" "Todo" entry (file+headline "Todo.org" "Inbox")
"* TODO %?\n\n %a")))
(setq org-roam-dailies-capture-templates
'(("d" "default" entry
"* %?"
:target (file+head "%<%Y-%m-%d>.org" "#+title: %<%Y-%m-%d>\n"))
("t" "todo" entry
"* TODO %?\n\n %a"
:target (file+head "%<%Y-%m-%d>.org" "#+title: %<%Y-%m-%d>\n"))))
(setq org-refile-targets
`((,(concat (file-name-as-directory org-directory) "Todo.org") :maxlevel . 1)))
(add-hook 'org-mode-hook (lambda ()
(electric-pair-mode)
(org-indent-mode)
@ -143,6 +216,7 @@ just in in the current buffer."
(org-roam-completion-everywhere t)
:config
(org-roam-db-autosync-mode)
(aa/org-agenda-files)
(require 'org-roam-protocol))
(use-package org-roam-ui
@ -375,7 +449,7 @@ just in in the current buffer."
;; Org Mode
"o" '(evil-window-map :which-key "Org Mode")
"oa" 'org-agenda
"oc" 'org-capture
"oc" 'org-roam-dailies-capture-today
"ot" 'org-roam-dailies-goto-today
"of" 'org-roam-node-find
"or" 'org-refile