Skip to content

Commit 40ba3e1

Browse files
Reload syntax if new source code block filetype was added. Fixes #55.
1 parent 0b14c09 commit 40ba3e1

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

lua/orgmode/parser/files.lua

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,23 @@ function Files.reload(file, callback)
5151
local category = vim.fn.fnamemodify(file, ':t:r')
5252
local is_archived = config:is_archive_file(file)
5353
local stat = vim.loop.fs_stat(file)
54+
local prev_file = Files.get(file)
5455
if not stat then
5556
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, true)
5657
Files.files[file] = parser.parse(lines, category, file, is_archived)
58+
Files._check_source_blocks(prev_file, Files.get(file))
5759
Files._build_tags()
5860
if callback then
5961
callback()
6062
end
61-
return Files.files[file]
63+
return Files.get(file)
6264
end
6365
return utils.readfile(file, function(err, result)
6466
if err then
6567
return
6668
end
6769
Files.files[file] = parser.parse(result, category, file, is_archived)
70+
Files._check_source_blocks(prev_file, Files.get(file))
6871
Files._build_tags()
6972
if callback then
7073
callback()
@@ -207,6 +210,20 @@ function Files._build_tags()
207210
Files.tags = taglist
208211
end
209212

213+
---@param old_file? Root
214+
---@param new_file Root
215+
function Files._check_source_blocks(old_file, new_file)
216+
local old_source_blocks = old_file and old_file.source_code_filetypes or {}
217+
local new_source_blocks = new_file.source_code_filetypes or {}
218+
for _, ft in ipairs(new_source_blocks) do
219+
if not vim.tbl_contains(old_source_blocks, ft) then
220+
return vim.schedule(function()
221+
vim.cmd([[filetype detect]])
222+
end)
223+
end
224+
end
225+
end
226+
210227
function Files.autocomplete_tags(arg_lead)
211228
local join_char = '[%+%-:&|]'
212229
local parts = vim.split(arg_lead, join_char)

0 commit comments

Comments
 (0)