Browse Source

org-list: Fix statistics updating with cookie in sublist

* lisp/org-list.el (org-update-checkbox-count): Properly update
  statistics cookies in a sublist.

* testing/lisp/test-org-list.el (test-org-list/update-checkbox-count):
Add test.

Reported-by: Gerald Wildgruber <Gerald.Wildgruber@unibas.ch>
<http://permalink.gmane.org/gmane.emacs.orgmode/99792>
Nicolas Goaziou 9 years ago
parent
commit
ac0661189e
2 changed files with 16 additions and 7 deletions
  1. 9 6
      lisp/org-list.el
  2. 7 1
      testing/lisp/test-org-list.el

+ 9 - 6
lisp/org-list.el

@@ -2527,17 +2527,20 @@ With optional prefix argument ALL, do this for the whole buffer."
 	     (let* ((container
 		     (org-element-lineage
 		      context
-		      '(drawer center-block dynamic-block inlinetask plain-list
+		      '(drawer center-block dynamic-block inlinetask item
 			       quote-block special-block verse-block)))
-		    (beg (if container (org-element-property :begin container)
+		    (beg (if container
+			     (org-element-property :contents-begin container)
 			   (save-excursion
-			     (org-with-limited-levels (outline-previous-heading))
+			     (org-with-limited-levels
+			      (outline-previous-heading))
 			     (point)))))
 	       (or (cdr (assq beg cache))
 		   (save-excursion
 		     (goto-char beg)
 		     (let ((end
-			    (if container (org-element-property :end container)
+			    (if container
+				(org-element-property :contents-end container)
 			      (save-excursion
 				(org-with-limited-levels (outline-next-heading))
 				(point))))
@@ -2556,9 +2559,9 @@ With optional prefix argument ALL, do this for the whole buffer."
 		       (let ((count
 			      (funcall count-boxes
 				       (and (eq (org-element-type container)
-						'plain-list)
+						'item)
 					    (org-element-property
-					     :contents-begin container))
+					     :begin container))
 				       structs
 				       recursivep)))
 			 (push (cons beg count) cache)

+ 7 - 1
testing/lisp/test-org-list.el

@@ -813,7 +813,7 @@
 		 (org-test-with-temp-text "* [%]\n- [X] item"
 		   (org-update-checkbox-count)
 		   (buffer-string))))
-  ;; From a list.
+  ;; From a list or a sub-list.
   (should
    (string-match "\\[0/1\\]"
 		 (org-test-with-temp-text "- [/]\n  - [ ] item"
@@ -829,6 +829,12 @@
 		 (org-test-with-temp-text "- [%]\n  - [X] item"
 		   (org-update-checkbox-count)
 		   (buffer-string))))
+  (should
+   (string-match
+    "\\[1/1\\]"
+    (org-test-with-temp-text "- [ ] item 1\n- [ ] item 2 [/]\n  - [X] sub 1"
+      (org-update-checkbox-count)
+      (buffer-string))))
   ;; Count do not apply to sub-lists unless count is not hierarchical.
   ;; This state can be achieved with COOKIE_DATA node property set to
   ;; "recursive".