Selaa lähdekoodia

org-clock: Fix missing properties in Clock table

* lisp/org-clock.el (org-clocktable-write-default): Do not ignore
  properties specified by :properties parameter.

* testing/lisp/test-org-clock.el (test-org-clock/clocktable/properties):
  New test.

The regression was introduced in b897ab722.

Reported-by: Dale <dale@codefu.org>
<http://permalink.gmane.org/gmane.emacs.orgmode/112219>
Nicolas Goaziou 8 vuotta sitten
vanhempi
commit
a6c318f471
2 muutettua tiedostoa jossa 61 lisäystä ja 7 poistoa
  1. 6 7
      lisp/org-clock.el
  2. 55 0
      testing/lisp/test-org-clock.el

+ 6 - 7
lisp/org-clock.el

@@ -2587,7 +2587,7 @@ from the dynamic block definition."
 
 	  ;; Get the list of node entries and iterate over it
 	  (when (> maxlevel 0)
-	    (pcase-dolist (`(,level ,headline ,ts ,time . ,props) entries)
+	    (pcase-dolist (`(,level ,headline ,ts ,time ,props) entries)
 	      (when narrow-cut-p
 		(setq headline
 		      (if (and (string-match
@@ -2599,12 +2599,11 @@ from the dynamic block definition."
 				  (org-shorten-string (match-string 3 headline)
 						      narrow))
 			(org-shorten-string headline narrow))))
-	      (cl-flet ((format-field
-			 (let ((marker (pcase level
-					 ((guard (not emph)) "")
-					 (1 "*") (2 "/") (_ ""))))
-			   (lambda (field)
-			     (format "%s%s%s |" marker field marker)))))
+	      (cl-flet ((format-field (f) (format (cond ((not emph) "%s |")
+							((= level 1) "*%s* |")
+							((= level 2) "/%s/ |")
+							(t "%s |"))
+						  f)))
 		(insert-before-markers
 		 "|"		       ;start the table line
 		 (if multifile "|" "") ;free space for file name column?

+ 55 - 0
testing/lisp/test-org-clock.el

@@ -695,6 +695,61 @@ CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
       (buffer-substring-no-properties (line-beginning-position 3)
                                       (line-beginning-position 9))))))
 
+(ert-deftest test-org-clock/clocktable/properties ()
+  "Test \":properties\" parameter in Clock table."
+  ;; Include a new column with list properties.
+  (should
+   (equal
+    "| A | Headline     | Time    |   |
+|---+--------------+---------+---|
+|   | *Total time* | *26:00* |   |
+|---+--------------+---------+---|
+| 1 | Foo          | 26:00   |   |
+"
+    (org-test-with-temp-text
+        "* Foo
+:PROPERTIES:
+:A: 1
+:END:
+CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
+"
+      (test-org-clock-clocktable-contents-at-point ":properties (\"A\")"))))
+  (should
+   (equal
+    "| A | Headline     | Time    |       |
+|---+--------------+---------+-------|
+|   | *Total time* | *52:00* |       |
+|---+--------------+---------+-------|
+|   | Foo          | 52:00   |       |
+| 1 | \\_  Bar      |         | 26:00 |
+"
+    (org-test-with-temp-text
+        "* Foo
+CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
+** Bar
+:PROPERTIES:
+:A: 1
+:END:
+CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
+"
+      (test-org-clock-clocktable-contents-at-point ":properties (\"A\")"))))
+  ;; Handle missing properties.
+  (should
+   (equal
+    "| A | Headline     | Time    |   |
+|---+--------------+---------+---|
+|   | *Total time* | *26:00* |   |
+|---+--------------+---------+---|
+| 1 | Foo          | 26:00   |   |
+"
+    (org-test-with-temp-text
+        "* Foo
+:PROPERTIES:
+:A: 1
+:END:
+CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
+"
+      (test-org-clock-clocktable-contents-at-point ":properties (\"A\")")))))
 
 (provide 'test-org-clock)
 ;;; test-org-clock.el end here