org-clock: Fix infloop when creating a clock table

* lisp/org-clock.el (org-clock-sum): Fix infloop when first headline in
  scope has a level strictly greater than 1.

Reported-by: Yichao Woo <wooyichao@gmail.com>
<http://permalink.gmane.org/gmane.emacs.orgmode/108606>
This commit is contained in:
Nicolas Goaziou 2016-08-20 00:22:13 +02:00
parent 8301b72ed2
commit 589e96321b
2 changed files with 24 additions and 10 deletions

View File

@ -1871,15 +1871,13 @@ PROPNAME lets you set a custom text property instead of :org-clock-minutes."
(goto-char (match-beginning 0))
(put-text-property (point) (point-at-eol)
(or propname :org-clock-minutes) time)
(if headline-filter
(save-excursion
(save-match-data
(while
(> (funcall outline-level) 1)
(outline-up-heading 1 t)
(put-text-property
(point) (point-at-eol)
:org-clock-force-headline-inclusion t))))))
(when headline-filter
(save-excursion
(save-match-data
(while (org-up-heading-safe)
(put-text-property
(point) (line-end-position)
:org-clock-force-headline-inclusion t))))))
(setq t1 0)
(loop for l from level to (1- lmax) do
(aset ltimes l 0)))))))

View File

@ -318,7 +318,23 @@ contents. The clocktable doesn't appear in the buffer."
(insert (org-test-clock-create-clock "-10y 15:00" "-10y 18:00"))
(insert (org-test-clock-create-clock "-2d 15:00" "-2d 18:00"))
(test-org-clock-clocktable-contents-at-point
":block untilnow :indent nil")))))
":block untilnow :indent nil"))))
;; Test tag filtering.
(should
(equal
"| Headline | Time | |
|--------------+--------+------|
| *Total time* | *2:00* | |
|--------------+--------+------|
| H1 | | 2:00 |
"
(org-test-with-temp-text "** H1\n\n*** H2 :tag:\n\n*** H3\n<point>"
(insert (org-test-clock-create-clock ". 1:00" ". 2:00"))
(goto-line 4)
(insert (org-test-clock-create-clock ". 2:00" ". 4:00"))
(goto-line 2)
(test-org-clock-clocktable-contents-at-point
":tags \"tag\" :indent nil")))))
(provide 'test-org-clock)
;;; test-org-clock.el end here