@@ -421,7 +421,7 @@ function Config:setup_ts_predicates()
421
421
if not text or vim .trim (text ) == ' ' then
422
422
return
423
423
end
424
- metadata [' injection.language' ] = utils . detect_filetype (text , true )
424
+ metadata [' injection.language' ] = self : detect_filetype (text )
425
425
end , { force = true , all = true })
426
426
427
427
vim .treesitter .query .add_directive (' org-set-inline-block-language!' , function (match , _ , bufnr , pred , metadata )
@@ -438,7 +438,7 @@ function Config:setup_ts_predicates()
438
438
text = text :sub (5 )
439
439
-- Remove opening brackend and parameters: lua[params]{ -> lua
440
440
text = text :gsub (' [%{%[].*' , ' ' )
441
- metadata [' injection.language' ] = utils . detect_filetype (text , true )
441
+ metadata [' injection.language' ] = self : detect_filetype (text )
442
442
end , { force = true , all = true })
443
443
444
444
vim .treesitter .query .add_predicate (' org-is-headline-level?' , function (match , _ , _ , predicate )
@@ -542,6 +542,60 @@ function Config:use_property_inheritance(property_name)
542
542
end
543
543
end
544
544
545
+ --- @param filetype_name string
546
+ --- @param use_ftmatch ? boolean Use vim.filetype.match to detect filetype
547
+ function Config :detect_filetype (filetype_name , use_ftmatch )
548
+ local name = filetype_name :lower ()
549
+
550
+ if not self ._ft_map then
551
+ self ._ft_map = {}
552
+ end
553
+
554
+ if self ._ft_map [name ] then
555
+ return self ._ft_map [name ]
556
+ end
557
+
558
+ local filetype = self :_get_filetype_name (name )
559
+
560
+ if use_ftmatch then
561
+ local filename = ' __org__detect_filetype__.' .. filetype
562
+ local ft = vim .filetype .match ({ filename = filename })
563
+ if ft then
564
+ self ._ft_map [name ] = ft
565
+ return ft
566
+ end
567
+ end
568
+
569
+ self ._ft_map [name ] = filetype
570
+ return filetype
571
+ end
572
+
573
+ --- @private
574
+ --- @param filetype string
575
+ function Config :_get_filetype_name (filetype )
576
+ local map = {
577
+ [' emacs-lisp' ] = ' lisp' ,
578
+ elisp = ' lisp' ,
579
+ js = ' javascript' ,
580
+ ts = ' typescript' ,
581
+ md = ' markdown' ,
582
+ ex = ' elixir' ,
583
+ pl = ' perl' ,
584
+ sh = ' bash' ,
585
+ shell = ' bash' ,
586
+ uxn = ' uxntal' ,
587
+ }
588
+ if map [filetype ] then
589
+ return map [filetype ]
590
+ end
591
+
592
+ if self .opts .org_edit_src_filetype_map [filetype ] then
593
+ return self .opts .org_edit_src_filetype_map [filetype ]
594
+ end
595
+
596
+ return filetype
597
+ end
598
+
545
599
--- @type OrgConfig
546
600
instance = Config :new ()
547
601
return instance
0 commit comments