0

I'd like to have an Org file with the following structure

* Books
** Fantasy
*** TOREAD Fantasy Book 1
*** READING Fantasy Book 2
*** TOREAD Fantasy Book 3

** Comedy
*** TOREAD Comedy Book 1

* Articles
** Science
*** TOREAD Article 1


* Archive
** Books
*** Fantasy
**** READ Fantasy Book X
**** WONTREAD Fantasy Book X
*** Comedy
** Articles
*** Science

In words, some hierarchy, and an archived version of that hierarchy with items flagged as done (here READ and WONTREAD). The goal is for the archiving to be done automagically when flagging the item as done.

As an example: If Fantasy Book 2 were to be set as READ, it would fall under Archive>Books>Fantasy, at the bottom of it.

Question: Is this doable? Is this legal?

My org-foo is in its infancy, and help would be much appreciated.

Thanks!

2
1

You could use org-after-todo-state-change-hook, which

Hook which is run after the state of a TODO item was changed. The new state (a string with a TODO keyword, or nil) is available in the Lisp variable ‘org-state’.

(add-hook 'org-after-todo-state-change-hook 'konstantin/org-archive-when-done)

And the function to be hooked is the konstantin/org-archive-when-done

(defun konstantin/org-archive-when-done ()
  "Archive item when TODO state changed to DONE"
  (if (member org-state '("DONE" "DELEGATED"))
      (org-archive-subtree)
    ()))

Here you can see list of stages like ("DONE" "DELEGATED"), which means to be like DONE. In your case it is ("READ" "WONTREAD").

For automatically load this function, put its into init.el.

7
  • 1
    Thanks for your answer, but I believe the focus of my question is elsewhere: I wonder how to make org-archive-subtree work as I asked, that is, putting the item on the Archive sub tree in the file, at the same hierarchical entry, at the end of it. Did I miss that?
    – Michaël
    Dec 25 '16 at 14:25
  • 1
    @Michaël Where archived items go is decided by org-archive-location. Try setting it to "::* Archive"
    – erikstokes
    Dec 25 '16 at 15:19
  • @erikstokes: Thanks for your comment! However, I feel this is not the important part again: the archived item should fall within the same tree on the Archived header. Cheers!
    – Michaël
    Dec 25 '16 at 17:56
  • @Michaël That can also be done, but is more than a comment. Try asking a separate question.
    – erikstokes
    Dec 25 '16 at 18:44
  • 1
    @Michaël I think you're asking two questions here: 1) How do I automatically archive entries on marking them DONE and 2) How to preserve the outline structure when archiving.
    – erikstokes
    Dec 25 '16 at 22:26

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.