diff --git a/autoload/neosnippet/helpers.vim b/autoload/neosnippet/helpers.vim index 53e56a3..495d02b 100644 --- a/autoload/neosnippet/helpers.vim +++ b/autoload/neosnippet/helpers.vim @@ -181,6 +181,13 @@ function! neosnippet#helpers#substitute_selected_text(type, text) abort "{{{ endtry endfunction"}}} +function! neosnippet#helpers#vim2json(expr) abort "{{{ + return has('patch-7.4.1498') ? js_encode(a:expr) : string(a:expr) +endfunction "}}} +function! neosnippet#helpers#json2vim(expr) abort "{{{ + sandbox return has('patch-7.4.1498') ? js_decode(a:expr) : eval(a:expr) +endfunction "}}} + function! s:is_beginning_of_line(cur_text) abort "{{{ let keyword_pattern = '\S\+' let cur_keyword_str = matchstr(a:cur_text, keyword_pattern.'$') diff --git a/autoload/neosnippet/parser.vim b/autoload/neosnippet/parser.vim index 31637db..cf81554 100644 --- a/autoload/neosnippet/parser.vim +++ b/autoload/neosnippet/parser.vim @@ -36,15 +36,21 @@ function! neosnippet#parser#_parse_snippets(filename) abort "{{{ endif let cache_dir = neosnippet#variables#data_dir() - if s:Cache.check_old_cache(cache_dir, a:filename) + let snippets = {} + if !s:Cache.check_old_cache(cache_dir, a:filename) + try + let snippets = neosnippet#helpers#json2vim( + \ s:Cache.readfile(cache_dir, a:filename)[0]) + catch + endtry + endif + if empty(snippets) || s:Cache.check_old_cache(cache_dir, a:filename) let [snippets, sourced] = s:parse(a:filename) if len(snippets) > 5 && !neosnippet#util#is_sudo() && !sourced call s:Cache.writefile( - \ cache_dir, a:filename, [string(snippets)]) + \ cache_dir, a:filename, + \ [neosnippet#helpers#vim2json(snippets)]) endif - else - sandbox let snippets = eval( - \ s:Cache.readfile(cache_dir, a:filename)[0]) endif return snippets