Browse Source

Fix #407 supports extends feature in snipMate

Shougo Matsushita 2 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
67 67
       " Ignore.
68 68
     elseif line =~ '^include'
69 69
       " Include snippets file.
70
-      for file in split(globpath(join(
71
-            \ neosnippet#helpers#get_snippets_directory(), ','),
72
-            \ matchstr(line, '^include\s\+\zs.*$')), '\n')
73
-        let snippets = extend(snippets,
74
-              \ neosnippet#parser#_parse_snippets(file))
70
+      let snippets = extend(snippets, s:include_snippets(
71
+            \ [matchstr(line, '^include\s\+\zs.*$')]))
72
+    elseif line =~ '^extends'
73
+      " Extend snippets files.
74
+      let fts = split(matchstr(line, '^extends\s\+\zs.*$'), '\s*,\s*')
75
+      for ft in fts
76
+        let snippets = extend(snippets, s:include_snippets(
77
+              \ [ft.'.snip', ft.'.snippets', ft.'/*']))
75 78
       endfor
76 79
     elseif line =~ '^source'
77 80
       " Source Vim script file.
@@ -416,3 +419,15 @@ function! neosnippet#parser#_conceal_argument(arg, cnt, args) abort
416 419
   endif
417 420
   return printf('%s${%d:#:%s%s}', outside, a:cnt, inside, escape(a:arg, '{}'))
418 421
 endfunction
422
+
423
+function! s:include_snippets(globs) abort
424
+  let snippets = {}
425
+  for glob in a:globs
426
+      for file in split(globpath(join(
427
+            \ neosnippet#helpers#get_snippets_directory(), ','), glob), '\n')
428
+        call extend(snippets, neosnippet#parser#_parse_snippets(file))
429
+      endfor
430
+  endfor
431
+
432
+  return snippets
433
+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.
672 672
 >
673 673
 	include javascript/*
674 674
 <
675
+Neosnippet also supports "extends" syntax like snipMate.
675 676
 
677
+>
678
+	extends c
679
+<
680
+It behaves like this:
681
+
682
+>
683
+	include c.snip
684
+	include c.snippets
685
+	include c/*
686
+<
676 687
 If you include snippet files it can happen that the same snippet name is used
677 688
 multiple times in snippet files. Neosnippet produces a warning if it detects
678 689
 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
30 30
       \ '\\[`]' contained
31 31
 
32 32
 syntax match   neosnippetKeyword
33
-      \ '^\%(include\|source\|snippet\|abbr\|prev_word\|delete\|alias\|options\|regexp\|TARGET\)' contained
33
+      \ '^\%(include\|extends\|source\|snippet\|abbr\|prev_word\|delete\|alias\|options\|regexp\|TARGET\)' contained
34 34
 syntax keyword   neosnippetOption
35 35
       \ head word indent contained
36 36
 syntax match   neosnippetPrevWords