Implement cache feature

This commit is contained in:
Shougo Matsushita 2014-05-11 17:56:27 +09:00
parent e8b1af724b
commit 8b504f2dd8
3 changed files with 29 additions and 1 deletions

View File

@ -35,7 +35,17 @@ function! neosnippet#parser#_parse(snippet_file) "{{{
return {}
endif
return s:parse(a:snippet_file)
let cache_dir = neosnippet#variables#data_dir()
if s:Cache.check_old_cache(cache_dir, a:snippet_file)
let snippets = s:parse(a:snippet_file)
if len(snippets) > 5
call s:Cache.writefile(cache_dir, a:snippet_file, [string(snippets)])
endif
else
sandbox let snippets = eval(s:Cache.readfile(cache_dir, a:snippet_file)[0])
endif
return snippets
endfunction"}}}
function! s:parse(snippet_file) "{{{

View File

@ -73,6 +73,17 @@ function! neosnippet#variables#runtime_dir() "{{{
return s:runtime_dir
endfunction"}}}
function! neosnippet#variables#data_dir() "{{{
let g:neosnippet#data_directory =
\ substitute(fnamemodify(get(
\ g:, 'neosnippet#data_directory', '~/.cache/neosnippet'),
\ ':p'), '\\', '/', 'g')
if !isdirectory(g:neosnippet#data_directory)
call mkdir(g:neosnippet#data_directory, 'p')
endif
return g:neosnippet#data_directory
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo

View File

@ -230,6 +230,13 @@ g:neosnippet#scope_aliases
let g:neosnippet#scope_aliases = {}
let g:neosnippet#scope_aliases['ruby'] = 'ruby,ruby-rails'
g:neosnippet_data_directory *g:neosnippet_data_directory*
Specifies directory for neosnippet cache. If the directory
doesn't exist the directory will be automatically generated.
Default value is expand('~/.cache/neosnippet'); the absolute
path of it.
------------------------------------------------------------------------------
KEY MAPPINGS *neosnippet-key-mappings*