From d17ae721a1ce9be8a33e6237ba26a3f6cc70bcf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20BENO=C3=8ET?= Date: Sun, 18 Jun 2023 11:35:56 +0200 Subject: [PATCH] cfg-pre - Support loading plugin configuration before or after the plugin --- cfg-pre/75-dein.vim | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/cfg-pre/75-dein.vim b/cfg-pre/75-dein.vim index 8ac38d6..eaf2e30 100644 --- a/cfg-pre/75-dein.vim +++ b/cfg-pre/75-dein.vim @@ -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