- Lazy initialization.

This commit is contained in:
Shougo Matsushita 2013-01-20 11:59:32 +09:00
parent bdc7f9cb5b
commit cc4d978744
3 changed files with 63 additions and 29 deletions

View File

@ -1,7 +1,7 @@
"============================================================================= "=============================================================================
" FILE: neosnippet.vim " FILE: neosnippet.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com> " AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" Last Modified: 13 Jan 2013. " Last Modified: 20 Jan 2013.
" License: MIT license {{{ " License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining " Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the " a copy of this software and associated documentation files (the
@ -47,8 +47,31 @@ let s:neosnippet_options = [
\] \]
"}}} "}}}
function! neosnippet#initialize() "{{{ function! neosnippet#_lazy_initialize() "{{{
" Dummy. if !exists('s:lazy_progress')
let s:lazy_progress = 0
endif
if s:lazy_progress == 0
elseif s:lazy_progress == 1
call s:initialize_script_variables()
elseif s:lazy_progress == 2
call s:initialize_others()
else
call s:initialize_cache()
endif
let s:lazy_progress += 1
endfunction"}}}
function! s:check_initialize() "{{{
if !exists('s:is_initialized')
let s:is_initialized = 1
call s:initialize_script_variables()
call s:initialize_others()
call s:initialize_cache()
endif
endfunction"}}} endfunction"}}}
" For echodoc. "{{{ " For echodoc. "{{{
@ -173,6 +196,8 @@ function! s:initialize_snippet_options() "{{{
endfunction"}}} endfunction"}}}
function! neosnippet#edit_snippets(args) "{{{ function! neosnippet#edit_snippets(args) "{{{
call s:check_initialize()
let [args, options] = neosnippet#util#parse_options( let [args, options] = neosnippet#util#parse_options(
\ a:args, s:neosnippet_options) \ a:args, s:neosnippet_options)
@ -233,6 +258,8 @@ function! s:initialize_options(options) "{{{
endfunction"}}} endfunction"}}}
function! neosnippet#make_cache(filetype) "{{{ function! neosnippet#make_cache(filetype) "{{{
call s:check_initialize()
let filetype = a:filetype == '' ? let filetype = a:filetype == '' ?
\ &filetype : a:filetype \ &filetype : a:filetype
if filetype ==# '' if filetype ==# ''
@ -260,6 +287,8 @@ function! neosnippet#make_cache(filetype) "{{{
endfunction"}}} endfunction"}}}
function! neosnippet#source_file(filename) "{{{ function! neosnippet#source_file(filename) "{{{
call s:check_initialize()
let neosnippet = neosnippet#get_current_neosnippet() let neosnippet = neosnippet#get_current_neosnippet()
call s:parse_snippets_file(neosnippet.snippets, a:filename) call s:parse_snippets_file(neosnippet.snippets, a:filename)
endfunction"}}} endfunction"}}}
@ -982,6 +1011,8 @@ function! neosnippet#get_current_neosnippet() "{{{
return b:neosnippet return b:neosnippet
endfunction"}}} endfunction"}}}
function! neosnippet#get_snippets() "{{{ function! neosnippet#get_snippets() "{{{
call s:check_initialize()
let neosnippet = neosnippet#get_current_neosnippet() let neosnippet = neosnippet#get_current_neosnippet()
let snippets = copy(neosnippet.snippets) let snippets = copy(neosnippet.snippets)
for filetype in s:get_sources_filetypes(neosnippet#get_filetype()) for filetype in s:get_sources_filetypes(neosnippet#get_filetype())
@ -1077,6 +1108,8 @@ function! s:SID_PREFIX() "{{{
endfunction"}}} endfunction"}}}
function! s:trigger(function) "{{{ function! s:trigger(function) "{{{
call s:check_initialize()
let cur_text = neosnippet#util#get_cur_text() let cur_text = neosnippet#util#get_cur_text()
let col = col('.') let col = col('.')
@ -1233,20 +1266,10 @@ function! neosnippet#jump_impl()
return s:trigger('neosnippet#jump') return s:trigger('neosnippet#jump')
endfunction endfunction
function! s:initialize() "{{{ function! s:initialize_script_variables() "{{{
augroup neosnippet "{{{
autocmd!
" Set caching event.
autocmd FileType * call neosnippet#caching()
" Recaching events
autocmd BufWritePost *.snip,*.snippets
\ call neosnippet#recaching()
autocmd BufEnter *
\ call neosnippet#clear_select_mode_mappings()
augroup END"}}}
" Initialize. " Initialize.
let s:snippets_expand_stack = [] let s:snippets_expand_stack = []
let s:snippets = {}
if get(g:, 'neocomplcache_snippets_disable_runtime_snippets', 0) if get(g:, 'neocomplcache_snippets_disable_runtime_snippets', 0)
" Set for backward compatibility. " Set for backward compatibility.
@ -1271,6 +1294,25 @@ function! s:initialize() "{{{
call add(s:snippets_dir, dir) call add(s:snippets_dir, dir)
endfor endfor
call map(s:snippets_dir, 'substitute(v:val, "[\\\\/]$", "", "")') call map(s:snippets_dir, 'substitute(v:val, "[\\\\/]$", "", "")')
endfunction"}}}
function! s:initialize_cache() "{{{
" Caching _ snippets.
call neosnippet#make_cache('_')
" Initialize check.
call neosnippet#caching()
endfunction"}}}
function! s:initialize_others() "{{{
augroup neosnippet "{{{
autocmd!
" Set caching event.
autocmd FileType * call neosnippet#caching()
" Recaching events
autocmd BufWritePost *.snip,*.snippets
\ call neosnippet#recaching()
autocmd BufEnter *
\ call neosnippet#clear_select_mode_mappings()
augroup END"}}}
augroup neosnippet augroup neosnippet
autocmd BufNewFile,BufRead,Syntax * autocmd BufNewFile,BufRead,Syntax *
@ -1293,23 +1335,11 @@ function! s:initialize() "{{{
hi def link neosnippetExpandSnippets Special hi def link neosnippetExpandSnippets Special
" Caching _ snippets.
call neosnippet#make_cache('_')
" Initialize check.
call neosnippet#caching()
if get(g:, 'loaded_echodoc', 0) if get(g:, 'loaded_echodoc', 0)
call echodoc#register('snippets_complete', s:doc_dict) call echodoc#register('snippets_complete', s:doc_dict)
endif endif
endfunction"}}} endfunction"}}}
if !exists('s:snippets')
let s:snippets = {}
call s:initialize()
endif
let &cpo = s:save_cpo let &cpo = s:save_cpo
unlet s:save_cpo unlet s:save_cpo

View File

@ -715,6 +715,9 @@ A: Please try below settings. It defines snipMate function.
============================================================================== ==============================================================================
CHANGELOG *neosnippet-changelog* CHANGELOG *neosnippet-changelog*
2013-01-20
- Lazy initialization.
2013-01-13 2013-01-13
- Added neosnippet#expandable_or_jumpable(). - Added neosnippet#expandable_or_jumpable().

View File

@ -1,7 +1,7 @@
"============================================================================= "=============================================================================
" FILE: neosnippet.vim " FILE: neosnippet.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com> " AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" Last Modified: 02 Jan 2013. " Last Modified: 20 Jan 2013.
" License: MIT license {{{ " License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining " Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the " a copy of this software and associated documentation files (the
@ -89,7 +89,8 @@ inoremap <expr><silent> <Plug>(neosnippet_start_unite_snippet)
"}}} "}}}
augroup neosnippet "{{{ augroup neosnippet "{{{
autocmd InsertEnter * call neosnippet#initialize() autocmd CursorHold,CursorMovedI
\ * call neosnippet#_lazy_initialize()
augroup END"}}} augroup END"}}}
" Commands. "{{{ " Commands. "{{{