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. " Ignore.
elseif line =~ '^include' elseif line =~ '^include'
" Include snippets file. " Include snippets file.
for file in split(globpath(join( let snippets = extend(snippets, s:include_snippets(
\ neosnippet#helpers#get_snippets_directory(), ','), \ [matchstr(line, '^include\s\+\zs.*$')]))
\ matchstr(line, '^include\s\+\zs.*$')), '\n') elseif line =~ '^extends'
let snippets = extend(snippets, " Extend snippets files.
\ neosnippet#parser#_parse_snippets(file)) 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 endfor
elseif line =~ '^source' elseif line =~ '^source'
" Source Vim script file. " Source Vim script file.
@ -416,3 +419,15 @@ function! neosnippet#parser#_conceal_argument(arg, cnt, args) abort
endif endif
return printf('%s${%d:#:%s%s}', outside, a:cnt, inside, escape(a:arg, '{}')) return printf('%s${%d:#:%s%s}', outside, a:cnt, inside, escape(a:arg, '{}'))
endfunction 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/* 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 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 multiple times in snippet files. Neosnippet produces a warning if it detects
this. If you want to overwrite a snippet explicitly, please use: this. If you want to overwrite a snippet explicitly, please use:

View File

@ -30,7 +30,7 @@ syntax match neosnippetEscape
\ '\\[`]' contained \ '\\[`]' contained
syntax match neosnippetKeyword 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 syntax keyword neosnippetOption
\ head word indent contained \ head word indent contained
syntax match neosnippetPrevWords syntax match neosnippetPrevWords