2

I've started using org-mode and am now at the point where I really need archiving. However, I often have sub-projects which are hard to understand without the containing project (i.e., the ancestors in the tree).

Is it possible to archive a subtree while creating the super-tree (if it does not exist yet)?

Concrete example. Say my gtd.org file looks like this:

* Private
** TODO Organize all my Todos
[…] 

* Work
[…]
** TODO Awesome Project
*** DONE Organize all my Todos
**** DONE Do X
**** DONE Do Y
*** TODO Get Work Done

And my gtd.org_archive file is empty. Now, when I archive the "DONE Organize all my Todos" task, this is what I want my archive file to look like:

* Work
** Awesome Project
*** DONE Organize all my Todos
**** DONE Do X
**** DONE Do Y

Obviously, when later archiving other stuff, it should figure out whether the containing tree must be created or is already there. E.g., if I later set the "Get Work Done" to DONE and archive it, this is how the archive should look like:

* Work
** Awesome Project
*** DONE Organize all my Todos
**** DONE Do X
**** DONE Do Y
*** DONE Get Work Done

It should not create a new * Work / ** Awesome Project tree. However, when I later archive the "Organize all my Todos" under "Private", it should not be mixed up with the one under work, but look like this:

* Private
** DONE Organize all my Todos

* Work
** Awesome Project
*** DONE Organize all my Todos
**** DONE Do X
**** DONE Do Y
*** DONE Get Work Done

Is there any way of achieving this using org-mode?

Thanks in advance.

1

In the org mode FAQ is a link to code from edgimar which should be able to preserve the structure.

I'm unsure if I should insert the code here or if it's too long for that. I'll open this answer as wiki in case someone else wants to decide.

  • Can't find the Wiki checkbox in the app, will change from home. – p_wiersig Feb 13 at 11:08
  • Great, that's pretty much what I was looking for! However, for some reason the save-buffer command in line 115 seems not to work - emacs keeps asking me whether I really want to kill the unsaved buffer. I removed the kill-buffer and save the buffer manually now. However, I still wonder why save-buffer seems to be ignored… – Lukas Barth Feb 13 at 13:33
  • Oh, that's probably because save-buffer always saves the current buffer. That worked for edgimar, because he archived in the same file, but I use a separate archive file… I guess it should be something along the lines of: (when (not (eq source-buffer target-buffer)) (with-current-buffer target-buffer (save-buffer) ) ) – Lukas Barth Feb 13 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.