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)
|
if has_key(snippets, filetype)
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let snippets[filetype] = {}
|
let snippets[filetype] = {}
|
||||||
|
|
||||||
let path = join(neosnippet#helpers#get_snippets_directory(), ',')
|
let path = join(neosnippet#helpers#get_snippets_directory(), ',')
|
||||||
let snippets_files = []
|
|
||||||
for glob in s:get_list().flatten(
|
for filename in s:get_snippets_files(path, filetype)
|
||||||
\ map(split(get(g:neosnippet#scope_aliases,
|
let snippets[filetype] = extend(snippets[filetype],
|
||||||
\ filetype, filetype), '\s*,\s*'), "
|
\ neosnippet#parser#_parse_snippets(filename))
|
||||||
\ [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')
|
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
let snippets = neosnippet#variables#snippets()
|
if g:neosnippet#enable_snipmate_compatibility
|
||||||
for snippets_file in reverse(s:get_list().uniq(snippets_files))
|
" Load file snippets
|
||||||
let snippets[filetype] = extend(snippets[filetype],
|
for filename in s:get_snippet_files(path, filetype)
|
||||||
\ neosnippet#parser#_parse_snippets(snippets_file))
|
let trigger = fnamemodify(filename, ':t:r')
|
||||||
endfor
|
let snippets[filetype][trigger] =
|
||||||
|
\ neosnippet#parser#_parse_snippet(filename, trigger)
|
||||||
|
endfor
|
||||||
|
endif
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
|
||||||
function! neosnippet#commands#_source(filename) "{{{
|
function! neosnippet#commands#_source(filename) "{{{
|
||||||
@ -228,6 +226,31 @@ function! s:initialize_options(options) "{{{
|
|||||||
return options
|
return options
|
||||||
endfunction"}}}
|
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
|
let &cpo = s:save_cpo
|
||||||
unlet s:save_cpo
|
unlet s:save_cpo
|
||||||
|
|
||||||
|
@ -49,6 +49,22 @@ function! neosnippet#parser#_parse_snippets(filename) "{{{
|
|||||||
|
|
||||||
return snippets
|
return snippets
|
||||||
endfunction"}}}
|
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) "{{{
|
function! s:parse(snippets_file) "{{{
|
||||||
let dup_check = {}
|
let dup_check = {}
|
||||||
@ -117,8 +133,11 @@ endfunction"}}}
|
|||||||
|
|
||||||
function! s:parse_snippet_name(snippets_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 = {
|
||||||
\ 'options' : neosnippet#parser#_initialize_snippet_options() }
|
\ 'word' : '',
|
||||||
|
\ 'linenr' : a:linenr,
|
||||||
|
\ 'options' : neosnippet#parser#_initialize_snippet_options()
|
||||||
|
\ }
|
||||||
|
|
||||||
" Try using the name without the description (abbr).
|
" Try using the name without the description (abbr).
|
||||||
let snippet_dict.name = matchstr(a:line, '^snippet\s\+\zs\S\+')
|
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*
|
||||||
g:neosnippet#enable_snipmate_compatibility
|
g:neosnippet#enable_snipmate_compatibility
|
||||||
If this variable is not 0, neosnippet will enable the snipMate
|
If this variable is not 0, neosnippet will enable the snipMate
|
||||||
compatibility feature (For example: Filename() function) and
|
compatibility features:
|
||||||
load |g:snippets_dir| and snipMate snippets automatically from
|
|
||||||
|
1. Define Filename() function.
|
||||||
|
2. Load |g:snippets_dir| and snipMate snippets files from
|
||||||
'runtimepath'.
|
'runtimepath'.
|
||||||
|
3. Enable file snippets feature in snipMate.
|
||||||
|
|
||||||
The default value is 0.
|
The default value is 0.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user