Hello! See two attached patches. All tests pass on my computer.
Every once in a while I feel obligated to go back to org-clock-sum to try and optimize it. I have a file with 8 clocktables in it and it takes forever to update. This time I decided instead of trying to optimize, I'm just going to try and understand. The regex has been altered slightly. 1. Instead of using "[ \t]", I decided to use [[:blank:]]. No real reason. I just think it's easier to read and maybe slightly more correct? 2. For the timestamps, instead of ".*?" (using a non-greedy ".*") I decided to use "[^]]*" (accept everything except "]"). I did this simply because I'm not used to using non-greedy regex's. Maybe this way performs better? I didn't test that. 3. I used the variable `org-outline-regexp' but that doesn't actually change the regex.
>From 3c3d7abed25cafb2be1096ca079a0e8be907c644 Mon Sep 17 00:00:00 2001 From: Morgan Smith <morgan.j.sm...@outlook.com> Date: Thu, 11 Apr 2024 12:23:21 -0400 Subject: [PATCH 1/2] lisp/org-clock.el (org-clock-sum): Rewrite regex using rx --- lisp/org-clock.el | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lisp/org-clock.el b/lisp/org-clock.el index 65a54579a..5ef987ab8 100644 --- a/lisp/org-clock.el +++ b/lisp/org-clock.el @@ -2008,9 +2008,23 @@ each headline in the time range with point at the headline. Headlines for which HEADLINE-FILTER returns nil are excluded from the clock summation. PROPNAME lets you set a custom text property instead of :org-clock-minutes." (with-silent-modifications - (let* ((re (concat "^\\(\\*+\\)[ \t]\\|^[ \t]*" - org-clock-string - "[ \t]*\\(?:\\(\\[.*?\\]\\)-+\\(\\[.*?\\]\\)\\|=>[ \t]+\\([0-9]+\\):\\([0-9]+\\)\\)")) + (let* ((re (rx line-start + (or + (group (regexp org-outline-regexp)) + (seq (* blank) + (literal org-clock-string) + (* blank) + (or + (seq + (group "[" (* (not "]")) "]") + (+ "-") + (group "[" (* (not "]")) "]")) + (seq + "=>" + (+ blank) + (group (+ digit)) + ":" + (group (+ digit)))))))) (lmax 30) (ltimes (make-vector lmax 0)) (level 0) -- 2.41.0
>From e5298920568e4c5a34589640f11edfa09a98d0d1 Mon Sep 17 00:00:00 2001 From: Morgan Smith <morgan.j.sm...@outlook.com> Date: Thu, 11 Apr 2024 12:51:18 -0400 Subject: [PATCH 2/2] Test clock times without timestamps * testing/lisp/test-org-clock.el (test-org-clock/clocktable/insert): Add a clock time that does not include timestamps. --- testing/lisp/test-org-clock.el | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/testing/lisp/test-org-clock.el b/testing/lisp/test-org-clock.el index 44c62e7bc..be8acb529 100644 --- a/testing/lisp/test-org-clock.el +++ b/testing/lisp/test-org-clock.el @@ -345,13 +345,12 @@ CLOCK: [2022-11-03 %s 06:00]--[2022-11-03 %s 06:01] => 0:01 (equal "| Headline | Time | |--------------+--------| -| *Total time* | *1:00* | +| *Total time* | *2:00* | |--------------+--------| -| H1 | 1:00 |" +| H1 | 2:00 |" (org-test-with-temp-text "* H1\n<point>" - (insert (org-test-clock-create-clock ". 1:00" ". 2:00")) - - (goto-line 2) + (insert (org-test-clock-create-clock ". 1:00" ". 2:00") + "CLOCK: => 1:00\n") (require 'org-clock) (org-dynamic-block-insert-dblock "clocktable") -- 2.41.0