1 " Syntax highlighting for snippet files (used for UltiSnips.vim)
2 " Revision: 26/03/11 19:53:33
4 if exists("b:current_syntax")
8 if expand("%:p:h") =~ "snippets" && search("^endsnippet", "nw") == 0
9 \ && !exists("b:ultisnips_override_snipmate")
10 " this appears to be a snipmate file
11 " It's in a directory called snippets/ and there's no endsnippet keyword
12 " anywhere in the file.
13 source <sfile>:h/snippets_snipmate.vim
17 " Embedded Syntaxes {{{1
20 syntax include @Python syntax/python.vim
21 unlet b:current_syntax
22 syntax include @Viml syntax/vim.vim
23 unlet b:current_syntax
24 syntax include @Shell syntax/sh.vim
25 unlet b:current_syntax
27 " Ignore errors about syntax files that can't be loaded more than once
30 " Syntax definitions {{{1
34 syn match snipComment "^#.*" contains=snipTODO display
35 syn keyword snipTODO contained display FIXME NOTE NOTES TODO XXX
39 syn match snipLeadingSpaces "^\t* \+" contained
43 syn match snipExtends "^extends\%(\s.*\|$\)" contains=snipExtendsKeyword display
44 syn match snipExtendsKeyword "^extends" contained display
50 syn region snipSnippet start="^snippet\_s" end="^endsnippet\s*$" contains=snipSnippetHeader fold keepend
51 syn match snipSnippetHeader "^.*$" nextgroup=snipSnippetBody,snipSnippetFooter skipnl contained contains=snipSnippetHeaderKeyword
52 syn match snipSnippetHeaderKeyword "^snippet" contained nextgroup=snipSnippetTrigger skipwhite
53 syn region snipSnippetBody start="\_." end="^\zeendsnippet\s*$" contained nextgroup=snipSnippetFooter contains=snipLeadingSpaces,@snipTokens
54 syn match snipSnippetFooter "^endsnippet.*" contained contains=snipSnippetFooterKeyword
55 syn match snipSnippetFooterKeyword "^endsnippet" contained
57 " The current parser is a bit lax about parsing. For example, given this:
59 " it treats `foo"bar"` as the trigger. But with this:
60 " snippet foo"bar baz"
61 " it treats `foo` as the trigger and "bar baz" as the description.
62 " I think this is an accident. Instead, we'll assume the description must
63 " be surrounded by spaces. That means we'll treat
65 " as a trigger `foo"bar"` and
66 " snippet foo"bar baz"
67 " as an attempted multiword snippet `foo"bar baz"` that is invalid.
68 " NB: UltiSnips parses right-to-left, which Vim doesn't support, so that makes
69 " the following patterns very complicated.
70 syn match snipSnippetTrigger "\S\+" contained nextgroup=snipSnippetDocString,snipSnippetTriggerInvalid skipwhite
71 " We want to match a trailing " as the start of a doc comment, but we also
72 " want to allow for using " as the delimiter in a multiword/pattern snippet.
73 " So we have to define this twice, once in the general case that matches a
74 " trailing " as the doc comment, and once for the case of the multiword
75 " delimiter using " that has more constraints
76 syn match snipSnippetTrigger ,".\{-}"\ze\%(\s\+"\%(\s*\S\)\@=[^"]*\%("\s\+[^"[:space:]]\+\|"\)\=\)\=\s*$, contained nextgroup=snipSnippetDocString skipwhite
77 syn match snipSnippetTrigger ,\%(\(\S\).\{-}\1\|\S\+\)\ze\%(\s\+"[^"]*\%("\s\+\%("[^"]\+"\s\+[^"[:space:]]*e[^"[:space:]]*\)\|"\)\=\)\=\s*$, contained nextgroup=snipSnippetDocContextString skipwhite
78 syn match snipSnippetTrigger ,\([^"[:space:]]\).\{-}\1\%(\s*$\)\@!\ze\%(\s\+"[^"]*\%("\s\+\%("[^"]\+"\s\+[^"[:space:]]*e[^"[:space:]]*\|[^"[:space:]]\+\)\|"\)\=\)\=\s*$, contained nextgroup=snipSnippetDocString skipwhite
79 syn match snipSnippetTriggerInvalid ,\S\@=.\{-}\S\ze\%(\s\+"[^"]*\%("\s\+[^"[:space:]]\+\s*\|"\s*\)\=\|\s*\)$, contained nextgroup=snipSnippetDocString skipwhite
80 syn match snipSnippetDocString ,"[^"]*", contained nextgroup=snipSnippetOptions skipwhite
81 syn match snipSnippetDocContextString ,"[^"]*", contained nextgroup=snipSnippetContext skipwhite
82 syn match snipSnippetContext ,"[^"]\+", contained skipwhite contains=snipSnippetContextP
83 syn region snipSnippetContextP start=,"\@<=., end=,\ze", contained contains=@Python nextgroup=snipSnippetOptions skipwhite keepend
84 syn match snipSnippetOptions ,\S\+, contained contains=snipSnippetOptionFlag
85 syn match snipSnippetOptionFlag ,[biwrtsmxAe], contained
87 " Command substitution {{{4
89 syn region snipCommand keepend matchgroup=snipCommandDelim start="`" skip="\\[{}\\$`]" end="`" contained contains=snipPythonCommand,snipVimLCommand,snipShellCommand,snipCommandSyntaxOverride
90 syn region snipShellCommand start="\ze\_." skip="\\[{}\\$`]" end="\ze`" contained contains=@Shell
91 syn region snipPythonCommand matchgroup=snipPythonCommandP start="`\@<=!p\_s" skip="\\[{}\\$`]" end="\ze`" contained contains=@Python
92 syn region snipVimLCommand matchgroup=snipVimLCommandV start="`\@<=!v\_s" skip="\\[{}\\$`]" end="\ze`" contained contains=@Viml
93 syn cluster snipTokens add=snipCommand
94 syn cluster snipTabStopTokens add=snipCommand
96 " unfortunately due to the balanced braces parsing of commands, if a { occurs
97 " in the command, we need to prevent the embedded syntax highlighting.
98 " Otherwise, we can't track the balanced braces properly.
100 syn region snipCommandSyntaxOverride start="\%(\\[{}\\$`]\|\_[^`"{]\)*\ze{" skip="\\[{}\\$`]" end="\ze`" contained contains=snipBalancedBraces transparent
104 syn match snipEscape "\\[{}\\$`]" contained
105 syn cluster snipTokens add=snipEscape
106 syn cluster snipTabStopTokens add=snipEscape
108 syn match snipMirror "\$\d\+" contained
109 syn cluster snipTokens add=snipMirror
110 syn cluster snipTabStopTokens add=snipMirror
112 syn region snipTabStop matchgroup=snipTabStop start="\${\d\+[:}]\@=" end="}" contained contains=snipTabStopDefault extend
113 syn region snipTabStopDefault matchgroup=snipTabStop start=":" skip="\\[{}]" end="\ze}" contained contains=snipTabStopEscape,snipBalancedBraces,@snipTabStopTokens keepend
114 syn match snipTabStopEscape "\\[{}]" contained
115 syn region snipBalancedBraces start="{" end="}" contained transparent extend
116 syn cluster snipTokens add=snipTabStop
117 syn cluster snipTabStopTokens add=snipTabStop
119 syn region snipVisual matchgroup=snipVisual start="\${VISUAL[:}/]\@=" end="}" contained contains=snipVisualDefault,snipTransformationPattern extend
120 syn region snipVisualDefault matchgroup=snipVisual start=":" end="\ze[}/]" contained contains=snipTabStopEscape nextgroup=snipTransformationPattern
121 syn cluster snipTokens add=snipVisual
122 syn cluster snipTabStopTokens add=snipVisual
124 syn region snipTransformation matchgroup=snipTransformation start="\${\d\/\@=" end="}" contained contains=snipTransformationPattern
125 syn region snipTransformationPattern matchgroup=snipTransformationPatternDelim start="/" end="\ze/" contained contains=snipTransformationEscape nextgroup=snipTransformationReplace skipnl
126 syn region snipTransformationReplace matchgroup=snipTransformationPatternDelim start="/" end="/" contained contains=snipTransformationEscape nextgroup=snipTransformationOptions skipnl
127 syn region snipTransformationOptions start="\ze[^}]" end="\ze}" contained contains=snipTabStopEscape
128 syn match snipTransformationEscape "\\/" contained
129 syn cluster snipTokens add=snipTransformation
130 syn cluster snipTabStopTokens add=snipTransformation
134 " Generic (non-Python) {{{4
136 syn region snipGlobal start="^global\_s" end="^\zeendglobal\s*$" contains=snipGlobalHeader nextgroup=snipGlobalFooter fold keepend
137 syn match snipGlobalHeader "^.*$" nextgroup=snipGlobalBody,snipGlobalFooter skipnl contained contains=snipGlobalHeaderKeyword
138 syn region snipGlobalBody start="\_." end="^\zeendglobal\s*$" contained contains=snipLeadingSpaces
142 syn region snipGlobal start=,^global\s\+!p\%(\s\+"[^"]*\%("\s\+[^"[:space:]]\+\|"\)\=\)\=\s*$, end=,^\zeendglobal\s*$, contains=snipGlobalPHeader nextgroup=snipGlobalFooter fold keepend
143 syn match snipGlobalPHeader "^.*$" nextgroup=snipGlobalPBody,snipGlobalFooter skipnl contained contains=snipGlobalHeaderKeyword
144 syn match snipGlobalHeaderKeyword "^global" contained nextgroup=snipSnippetTrigger skipwhite
145 syn region snipGlobalPBody start="\_." end="^\zeendglobal\s*$" contained contains=@Python
149 syn match snipGlobalFooter "^endglobal.*" contained contains=snipGlobalFooterKeyword
150 syn match snipGlobalFooterKeyword "^endglobal" contained
154 syn match snipPriority "^priority\%(\s.*\|$\)" contains=snipPriorityKeyword display
155 syn match snipPriorityKeyword "^priority" contained nextgroup=snipPriorityValue skipwhite display
156 syn match snipPriorityValue "-\?\d\+" contained display
160 syn match snipContext "^context.*$" contains=snipContextKeyword display skipwhite
161 syn match snipContextKeyword "context" contained nextgroup=snipContextValue skipwhite display
162 syn match snipContextValue '"[^"]*"' contained contains=snipContextValueP
163 syn region snipContextValueP start=,"\@<=., end=,\ze", contained contains=@Python skipwhite keepend
167 syn match snipAction "^\%(pre_expand\|post_expand\|post_jump\).*$" contains=snipActionKeyword display skipwhite
168 syn match snipActionKeyword "\%(pre_expand\|post_expand\|post_jump\)" contained nextgroup=snipActionValue skipwhite display
169 syn match snipActionValue '"[^"]*"' contained contains=snipActionValueP
170 syn region snipActionValueP start=,"\@<=., end=,\ze", contained contains=@Python skipwhite keepend
172 " Snippt Clearing {{{2
174 syn match snipClear "^clearsnippets\%(\s.*\|$\)" contains=snipClearKeyword display
175 syn match snipClearKeyword "^clearsnippets" contained display
177 " Highlight groups {{{1
179 hi def link snipComment Comment
180 hi def link snipTODO Todo
181 hi def snipLeadingSpaces term=reverse ctermfg=15 ctermbg=4 gui=reverse guifg=#dc322f
183 hi def link snipKeyword Keyword
185 hi def link snipExtendsKeyword snipKeyword
187 hi def link snipSnippetHeaderKeyword snipKeyword
188 hi def link snipSnippetFooterKeyword snipKeyword
190 hi def link snipSnippetTrigger Identifier
191 hi def link snipSnippetTriggerInvalid Error
192 hi def link snipSnippetDocString String
193 hi def link snipSnippetDocContextString String
194 hi def link snipSnippetOptionFlag Special
196 hi def link snipGlobalHeaderKeyword snipKeyword
197 hi def link snipGlobalFooterKeyword snipKeyword
199 hi def link snipCommand Special
200 hi def link snipCommandDelim snipCommand
201 hi def link snipShellCommand snipCommand
202 hi def link snipVimLCommand snipCommand
203 hi def link snipPythonCommandP PreProc
204 hi def link snipVimLCommandV PreProc
205 hi def link snipSnippetContext String
206 hi def link snipContext String
207 hi def link snipAction String
209 hi def link snipEscape Special
210 hi def link snipMirror StorageClass
211 hi def link snipTabStop Define
212 hi def link snipTabStopDefault String
213 hi def link snipTabStopEscape Special
214 hi def link snipVisual snipTabStop
215 hi def link snipVisualDefault snipTabStopDefault
216 hi def link snipTransformation snipTabStop
217 hi def link snipTransformationPattern String
218 hi def link snipTransformationPatternDelim Operator
219 hi def link snipTransformationReplace String
220 hi def link snipTransformationEscape snipEscape
221 hi def link snipTransformationOptions Operator
223 hi def link snipContextKeyword Keyword
225 hi def link snipPriorityKeyword Keyword
226 hi def link snipPriorityValue Number
228 hi def link snipActionKeyword Keyword
230 hi def link snipClearKeyword Keyword
234 let b:current_syntax = "snippets"