org-after-todo-statistics-hook allows you to do something to a node after its 
statistics cookie got updated. Unfortunately, it does this only for TODO 
subheadings and it doesn't work with checkboxes.

Use case: Grading assignments. Each assignment is a subheading. Each student's 
work for that assignment is a plain list item with a checkbox. When I finish 
grading one of them, I tick off the checkbox. At this point, I want the 
heading's TODO status to change:

- If all items are complete, change it to DONE.
- If there exist both finished and unfinished list items, change it to INPROG.
- If all items are still open, change it to TODO. (This could happen if I 
mistakenly ticked a checkbox and then un-ticked it.)

This should then cascade upward to the parent's statistics, all the way to the 
top level, so I can see at a glance (even with all top-level trees folded) that 
there is something remaining to grade.

I don't want to use subheadings for each student's work, because then my TODO 
agenda views will get cluttered with multiple entries per assignment.

Actually... after a little more poking around, the problem seems to be that 
org-update-checkbox-count refers to no hooks whatsoever. Should it go toward 
the end, here? (Untested.)

      (mapc (lambda (cookie)
              (let* ((beg (car cookie))
                     (end (nth 1 cookie))
                     (percentp (nth 2 cookie))
                     (checked (car (nth 3 cookie)))
                     (total (cdr (nth 3 cookie)))
                     (new (if percentp
                              (format "[%d%%]" (/ (* 100 checked)
                                                  (max 1 total)))
                            (format "[%d/%d]" checked total))))
                (goto-char beg)
                (insert new)
                (delete-region (point) (+ (point) (- end beg)))
                (run-hook-with-args 'org-after-todo-statistics-hook
                                    checked (- total checked))
                (when org-auto-align-tags (org-fix-tags-on-the-fly))))
            cookies-list))))

hjh



Reply via email to