I want to update an org-mode checkbox total count automatically. For example, if I have this:

* TODO Parent task [0/2] ;; I have 0/2
** TODO Children1
** TODO Children2

And then, if I add a third task, the parent task checkbox should be changed automatically to 3.

* TODO Parent task [0/3] ;; now I have 0/3
** TODO Children1
** TODO Children2
** TODO New

The same way, if I remove any task, the parent checkbox should immediately change to [0/2].

How do I do this?


Use @wasamasa's solution for adding new headers.

There are no default org commands for removing a heading and updating the todo count at the same time. It is possible to update all todo counts in the document by calling function org-update-statistics-cookies with the universal argument (C-u C-c #).

There many ways to remove a heading, so not all of them can not trigger the todo update. You have to create a function for it and include the non-interactive function org-update-parent-todo-statistics to the end of it. The alternative is to modify an existing command.

The following shows how to modify a command from the worf package:

;; define an advice
(defadvice worf-delete-subtree (after my-org-update-parent-todo ())
;; activate all advices to this function
(ad-activate 'worf-delete-subtree)

Execute both sexps, place the cursor at the asterisks of the header you want to remove, and press C-d. The line is deleted and the todo count is updated.


Use M-S-RET to add the TODO item and update the above item's count.

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.