My dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

235 lines
11 KiB

  1. " Syntax highlighting for snippet files (used for UltiSnips.vim)
  2. " Revision: 26/03/11 19:53:33
  3. if exists("b:current_syntax")
  4. finish
  5. endif
  6. if expand("%:p:h") =~ "snippets" && search("^endsnippet", "nw") == 0
  7. \ && !exists("b:ultisnips_override_snipmate")
  8. " this appears to be a snipmate file
  9. " It's in a directory called snippets/ and there's no endsnippet keyword
  10. " anywhere in the file.
  11. source <sfile>:h/snippets_snipmate.vim
  12. finish
  13. endif
  14. " Embedded Syntaxes {{{1
  15. try
  16. syntax include @Python syntax/python.vim
  17. unlet b:current_syntax
  18. syntax include @Viml syntax/vim.vim
  19. unlet b:current_syntax
  20. syntax include @Shell syntax/sh.vim
  21. unlet b:current_syntax
  22. catch /E403/
  23. " Ignore errors about syntax files that can't be loaded more than once
  24. endtry
  25. " Syntax definitions {{{1
  26. " Comments {{{2
  27. syn match snipComment "^#.*" contains=snipTODO display
  28. syn keyword snipTODO contained display FIXME NOTE NOTES TODO XXX
  29. " Errors {{{2
  30. syn match snipLeadingSpaces "^\t* \+" contained
  31. " Extends {{{2
  32. syn match snipExtends "^extends\%(\s.*\|$\)" contains=snipExtendsKeyword display
  33. syn match snipExtendsKeyword "^extends" contained display
  34. " Definitions {{{2
  35. " snippet {{{3
  36. syn region snipSnippet start="^snippet\_s" end="^endsnippet\s*$" contains=snipSnippetHeader fold keepend
  37. syn match snipSnippetHeader "^.*$" nextgroup=snipSnippetBody,snipSnippetFooter skipnl contained contains=snipSnippetHeaderKeyword
  38. syn match snipSnippetHeaderKeyword "^snippet" contained nextgroup=snipSnippetTrigger skipwhite
  39. syn region snipSnippetBody start="\_." end="^\zeendsnippet\s*$" contained nextgroup=snipSnippetFooter contains=snipLeadingSpaces,@snipTokens
  40. syn match snipSnippetFooter "^endsnippet.*" contained contains=snipSnippetFooterKeyword
  41. syn match snipSnippetFooterKeyword "^endsnippet" contained
  42. " The current parser is a bit lax about parsing. For example, given this:
  43. " snippet foo"bar"
  44. " it treats `foo"bar"` as the trigger. But with this:
  45. " snippet foo"bar baz"
  46. " it treats `foo` as the trigger and "bar baz" as the description.
  47. " I think this is an accident. Instead, we'll assume the description must
  48. " be surrounded by spaces. That means we'll treat
  49. " snippet foo"bar"
  50. " as a trigger `foo"bar"` and
  51. " snippet foo"bar baz"
  52. " as an attempted multiword snippet `foo"bar baz"` that is invalid.
  53. " NB: UltiSnips parses right-to-left, which Vim doesn't support, so that makes
  54. " the following patterns very complicated.
  55. syn match snipSnippetTrigger "\S\+" contained nextgroup=snipSnippetDocString,snipSnippetTriggerInvalid skipwhite
  56. " We want to match a trailing " as the start of a doc comment, but we also
  57. " want to allow for using " as the delimiter in a multiword/pattern snippet.
  58. " So we have to define this twice, once in the general case that matches a
  59. " trailing " as the doc comment, and once for the case of the multiword
  60. " delimiter using " that has more constraints
  61. syn match snipSnippetTrigger ,".\{-}"\ze\%(\s\+"\%(\s*\S\)\@=[^"]*\%("\s\+[^"[:space:]]\+\|"\)\=\)\=\s*$, contained nextgroup=snipSnippetDocString skipwhite
  62. syn match snipSnippetTrigger ,\%(\(\S\).\{-}\1\|\S\+\)\ze\%(\s\+"[^"]*\%("\s\+\%("[^"]\+"\s\+[^"[:space:]]*e[^"[:space:]]*\)\|"\)\=\)\=\s*$, contained nextgroup=snipSnippetDocContextString skipwhite
  63. syn match snipSnippetTrigger ,\([^"[:space:]]\).\{-}\1\%(\s*$\)\@!\ze\%(\s\+"[^"]*\%("\s\+\%("[^"]\+"\s\+[^"[:space:]]*e[^"[:space:]]*\|[^"[:space:]]\+\)\|"\)\=\)\=\s*$, contained nextgroup=snipSnippetDocString skipwhite
  64. syn match snipSnippetTriggerInvalid ,\S\@=.\{-}\S\ze\%(\s\+"[^"]*\%("\s\+[^"[:space:]]\+\s*\|"\s*\)\=\|\s*\)$, contained nextgroup=snipSnippetDocString skipwhite
  65. syn match snipSnippetDocString ,"[^"]*", contained nextgroup=snipSnippetOptions skipwhite
  66. syn match snipSnippetDocContextString ,"[^"]*", contained nextgroup=snipSnippetContext skipwhite
  67. syn match snipSnippetContext ,"[^"]\+", contained skipwhite contains=snipSnippetContextP
  68. syn region snipSnippetContextP start=,"\@<=., end=,\ze", contained contains=@Python nextgroup=snipSnippetOptions skipwhite keepend
  69. syn match snipSnippetOptions ,\S\+, contained contains=snipSnippetOptionFlag
  70. syn match snipSnippetOptionFlag ,[biwrtsmxAe], contained
  71. " Command substitution {{{4
  72. syn region snipCommand keepend matchgroup=snipCommandDelim start="`" skip="\\[{}\\$`]" end="`" contained contains=snipPythonCommand,snipVimLCommand,snipShellCommand,snipCommandSyntaxOverride
  73. syn region snipShellCommand start="\ze\_." skip="\\[{}\\$`]" end="\ze`" contained contains=@Shell
  74. syn region snipPythonCommand matchgroup=snipPythonCommandP start="`\@<=!p\_s" skip="\\[{}\\$`]" end="\ze`" contained contains=@Python
  75. syn region snipVimLCommand matchgroup=snipVimLCommandV start="`\@<=!v\_s" skip="\\[{}\\$`]" end="\ze`" contained contains=@Viml
  76. syn cluster snipTokens add=snipCommand
  77. syn cluster snipTabStopTokens add=snipCommand
  78. " unfortunately due to the balanced braces parsing of commands, if a { occurs
  79. " in the command, we need to prevent the embedded syntax highlighting.
  80. " Otherwise, we can't track the balanced braces properly.
  81. syn region snipCommandSyntaxOverride start="\%(\\[{}\\$`]\|\_[^`"{]\)*\ze{" skip="\\[{}\\$`]" end="\ze`" contained contains=snipBalancedBraces transparent
  82. " Tab Stops {{{4
  83. syn match snipEscape "\\[{}\\$`]" contained
  84. syn cluster snipTokens add=snipEscape
  85. syn cluster snipTabStopTokens add=snipEscape
  86. syn match snipMirror "\$\d\+" contained
  87. syn cluster snipTokens add=snipMirror
  88. syn cluster snipTabStopTokens add=snipMirror
  89. syn region snipTabStop matchgroup=snipTabStop start="\${\d\+[:}]\@=" end="}" contained contains=snipTabStopDefault extend
  90. syn region snipTabStopDefault matchgroup=snipTabStop start=":" skip="\\[{}]" end="\ze}" contained contains=snipTabStopEscape,snipBalancedBraces,@snipTabStopTokens keepend
  91. syn match snipTabStopEscape "\\[{}]" contained
  92. syn region snipBalancedBraces start="{" end="}" contained transparent extend
  93. syn cluster snipTokens add=snipTabStop
  94. syn cluster snipTabStopTokens add=snipTabStop
  95. syn region snipVisual matchgroup=snipVisual start="\${VISUAL[:}/]\@=" end="}" contained contains=snipVisualDefault,snipTransformationPattern extend
  96. syn region snipVisualDefault matchgroup=snipVisual start=":" end="\ze[}/]" contained contains=snipTabStopEscape nextgroup=snipTransformationPattern
  97. syn cluster snipTokens add=snipVisual
  98. syn cluster snipTabStopTokens add=snipVisual
  99. syn region snipTransformation matchgroup=snipTransformation start="\${\d\/\@=" end="}" contained contains=snipTransformationPattern
  100. syn region snipTransformationPattern matchgroup=snipTransformationPatternDelim start="/" end="\ze/" contained contains=snipTransformationEscape nextgroup=snipTransformationReplace skipnl
  101. syn region snipTransformationReplace matchgroup=snipTransformationPatternDelim start="/" end="/" contained contains=snipTransformationEscape nextgroup=snipTransformationOptions skipnl
  102. syn region snipTransformationOptions start="\ze[^}]" end="\ze}" contained contains=snipTabStopEscape
  103. syn match snipTransformationEscape "\\/" contained
  104. syn cluster snipTokens add=snipTransformation
  105. syn cluster snipTabStopTokens add=snipTransformation
  106. " global {{{3
  107. " Generic (non-Python) {{{4
  108. syn region snipGlobal start="^global\_s" end="^\zeendglobal\s*$" contains=snipGlobalHeader nextgroup=snipGlobalFooter fold keepend
  109. syn match snipGlobalHeader "^.*$" nextgroup=snipGlobalBody,snipGlobalFooter skipnl contained contains=snipGlobalHeaderKeyword
  110. syn region snipGlobalBody start="\_." end="^\zeendglobal\s*$" contained contains=snipLeadingSpaces
  111. " Python (!p) {{{4
  112. syn region snipGlobal start=,^global\s\+!p\%(\s\+"[^"]*\%("\s\+[^"[:space:]]\+\|"\)\=\)\=\s*$, end=,^\zeendglobal\s*$, contains=snipGlobalPHeader nextgroup=snipGlobalFooter fold keepend
  113. syn match snipGlobalPHeader "^.*$" nextgroup=snipGlobalPBody,snipGlobalFooter skipnl contained contains=snipGlobalHeaderKeyword
  114. syn match snipGlobalHeaderKeyword "^global" contained nextgroup=snipSnippetTrigger skipwhite
  115. syn region snipGlobalPBody start="\_." end="^\zeendglobal\s*$" contained contains=@Python
  116. " Common {{{4
  117. syn match snipGlobalFooter "^endglobal.*" contained contains=snipGlobalFooterKeyword
  118. syn match snipGlobalFooterKeyword "^endglobal" contained
  119. " priority {{{3
  120. syn match snipPriority "^priority\%(\s.*\|$\)" contains=snipPriorityKeyword display
  121. syn match snipPriorityKeyword "^priority" contained nextgroup=snipPriorityValue skipwhite display
  122. syn match snipPriorityValue "-\?\d\+" contained display
  123. " context {{{3
  124. syn match snipContext "^context.*$" contains=snipContextKeyword display skipwhite
  125. syn match snipContextKeyword "context" contained nextgroup=snipContextValue skipwhite display
  126. syn match snipContextValue '"[^"]*"' contained contains=snipContextValueP
  127. syn region snipContextValueP start=,"\@<=., end=,\ze", contained contains=@Python skipwhite keepend
  128. " Actions {{{3
  129. syn match snipAction "^\%(pre_expand\|post_expand\|post_jump\).*$" contains=snipActionKeyword display skipwhite
  130. syn match snipActionKeyword "\%(pre_expand\|post_expand\|post_jump\)" contained nextgroup=snipActionValue skipwhite display
  131. syn match snipActionValue '"[^"]*"' contained contains=snipActionValueP
  132. syn region snipActionValueP start=,"\@<=., end=,\ze", contained contains=@Python skipwhite keepend
  133. " Snippt Clearing {{{2
  134. syn match snipClear "^clearsnippets\%(\s.*\|$\)" contains=snipClearKeyword display
  135. syn match snipClearKeyword "^clearsnippets" contained display
  136. " Highlight groups {{{1
  137. hi def link snipComment Comment
  138. hi def link snipTODO Todo
  139. hi def snipLeadingSpaces term=reverse ctermfg=15 ctermbg=4 gui=reverse guifg=#dc322f
  140. hi def link snipKeyword Keyword
  141. hi def link snipExtendsKeyword snipKeyword
  142. hi def link snipSnippetHeaderKeyword snipKeyword
  143. hi def link snipSnippetFooterKeyword snipKeyword
  144. hi def link snipSnippetTrigger Identifier
  145. hi def link snipSnippetTriggerInvalid Error
  146. hi def link snipSnippetDocString String
  147. hi def link snipSnippetDocContextString String
  148. hi def link snipSnippetOptionFlag Special
  149. hi def link snipGlobalHeaderKeyword snipKeyword
  150. hi def link snipGlobalFooterKeyword snipKeyword
  151. hi def link snipCommand Special
  152. hi def link snipCommandDelim snipCommand
  153. hi def link snipShellCommand snipCommand
  154. hi def link snipVimLCommand snipCommand
  155. hi def link snipPythonCommandP PreProc
  156. hi def link snipVimLCommandV PreProc
  157. hi def link snipSnippetContext String
  158. hi def link snipContext String
  159. hi def link snipAction String
  160. hi def link snipEscape Special
  161. hi def link snipMirror StorageClass
  162. hi def link snipTabStop Define
  163. hi def link snipTabStopDefault String
  164. hi def link snipTabStopEscape Special
  165. hi def link snipVisual snipTabStop
  166. hi def link snipVisualDefault snipTabStopDefault
  167. hi def link snipTransformation snipTabStop
  168. hi def link snipTransformationPattern String
  169. hi def link snipTransformationPatternDelim Operator
  170. hi def link snipTransformationReplace String
  171. hi def link snipTransformationEscape snipEscape
  172. hi def link snipTransformationOptions Operator
  173. hi def link snipContextKeyword Keyword
  174. hi def link snipPriorityKeyword Keyword
  175. hi def link snipPriorityValue Number
  176. hi def link snipActionKeyword Keyword
  177. hi def link snipClearKeyword Keyword
  178. " }}}1
  179. let b:current_syntax = "snippets"