cfg-pre - Support loading plugin configuration before or after the plugin

This commit is contained in:
Emmanuel BENOîT 2023-06-18 11:35:56 +02:00
parent 725add3819
commit d17ae721a1
No known key found for this signature in database
GPG key ID: 2356DC6956CF54EF

View file

@ -26,21 +26,30 @@ if has( 'vim_starting' )
if &compatible if &compatible
set nocompatible set nocompatible
endif endif
let s:dein_path = g:bundles_dir . "repos/github.com/Shougo/dein.vim"
let s:dein_path = g:bundles_dir . "github.com/Shougo/dein.vim"
if !isdirectory(s:dein_path) if !isdirectory(s:dein_path)
execute '!git clone https://github.com/Shougo/dein.vim' s:dein_path execute '!git clone https://github.com/Shougo/dein.vim' s:dein_path
endif endif
let &g:runtimepath = &g:runtimepath . "," . s:dein_path let &g:runtimepath = &g:runtimepath . "," . s:dein_path
endif endif
" Function that sets a hook to be executed before or after a plugin is loaded.
function! LoadPluginHook(plugins_dir, pname, hook, file_ext)
let l:cfgfile = GetConfigFilePath( a:plugins_dir ,
\ s:pname . "." . a:file_ext . ".vim" )
if l:cfgfile != ""
call dein#set_hook(a:pname, "hook_" . a:hook,
\ join(readfile(l:cfgfile), "\n")
\ )
endif
endfunction
" Start initializing plugins
call dein#begin( g:bundles_dir )
call dein#options(#{ call dein#options(#{
\ lazy_plugins: v:true, \ lazy_plugins: v:true,
\ install_progress_type: 'floating', \ install_progress_type: 'floating',
\ }) \ })
call dein#begin( g:bundles_dir )
" Load Dein itself
call dein#add(s:dein_path) call dein#add(s:dein_path)
" Load all plugins from ${plugins directory}/*.load.vim " Load all plugins from ${plugins directory}/*.load.vim
@ -50,19 +59,12 @@ let s:bundle_load_files = GetConfigFiles( s:plugins_dir , "*.load.vim" )
for s:plfn in values( s:bundle_load_files ) for s:plfn in values( s:bundle_load_files )
execute "source" s:plfn execute "source" s:plfn
" Create configuration loading hooks
let s:pname = fnamemodify( s:plfn , ":t:r:r" ) let s:pname = fnamemodify( s:plfn , ":t:r:r" )
let s:cfgfile = GetConfigFilePath( s:plugins_dir , call LoadPluginHook(s:plugins_dir, s:pname, "source", "cfg")
\ s:pname . ".cfg.vim" ) call LoadPluginHook(s:plugins_dir, s:pname, "post_source", "post")
if s:cfgfile != ""
call dein#set_hook(s:pname, 'hook_post_source',
\ join(readfile(s:cfgfile), "\n")
\ )
endif
endfor endfor
call dein#end() call dein#end()
autocmd VimEnter * call dein#call_hook('post_source')
function! CheckDeinInstall() function! CheckDeinInstall()
" Let Dein check for installations " Let Dein check for installations