summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2017-05-27 18:12:38 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2017-05-27 18:12:38 +0200
commit75e9fdac6c4f9b1b433c5bbdc734e4afb6c8bc1d (patch)
tree3783df21f0a9b74a93438265fc4f2eca98668b16
parent2d29269bb1b9af08011e091913798b6598e4b156 (diff)
downloadorg-mode-75e9fdac6c4f9b1b433c5bbdc734e4afb6c8bc1d.tar.gz
org-clock: Fix number of time columns in clock table
* lisp/org-clock.el (org-clocktable-write-default): Limit number of time columns to the deepest headline level. * testing/lisp/test-org-clock.el (test-org-clock/clocktable/maxlevel): Update tests.
-rw-r--r--lisp/org-clock.el16
-rw-r--r--testing/lisp/test-org-clock.el12
2 files changed, 20 insertions, 8 deletions
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 3a67d2d..ff2f874 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -2474,8 +2474,20 @@ from the dynamic block definition."
(level? (and (not compact?) (plist-get params :level)))
(timestamp (plist-get params :timestamp))
(properties (plist-get params :properties))
- (time-columns (if compact? 1
- (min maxlevel (or (plist-get params :tcolumns) 100))))
+ (time-columns
+ (if (or compact? (< maxlevel 2)) 1
+ ;; Deepest headline level is a hard limit for the number
+ ;; of time columns.
+ (let ((levels
+ (cl-mapcan
+ (lambda (table)
+ (pcase table
+ (`(,_ ,(and (pred wholenump) (pred (/= 0))) ,entries)
+ (mapcar #'car entries))))
+ tables)))
+ (min maxlevel
+ (or (plist-get params :tcolumns) 100)
+ (if (null levels) 1 (apply #'max levels))))))
(indent (or compact? (plist-get params :indent)))
(formula (plist-get params :formula))
(case-fold-search t)
diff --git a/testing/lisp/test-org-clock.el b/testing/lisp/test-org-clock.el
index 14eb0a0..6d4cbdb 100644
--- a/testing/lisp/test-org-clock.el
+++ b/testing/lisp/test-org-clock.el
@@ -370,12 +370,12 @@ CLOCK: [2012-03-29 Thu 16:40]--[2014-03-04 Thu 00:41] => 16905:01
(ert-deftest test-org-clock/clocktable/maxlevel ()
"Test \":maxlevel\" parameter in Clock table."
(should
- (equal "| Headline | Time | | |
-|--------------+--------+------+---|
-| *Total time* | *6:00* | | |
-|--------------+--------+------+---|
-| Foo | 6:00 | | |
-| \\_ Bar | | 2:00 | |
+ (equal "| Headline | Time | |
+|--------------+--------+------|
+| *Total time* | *6:00* | |
+|--------------+--------+------|
+| Foo | 6:00 | |
+| \\_ Bar | | 2:00 |
"
(org-test-with-temp-text
"