From 589e96321b6eff3813cce305d370f883636cb2a3 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sat, 20 Aug 2016 00:22:13 +0200 Subject: [PATCH] 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 --- lisp/org-clock.el | 16 +++++++--------- testing/lisp/test-org-clock.el | 18 +++++++++++++++++- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/lisp/org-clock.el b/lisp/org-clock.el index 66be79777..b2726595b 100644 --- a/lisp/org-clock.el +++ b/lisp/org-clock.el @@ -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))))))) diff --git a/testing/lisp/test-org-clock.el b/testing/lisp/test-org-clock.el index 29e7de8d3..b4ed925f7 100644 --- a/testing/lisp/test-org-clock.el +++ b/testing/lisp/test-org-clock.el @@ -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" + (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