From mboxrd@z Thu Jan 1 00:00:00 1970 From: James Harkins Subject: after-todo-statistics hook for checkboxes Date: Wed, 15 Oct 2014 19:08:31 +0800 Message-ID: <87a94xk2ts.wl-jamshark70@qq.com> Mime-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:42809) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XeMST-0008V8-L3 for emacs-orgmode@gnu.org; Wed, 15 Oct 2014 07:09:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XeMSO-0003pk-4f for emacs-orgmode@gnu.org; Wed, 15 Oct 2014 07:09:33 -0400 Received: from smtpbgjp2.qq.com ([54.238.162.12]:39802) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XeMSN-0003kM-9O for emacs-orgmode@gnu.org; Wed, 15 Oct 2014 07:09:28 -0400 Received: from hjh-e431.qq.com (unknown [113.109.22.122]) by esmtp4.qq.com (ESMTP) with SMTP id 0 for ; Wed, 15 Oct 2014 19:08:32 +0800 (CST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: orgmode 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