Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix custom highlight queries #240

Merged
merged 1 commit into from
Mar 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 47 additions & 27 deletions lua/orgmode/colors/todo_highlighter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,55 @@ local function add_todo_keyword_highlights()
end
local todo_keywords = config:get_todo_keywords()
local faces = highlights.parse_todo_keyword_faces()
utils.readfile(
query_files[1],
vim.schedule_wrap(function(err, lines)
if err then
return
end
local todo_type = table.concat(
vim.tbl_map(function(word)
return string.format('"%s"', word)
end, todo_keywords.TODO),
' '
local all_lines = {}
for i, _ in pairs(query_files) do
if i ~= #query_files then
utils.readfile(
query_files[i],
vim.schedule_wrap(function(err, lines)
if err then
return
end
for _, v in ipairs(lines) do
table.insert(all_lines, v)
end
end)
)
local done_type = table.concat(
vim.tbl_map(function(word)
return string.format('"%s"', word)
end, todo_keywords.DONE),
' '
else
utils.readfile(
query_files[i],
vim.schedule_wrap(function(err, lines)
if err then
return
end
local todo_type = table.concat(
vim.tbl_map(function(word)
return string.format('"%s"', word)
end, todo_keywords.TODO),
' '
)
local done_type = table.concat(
vim.tbl_map(function(word)
return string.format('"%s"', word)
end, todo_keywords.DONE),
' '
)
table.insert(lines, string.format([[(item . (expr) @OrgTODO (#any-of? @OrgTODO %s))]], todo_type))
table.insert(lines, string.format([[(item . (expr) @OrgDONE (#any-of? @OrgDONE %s))]], done_type))
for face_name, face_hl in pairs(faces) do
table.insert(lines, string.format([[(item . (expr) @%s (#eq? @%s %s))]], face_hl, face_hl, face_name))
end
for _, v in ipairs(lines) do
table.insert(all_lines, v)
end
vim.treesitter.set_query('org', 'highlights', table.concat(all_lines, '\n'))
if vim.bo.filetype == 'org' then
vim.cmd([[filetype detect]])
end
end)
)
table.insert(lines, string.format([[(item . (expr) @OrgTODO (#any-of? @OrgTODO %s))]], todo_type))
table.insert(lines, string.format([[(item . (expr) @OrgDONE (#any-of? @OrgDONE %s))]], done_type))
for face_name, face_hl in pairs(faces) do
table.insert(lines, string.format([[(item . (expr) @%s (#eq? @%s %s))]], face_hl, face_hl, face_name))
end
vim.treesitter.set_query('org', 'highlights', table.concat(lines, '\n'))
if vim.bo.filetype == 'org' then
vim.cmd([[filetype detect]])
end
end)
)
end
end
end

return {
Expand Down