Use snippets_file instead of snippet_file
This commit is contained in:
parent
fead622ed0
commit
32e56accfa
@ -119,9 +119,9 @@ function! neosnippet#commands#_make_cache(filetype) "{{{
|
|||||||
endfor
|
endfor
|
||||||
|
|
||||||
let snippets = neosnippet#variables#snippets()
|
let snippets = neosnippet#variables#snippets()
|
||||||
for snippet_file in reverse(s:get_list().uniq(snippets_files))
|
for snippets_file in reverse(s:get_list().uniq(snippets_files))
|
||||||
let snippets[filetype] = extend(snippets[filetype],
|
let snippets[filetype] = extend(snippets[filetype],
|
||||||
\ neosnippet#parser#_parse(snippet_file))
|
\ neosnippet#parser#_parse(snippets_file))
|
||||||
endfor
|
endfor
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
|
||||||
|
@ -28,33 +28,33 @@ set cpo&vim
|
|||||||
|
|
||||||
let s:Cache = neosnippet#util#get_vital().import('System.Cache')
|
let s:Cache = neosnippet#util#get_vital().import('System.Cache')
|
||||||
|
|
||||||
function! neosnippet#parser#_parse(snippet_file) "{{{
|
function! neosnippet#parser#_parse(snippets_file) "{{{
|
||||||
if !filereadable(a:snippet_file)
|
if !filereadable(a:snippets_file)
|
||||||
call neosnippet#util#print_error(
|
call neosnippet#util#print_error(
|
||||||
\ printf('snippet file "%s" is not found.', a:snippet_file))
|
\ printf('snippet file "%s" is not found.', a:snippets_file))
|
||||||
return {}
|
return {}
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let cache_dir = neosnippet#variables#data_dir()
|
let cache_dir = neosnippet#variables#data_dir()
|
||||||
if s:Cache.check_old_cache(cache_dir, a:snippet_file)
|
if s:Cache.check_old_cache(cache_dir, a:snippets_file)
|
||||||
let snippets = s:parse(a:snippet_file)
|
let snippets = s:parse(a:snippets_file)
|
||||||
if len(snippets) > 5 && !neosnippet#util#is_sudo()
|
if len(snippets) > 5 && !neosnippet#util#is_sudo()
|
||||||
call s:Cache.writefile(cache_dir, a:snippet_file, [string(snippets)])
|
call s:Cache.writefile(cache_dir, a:snippets_file, [string(snippets)])
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
sandbox let snippets = eval(s:Cache.readfile(cache_dir, a:snippet_file)[0])
|
sandbox let snippets = eval(s:Cache.readfile(cache_dir, a:snippets_file)[0])
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return snippets
|
return snippets
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
|
||||||
function! s:parse(snippet_file) "{{{
|
function! s:parse(snippets_file) "{{{
|
||||||
let dup_check = {}
|
let dup_check = {}
|
||||||
let snippet_dict = {}
|
let snippet_dict = {}
|
||||||
let linenr = 1
|
let linenr = 1
|
||||||
let snippets = {}
|
let snippets = {}
|
||||||
|
|
||||||
for line in readfile(a:snippet_file)
|
for line in readfile(a:snippets_file)
|
||||||
if line =~ '^\h\w*.*\s$'
|
if line =~ '^\h\w*.*\s$'
|
||||||
" Delete spaces.
|
" Delete spaces.
|
||||||
let line = substitute(line, '\s\+$', '', '')
|
let line = substitute(line, '\s\+$', '', '')
|
||||||
@ -66,11 +66,11 @@ function! s:parse(snippet_file) "{{{
|
|||||||
" Include snippets.
|
" Include snippets.
|
||||||
let filename = matchstr(line, '^include\s\+\zs.*$')
|
let filename = matchstr(line, '^include\s\+\zs.*$')
|
||||||
|
|
||||||
for snippet_file in split(globpath(join(
|
for snippets_file in split(globpath(join(
|
||||||
\ neosnippet#helpers#get_snippets_directory(), ','),
|
\ neosnippet#helpers#get_snippets_directory(), ','),
|
||||||
\ filename), '\n')
|
\ filename), '\n')
|
||||||
let snippets = extend(snippets,
|
let snippets = extend(snippets,
|
||||||
\ neosnippet#parser#_parse(snippet_file))
|
\ neosnippet#parser#_parse(snippets_file))
|
||||||
endfor
|
endfor
|
||||||
elseif line =~ '^delete\s'
|
elseif line =~ '^delete\s'
|
||||||
let name = matchstr(line, '^delete\s\+\zs.*$')
|
let name = matchstr(line, '^delete\s\+\zs.*$')
|
||||||
@ -81,11 +81,11 @@ function! s:parse(snippet_file) "{{{
|
|||||||
if !empty(snippet_dict)
|
if !empty(snippet_dict)
|
||||||
" Set previous snippet.
|
" Set previous snippet.
|
||||||
call s:set_snippet_dict(snippet_dict,
|
call s:set_snippet_dict(snippet_dict,
|
||||||
\ snippets, dup_check, a:snippet_file)
|
\ snippets, dup_check, a:snippets_file)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let snippet_dict = s:parse_snippet_name(
|
let snippet_dict = s:parse_snippet_name(
|
||||||
\ a:snippet_file, line, linenr, dup_check)
|
\ a:snippets_file, line, linenr, dup_check)
|
||||||
elseif !empty(snippet_dict)
|
elseif !empty(snippet_dict)
|
||||||
if line =~ '^\s' || line == ''
|
if line =~ '^\s' || line == ''
|
||||||
if snippet_dict.word == ''
|
if snippet_dict.word == ''
|
||||||
@ -97,7 +97,7 @@ function! s:parse(snippet_file) "{{{
|
|||||||
\ substitute(line, '^ *', '', '') . "\n"
|
\ substitute(line, '^ *', '', '') . "\n"
|
||||||
else
|
else
|
||||||
call s:add_snippet_attribute(
|
call s:add_snippet_attribute(
|
||||||
\ a:snippet_file, line, linenr, snippet_dict)
|
\ a:snippets_file, line, linenr, snippet_dict)
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@ -107,13 +107,13 @@ function! s:parse(snippet_file) "{{{
|
|||||||
if !empty(snippet_dict)
|
if !empty(snippet_dict)
|
||||||
" Set previous snippet.
|
" Set previous snippet.
|
||||||
call s:set_snippet_dict(snippet_dict,
|
call s:set_snippet_dict(snippet_dict,
|
||||||
\ snippets, dup_check, a:snippet_file)
|
\ snippets, dup_check, a:snippets_file)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return snippets
|
return snippets
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
|
||||||
function! s:parse_snippet_name(snippet_file, line, linenr, dup_check) "{{{
|
function! s:parse_snippet_name(snippets_file, line, linenr, dup_check) "{{{
|
||||||
" Initialize snippet dict.
|
" Initialize snippet dict.
|
||||||
let snippet_dict = { 'word' : '', 'linenr' : a:linenr,
|
let snippet_dict = { 'word' : '', 'linenr' : a:linenr,
|
||||||
\ 'options' : neosnippet#parser#_initialize_snippet_options() }
|
\ 'options' : neosnippet#parser#_initialize_snippet_options() }
|
||||||
@ -142,7 +142,7 @@ function! s:parse_snippet_name(snippet_file, line, linenr, dup_check) "{{{
|
|||||||
let dup = a:dup_check[snippet_dict.name]
|
let dup = a:dup_check[snippet_dict.name]
|
||||||
call neosnippet#util#print_error(printf(
|
call neosnippet#util#print_error(printf(
|
||||||
\ '%s:%d is overriding `%s` from %s:%d',
|
\ '%s:%d is overriding `%s` from %s:%d',
|
||||||
\ a:snippet_file, a:linenr, snippet_dict.name,
|
\ a:snippets_file, a:linenr, snippet_dict.name,
|
||||||
\ dup.action__path, dup.action__line))
|
\ dup.action__path, dup.action__line))
|
||||||
call neosnippet#util#print_error(printf(
|
call neosnippet#util#print_error(printf(
|
||||||
\ 'Please rename the snippet name or use `delete %s`.',
|
\ 'Please rename the snippet name or use `delete %s`.',
|
||||||
@ -152,7 +152,7 @@ function! s:parse_snippet_name(snippet_file, line, linenr, dup_check) "{{{
|
|||||||
return snippet_dict
|
return snippet_dict
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
|
||||||
function! s:add_snippet_attribute(snippet_file, line, linenr, snippet_dict) "{{{
|
function! s:add_snippet_attribute(snippets_file, line, linenr, snippet_dict) "{{{
|
||||||
" Allow overriding/setting of the description (abbr) of the snippet.
|
" Allow overriding/setting of the description (abbr) of the snippet.
|
||||||
" This will override what was set via the snippet line.
|
" This will override what was set via the snippet line.
|
||||||
if a:line =~ '^abbr\s'
|
if a:line =~ '^abbr\s'
|
||||||
@ -178,7 +178,7 @@ function! s:add_snippet_attribute(snippet_file, line, linenr, snippet_dict) "{{{
|
|||||||
\ '^options\s\+\zs.*$'), '[,[:space:]]\+')
|
\ '^options\s\+\zs.*$'), '[,[:space:]]\+')
|
||||||
if !has_key(a:snippet_dict.options, option)
|
if !has_key(a:snippet_dict.options, option)
|
||||||
call neosnippet#util#print_error(
|
call neosnippet#util#print_error(
|
||||||
\ printf('%s:%d', a:snippet_file, a:linenr))
|
\ printf('%s:%d', a:snippets_file, a:linenr))
|
||||||
call neosnippet#util#print_error(
|
call neosnippet#util#print_error(
|
||||||
\ printf('Invalid option name : "%s"', option))
|
\ printf('Invalid option name : "%s"', option))
|
||||||
else
|
else
|
||||||
@ -187,20 +187,20 @@ function! s:add_snippet_attribute(snippet_file, line, linenr, snippet_dict) "{{{
|
|||||||
endfor
|
endfor
|
||||||
else
|
else
|
||||||
call neosnippet#util#print_error(
|
call neosnippet#util#print_error(
|
||||||
\ printf('%s:%d', a:snippet_file, a:linenr))
|
\ printf('%s:%d', a:snippets_file, a:linenr))
|
||||||
call neosnippet#util#print_error(
|
call neosnippet#util#print_error(
|
||||||
\ printf('Invalid syntax : "%s"', a:line))
|
\ printf('Invalid syntax : "%s"', a:line))
|
||||||
endif
|
endif
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
|
||||||
function! s:set_snippet_dict(snippet_dict, snippets, dup_check, snippet_file) "{{{
|
function! s:set_snippet_dict(snippet_dict, snippets, dup_check, snippets_file) "{{{
|
||||||
if empty(a:snippet_dict)
|
if empty(a:snippet_dict)
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let action_pattern = '^snippet\s\+' . a:snippet_dict.name . '$'
|
let action_pattern = '^snippet\s\+' . a:snippet_dict.name . '$'
|
||||||
let snippet = neosnippet#parser#_initialize_snippet(
|
let snippet = neosnippet#parser#_initialize_snippet(
|
||||||
\ a:snippet_dict, a:snippet_file,
|
\ a:snippet_dict, a:snippets_file,
|
||||||
\ a:snippet_dict.linenr, action_pattern,
|
\ a:snippet_dict.linenr, action_pattern,
|
||||||
\ a:snippet_dict.name)
|
\ a:snippet_dict.name)
|
||||||
let a:snippets[a:snippet_dict.name] = snippet
|
let a:snippets[a:snippet_dict.name] = snippet
|
||||||
|
Loading…
Reference in New Issue
Block a user