Skip to content

Commit 8be9a4b

Browse files
authored
Don't reload orgfile twice (#458)
1 parent e950636 commit 8be9a4b

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lua/orgmode/colors/todo_highlighter.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local config = require('orgmode.config')
22
local highlights = require('orgmode.colors.highlights')
3+
local tree_utils = require('orgmode.utils.treesitter')
34
local utils = require('orgmode.utils')
45

56
local function add_todo_keyword_highlights()
@@ -52,7 +53,7 @@ local function add_todo_keyword_highlights()
5253
end
5354
vim.treesitter.set_query('org', 'highlights', table.concat(all_lines, '\n'))
5455
if vim.bo.filetype == 'org' then
55-
vim.cmd([[filetype detect]])
56+
tree_utils.restart_highlights()
5657
end
5758
end)
5859
)

lua/orgmode/utils/treesitter.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ function M.parse(bufnr)
1212
return vim.treesitter.get_parser(bufnr or 0, 'org', {}):parse()
1313
end
1414

15+
-- Reload treesitter highlighter without triggering FileType autocommands that include reloading entire file
16+
function M.restart_highlights(bufnr)
17+
bufnr = bufnr or 0
18+
require('nvim-treesitter.configs').reattach_module('highlight', bufnr, 'org')
19+
end
20+
1521
function M.parse_query(query)
1622
local ts_query = query_cache[query]
1723
if not ts_query then

0 commit comments

Comments
 (0)