Skip to content

Instantly share code, notes, and snippets.



Forked from d12frosted/agenda.el
Created Feb 27, 2021
What would you like to do?
(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
(seq-find ; (3)
(lambda (type)
(eq type 'todo))
(org-element-map ; (2)
(org-element-parse-buffer 'headline) ; (1)
(lambda (h)
(org-element-property :todo-type h)))))
(defun +org-notes-project-update-tag ()
"Update PROJECT tag in the current buffer."
(when (and (not (active-minibuffer-window))
(let* ((file (buffer-file-name (buffer-base-buffer)))
(all-tags (org-roam--extract-tags file))
(prop-tags (org-roam--extract-tags-prop file))
(tags prop-tags))
(if (+org-notes-project-p)
(setq tags (cons "Project" tags))
(setq tags (remove "Project" tags)))
(unless (eq prop-tags tags)
(combine-and-quote-strings (seq-uniq tags)))))))
(defun +org-notes-buffer-p ()
"Return non-nil if the currently visited buffer is a note."
(and buffer-file-name
(expand-file-name (file-name-as-directory org-roam-directory))
(file-name-directory buffer-file-name))))
(defun +org-notes-project-files ()
"Return a list of note files containing Project tag."
[:select file
:from tags
:where (like tags (quote "%\"Project\"%"))])))
(defun +agenda-files-update (&rest _)
"Update the value of `org-agenda-files'."
(setq org-agenda-files (+org-notes-project-files)))
(add-hook 'find-file-hook #'+org-notes-project-update-tag)
(add-hook 'before-save-hook #'+org-notes-project-update-tag)
(advice-add 'org-agenda :before #'+agenda-files-update)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment