Skip to content

Commit 8121c22

Browse files
feat(clock): Clock out headline when it's marked as done
Closes #972
1 parent f67d771 commit 8121c22

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---@param event OrgTodoChangedEvent
2+
return function(event)
3+
if event.headline:is_done() and not event.was_done and (event.old_todo_state and event.old_todo_state ~= '') then
4+
event.headline:clock_out()
5+
end
6+
end

lua/orgmode/events/listeners/init.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
local Events = require('orgmode.events.types')
22
local AlignTags = require('orgmode.events.listeners.align_tags')
3+
local ClockOut = require('orgmode.events.listeners.clock_out')
34

45
return {
56
[Events.TodoChanged] = {
67
AlignTags,
8+
ClockOut,
79
},
810
[Events.HeadlineDemoted] = {
911
AlignTags,

lua/orgmode/org/mappings.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,10 +477,10 @@ function OrgMappings:_todo_change_state(direction)
477477
local repeat_note_template = ('%s- State %-12s from %-12s [%s]'):format(
478478
indent,
479479
[["]] .. new_todo .. [["]],
480-
[["]] .. old_state .. [["]],
480+
[["]] .. (old_state or '') .. [["]],
481481
Date.now():to_string()
482482
)
483-
local repeat_note_title = ('Insert note for state change from "%s" to "%s"'):format(old_state, new_todo)
483+
local repeat_note_title = ('Insert note for state change from "%s" to "%s"'):format(old_state or '', new_todo)
484484

485485
if log_repeat_enabled then
486486
item:set_property('LAST_REPEAT', Date.now():to_wrapped_string(false))

0 commit comments

Comments
 (0)