2011-02-17 08:07:27 -05:00
|
|
|
" Syntax highlighting for snippet files (used for UltiSnips.vim)
|
2011-03-27 02:07:44 -04:00
|
|
|
" Revision: 26/03/11 19:53:33
|
|
|
|
|
|
|
|
if exists("b:current_syntax")
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
2014-07-01 00:14:55 -04:00
|
|
|
if expand("%:p:h:t") == "snippets" && search("^endsnippet", "nw") == 0
|
|
|
|
\ && !exists("b:ultisnips_override_snipmate")
|
|
|
|
" this appears to be a snipmate file
|
|
|
|
" It's in a directory called snippets/ and there's no endsnippet keyword
|
|
|
|
" anywhere in the file.
|
|
|
|
source <sfile>:h/snippets_snipmate.vim
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
2014-06-30 02:04:37 -04:00
|
|
|
" Embedded Syntaxes {{{1
|
|
|
|
|
2014-07-30 07:34:15 -04:00
|
|
|
try
|
|
|
|
syntax include @Python syntax/python.vim
|
|
|
|
unlet b:current_syntax
|
|
|
|
syntax include @Viml syntax/vim.vim
|
|
|
|
unlet b:current_syntax
|
|
|
|
syntax include @Shell syntax/sh.vim
|
|
|
|
unlet b:current_syntax
|
|
|
|
catch /E403/
|
|
|
|
" Ignore errors about syntax files that can't be loaded more than once
|
|
|
|
endtry
|
2011-02-17 08:07:27 -05:00
|
|
|
|
2014-06-30 02:04:37 -04:00
|
|
|
" Syntax definitions {{{1
|
|
|
|
|
|
|
|
" Comments {{{2
|
|
|
|
|
2014-06-30 02:22:53 -04:00
|
|
|
syn match snipComment "^#.*" contains=snipTODO display
|
|
|
|
syn keyword snipTODO contained display FIXME NOTE NOTES TODO XXX
|
2011-03-27 02:07:44 -04:00
|
|
|
|
2014-06-30 18:41:35 -04:00
|
|
|
" Errors {{{2
|
2014-06-30 02:04:37 -04:00
|
|
|
|
2014-06-30 18:41:35 -04:00
|
|
|
syn match snipLeadingSpaces "^\t* \+" contained
|
2011-02-19 14:00:24 -05:00
|
|
|
|
2014-06-30 02:04:37 -04:00
|
|
|
" Extends {{{2
|
|
|
|
|
2014-06-30 02:22:53 -04:00
|
|
|
syn match snipExtends "^extends\%(\s.*\|$\)" contains=snipExtendsKeyword display
|
|
|
|
syn match snipExtendsKeyword "^extends" contained display
|
2011-02-17 08:07:27 -05:00
|
|
|
|
2014-06-30 02:04:37 -04:00
|
|
|
" Definitions {{{2
|
|
|
|
|
|
|
|
" snippet {{{3
|
|
|
|
|
2014-06-30 22:26:28 -04:00
|
|
|
syn region snipSnippet start="^snippet\_s" end="^\zeendsnippet\s*$" contains=snipSnippetHeader nextgroup=snipSnippetFooter fold keepend
|
2014-06-30 03:00:20 -04:00
|
|
|
syn match snipSnippetHeader "^.*$" nextgroup=snipSnippetBody,snipSnippetFooter skipnl contained contains=snipSnippetHeaderKeyword
|
|
|
|
syn match snipSnippetHeaderKeyword "^snippet" contained nextgroup=snipSnippetTrigger skipwhite
|
2014-06-30 22:26:28 -04:00
|
|
|
syn region snipSnippetBody start="\_." end="^\zeendsnippet\s*$" contained contains=snipLeadingSpaces,@snipTokens
|
2014-06-30 02:33:36 -04:00
|
|
|
syn match snipSnippetFooter "^endsnippet.*" contained contains=snipSnippetFooterKeyword
|
|
|
|
syn match snipSnippetFooterKeyword "^endsnippet" contained
|
2014-06-29 23:47:22 -04:00
|
|
|
|
2014-06-30 16:38:58 -04:00
|
|
|
" The current parser is a bit lax about parsing. For example, given this:
|
|
|
|
" snippet foo"bar"
|
|
|
|
" it treats `foo"bar"` as the trigger. But with this:
|
|
|
|
" snippet foo"bar baz"
|
|
|
|
" it treats `foo` as the trigger and "bar baz" as the description.
|
|
|
|
" I think this is an accident. Instead, we'll assume the description must
|
|
|
|
" be surrounded by spaces. That means we'll treat
|
|
|
|
" snippet foo"bar"
|
|
|
|
" as a trigger `foo"bar"` and
|
|
|
|
" snippet foo"bar baz"
|
|
|
|
" as an attempted multiword snippet `foo"bar baz"` that is invalid.
|
|
|
|
" NB: UltiSnips parses right-to-left, which Vim doesn't support, so that makes
|
|
|
|
" the following patterns very complicated.
|
|
|
|
syn match snipSnippetTrigger "\S\+" contained nextgroup=snipSnippetDocString,snipSnippetTriggerInvalid skipwhite
|
|
|
|
" We want to match a trailing " as the start of a doc comment, but we also
|
|
|
|
" want to allow for using " as the delimiter in a multiword/pattern snippet.
|
|
|
|
" So we have to define this twice, once in the general case that matches a
|
|
|
|
" trailing " as the doc comment, and once for the case of the multiword
|
|
|
|
" delimiter using " that has more constraints
|
|
|
|
syn match snipSnippetTrigger ,\([^"[:space:]]\).\{-}\1\%(\s*$\)\@!\ze\%(\s\+"[^"]*\%("\s\+[^"[:space:]]\+\|"\)\=\)\=\s*$, contained nextgroup=snipSnippetDocString skipwhite
|
|
|
|
syn match snipSnippetTrigger ,".\{-}"\ze\%(\s\+"\%(\s*\S\)\@=[^"]*\%("\s\+[^"[:space:]]\+\|"\)\=\)\=\s*$, contained nextgroup=snipSnippetDocString skipwhite
|
|
|
|
syn match snipSnippetTriggerInvalid ,\S\@=.\{-}\S\ze\%(\s\+"[^"]*\%("\s\+[^"[:space:]]\+\s*\|"\s*\)\=\|\s*\)$, contained nextgroup=snipSnippetDocString skipwhite
|
|
|
|
syn match snipSnippetDocString ,"[^"]*\%("\ze\s*\%(\s[^"[:space:]]\+\s*\)\=\)\=$, contained nextgroup=snipSnippetOptions skipwhite
|
|
|
|
syn match snipSnippetOptions ,\S\+, contained contains=snipSnippetOptionFlag
|
|
|
|
syn match snipSnippetOptionFlag ,[biwrts], contained
|
|
|
|
|
2014-06-30 02:04:37 -04:00
|
|
|
" Command substitution {{{4
|
|
|
|
|
2014-07-01 00:14:55 -04:00
|
|
|
syn region snipCommand keepend matchgroup=snipCommandDelim start="`" skip="\\[{}\\$`]" end="`" contained contains=snipPythonCommand,snipVimLCommand,snipShellCommand,snipCommandSyntaxOverride
|
2014-06-29 23:47:22 -04:00
|
|
|
syn region snipShellCommand start="\ze\_." skip="\\[{}\\$`]" end="\ze`" contained contains=@Shell
|
|
|
|
syn region snipPythonCommand matchgroup=snipPythonCommandP start="`\@<=!p\_s" skip="\\[{}\\$`]" end="\ze`" contained contains=@Python
|
|
|
|
syn region snipVimLCommand matchgroup=snipVimLCommandV start="`\@<=!v\_s" skip="\\[{}\\$`]" end="\ze`" contained contains=@Viml
|
2014-06-30 22:15:56 -04:00
|
|
|
syn cluster snipTokens add=snipCommand
|
2014-07-01 00:14:55 -04:00
|
|
|
syn cluster snipTabStopTokens add=snipCommand
|
2014-06-29 23:47:22 -04:00
|
|
|
|
2014-06-30 23:10:42 -04:00
|
|
|
" unfortunately due to the balanced braces parsing of commands, if a { occurs
|
|
|
|
" in the command, we need to prevent the embedded syntax highlighting.
|
|
|
|
" Otherwise, we can't track the balanced braces properly.
|
|
|
|
|
|
|
|
syn region snipCommandSyntaxOverride start="\%(\\[{}\\$`]\|\_[^`"{]\)*\ze{" skip="\\[{}\\$`]" end="\ze`" contained contains=snipBalancedBraces transparent
|
|
|
|
|
2014-06-30 22:15:56 -04:00
|
|
|
" Tab Stops {{{4
|
2014-06-30 02:04:37 -04:00
|
|
|
|
2014-06-30 22:15:56 -04:00
|
|
|
syn match snipEscape "\\[{}\\$`]" contained
|
|
|
|
syn cluster snipTokens add=snipEscape
|
2014-07-01 00:14:55 -04:00
|
|
|
syn cluster snipTabStopTokens add=snipEscape
|
2014-06-30 22:15:56 -04:00
|
|
|
|
|
|
|
syn match snipMirror "\$\d\+" contained
|
|
|
|
syn cluster snipTokens add=snipMirror
|
2014-07-01 00:14:55 -04:00
|
|
|
syn cluster snipTabStopTokens add=snipMirror
|
2014-06-30 22:15:56 -04:00
|
|
|
|
2014-08-05 20:21:35 -04:00
|
|
|
syn region snipTabStop matchgroup=snipTabStop start="\${\d\+[:}]\@=" end="}" contained contains=snipTabStopDefault extend
|
2014-07-01 00:14:55 -04:00
|
|
|
syn region snipTabStopDefault matchgroup=snipTabStop start=":" skip="\\[{}]" end="\ze}" contained contains=snipTabStopEscape,snipBalancedBraces,@snipTabStopTokens keepend
|
2014-06-30 22:15:56 -04:00
|
|
|
syn match snipTabStopEscape "\\[{}]" contained
|
2014-06-30 23:10:42 -04:00
|
|
|
syn region snipBalancedBraces start="{" end="}" contained transparent extend
|
2014-06-30 22:15:56 -04:00
|
|
|
syn cluster snipTokens add=snipTabStop
|
2014-07-01 00:14:55 -04:00
|
|
|
syn cluster snipTabStopTokens add=snipTabStop
|
2014-06-30 22:15:56 -04:00
|
|
|
|
|
|
|
syn region snipVisual matchgroup=snipVisual start="\${VISUAL[:}/]\@=" end="}" contained contains=snipVisualDefault,snipTransformationPattern
|
|
|
|
syn region snipVisualDefault matchgroup=snipVisual start=":" end="\ze[}/]" contained contains=snipTabStopEscape nextgroup=snipTransformationPattern
|
|
|
|
syn cluster snipTokens add=snipVisual
|
2014-07-01 00:14:55 -04:00
|
|
|
syn cluster snipTabStopTokens add=snipVisual
|
2014-06-30 22:15:56 -04:00
|
|
|
|
|
|
|
syn region snipTransformation matchgroup=snipTransformation start="\${\d\/\@=" end="}" contained contains=snipTransformationPattern
|
|
|
|
syn region snipTransformationPattern matchgroup=snipTransformationPatternDelim start="/" end="\ze/" contained contains=snipTransformationEscape nextgroup=snipTransformationReplace skipnl
|
|
|
|
syn region snipTransformationReplace matchgroup=snipTransformationPatternDelim start="/" end="/" contained contains=snipTransformationEscape nextgroup=snipTransformationOptions skipnl
|
|
|
|
syn region snipTransformationOptions start="\ze[^}]" end="\ze}" contained contains=snipTabStopEscape
|
|
|
|
syn match snipTransformationEscape "\\/" contained
|
|
|
|
syn cluster snipTokens add=snipTransformation
|
2014-07-01 00:14:55 -04:00
|
|
|
syn cluster snipTabStopTokens add=snipTransformation
|
2011-02-17 08:07:27 -05:00
|
|
|
|
2014-06-30 02:04:37 -04:00
|
|
|
" global {{{3
|
|
|
|
|
2014-06-30 02:44:22 -04:00
|
|
|
" Generic (non-Python) {{{4
|
2014-06-30 03:00:20 -04:00
|
|
|
|
2014-06-30 22:26:28 -04:00
|
|
|
syn region snipGlobal start="^global\_s" end="^\zeendglobal\s*$" contains=snipGlobalHeader nextgroup=snipGlobalFooter fold keepend
|
2014-06-30 03:00:20 -04:00
|
|
|
syn match snipGlobalHeader "^.*$" nextgroup=snipGlobalBody,snipGlobalFooter skipnl contained contains=snipGlobalHeaderKeyword
|
2014-06-30 22:26:28 -04:00
|
|
|
syn region snipGlobalBody start="\_." end="^\zeendglobal\s*$" contained contains=snipLeadingSpaces
|
2014-06-30 02:44:22 -04:00
|
|
|
|
|
|
|
" Python (!p) {{{4
|
|
|
|
|
2014-06-30 22:26:28 -04:00
|
|
|
syn region snipGlobal start=,^global\s\+!p\%(\s\+"[^"]*\%("\s\+[^"[:space:]]\+\|"\)\=\)\=\s*$, end=,^\zeendglobal\s*$, contains=snipGlobalPHeader nextgroup=snipGlobalFooter fold keepend
|
2014-06-30 03:00:20 -04:00
|
|
|
syn match snipGlobalPHeader "^.*$" nextgroup=snipGlobalPBody,snipGlobalFooter skipnl contained contains=snipGlobalHeaderKeyword
|
|
|
|
syn match snipGlobalHeaderKeyword "^global" contained nextgroup=snipSnippetTrigger skipwhite
|
2014-06-30 22:26:28 -04:00
|
|
|
syn region snipGlobalPBody start="\_." end="^\zeendglobal\s*$" contained contains=@Python
|
2011-02-17 08:07:27 -05:00
|
|
|
|
2014-06-30 03:00:20 -04:00
|
|
|
" Common {{{4
|
|
|
|
|
|
|
|
syn match snipGlobalFooter "^endglobal.*" contained contains=snipGlobalFooterKeyword
|
|
|
|
syn match snipGlobalFooterKeyword "^endglobal" contained
|
|
|
|
|
2014-06-30 02:04:37 -04:00
|
|
|
" priority {{{3
|
|
|
|
|
2014-06-30 02:22:53 -04:00
|
|
|
syn match snipPriority "^priority\%(\s.*\|$\)" contains=snipPriorityKeyword display
|
|
|
|
syn match snipPriorityKeyword "^priority" contained nextgroup=snipPriorityValue skipwhite display
|
|
|
|
syn match snipPriorityValue "-\?\d\+" contained display
|
2012-11-24 04:12:36 -05:00
|
|
|
|
2014-06-30 02:04:37 -04:00
|
|
|
" Snippt Clearing {{{2
|
|
|
|
|
2014-06-30 02:22:53 -04:00
|
|
|
syn match snipClear "^clearsnippets\%(\s.*\|$\)" contains=snipClearKeyword display
|
|
|
|
syn match snipClearKeyword "^clearsnippets" contained display
|
2014-06-30 02:04:37 -04:00
|
|
|
|
|
|
|
" Highlight groups {{{1
|
2011-02-17 08:07:27 -05:00
|
|
|
|
2014-06-29 22:36:07 -04:00
|
|
|
hi def link snipComment Comment
|
2014-06-30 21:38:50 -04:00
|
|
|
hi def link snipTODO Todo
|
2014-06-30 18:41:35 -04:00
|
|
|
hi def snipLeadingSpaces term=reverse ctermfg=15 ctermbg=4 gui=reverse guifg=#dc322f
|
2011-02-19 14:00:24 -05:00
|
|
|
|
2014-06-29 22:36:07 -04:00
|
|
|
hi def link snipKeyword Keyword
|
2011-02-17 08:07:27 -05:00
|
|
|
|
2014-06-30 02:44:22 -04:00
|
|
|
hi def link snipExtendsKeyword snipKeyword
|
2011-02-17 08:07:27 -05:00
|
|
|
|
2014-06-30 02:33:36 -04:00
|
|
|
hi def link snipSnippetHeaderKeyword snipKeyword
|
|
|
|
hi def link snipSnippetFooterKeyword snipKeyword
|
|
|
|
|
2014-06-30 16:38:58 -04:00
|
|
|
hi def link snipSnippetTrigger Identifier
|
|
|
|
hi def link snipSnippetTriggerInvalid Error
|
|
|
|
hi def link snipSnippetDocString String
|
|
|
|
hi def link snipSnippetOptionFlag Special
|
|
|
|
|
2014-06-30 02:44:22 -04:00
|
|
|
hi def link snipGlobalHeaderKeyword snipKeyword
|
|
|
|
hi def link snipGlobalFooterKeyword snipKeyword
|
2014-06-29 23:47:22 -04:00
|
|
|
|
2014-06-29 22:36:07 -04:00
|
|
|
hi def link snipCommand Special
|
2014-06-29 23:47:22 -04:00
|
|
|
hi def link snipCommandDelim snipCommand
|
|
|
|
hi def link snipShellCommand snipCommand
|
2014-06-29 22:36:07 -04:00
|
|
|
hi def link snipVimLCommand snipCommand
|
2014-06-29 23:47:22 -04:00
|
|
|
hi def link snipPythonCommandP PreProc
|
|
|
|
hi def link snipVimLCommandV PreProc
|
|
|
|
|
2014-06-30 22:15:56 -04:00
|
|
|
hi def link snipEscape Special
|
|
|
|
hi def link snipMirror StorageClass
|
|
|
|
hi def link snipTabStop Define
|
|
|
|
hi def link snipTabStopDefault String
|
|
|
|
hi def link snipTabStopEscape Special
|
|
|
|
hi def link snipVisual snipTabStop
|
|
|
|
hi def link snipVisualDefault snipTabStopDefault
|
|
|
|
hi def link snipTransformation snipTabStop
|
|
|
|
hi def link snipTransformationPattern String
|
|
|
|
hi def link snipTransformationPatternDelim Operator
|
|
|
|
hi def link snipTransformationReplace String
|
|
|
|
hi def link snipTransformationEscape snipEscape
|
|
|
|
hi def link snipTransformationOptions Operator
|
2011-02-17 08:07:27 -05:00
|
|
|
|
2014-06-30 02:11:11 -04:00
|
|
|
hi def link snipPriorityKeyword Keyword
|
|
|
|
hi def link snipPriorityValue Number
|
|
|
|
|
|
|
|
hi def link snipClearKeyword Keyword
|
2012-11-24 04:12:36 -05:00
|
|
|
|
2014-06-30 02:04:37 -04:00
|
|
|
" }}}1
|
|
|
|
|
2014-06-29 22:42:57 -04:00
|
|
|
let b:current_syntax = "snippets"
|