From 97e08865965a511f4cc436c3784e56936aaa29d8 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Fri, 23 Oct 2015 08:15:02 +0900 Subject: [PATCH] Fix #294 improve snippet initialization --- autoload/neosnippet/init.vim | 32 ------------------------------ autoload/neosnippet/variables.vim | 33 ++++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 39 deletions(-) diff --git a/autoload/neosnippet/init.vim b/autoload/neosnippet/init.vim index 04ae884..3aaf2f3 100644 --- a/autoload/neosnippet/init.vim +++ b/autoload/neosnippet/init.vim @@ -29,7 +29,6 @@ set cpo&vim function! neosnippet#init#_initialize() "{{{ let s:is_initialized = 1 - call s:initialize_script_variables() call s:initialize_others() call s:initialize_cache() endfunction"}}} @@ -40,37 +39,6 @@ function! neosnippet#init#check() "{{{ endif endfunction"}}} -function! s:initialize_script_variables() "{{{ - " Set runtime dir. - let runtime_dir = neosnippet#variables#runtime_dir() - let runtime_dir += split(globpath(&runtimepath, 'neosnippets'), '\n') - if empty(runtime_dir) && empty(g:neosnippet#disable_runtime_snippets) - call neosnippet#util#print_error( - \ 'neosnippet default snippets cannot be loaded.') - call neosnippet#util#print_error( - \ 'You must install neosnippet-snippets or disable runtime snippets.') - endif - if g:neosnippet#enable_snipmate_compatibility - " Load snipMate snippet directories. - let runtime_dir += split(globpath(&runtimepath, - \ 'snippets'), '\n') - if exists('g:snippets_dir') - let runtime_dir += neosnippet#util#option2list(g:snippets_dir) - endif - endif - call map(runtime_dir, 'substitute(v:val, "[\\\\/]$", "", "")') - - " Set snippets_dir. - let snippets_dir = neosnippet#variables#snippets_dir() - for dir in neosnippet#util#option2list(g:neosnippet#snippets_directory) - let dir = neosnippet#util#expand(dir) - if !isdirectory(dir) && !neosnippet#util#is_sudo() - call mkdir(dir, 'p') - endif - call add(snippets_dir, dir) - endfor - call map(snippets_dir, 'substitute(v:val, "[\\\\/]$", "", "")') -endfunction"}}} function! s:initialize_cache() "{{{ " Make cache for _ snippets. call neosnippet#commands#_make_cache('_') diff --git a/autoload/neosnippet/variables.vim b/autoload/neosnippet/variables.vim index 5703ea6..a09f9d9 100644 --- a/autoload/neosnippet/variables.vim +++ b/autoload/neosnippet/variables.vim @@ -64,18 +64,37 @@ function! neosnippet#variables#set_snippets(list) "{{{ let s:snippets = a:list endfunction"}}} function! neosnippet#variables#snippets_dir() "{{{ - if !exists('s:snippets_dir') - let s:snippets_dir = [] - endif + " Set snippets_dir. + let snippets_dir = [] + for dir in neosnippet#util#option2list(g:neosnippet#snippets_directory) + let dir = neosnippet#util#expand(dir) + if !isdirectory(dir) && !neosnippet#util#is_sudo() + call mkdir(dir, 'p') + endif + call add(snippets_dir, dir) + endfor - return s:snippets_dir + return map(snippets_dir, 'substitute(v:val, "[\\\\/]$", "", "")') endfunction"}}} function! neosnippet#variables#runtime_dir() "{{{ - if !exists('s:runtime_dir') - let s:runtime_dir = [] + " Set runtime dir. + let runtime_dir = split(globpath(&runtimepath, 'neosnippets'), '\n') + if empty(runtime_dir) && empty(g:neosnippet#disable_runtime_snippets) + call neosnippet#util#print_error( + \ 'neosnippet default snippets cannot be loaded.') + call neosnippet#util#print_error( + \ 'You must install neosnippet-snippets or disable runtime snippets.') + endif + if g:neosnippet#enable_snipmate_compatibility + " Load snipMate snippet directories. + let runtime_dir += split(globpath(&runtimepath, + \ 'snippets'), '\n') + if exists('g:snippets_dir') + let runtime_dir += neosnippet#util#option2list(g:snippets_dir) + endif endif - return s:runtime_dir + return map(runtime_dir, 'substitute(v:val, "[\\\\/]$", "", "")') endfunction"}}} function! neosnippet#variables#data_dir() "{{{ let g:neosnippet#data_directory =