Improve loading time when matchparen_enabled=0

Also be more robust in loading pi_paren's plugin/matchparen.vim
cf. #25, cf. SpaceVim/SpaceVim/#1482
This commit is contained in:
Andy K. Massimino
2018-04-02 14:49:10 -04:00
parent 2f4c4a9261
commit fb09f4ae8e
3 changed files with 20 additions and 11 deletions

View File

@@ -61,6 +61,9 @@ endfunction
function! s:init_modules()
for l:mod in [ 'loader', 'matchparen' ]
if !get(g:, 'matchup_'.l:mod.'_enabled', 1)
continue
endif
call matchup#perf#tic('loading_module')
call matchup#{l:mod}#init_module()
call matchup#perf#toc('loading_module', l:mod)

View File

@@ -21,6 +21,8 @@ endfunction
" }}}1
function! matchup#matchparen#enable() " {{{1
let g:matchup_matchparen_enabled = 1
if g:matchup_matchparen_deferred
\ && (!has('timers') || !exists('*timer_pause')
\ || has('nvim') && !has('nvim-0.2.1'))
@@ -40,8 +42,6 @@ function! matchup#matchparen#enable() " {{{1
autocmd TextChangedP * call s:matchparen.highlight_deferred()
endif
autocmd WinLeave * call s:matchparen.clear()
" autocmd BufLeave * call s:matchparen.clear()
" autocmd InsertEnter,InsertLeave * call s:matchparen.highlight()
autocmd InsertEnter * call s:matchparen.highlight(1, 1)
augroup END
@@ -86,8 +86,9 @@ let s:pi_paren_sid = -1
" }}}1
function! matchup#matchparen#disable() " {{{1
let g:matchup_matchparen_enabled = 0
call s:matchparen.clear()
autocmd! matchup_matchparen
silent! autocmd! matchup_matchparen
endfunction
" }}}1
@@ -96,9 +97,10 @@ function! matchup#matchparen#toggle(...) " {{{1
\ ? a:1
\ : !g:matchup_matchparen_enabled
if g:matchup_matchparen_enabled
call matchup#matchparen#enable()
call s:matchparen.highlight(1)
else
call s:matchparen.clear()
call matchup#matchparen#disable()
endif
endfunction

View File

@@ -30,14 +30,18 @@ if exists('g:loaded_matchit')
endif
let g:loaded_matchit = 1
if get(g:, 'matchup_matchparen_enabled', 1)
if !exists('g:loaded_matchparen')
runtime plugin/matchparen.vim
endif
" ensure pi_paren is loaded but deactivated
try
runtime plugin/matchparen.vim
au! matchparen
command! NoMatchParen call matchup#matchparen#toggle(0)
command! DoMatchParen call matchup#matchparen#toggle(1)
endif
catch /^Vim\%((\a\+)\)\=:E216/
unlet! g:loaded_matchparen
runtime plugin/matchparen.vim
silent! au! matchparen
let g:loaded_matchparen = 1
endtry
command! NoMatchParen call matchup#matchparen#toggle(0)
command! DoMatchParen call matchup#matchparen#toggle(1)
if get(g:, 'matchup_override_vimtex', 0)
let g:vimtex_matchparen_enabled = 0