Fix #407 supports extends feature in snipMate

This commit is contained in:
Shougo Matsushita 2017-11-23 13:48:00 +09:00
parent ddd01d0ee3
commit 9ee1b4e059
3 changed files with 32 additions and 6 deletions

View File

@ -67,11 +67,14 @@ function! s:parse(snippets_file) abort
" Ignore.
elseif line =~ '^include'
" Include snippets file.
for file in split(globpath(join(
\ neosnippet#helpers#get_snippets_directory(), ','),
\ matchstr(line, '^include\s\+\zs.*$')), '\n')
let snippets = extend(snippets,
\ neosnippet#parser#_parse_snippets(file))
let snippets = extend(snippets, s:include_snippets(
\ [matchstr(line, '^include\s\+\zs.*$')]))
elseif line =~ '^extends'
" Extend snippets files.
let fts = split(matchstr(line, '^extends\s\+\zs.*$'), '\s*,\s*')
for ft in fts
let snippets = extend(snippets, s:include_snippets(
\ [ft.'.snip', ft.'.snippets', ft.'/*']))
endfor
elseif line =~ '^source'
" Source Vim script file.
@ -416,3 +419,15 @@ function! neosnippet#parser#_conceal_argument(arg, cnt, args) abort
endif
return printf('%s${%d:#:%s%s}', outside, a:cnt, inside, escape(a:arg, '{}'))
endfunction
function! s:include_snippets(globs) abort
let snippets = {}
for glob in a:globs
for file in split(globpath(join(
\ neosnippet#helpers#get_snippets_directory(), ','), glob), '\n')
call extend(snippets, neosnippet#parser#_parse_snippets(file))
endfor
endfor
return snippets
endfunction

View File

@ -672,7 +672,18 @@ Or if you want to include a whole directory with file type snippets.
>
include javascript/*
<
Neosnippet also supports "extends" syntax like snipMate.
>
extends c
<
It behaves like this:
>
include c.snip
include c.snippets
include c/*
<
If you include snippet files it can happen that the same snippet name is used
multiple times in snippet files. Neosnippet produces a warning if it detects
this. If you want to overwrite a snippet explicitly, please use:

View File

@ -30,7 +30,7 @@ syntax match neosnippetEscape
\ '\\[`]' contained
syntax match neosnippetKeyword
\ '^\%(include\|source\|snippet\|abbr\|prev_word\|delete\|alias\|options\|regexp\|TARGET\)' contained
\ '^\%(include\|extends\|source\|snippet\|abbr\|prev_word\|delete\|alias\|options\|regexp\|TARGET\)' contained
syntax keyword neosnippetOption
\ head word indent contained
syntax match neosnippetPrevWords