Skip to content

Commit 80f0722

Browse files
Fix src block filetype detection. Closes #170.
1 parent dbaef0c commit 80f0722

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lua/orgmode/org/syntax.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@ local function load_code_blocks()
1212
return
1313
end
1414

15+
local loaded_filetypes = {}
16+
1517
for _, ft in ipairs(orgfile.source_code_filetypes) do
16-
vim.cmd(string.format([[silent! syntax include @orgmodeBlockSrc%s syntax/%s.vim]], ft, ft))
17-
vim.cmd([[unlet! b:current_syntax]])
18+
local ok, result = pcall(vim.api.nvim_get_runtime_file, string.format('syntax/%s.vim', ft), false)
19+
if ok and #result > 0 then
20+
vim.cmd(string.format([[silent! syntax include @orgmodeBlockSrc%s syntax/%s.vim]], ft, ft))
21+
vim.cmd([[unlet! b:current_syntax]])
22+
table.insert(loaded_filetypes, ft)
23+
end
1824
end
1925

20-
for _, ft in ipairs(orgfile.source_code_filetypes) do
26+
for _, ft in ipairs(loaded_filetypes) do
2127
vim.cmd(
2228
string.format(
2329
[[syntax region orgmodeBlockSrc%s matchgroup=comment start="^\s*#+BEGIN_SRC\ %s\s*.*$" end="^\s*#+END_SRC\s*$" keepend contains=@orgmodeBlockSrc%s,org_block_delimiter]],

0 commit comments

Comments
 (0)