@@ -421,7 +421,7 @@ function Config:setup_ts_predicates()
421421 if not text or vim .trim (text ) == ' ' then
422422 return
423423 end
424- metadata [' injection.language' ] = utils . detect_filetype (text , true )
424+ metadata [' injection.language' ] = self : detect_filetype (text )
425425 end , { force = true , all = true })
426426
427427 vim .treesitter .query .add_directive (' org-set-inline-block-language!' , function (match , _ , bufnr , pred , metadata )
@@ -438,7 +438,7 @@ function Config:setup_ts_predicates()
438438 text = text :sub (5 )
439439 -- Remove opening brackend and parameters: lua[params]{ -> lua
440440 text = text :gsub (' [%{%[].*' , ' ' )
441- metadata [' injection.language' ] = utils . detect_filetype (text , true )
441+ metadata [' injection.language' ] = self : detect_filetype (text )
442442 end , { force = true , all = true })
443443
444444 vim .treesitter .query .add_predicate (' org-is-headline-level?' , function (match , _ , _ , predicate )
@@ -542,6 +542,60 @@ function Config:use_property_inheritance(property_name)
542542 end
543543end
544544
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+
545599--- @type OrgConfig
546600instance = Config :new ()
547601return instance
0 commit comments