I'm trying to archive
DONE org-mode tasks while maintaining the subtree structure. There's a partial solution for what I'm trying to attempt at https://gist.github.com/edgimar/072d99d8650abe81a9fe7c8687c0c993.
This could be a really nice solution, however, it only works for me when executing on a single
DONE task. If I try extending it to all
DONE tasks in a subtree using
org-map-entries as shown below, it creates a new top-level
* ARCHIVED heading each time it's run. Is there a way to avoid this unwanted behavior?
Example of undesired behavior with
Define function to operate on all
DONE tasks in current subtree:
(defun org-archive-done-tasks () (interactive) (org-map-entries 'org-archive-subtree-hierarchical "/DONE" 'tree))
org-archive-subtree-hierarchical defined in above link.
Now if I take the following buffer
* Project 1 ** TODO Task 1 ** TODO Task 2 ** TODO Task 3
and mark Task 1 as
org-archive-done-tasks on Project 1, and then do the same for Task 2, I get
* ARCHIVED ** Project 1 *** DONE Task 1 * ARCHIVED ** Project 1 *** DONE Task 2 * Project 1 ** TODO Task 3
Here is the desired result, which is what would happen if
org-archive-subtree-hierarchical were run directly on
** DONE Task 1 and then
** DONE Task 2 (as children of
* Project 1)
* ARCHIVED ** Project 1 *** DONE Task 1 *** DONE Task 2 * Project 1 ** TODO Task 3
The whole point is to avoid having to run such an archive command on each individual
DONE task. Is the desired behavior possible using something similar to
org-map-entries? Is there a better method of executing
org-archive-subtree-hierarchical on all
DONE tasks in a subtree multiple times without duplicating the archive target heading?