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
set nocompatible
endif
let s:dein_path = g:bundles_dir . "github.com/Shougo/dein.vim"
let s:dein_path = g:bundles_dir . "repos/github.com/Shougo/dein.vim"
if !isdirectory(s:dein_path)
execute '!git clone https://github.com/Shougo/dein.vim' s:dein_path
endif
let &g:runtimepath = &g:runtimepath . "," . s:dein_path
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(#{
\ lazy_plugins: v:true,
\ install_progress_type: 'floating',
\ })
call dein#begin( g:bundles_dir )
" Load Dein itself
call dein#add(s:dein_path)
" 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 )
execute "source" s:plfn
" Create configuration loading hooks
let s:pname = fnamemodify( s:plfn , ":t:r:r" )
let s:cfgfile = GetConfigFilePath( s:plugins_dir ,
\ s:pname . ".cfg.vim" )
if s:cfgfile != ""
call dein#set_hook(s:pname, 'hook_post_source',
\ join(readfile(s:cfgfile), "\n")
\ )
endif
call LoadPluginHook(s:plugins_dir, s:pname, "source", "cfg")
call LoadPluginHook(s:plugins_dir, s:pname, "post_source", "post")
endfor
call dein#end()
autocmd VimEnter * call dein#call_hook('post_source')
function! CheckDeinInstall()
" Let Dein check for installations