@@ -785,6 +785,7 @@ function Plugin:on(events)
785
785
786
786
-- Create autocmds for each event within this group
787
787
for _ , event in ipairs (self .events ) do
788
+ event = event == ' StriveDone' and ' User StriveDone' or event
788
789
local pattern
789
790
if event :find (' %s' ) then
790
791
local t = vim .split (event , ' %s' )
@@ -806,6 +807,16 @@ function Plugin:on(events)
806
807
return self
807
808
end
808
809
810
+ local function _split (s , sep )
811
+ local t = {}
812
+ for c in vim .gsplit (s , sep , { trimempty = true }) do
813
+ if # c > 0 then
814
+ table.insert (t , c )
815
+ end
816
+ end
817
+ return t
818
+ end
819
+
809
820
-- Set up lazy loading for specific filetypes
810
821
function Plugin :ft (filetypes )
811
822
self .is_lazy = true
@@ -817,9 +828,38 @@ function Plugin:ft(filetypes)
817
828
group = id ,
818
829
pattern = self .filetypes ,
819
830
once = true ,
820
- callback = function ()
831
+ callback = function (args )
821
832
if not self .loaded then
822
- self :load ()
833
+ return self :load (false , function ()
834
+ local res = api .nvim_exec2 (' autocmd FileType' , { output = true })
835
+ if not res .output then
836
+ return
837
+ end
838
+ res = { unpack (vim .split (res .output , ' \n ' ), 1 ) }
839
+ local group_start = nil
840
+ for i , item in ipairs (res ) do
841
+ if item :find (' FileType$' ) then
842
+ group_start = i
843
+ end
844
+ if item :find (self .plugin_name , 1 , true ) then
845
+ local data = _split (item , ' %s' )
846
+ if data [1 ] == ' *' or data [1 ] == vim .bo [args .buf ].filetype then
847
+ local au_id = data [3 ]:match (' (%d+):' )
848
+ if not au_id then
849
+ return
850
+ end
851
+ local g = res [group_start ]:match (' ^(.-)%s+FileType$' )
852
+ api .nvim_exec_autocmds (' FileType' , {
853
+ group = g ,
854
+ modeline = false ,
855
+ buffer = args .buf ,
856
+ data = args .data ,
857
+ })
858
+ break
859
+ end
860
+ end
861
+ end
862
+ end )
823
863
end
824
864
end ,
825
865
})
@@ -858,7 +898,7 @@ function Plugin:cmd(commands)
858
898
bang = true ,
859
899
complete = function (_ , cmd_line )
860
900
if not self .loaded then
861
- self :load ()
901
+ return self :load ()
862
902
end
863
903
local ok , result = pcall (vim .fn .getcompletion , cmd_line , ' cmdline' )
864
904
return ok and result or {}
@@ -877,7 +917,7 @@ function Plugin:cond(condition)
877
917
(type (condition ) == ' string' and api .nvim_eval (condition ))
878
918
or (type (condition ) == ' function' and condition ())
879
919
then
880
- self :load ()
920
+ self :load (true )
881
921
end
882
922
return self
883
923
end
@@ -1511,7 +1551,6 @@ function M.clean()
1511
1551
1512
1552
-- Scan both start and opt directories
1513
1553
scan_directory (PACK_DIR )
1514
- scan_directory (OPT_DIR )
1515
1554
1516
1555
local strive_plugin = Plugin .new ({
1517
1556
name = ' nvimdev/strive' ,
@@ -1627,7 +1666,7 @@ local function setup_auto_install()
1627
1666
1628
1667
-- UI has not initialized yet, register for UIEnter event
1629
1668
api .nvim_create_autocmd (' UIEnter' , {
1630
- group = api .nvim_create_augroup (' strive_auto_install ' , { clear = true }),
1669
+ group = api .nvim_create_augroup (' strive ' , { clear = false }),
1631
1670
callback = function ()
1632
1671
vim .schedule (function ()
1633
1672
M .log (' debug' , ' UIEnter triggered, installing plugins' )
@@ -1644,6 +1683,19 @@ if DEFAULT_SETTINGS.auto_install then
1644
1683
setup_auto_install ()
1645
1684
end
1646
1685
1686
+ api .nvim_create_autocmd (' UIEnter' , {
1687
+ group = api .nvim_create_augroup (' strive' , { clear = false }),
1688
+ once = true ,
1689
+ callback = function ()
1690
+ vim .schedule (function ()
1691
+ api .nvim_exec_autocmds (' User' , {
1692
+ pattern = ' StriveDone' ,
1693
+ modeline = false ,
1694
+ })
1695
+ end )
1696
+ end ,
1697
+ })
1698
+
1647
1699
local t = { install = 1 , update = 2 , clean = 3 }
1648
1700
api .nvim_create_user_command (' Strive' , function (args )
1649
1701
if t [args .args ] then
0 commit comments