emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* after-todo-statistics hook for checkboxes
@ 2014-10-15 11:08 James Harkins
  2014-10-15 13:38 ` James Harkins
  0 siblings, 1 reply; 10+ messages in thread
From: James Harkins @ 2014-10-15 11:08 UTC (permalink / raw)
  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

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2014-10-20 12:46 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-15 11:08 after-todo-statistics hook for checkboxes James Harkins
2014-10-15 13:38 ` James Harkins
2014-10-15 13:45   ` Nicolas Goaziou
     [not found]     ` <1491661ce88.27cd.0bb60a3c7e492ea180363c67eb170725@qq.com>
2014-10-16  1:01       ` James Harkins
2014-10-16 16:39         ` Nicolas Goaziou
2014-10-16 23:23           ` James Harkins
2014-10-17 20:22             ` Nicolas Goaziou
2014-10-18  2:21               ` James Harkins
2014-10-18  7:31                 ` Nicolas Goaziou
2014-10-20 12:46                   ` Bastien

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).