Skip to content

Commit 5fc272f

Browse files
committed
Add get_logging_behavior to TodoConfig
Adds a method to the `TodoConfig` type to make determining whether to log a time, note, or not log at all for a give TodoConfig easier.
1 parent 35134c7 commit 5fc272f

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

lua/orgmode/parser/todo-config.lua

+29
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,35 @@ function TodoConfig:parse(input)
6969

7070
return TodoConfig:_new(words), input
7171
end
72+
73+
--- @param from string
74+
--- @param to string
75+
--- @return TodoConfigRecordBehavior
76+
function TodoConfig:get_logging_behavior(from, to)
77+
--- Find the from config
78+
local from_config = self:_find_word(from)
79+
local to_config = self:_find_word(to)
80+
81+
-- Ensure the described transition is valid
82+
if from_config == nil or to_config == nil then
83+
return false
84+
end
85+
86+
return to_config.on_enter or from_config.on_leave
87+
end
88+
89+
--- Finds the word config with the associated name
90+
--- @private
91+
--- @param name string
92+
--- @return TodoConfigWord?
93+
function TodoConfig:_find_word(name)
94+
for _, x in ipairs(self.words) do
95+
if x.name == name then
96+
return x
97+
end
98+
end
99+
100+
return nil
72101
end
73102

74103
--- @param name string

0 commit comments

Comments
 (0)