mirror of
https://github.com/librephoenix/nixos-config
synced 2025-01-19 07:05:51 +05:30
Updated org-roam-agenda auto-tagger for todo items
This commit is contained in:
parent
9358a76e6c
commit
4def9b1ef4
|
@ -637,6 +637,36 @@ same directory as the org-buffer and insert a link to this file."
|
||||||
(with-current-buffer (get-file-buffer the-daily-node-filename) (kill-buffer))
|
(with-current-buffer (get-file-buffer the-daily-node-filename) (kill-buffer))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
(defun org-current-buffer-has-todos ()
|
||||||
|
"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."
|
||||||
|
(org-element-map ; (2)
|
||||||
|
(org-element-parse-buffer 'headline) ; (1)
|
||||||
|
'headline
|
||||||
|
(lambda (h)
|
||||||
|
(eq (org-element-property :todo-type h)
|
||||||
|
'todo))
|
||||||
|
nil 'first-match)) ; (3)
|
||||||
|
|
||||||
|
(defun org-has-recent-timestamps (OLD-DAYS)
|
||||||
|
"Return non-nil only if current buffer has entries with timestamps
|
||||||
|
more recent than OLD-DAYS days"
|
||||||
|
(interactive)
|
||||||
|
(if (org-element-map (org-element-parse-buffer) 'timestamp
|
||||||
|
(lambda (h)
|
||||||
|
(org-element-property :raw-value h)))
|
||||||
|
(org-element-map ; (2)
|
||||||
|
(org-element-parse-buffer) ; (1)
|
||||||
|
'timestamp
|
||||||
|
(lambda (h)
|
||||||
|
(time-less-p (time-subtract (current-time) (* 60 60 24 OLD-DAYS)) (date-to-time (org-element-property :raw-value h))))
|
||||||
|
nil 'first-match) nil))
|
||||||
|
|
||||||
|
(setq org-timestamp-days-for-old 21)
|
||||||
|
|
||||||
; This has a bug where it won't sync a new agenda file
|
; This has a bug where it won't sync a new agenda file
|
||||||
; if I'm editing an org roam node file while set to another
|
; if I'm editing an org roam node file while set to another
|
||||||
; org roam db
|
; org roam db
|
||||||
|
@ -645,7 +675,7 @@ same directory as the org-buffer and insert a link to this file."
|
||||||
(when (string= (message "%s" major-mode) "org-mode")
|
(when (string= (message "%s" major-mode) "org-mode")
|
||||||
(if (org-roam-node-p (org-roam-node-at-point))
|
(if (org-roam-node-p (org-roam-node-at-point))
|
||||||
(funcall (lambda()
|
(funcall (lambda()
|
||||||
(if (or (text-in-buffer-p "SCHEDULED: <") (text-in-buffer-p "DEADLINE: <"))
|
(if (or (org-current-buffer-has-todos) (org-has-recent-timestamps org-timestamps-days-for-old))
|
||||||
(org-roam-tag-add '("todos"))
|
(org-roam-tag-add '("todos"))
|
||||||
(org-roam-tag-remove '("todos"))
|
(org-roam-tag-remove '("todos"))
|
||||||
)
|
)
|
||||||
|
|
|
@ -747,6 +747,36 @@ exit
|
||||||
(with-current-buffer (get-file-buffer the-daily-node-filename) (kill-buffer))
|
(with-current-buffer (get-file-buffer the-daily-node-filename) (kill-buffer))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
(defun org-current-buffer-has-todos ()
|
||||||
|
"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."
|
||||||
|
(org-element-map ; (2)
|
||||||
|
(org-element-parse-buffer 'headline) ; (1)
|
||||||
|
'headline
|
||||||
|
(lambda (h)
|
||||||
|
(eq (org-element-property :todo-type h)
|
||||||
|
'todo))
|
||||||
|
nil 'first-match)) ; (3)
|
||||||
|
|
||||||
|
(defun org-has-recent-timestamps (OLD-DAYS)
|
||||||
|
"Return non-nil only if current buffer has entries with timestamps
|
||||||
|
more recent than OLD-DAYS days"
|
||||||
|
(interactive)
|
||||||
|
(if (org-element-map (org-element-parse-buffer) 'timestamp
|
||||||
|
(lambda (h)
|
||||||
|
(org-element-property :raw-value h)))
|
||||||
|
(org-element-map ; (2)
|
||||||
|
(org-element-parse-buffer) ; (1)
|
||||||
|
'timestamp
|
||||||
|
(lambda (h)
|
||||||
|
(time-less-p (time-subtract (current-time) (* 60 60 24 OLD-DAYS)) (date-to-time (org-element-property :raw-value h))))
|
||||||
|
nil 'first-match) nil))
|
||||||
|
|
||||||
|
(setq org-timestamp-days-for-old 21)
|
||||||
|
|
||||||
; This has a bug where it won't sync a new agenda file
|
; This has a bug where it won't sync a new agenda file
|
||||||
; if I'm editing an org roam node file while set to another
|
; if I'm editing an org roam node file while set to another
|
||||||
; org roam db
|
; org roam db
|
||||||
|
@ -755,7 +785,7 @@ exit
|
||||||
(when (string= (message "%s" major-mode) "org-mode")
|
(when (string= (message "%s" major-mode) "org-mode")
|
||||||
(if (org-roam-node-p (org-roam-node-at-point))
|
(if (org-roam-node-p (org-roam-node-at-point))
|
||||||
(funcall (lambda()
|
(funcall (lambda()
|
||||||
(if (or (text-in-buffer-p "SCHEDULED: <") (text-in-buffer-p "DEADLINE: <"))
|
(if (or (org-current-buffer-has-todos) (org-has-recent-timestamps org-timestamps-days-for-old))
|
||||||
(org-roam-tag-add '("todos"))
|
(org-roam-tag-add '("todos"))
|
||||||
(org-roam-tag-remove '("todos"))
|
(org-roam-tag-remove '("todos"))
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue