org-list: fix update of check-boxes cookies in whole trees

* lisp/org-list.el (org-reset-checkbox-state-subtree): make the
  command more robust, and correctly update check-boxes in the whole
  sub-tree.
(org-update-checkbox-count): fix bug accumulating count of checkboxes
when walking a subtree.
(org-update-checkbox-count-maybe): add an optional argument passed to
org-update-checkbox-count.

Thanks to Paul Mead for the report.
This commit is contained in:
Nicolas Goaziou 2011-06-20 21:59:58 +02:00
parent 8608b6651d
commit a0bc3bdebc
1 changed files with 17 additions and 14 deletions

View File

@ -2176,17 +2176,19 @@ in subtree, ignoring drawers."
(defun org-reset-checkbox-state-subtree ()
"Reset all checkboxes in an entry subtree."
(interactive "*")
(save-restriction
(save-excursion
(org-narrow-to-subtree)
(org-show-subtree)
(goto-char (point-min))
(let ((end (point-max)))
(while (< (point) end)
(when (org-at-item-checkbox-p)
(replace-match "[ ]" t t nil 1))
(beginning-of-line 2))))
(org-update-checkbox-count-maybe)))
(if (org-before-first-heading-p)
(error "Not inside a tree")
(save-restriction
(save-excursion
(org-narrow-to-subtree)
(org-show-subtree)
(goto-char (point-min))
(let ((end (point-max)))
(while (< (point) end)
(when (org-at-item-checkbox-p)
(replace-match "[ ]" t t nil 1))
(beginning-of-line 2)))
(org-update-checkbox-count-maybe 'all)))))
(defun org-update-checkbox-count (&optional all)
"Update the checkbox statistics in the current section.
@ -2272,7 +2274,8 @@ With optional prefix argument ALL, do this for the whole buffer."
;; next headline, and save them in STRUCTS-BAK.
((org-on-heading-p)
(setq backup-end (save-excursion
(outline-next-heading) (point)))
(outline-next-heading) (point))
structs-bak nil)
(while (org-list-search-forward box-re backup-end 'move)
(let* ((struct (org-list-struct))
(bottom (org-list-get-bottom-point struct)))
@ -2327,10 +2330,10 @@ Otherwise it will be `org-todo'."
'org-checkbox-statistics-done
'org-checkbox-statistics-todo)))
(defun org-update-checkbox-count-maybe ()
(defun org-update-checkbox-count-maybe (&optional all)
"Update checkbox statistics unless turned off by user."
(when (cdr (assq 'checkbox org-list-automatic-rules))
(org-update-checkbox-count))
(org-update-checkbox-count all))
(run-hooks 'org-checkbox-statistics-hook))
(defvar org-last-indent-begin-marker (make-marker))