@@ -793,16 +793,9 @@ function Plugin:on(events)
793
793
group = id ,
794
794
pattern = pattern ,
795
795
once = true ,
796
- callback = function (args )
797
- if not self .loaded and self :load () then
798
- -- Re-emit the event once after plugin is loaded
799
- vim .schedule (function ()
800
- api .nvim_exec_autocmds (event , {
801
- buffer = args .buf ,
802
- modeline = false ,
803
- data = args .data ,
804
- })
805
- end )
796
+ callback = function ()
797
+ if not self .loaded then
798
+ self :load ()
806
799
end
807
800
end ,
808
801
})
@@ -822,9 +815,34 @@ function Plugin:ft(filetypes)
822
815
group = id ,
823
816
pattern = self .filetypes ,
824
817
once = true ,
825
- callback = function ()
826
- if not self .loaded then
827
- self :load ()
818
+ callback = function (args )
819
+ if not self .loaded and self :load () then
820
+ local augroup_name = nil
821
+ if self .plugin_name :find (' lspconfig' , 1 , true ) then
822
+ augroup_name = ' nvim.lsp.enable'
823
+ else
824
+ local res = api .nvim_exec2 (' autocmd FileType' , { output = true })
825
+ if not res .output then
826
+ return
827
+ end
828
+ res = { unpack (vim .split (res .output , ' \n ' ), 1 ) }
829
+ for i , item in ipairs (res ) do
830
+ if item :find (self .plugin_name , 1 , true ) then
831
+ augroup_name = res [i - 1 ]:match (' ^%s*(%S+)' )
832
+ end
833
+ end
834
+ end
835
+
836
+ if augroup_name then
837
+ vim .schedule (function ()
838
+ api .nvim_exec_autocmds (' FileType' , {
839
+ group = augroup_name ,
840
+ buffer = args .buf ,
841
+ data = args .data ,
842
+ modeline = false ,
843
+ })
844
+ end )
845
+ end
828
846
end
829
847
end ,
830
848
})
0 commit comments