Skip to content

Commit ce958be

Browse files
Merge pull request #304 from jgollenz/fix/multi-hyphen-todo-keyword
Handle multiple substitutions in custom todo keyword
2 parents 8fc7fff + 4c67c04 commit ce958be

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lua/orgmode/treesitter/headline.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ function Headline:todo()
124124

125125
local text = query.get_node_text(todo_node, 0)
126126
for _, word in ipairs(keywords) do
127-
local todo = text:match(word:gsub('-', '%%-'))
127+
-- there may be multiple substitutions necessary
128+
escaped_word = vim.pesc(word)
129+
local todo = text:match(escaped_word)
128130
if todo then
129131
return todo_node, word, vim.tbl_contains(done_keywords, word)
130132
end

tests/plenary/object/todo_state_spec.lua

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,22 @@ describe('Todo state', function()
1818

1919
it('should properly cycle through all defined custom states', function()
2020
config:extend({
21-
org_todo_keywords = { 'TODO', 'WAITING', 'PROCESSING', '|', 'CONFIRM', 'DONE' },
21+
org_todo_keywords = {
22+
'TODO',
23+
'WAITING',
24+
'PROCESSING',
25+
'HYPHEN-KEYWORD',
26+
'MULTI-HYPHEN-KEYWORD',
27+
'|',
28+
'CONFIRM',
29+
'DONE',
30+
},
2231
})
2332
local next_state = TodoState:new({ current_state = 'TODO' })
2433
assert.are.same({ value = 'WAITING', type = 'TODO', hl = 'OrgTODO' }, next_state:get_next())
2534
assert.are.same({ value = 'PROCESSING', type = 'TODO', hl = 'OrgTODO' }, next_state:get_next())
35+
assert.are.same({ value = 'HYPHEN-KEYWORD', type = 'TODO', hl = 'OrgTODO' }, next_state:get_next())
36+
assert.are.same({ value = 'MULTI-HYPHEN-KEYWORD', type = 'TODO', hl = 'OrgTODO' }, next_state:get_next())
2637
assert.are.same({ value = 'CONFIRM', type = 'DONE', hl = 'OrgDONE' }, next_state:get_next())
2738
assert.are.same({ value = 'DONE', type = 'DONE', hl = 'OrgDONE' }, next_state:get_next())
2839
assert.are.same({ value = '', type = '' }, next_state:get_next())
@@ -32,6 +43,8 @@ describe('Todo state', function()
3243
assert.are.same({ value = '', type = '' }, prev_state:get_prev())
3344
assert.are.same({ value = 'DONE', type = 'DONE', hl = 'OrgDONE' }, prev_state:get_prev())
3445
assert.are.same({ value = 'CONFIRM', type = 'DONE', hl = 'OrgDONE' }, prev_state:get_prev())
46+
assert.are.same({ value = 'MULTI-HYPHEN-KEYWORD', type = 'TODO', hl = 'OrgTODO' }, prev_state:get_prev())
47+
assert.are.same({ value = 'HYPHEN-KEYWORD', type = 'TODO', hl = 'OrgTODO' }, prev_state:get_prev())
3548
assert.are.same({ value = 'PROCESSING', type = 'TODO', hl = 'OrgTODO' }, prev_state:get_prev())
3649
assert.are.same({ value = 'WAITING', type = 'TODO', hl = 'OrgTODO' }, prev_state:get_prev())
3750
assert.are.same({ value = 'TODO', type = 'TODO', hl = 'OrgTODO' }, prev_state:get_prev())

0 commit comments

Comments
 (0)