Skip to content

Commit

Permalink
fix: allow the user to set the default todo state
Browse files Browse the repository at this point in the history
As the order of the org_todo_keywords define the order of the todo in
the agenda, a user may want to have a default TODO state different than
the first one in the org_todo_keywords list
  • Loading branch information
lyz-code committed Dec 24, 2024
1 parent 6bb6fec commit 8a1acbf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions lua/orgmode/config/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local DefaultConfig = {
org_agenda_files = '',
org_default_notes_file = '',
org_todo_keywords = { 'TODO', '|', 'DONE' },
org_todo_default_state = nil,
org_todo_repeat_to_state = nil,
org_todo_keyword_faces = {},
org_deadline_warning_days = 14,
Expand Down
15 changes: 11 additions & 4 deletions lua/orgmode/org/mappings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -739,18 +739,25 @@ function OrgMappings:insert_heading_respect_content(suffix)
end

function OrgMappings:insert_todo_heading_respect_content()
return self:insert_heading_respect_content(config:get_todo_keywords():first_by_type('TODO').value .. ' ')
local first_todo_keyword = config.org_todo_default_state or config:get_todo_keywords():first_by_type('TODO').value
if not first_todo_keyword then
error('No default TODO keyword found')
end
return self:insert_heading_respect_content(first_todo_keyword .. ' ')
end

function OrgMappings:insert_todo_heading()
local item = self.files:get_closest_headline_or_nil()
local first_todo_keyword = config:get_todo_keywords():first_by_type('TODO')
local first_todo_keyword = config.org_todo_default_state or config:get_todo_keywords():first_by_type('TODO').value
if not first_todo_keyword then
error('No default TODO keyword found')
end
if not item then
self:_insert_heading_from_plain_line(first_todo_keyword.value .. ' ')
self:_insert_heading_from_plain_line(first_todo_keyword .. ' ')
return vim.cmd([[startinsert!]])
else
vim.fn.cursor(item:get_range().start_line, 1)
return self:meta_return(first_todo_keyword.value .. ' ')
return self:meta_return(first_todo_keyword .. ' ')
end
end

Expand Down

0 comments on commit 8a1acbf

Please sign in to comment.