From e946c7d239aef41049448104b84d275617bf385f Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Thu, 5 Nov 2009 08:04:57 +0100 Subject: [PATCH] Fix TODO statistics bug Alessandro Paccacio writes: > I've an outline like this: > > * Project A > ** TODO Task A-1 [0/3] > *** TODO Subtask A-1-a > *** TODO Subtask A-1-b > *** TODO Subtask A-1-c > > where level 1 heading is the name of a project, level 2 heading is a > generic task broken into three level 3 headings. As suggested in > section 5.5 of the manual, I've hooked the org-summary-todo function > to org-after-todo-statistics-hook, in order to automatically change > the level 2 TODO to DONE when all the subtasks are DONE. > Unfortunately, when I change to DONE the first subtask, an unexpected > TODO is added to level 1 heading: > > * TODO Project A > ** TODO Task A-1 [1/3] > *** DONE Subtask A-1-a > *** TODO Subtask A-1-b > *** TODO Subtask A-1-c > > From now on, the switch TODO->DONE or DONE/TODO applies to level 1 > heading, even if the [/] cookie in level 2 is correctly updated: > > * DONE Project A > ** TODO Task A-1 [3/3] > *** DONE Subtask A-1-a > *** DONE Subtask A-1-b > *** DONE Subtask A-1-c > > Is there a way to apply the automatic change of TODO to the parent > heading only, as below? > > * Project A > ** DONE Task A-1 [3/3] > *** DONE Subtask A-1-a > *** DONE Subtask A-1-b > *** DONE Subtask A-1-c --- lisp/ChangeLog | 2 ++ lisp/org.el | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a4ab263f0..152a215e4 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -3,6 +3,8 @@ * org.el (org-refile): Refile to clock only if the prefix arg is 2. (org-sparse-tree): Fix docstring to be in line with prompt. + (org-update-parent-todo-statistics): Call + `org-after-todo-statistics-hook' on each level. 2009-11-04 Carsten Dominik diff --git a/lisp/org.el b/lisp/org.el index 194c53598..265acd135 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -9973,7 +9973,7 @@ statistics everywhere." (while (and (setq level (org-up-heading-safe)) (or recursive first) (>= (point) lim)) - (setq first nil) + (setq first nil cookie-present nil) (unless (and level (not (string-match "\\" @@ -10008,10 +10008,10 @@ statistics everywhere." ndel (- (match-end 0) (match-beginning 0))) (goto-char (match-beginning 0)) (insert new) - (delete-region (point) (+ (point) ndel)))) - (when cookie-present - (run-hook-with-args 'org-after-todo-statistics-hook - cnt-done (- cnt-all cnt-done))))) + (delete-region (point) (+ (point) ndel))) + (when cookie-present + (run-hook-with-args 'org-after-todo-statistics-hook + cnt-done (- cnt-all cnt-done)))))) (run-hooks 'org-todo-statistics-hook))) (defvar org-after-todo-statistics-hook nil