From 71eef9331edda3511fbfcc711d45af764f08c357 Mon Sep 17 00:00:00 2001 From: Kristijan Husak Date: Mon, 12 Aug 2024 22:45:37 +0200 Subject: [PATCH] fix(injections)!: Do not use vim.filetype.match for injections Potentially fixes issue: #792 --- lua/orgmode/config/init.lua | 2 +- lua/orgmode/utils/init.lua | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lua/orgmode/config/init.lua b/lua/orgmode/config/init.lua index 2cc7fb55e..ca1123b64 100644 --- a/lua/orgmode/config/init.lua +++ b/lua/orgmode/config/init.lua @@ -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) diff --git a/lua/orgmode/utils/init.lua b/lua/orgmode/utils/init.lua index 2caba3824..dd24aa467 100644 --- a/lua/orgmode/utils/init.lua +++ b/lua/orgmode/utils/init.lua @@ -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', @@ -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]