Browse Source

Fix #407 supports extends feature in snipMate

PR/fix-warning
Shougo Matsushita 6 years ago
parent
commit
9ee1b4e059
3 changed files with 32 additions and 6 deletions
  1. +20
    -5
      autoload/neosnippet/parser.vim
  2. +11
    -0
      doc/neosnippet.txt
  3. +1
    -1
      syntax/neosnippet.vim

+ 20
- 5
autoload/neosnippet/parser.vim 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(
\ 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 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

+ 11
- 0
doc/neosnippet.txt 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:


+ 1
- 1
syntax/neosnippet.vim 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


Loading…
Cancel
Save