Browse Source

org-colview: Fix {X%} and {X/} on recursive summaries

* lisp/org-colview.el (org-columns--summary-checkbox-count):
(org-columns--summary-checkbox-percent): Handle own output for higher
level summaries.
* testing/lisp/test-org-colview.el (test-org-colview/columns-summary):
  Add tests.
Nicolas Goaziou 7 years ago
parent
commit
39b3f45a7d
2 changed files with 88 additions and 3 deletions
  1. 6 3
      lisp/org-colview.el
  2. 82 0
      testing/lisp/test-org-colview.el

+ 6 - 3
lisp/org-colview.el

@@ -1234,14 +1234,17 @@ When PRINTF is non-nil, use it to format the result."
 (defun org-columns--summary-checkbox-count (check-boxes _)
   "Summarize CHECK-BOXES with a check-box cookie."
   (format "[%d/%d]"
-	  (cl-count "[X]" check-boxes :test #'equal)
+	  (cl-count-if (lambda (b) (or (equal b "[X]")
+				  (string-match-p "\\[\\([1-9]\\)/\\1\\]" b)))
+		       check-boxes)
 	  (length check-boxes)))
 
 (defun org-columns--summary-checkbox-percent (check-boxes _)
   "Summarize CHECK-BOXES with a check-box percent."
   (format "[%d%%]"
-	  (round (* 100.0 (cl-count "[X]" check-boxes :test #'equal))
-		 (float (length check-boxes)))))
+	  (round (* 100.0 (cl-count-if (lambda (b) (member b '("[X]" "[100%]")))
+				       check-boxes))
+		 (length check-boxes))))
 
 (defun org-columns--summary-min (values printf)
   "Compute the minimum of VALUES.

+ 82 - 0
testing/lisp/test-org-colview.el

@@ -337,6 +337,88 @@
 ** S1
 :PROPERTIES:
 :A: [X]
+:END:"
+      (let ((org-columns-default-format "%A{X%}")) (org-columns))
+      (get-char-property (point) 'org-columns-value-modified))))
+  ;; {X/} handles recursive summaries.
+  (should
+   (equal
+    "[1/2]"
+    (org-test-with-temp-text
+	"* H
+** S1
+:PROPERTIES:
+:A: [ ]
+:END:
+** S2
+*** S21
+:PROPERTIES:
+:A: [X]
+:END:
+*** S22
+:PROPERTIES:
+:A: [X]
+:END:"
+      (let ((org-columns-default-format "%A{X/}")) (org-columns))
+      (get-char-property (point) 'org-columns-value-modified))))
+  (should
+   (equal
+    "[1/2]"
+    (org-test-with-temp-text
+	"* H
+** S1
+:PROPERTIES:
+:A: [X]
+:END:
+** S2
+*** S21
+:PROPERTIES:
+:A: [ ]
+:END:
+*** S22
+:PROPERTIES:
+:A: [ ]
+:END:"
+      (let ((org-columns-default-format "%A{X/}")) (org-columns))
+      (get-char-property (point) 'org-columns-value-modified))))
+  ;; {X%} handles recursive summaries.
+  (should
+   (equal
+    "[50%]"
+    (org-test-with-temp-text
+	"* H
+** S1
+:PROPERTIES:
+:A: [ ]
+:END:
+** S2
+*** S21
+:PROPERTIES:
+:A: [X]
+:END:
+*** S22
+:PROPERTIES:
+:A: [X]
+:END:"
+      (let ((org-columns-default-format "%A{X%}")) (org-columns))
+      (get-char-property (point) 'org-columns-value-modified))))
+  (should
+   (equal
+    "[50%]"
+    (org-test-with-temp-text
+	"* H
+** S1
+:PROPERTIES:
+:A: [X]
+:END:
+** S2
+*** S21
+:PROPERTIES:
+:A: [ ]
+:END:
+*** S22
+:PROPERTIES:
+:A: [ ]
 :END:"
       (let ((org-columns-default-format "%A{X%}")) (org-columns))
       (get-char-property (point) 'org-columns-value-modified))))