Skip to content

Commit e04cb32

Browse files
feat(injections): Map some filetypes for injections
emacs-lisp -> lisp ts -> typescript js -> javascript md -> markdown
1 parent 69474c7 commit e04cb32

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lua/orgmode/config/init.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,26 @@ function Config:setup_ts_predicates()
358358

359359
return false
360360
end, true)
361+
362+
vim.treesitter.query.add_directive('org-set-block-language!', function(match, _, bufnr, pred, metadata)
363+
local lang_node = match[pred[2]]
364+
if not lang_node then
365+
return
366+
end
367+
local text = vim.treesitter.get_node_text(lang_node, bufnr)
368+
if not text or vim.trim(text) == '' then
369+
return
370+
end
371+
372+
local map = {
373+
['emacs-lisp'] = 'lisp',
374+
['js'] = 'javascript',
375+
['ts'] = 'typescript',
376+
['md'] = 'markdown',
377+
}
378+
379+
metadata['injection.language'] = map[text] or text
380+
end, true)
361381
end
362382

363383
function Config:ts_highlights_enabled()

queries/org/injections.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
(block parameter: (expr) @injection.language (contents) @injection.content (#set! injection.include-children))
1+
(block parameter: (expr) @_lang (contents) @injection.content (#set! injection.include-children) (#org-set-block-language! @_lang))

0 commit comments

Comments
 (0)