Fix #196 implement File snippets feature in snipMate
This commit is contained in:
parent
b2e90869af
commit
e30e797e73
@ -104,26 +104,24 @@ function! neosnippet#commands#_make_cache(filetype) "{{{
|
||||
if has_key(snippets, filetype)
|
||||
return
|
||||
endif
|
||||
|
||||
let snippets[filetype] = {}
|
||||
|
||||
let path = join(neosnippet#helpers#get_snippets_directory(), ',')
|
||||
let snippets_files = []
|
||||
for glob in s:get_list().flatten(
|
||||
\ map(split(get(g:neosnippet#scope_aliases,
|
||||
\ filetype, filetype), '\s*,\s*'), "
|
||||
\ [v:val.'.snip', v:val.'.snippet',
|
||||
\ v:val.'/**/*.snip', v:val.'/**/*.snippet']
|
||||
\ + (filetype != '_' &&
|
||||
\ !has_key(g:neosnippet#scope_aliases, filetype) ?
|
||||
\ [v:val . '_*.snip', v:val . '_*.snippet'] : [])"))
|
||||
let snippets_files += split(globpath(path, glob), '\n')
|
||||
|
||||
for filename in s:get_snippets_files(path, filetype)
|
||||
let snippets[filetype] = extend(snippets[filetype],
|
||||
\ neosnippet#parser#_parse_snippets(filename))
|
||||
endfor
|
||||
|
||||
let snippets = neosnippet#variables#snippets()
|
||||
for snippets_file in reverse(s:get_list().uniq(snippets_files))
|
||||
let snippets[filetype] = extend(snippets[filetype],
|
||||
\ neosnippet#parser#_parse_snippets(snippets_file))
|
||||
if g:neosnippet#enable_snipmate_compatibility
|
||||
" Load file snippets
|
||||
for filename in s:get_snippet_files(path, filetype)
|
||||
let trigger = fnamemodify(filename, ':t:r')
|
||||
let snippets[filetype][trigger] =
|
||||
\ neosnippet#parser#_parse_snippet(filename, trigger)
|
||||
endfor
|
||||
endif
|
||||
endfunction"}}}
|
||||
|
||||
function! neosnippet#commands#_source(filename) "{{{
|
||||
@ -228,6 +226,31 @@ function! s:initialize_options(options) "{{{
|
||||
return options
|
||||
endfunction"}}}
|
||||
|
||||
function! s:get_snippets_files(path, filetype) abort "{{{
|
||||
let snippets_files = []
|
||||
for glob in s:get_list().flatten(
|
||||
\ map(split(get(g:neosnippet#scope_aliases,
|
||||
\ a:filetype, a:filetype), '\s*,\s*'), "
|
||||
\ [v:val.'.snip', v:val.'.snippet',
|
||||
\ v:val.'/**/*.snip', v:val.'/**/*.snippet']
|
||||
\ + (a:filetype != '_' &&
|
||||
\ !has_key(g:neosnippet#scope_aliases, a:filetype) ?
|
||||
\ [v:val . '_*.snip', v:val . '_*.snippet'] : [])"))
|
||||
let snippets_files += split(globpath(a:path, glob), '\n')
|
||||
endfor
|
||||
return reverse(s:get_list().uniq(snippets_files))
|
||||
endfunction"}}}
|
||||
function! s:get_snippet_files(path, filetype) abort "{{{
|
||||
let snippet_files = []
|
||||
for glob in s:get_list().flatten(
|
||||
\ map(split(get(g:neosnippet#scope_aliases,
|
||||
\ a:filetype, a:filetype), '\s*,\s*'), "
|
||||
\ [v:val.'/*.snippet']"))
|
||||
let snippet_files += split(globpath(a:path, glob), '\n')
|
||||
endfor
|
||||
return reverse(s:get_list().uniq(snippet_files))
|
||||
endfunction"}}}
|
||||
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
||||
|
@ -49,6 +49,22 @@ function! neosnippet#parser#_parse_snippets(filename) "{{{
|
||||
|
||||
return snippets
|
||||
endfunction"}}}
|
||||
function! neosnippet#parser#_parse_snippet(filename, trigger) "{{{
|
||||
if !filereadable(a:filename)
|
||||
call neosnippet#util#print_error(
|
||||
\ printf('snippet file "%s" is not found.', a:filename))
|
||||
return {}
|
||||
endif
|
||||
|
||||
let snippet_dict = {
|
||||
\ 'word' : join(readfile(a:filename), "\n\t"),
|
||||
\ 'name' : a:trigger,
|
||||
\ 'options' : neosnippet#parser#_initialize_snippet_options()
|
||||
\ }
|
||||
|
||||
return neosnippet#parser#_initialize_snippet(
|
||||
\ snippet_dict, a:filename, 1, '', a:trigger)
|
||||
endfunction"}}}
|
||||
|
||||
function! s:parse(snippets_file) "{{{
|
||||
let dup_check = {}
|
||||
@ -117,8 +133,11 @@ endfunction"}}}
|
||||
|
||||
function! s:parse_snippet_name(snippets_file, line, linenr, dup_check) "{{{
|
||||
" Initialize snippet dict.
|
||||
let snippet_dict = { 'word' : '', 'linenr' : a:linenr,
|
||||
\ 'options' : neosnippet#parser#_initialize_snippet_options() }
|
||||
let snippet_dict = {
|
||||
\ 'word' : '',
|
||||
\ 'linenr' : a:linenr,
|
||||
\ 'options' : neosnippet#parser#_initialize_snippet_options()
|
||||
\ }
|
||||
|
||||
" Try using the name without the description (abbr).
|
||||
let snippet_dict.name = matchstr(a:line, '^snippet\s\+\zs\S\+')
|
||||
|
@ -198,9 +198,12 @@ g:neosnippet#disable_runtime_snippets
|
||||
*g:neosnippet#enable_snipmate_compatibility*
|
||||
g:neosnippet#enable_snipmate_compatibility
|
||||
If this variable is not 0, neosnippet will enable the snipMate
|
||||
compatibility feature (For example: Filename() function) and
|
||||
load |g:snippets_dir| and snipMate snippets automatically from
|
||||
compatibility features:
|
||||
|
||||
1. Define Filename() function.
|
||||
2. Load |g:snippets_dir| and snipMate snippets files from
|
||||
'runtimepath'.
|
||||
3. Enable file snippets feature in snipMate.
|
||||
|
||||
The default value is 0.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user