Skip to content

Commit d2ba9c0

Browse files
committed
Force reload of clocked headline before clock operations
Without this update, certain changes to the buffer would not be reflected in the `self.clocked_headline` attribute. This could cause changes such as the auto-clock-out of a previously clocked header to be inserted in the wrong location, corrupting the file.
1 parent 7365937 commit d2ba9c0

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lua/orgmode/clock/init.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,20 @@ function Clock:init()
2626
end
2727
end
2828

29+
function Clock:update_clocked_headline()
30+
local last_clocked_headline = self.files:get_clocked_headline()
31+
if last_clocked_headline and last_clocked_headline:is_clocked_in() then
32+
self.clocked_headline = last_clocked_headline
33+
end
34+
end
35+
2936
function Clock:has_clocked_headline()
37+
self:update_clocked_headline()
3038
return self.clocked_headline ~= nil
3139
end
3240

3341
function Clock:org_clock_in()
42+
self:update_clocked_headline()
3443
local item = self.files:get_closest_headline()
3544
if item:is_clocked_in() then
3645
return utils.echo_info(string.format('Clock continues in "%s"', item:get_title()))
@@ -54,6 +63,7 @@ function Clock:org_clock_in()
5463
end
5564

5665
function Clock:org_clock_out()
66+
self:update_clocked_headline()
5767
if not self.clocked_headline or not self.clocked_headline:is_clocked_in() then
5868
return
5969
end
@@ -63,6 +73,7 @@ function Clock:org_clock_out()
6373
end
6474

6575
function Clock:org_clock_cancel()
76+
self:update_clocked_headline()
6677
if not self.clocked_headline or not self.clocked_headline:is_clocked_in() then
6778
return utils.echo_info('No active clock')
6879
end
@@ -73,6 +84,7 @@ function Clock:org_clock_cancel()
7384
end
7485

7586
function Clock:org_clock_goto()
87+
self:update_clocked_headline()
7688
if not self.clocked_headline then
7789
return utils.echo_info('No active or recent clock task')
7890
end
@@ -100,6 +112,7 @@ function Clock:org_set_effort()
100112
end
101113

102114
function Clock:get_statusline()
115+
self:update_clocked_headline()
103116
if not self.clocked_headline or not self.clocked_headline:is_clocked_in() then
104117
return ''
105118
end

0 commit comments

Comments
 (0)