diff options
author | Nicolas Goaziou <n.goaziou@gmail.com> | 2011-06-20 21:59:58 +0200 |
---|---|---|
committer | Nicolas Goaziou <n.goaziou@gmail.com> | 2011-06-20 21:59:58 +0200 |
commit | a0bc3bdebc3a48937332b96de11bd6470018c047 (patch) | |
tree | 5dadecaa67a4f08b73a4ca8c9c3a0ff09424db04 | |
parent | 8608b6651d18f41cbc343dcac77d27b1f0280df9 (diff) | |
download | org-mode-a0bc3bdebc3a48937332b96de11bd6470018c047.tar.gz |
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.
-rw-r--r-- | lisp/org-list.el | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/lisp/org-list.el b/lisp/org-list.el index a8520fd..e7aba3e 100644 --- a/lisp/org-list.el +++ b/lisp/org-list.el @@ -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)) |