aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--oni-org/oni-org.el54
1 files changed, 53 insertions, 1 deletions
diff --git a/oni-org/oni-org.el b/oni-org/oni-org.el
index 242cc32..3ce98b4 100644
--- a/oni-org/oni-org.el
+++ b/oni-org/oni-org.el
@@ -958,7 +958,8 @@ placed above TARGET. Otherwise it will be placed below it."
(let ((components (org-heading-components)))
(list (cons 'done (and (org-entry-is-done-p) t))
(cons 'title (nth 4 components))
- (cons 'poms (string-to-number (or (alist-get "POMS" (org-entry-properties) nil nil #'string=) "0")))
+ (cons 'poms (length (oni-org-pomodoro-times-for-date
+ (org-parse-time-string date))))
(cons 'id (org-id-get-create)))))
(format "TODO=\"NEXT\"|CLOSED>=\"<%s 0:00>\"+CLOSED<=\"<%s 23:59>\""
date date)
@@ -991,5 +992,56 @@ placed above TARGET. Otherwise it will be placed below it."
(defalias 'org-dblock-write:oni-pomodoro-overview 'oni-org-dblock-write-pomodoro-overview)
(org-dynamic-block-define "oni-pomodoro-overview" #'oni-org-insert-pomodoro-overview)
+(defun oni-org-increment-property (property)
+ (interactive
+ (list (org-read-property-name)))
+ (let ((value (string-to-number (or (org-entry-get (point) property) "0"))))
+ (org-set-property property (number-to-string (1+ value)))))
+
+(add-to-list 'org-log-note-headings
+ (cons 'pomodoro "Finished a pomodoro on %t"))
+
+(defun oni-org-pomodoro-add-note ()
+ (interactive)
+ (org-add-log-setup 'pomodoro nil nil 'time))
+
+(defun oni-org-pomodoro-times ()
+ (let ((entry-beginning (org-entry-beginning-position))
+ (entry-end (org-entry-end-position))
+ results)
+ (save-excursion
+ (goto-char entry-beginning)
+ (save-match-data
+ (re-search-forward org-logbook-drawer-re entry-end)
+ (let ((logbook-beginning (match-beginning 0))
+ (logbook-end (match-end 0)))
+ (goto-char logbook-beginning)
+ (while (re-search-forward
+ (rx "Finished a pomodoro on "
+ (group "[" (one-or-more (not "]")) "]"))
+ logbook-end t)
+ (push (org-parse-time-string (match-string 1)) results)))))
+ results))
+
+(defun oni-org-pomodoro-times-for-date (date)
+ (let ((day (decoded-time-day date))
+ (month (decoded-time-month date))
+ (year (decoded-time-year date)))
+ (seq-filter (lambda (time) (and (= (decoded-time-day time) day)
+ (= (decoded-time-month time) month)
+ (= (decoded-time-year time) year)))
+ (oni-org-pomodoro-times))))
+
+;;; Archive Management
+
+(defun oni-org-archive-old-tasks ()
+ "Archive tasks in all agenda files that were closed before the current month."
+ (interactive)
+ (let ((match (format-time-string "CLOSED<\"<%Y-%m-01>\"")))
+ (mapc (lambda (p)
+ (goto-char p)
+ (org-archive-subtree))
+ (reverse (org-map-entries #'point match 'agenda)))))
+
(provide 'oni-org)
;;; oni-org.el ends here