I just very recently started using Emacs Org-mode to organize my tasks, and I really don't know anything about Emacs-Lisp.

What I have achieved is to mark a TODO entry as DONE when its children(sub-entry) are marked DONE by putting these commands in my Init file as instructed by the Org-mode manual.

(defun org-summary-todo (n-done n-not-done)
  "Switch entry to DONE when all subentries are done,
to TODO otherwise."       
  (let (org-log-done org-log-states) ;turn off logging                          
    (org-todo (if (= n-not-done 0) "DONE" "TODO"))))                             
(add-hook 'org-after-todo-statistics-hook #'org-summary-todo)

However, this doesn't work when I want it to change the status of a child(sub-entry) based on this child's child(sub-sub-entry). Effectively, I have this following TODO list:

* Testing[0%]                                                                   
** TODO Item1[100%]                                                             
*** DONE Item1.1...                                                             
*** DONE Item1.2...                                                             
** TODO Item2[0%]                                                               
*** TODO Item2.1                                                                
*** TODO Item2.2  

and notice how the first TODO should be DONE since it's 100% completed. The above code provided in the Org-mode manual could not achieve this effect.

Is there some additional commands I can put in the Init file to make this work?

  • FWIW, it works perfectly for me. I change states of third-level items and the TODO state of the second level items is changed appropriately (as well as the statistics cookie) and si is the state/cookie at the top level. So I'm not sure why you re not getting this behavior. What version of Org mode are you running? Are you changing the state with C-c t? – NickD Mar 19 at 18:52
  • I'm using org version 20200316. And yes I am changing states with C-c C-t – Yanzhou Mar 19 at 19:54
  • I did mean C-c C-t - sorry for the typo. The only thing I can think of is that somehow the hook has not been modified. Can you do C-h v org-after-todo-statistics-hook RET and see whether it includes the function above? – NickD Mar 19 at 20:37
  • One more thing: can you try it with emacs -q? Evaluate the above code somehow (C-x C-e will evaluate each s-expression if you put the cursor after the closing paren) and then try cycling through states. If it works, something in your init file is causing the problem: bisect it to ffigure out what. – NickD Mar 19 at 20:41
  • 1
    Just realized there was a typo in my command so the hook didn't find the function. Thank you for helping me debugging the issue @NickD – Yanzhou Mar 19 at 22:36

Your Answer

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

Browse other questions tagged or ask your own question.