Skip to content

Commit

Permalink
fix(injections)!: Do not use vim.filetype.match for injections
Browse files Browse the repository at this point in the history
Potentially fixes issue: nvim-orgmode#792
  • Loading branch information
kristijanhusak authored and SlayerOfTheBad committed Aug 16, 2024
1 parent 130f4b5 commit a9774ef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lua/orgmode/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ function Config:setup_ts_predicates()
if not text or vim.trim(text) == '' then
return
end
metadata['injection.language'] = utils.detect_filetype(text)
metadata['injection.language'] = utils.detect_filetype(text, true)
end, { force = true })

vim.treesitter.query.add_predicate('org-is-headline-level?', function(match, _, _, predicate)
Expand Down
13 changes: 8 additions & 5 deletions lua/orgmode/utils/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,9 @@ function utils.find(entries, check_fn)
end

---@param name string
---@param skip_ftmatch? boolean
---@return string
function utils.detect_filetype(name)
function utils.detect_filetype(name, skip_ftmatch)
local map = {
['emacs-lisp'] = 'lisp',
js = 'javascript',
Expand All @@ -580,10 +581,12 @@ function utils.detect_filetype(name)
sh = 'bash',
uxn = 'uxntal',
}
local filename = '__org__detect_filetype__.' .. (map[name] or name)
local ft = vim.filetype.match({ filename = filename })
if ft then
return ft
if not skip_ftmatch then
local filename = '__org__detect_filetype__.' .. (map[name] or name)
local ft = vim.filetype.match({ filename = filename })
if ft then
return ft
end
end
if map[name] then
return map[name]
Expand Down

0 comments on commit a9774ef

Please sign in to comment.