Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Archive DONE items to datetree based on CLOSED time
(defadvice org-archive-subtree
(around org-archive-subtree-to-data-tree activate)
"org-archive-subtree to date-tree"
(if (org-entry-is-done-p)
(let* ((dct (decode-time
(org-time-string-to-time
(cdar (org-entry-properties nil 'special "CLOSED")))))
(y (nth 5 dct))
(m (nth 4 dct))
(d (nth 3 dct))
(this-buffer (current-buffer))
(location (org-get-local-archive-location))
(afile (org-extract-archive-file location))
(org-archive-location
(format "%s::%s %04d-%02d-%02d %s" afile
(make-string (org-get-valid-level 0 2) ?*) y m d
(format-time-string "%A" (encode-time 0 0 0 d m y)))))
(message "afile=%s" afile)
(message "archive-loc=%s" org-archive-location)
(unless afile
(error "Invalid `org-archive-location'"))
(save-excursion
(switch-to-buffer (find-file-noselect afile))
(org-datetree-find-year-create y)
(org-datetree-find-month-create y m)
(org-datetree-find-day-create y m d)
(widen)
(switch-to-buffer this-buffer))
ad-do-it)
ad-do-it))
;; Execute the following in the file which you want to archive
(org-map-entries 'org-archive-subtree
(mapconcat
'(lambda (x) (format "TODO=\"%s\"" x))
org-done-keywords "|"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.