Skip to content

Commit

Permalink
feat(highlight): allow extended highlighting patterns (#185)
Browse files Browse the repository at this point in the history
Highlights the first capture group (as before), if there is a second
(typically nested) capture group, use it for keyword matching.

Allows highlighting `TODO(foo)` using `.*<((KEYWORDS)%(\(.{-1,}\))?):`.
  • Loading branch information
LunarLambda committed Jun 5, 2024
1 parent 70a93ce commit bc08c11
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lua/todo-comments/highlight.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ function M.match(str, patterns)
for _, pattern in pairs(patterns) do
local m = vim.fn.matchlist(str, [[\v\C]] .. pattern)
if #m > 1 and m[2] then
local kw = m[2]
local start = str:find(kw)
return start, start + #kw, kw
local match = m[2]
local kw = m[3] ~= "" and m[3] or m[2]
local start = str:find(match, 1, true)
return start, start + #match, kw
end
end
end
Expand Down

0 comments on commit bc08c11

Please sign in to comment.