Browse Source

Checkboxes: Allow recursive statistics.

Patch by Richard Klinda.
Carsten Dominik 16 years ago
parent
commit
a607b5b218
3 changed files with 32 additions and 12 deletions
  1. 13 10
      doc/org.texi
  2. 4 0
      lisp/ChangeLog
  3. 15 2
      lisp/org-list.el

+ 13 - 10
doc/org.texi

@@ -3778,16 +3778,19 @@ The @samp{[2/4]} and @samp{[1/3]} in the first and second line are cookies
 indicating how many checkboxes present in this entry have been checked off,
 and the total number of checkboxes are present.  This can give you an idea on
 how many checkboxes remain, even without opening a folded entry.  The cookies
-can be placed into a headline or into (the first line of) a plain list
-item. Each cookie covers all checkboxes structurally below the headline/item
-on which the cookie appear.  You have to insert the cookie yourself by typing
-either @samp{[/]} or @samp{[%]}.  With @samp{[/]} you get an @samp{n out of
-m} result, as in the examples above.  With @samp{[%]} you get information
-about the percentage of checkboxes checked (in the above example, this would
-be @samp{[50%]} and @samp{[33%]}, respectively).  In a headline, a cookie can
-both count checkboxes below the heading, or TODO states of children, and it
-will display whatever was changed last.  Set the property @code{COOKIE_DATA}
-to either @samp{checkbox} or @samp{todo} to resolve this issue.
+can be placed into a headline or into (the first line of) a plain list item.
+Each cookie covers checkboxes of direct children structurally below the
+headline/item on which the cookie appear@footnote{Set the variable
+@code{org-recursive-checkbox-statistics} if you want such cookes to represent
+the all checkboxes below the cookie, not just the direct children.}.  You
+have to insert the cookie yourself by typing either @samp{[/]} or @samp{[%]}.
+With @samp{[/]} you get an @samp{n out of m} result, as in the examples
+above.  With @samp{[%]} you get information about the percentage of
+checkboxes checked (in the above example, this would be @samp{[50%]} and
+@samp{[33%]}, respectively).  In a headline, a cookie can both count
+checkboxes below the heading, or TODO states of children, and it will display
+whatever was changed last.  Set the property @code{COOKIE_DATA} to either
+@samp{checkbox} or @samp{todo} to resolve this issue.
 
 @cindex blocking, of checkboxes
 @cindex checkbox blocking

+ 4 - 0
lisp/ChangeLog

@@ -9,6 +9,10 @@
 
 2009-05-08  Carsten Dominik  <carsten.dominik@gmail.com>
 
+	* org-list.el (org-update-checkbox-count): Allow recursive
+	statistics.
+	(org-hierarchical-checkbox-statistics): New option.
+
 	* org.el (org-cycle): Remove erraneous space character.
 
 	* org-icalendar.el (org-icalendar-timezone): Initialize from

+ 15 - 2
lisp/org-list.el

@@ -112,6 +112,12 @@ with \\[org-ctrl-c-ctrl-c\\]."
   :group 'org-plain-lists
   :type 'boolean)
 
+(defcustom org-hierarchical-checkbox-statistics t
+  "Non-nil means, checkbox statistics counts only the state of direct children.
+When nil, all boxes below the cookie are counted."
+  :group 'org-plain-lists
+  :type 'boolean)
+
 (defcustom org-description-max-indent 20
   "Maximum indentation for the second line of a description list.
 When the indentation would be larger than this, it will become
@@ -419,7 +425,10 @@ the whole buffer."
 	       (org-beginning-of-item)
 	       (setq curr-ind (org-get-indentation))
 	       (setq next-ind curr-ind)
-	       (while (and (bolp) (org-at-item-p) (= curr-ind next-ind))
+	       (while (and (bolp) (org-at-item-p)
+			   (if org-hierarchical-checkbox-statistics
+			       (= curr-ind next-ind)
+			     (<= curr-ind next-ind)))
 		 (save-excursion (end-of-line) (setq eline (point)))
 		 (if (re-search-forward re-box eline t)
 		     (if (member (match-string 2) '("[ ]" "[-]"))
@@ -427,7 +436,11 @@ the whole buffer."
 		       (setq c-on (1+ c-on))
 		       )
 		   )
-		 (org-end-of-item)
+		 (if org-hierarchical-checkbox-statistics
+		     (org-end-of-item)
+		   (end-of-line)
+		   (when (re-search-forward org-list-beginning-re lim t)
+		     (beginning-of-line)))
 		 (setq next-ind (org-get-indentation))
 		 )))
 	 (goto-char continue-from)