From 1ad7d54d75d9232cd4878502a64be3836b06dbda Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Sun, 29 Jun 2014 19:36:07 -0700 Subject: [PATCH 01/21] Fix highlighting of Python/VimL commands Also mark all the highlighting as default, so it can be overridden more easily by the user. --- syntax/snippets.vim | 46 +++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/syntax/snippets.vim b/syntax/snippets.vim index 085b408..14325ec 100644 --- a/syntax/snippets.vim +++ b/syntax/snippets.vim @@ -25,9 +25,9 @@ syn match snipExtends "^extends.*" contains=snipKeyword " snippet definitions syn match snipStart "^snippet.*" contained contains=snipKeyword,snipDocString syn match snipEnd "^endsnippet" contained contains=snipKeyword -syn region snipCommand contained keepend start="`" end="`" contains=snipPythonCommand,snipVimLCommand -syn region snipPythonCommand contained keepend start="`!p" end="`" contained contains=@Python -syn region snipVimLCommand contained keepend start="`!v" end="`" contained contains=@Viml +syn region snipCommand keepend start="`" end="`" contains=snipPythonCommand,snipVimLCommand +syn region snipPythonCommand keepend start="`!p" end="`" contained contains=@Python +syn region snipVimLCommand keepend start="`!v" end="`" contained contains=@Viml syn match snipVar "\$\d*" contained syn region snipVisual matchgroup=Define start="\${VISUAL" end="}" contained syn region snipVarExpansion matchgroup=Define start="\${\d*" end="}" contained contains=snipVar,snipVarExpansion,snipCommand @@ -44,29 +44,31 @@ syn match snipPriority "^priority" " highlighting rules -hi link snipComment Comment -hi link snipLeadingSpaces Error -hi link snipString String -hi link snipDocString String -hi link snipTabsOnly Error +hi def link snipComment Comment +hi def link snipLeadingSpaces Error +hi def link snipString String +hi def link snipDocString String +hi def link snipTabsOnly Error -hi link snipKeyword Keyword +hi def link snipKeyword Keyword -hi link snipExtends Statement +hi def link snipExtends Statement -hi link snipStart Statement -hi link snipEnd Statement -hi link snipCommand Special -hi link snipVar StorageClass -hi link snipVarExpansion Normal -hi link snipVisual Normal -hi link snippet Normal +hi def link snipStart Statement +hi def link snipEnd snipStart +hi def link snipCommand Special +hi def link snipPythonCommand snipCommand +hi def link snipVimLCommand snipCommand +hi def link snipVar StorageClass +hi def link snipVarExpansion Normal +hi def link snipVisual Normal +hi def link snippet Normal -hi link snipGlobalStart Statement -hi link snipGlobalEnd Statement -hi link snipGlobal Normal +hi def link snipGlobalStart Statement +hi def link snipGlobalEnd Statement +hi def link snipGlobal Normal -hi link snipClear Statement -hi link snipPriority Statement +hi def link snipClear Statement +hi def link snipPriority Statement let b:current_syntax = "snippet" From cab15099529c46740a403b77d11292383bb52d5a Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Sun, 29 Jun 2014 19:42:11 -0700 Subject: [PATCH 02/21] Fix embedded VimL highlighting The b:current_syntax variable is set by syntax-include, so it needs to be unset again or the second syntax-include does nothing. --- syntax/snippets.vim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/syntax/snippets.vim b/syntax/snippets.vim index 14325ec..9420ef6 100644 --- a/syntax/snippets.vim +++ b/syntax/snippets.vim @@ -6,7 +6,9 @@ if exists("b:current_syntax") endif syntax include @Python syntax/python.vim +unlet b:current_syntax syntax include @Viml syntax/vim.vim +unlet b:current_syntax " global matches syn match snipComment "^#.*" contains=snipTODO From 636546bebc1dc0dcfdffba4428cc956dd0538bb7 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Sun, 29 Jun 2014 19:42:57 -0700 Subject: [PATCH 03/21] Fix syntax name b:current_syntax should be set to "snippets", as that's the filetype, not "snippet". --- syntax/snippets.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/snippets.vim b/syntax/snippets.vim index 9420ef6..0d4988d 100644 --- a/syntax/snippets.vim +++ b/syntax/snippets.vim @@ -73,4 +73,4 @@ hi def link snipGlobal Normal hi def link snipClear Statement hi def link snipPriority Statement -let b:current_syntax = "snippet" +let b:current_syntax = "snippets" From 5b80ef187d5be31f02db55bb9acaf6e5c7b816e7 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Sun, 29 Jun 2014 20:06:25 -0700 Subject: [PATCH 04/21] Properly handle \` escapes in commands --- syntax/snippets.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/syntax/snippets.vim b/syntax/snippets.vim index 0d4988d..7acf165 100644 --- a/syntax/snippets.vim +++ b/syntax/snippets.vim @@ -27,9 +27,9 @@ syn match snipExtends "^extends.*" contains=snipKeyword " snippet definitions syn match snipStart "^snippet.*" contained contains=snipKeyword,snipDocString syn match snipEnd "^endsnippet" contained contains=snipKeyword -syn region snipCommand keepend start="`" end="`" contains=snipPythonCommand,snipVimLCommand -syn region snipPythonCommand keepend start="`!p" end="`" contained contains=@Python -syn region snipVimLCommand keepend start="`!v" end="`" contained contains=@Viml +syn region snipCommand keepend start="`" skip="\\[{}\\$`]" end="`" contains=snipPythonCommand,snipVimLCommand +syn region snipPythonCommand keepend start="`!p" skip="\\[{}\\$`]" end="`" contained contains=@Python +syn region snipVimLCommand keepend start="`!v" skip="\\[{}\\$`]" end="`" contained contains=@Viml syn match snipVar "\$\d*" contained syn region snipVisual matchgroup=Define start="\${VISUAL" end="}" contained syn region snipVarExpansion matchgroup=Define start="\${\d*" end="}" contained contains=snipVar,snipVarExpansion,snipCommand From 739e3d94ad95430137c6bf1ead2c9c7319043137 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Sun, 29 Jun 2014 20:47:22 -0700 Subject: [PATCH 05/21] Fix coloring of shell/VimL/Python command substitutions Include the sh syntax for shell commands. Make the matching on !v/!p work more accurately. Highlight the !v/!p separately from the embedded Python/VimL. AFAIK the only issue now is that "\`" escapes inside shell/VimL/Python are not treated as bare "`" characters by the embedded syntax, but I don't believe there's any way to fix that. --- syntax/snippets.vim | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/syntax/snippets.vim b/syntax/snippets.vim index 7acf165..96e24a1 100644 --- a/syntax/snippets.vim +++ b/syntax/snippets.vim @@ -9,6 +9,8 @@ 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 " global matches syn match snipComment "^#.*" contains=snipTODO @@ -27,9 +29,12 @@ syn match snipExtends "^extends.*" contains=snipKeyword " snippet definitions syn match snipStart "^snippet.*" contained contains=snipKeyword,snipDocString syn match snipEnd "^endsnippet" contained contains=snipKeyword -syn region snipCommand keepend start="`" skip="\\[{}\\$`]" end="`" contains=snipPythonCommand,snipVimLCommand -syn region snipPythonCommand keepend start="`!p" skip="\\[{}\\$`]" end="`" contained contains=@Python -syn region snipVimLCommand keepend start="`!v" skip="\\[{}\\$`]" end="`" contained contains=@Viml + +syn region snipCommand keepend matchgroup=snipCommandDelim start="`" skip="\\[{}\\$`]" end="`" contains=snipPythonCommand,snipVimLCommand,snipShellCommand +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 + syn match snipVar "\$\d*" contained syn region snipVisual matchgroup=Define start="\${VISUAL" end="}" contained syn region snipVarExpansion matchgroup=Define start="\${\d*" end="}" contained contains=snipVar,snipVarExpansion,snipCommand @@ -58,9 +63,15 @@ hi def link snipExtends Statement hi def link snipStart Statement hi def link snipEnd snipStart + hi def link snipCommand Special +hi def link snipCommandDelim snipCommand +hi def link snipShellCommand snipCommand hi def link snipPythonCommand snipCommand hi def link snipVimLCommand snipCommand +hi def link snipPythonCommandP PreProc +hi def link snipVimLCommandV PreProc + hi def link snipVar StorageClass hi def link snipVarExpansion Normal hi def link snipVisual Normal From 672117c478a66a38384be374b7a1fbee4b1e6184 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Sun, 29 Jun 2014 23:04:37 -0700 Subject: [PATCH 06/21] Add hierarchy to syntax file Redo comments with fold markers to provide an appropriate hierarchy to the syntax file itself. --- syntax/snippets.vim | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/syntax/snippets.vim b/syntax/snippets.vim index 96e24a1..4ce3d23 100644 --- a/syntax/snippets.vim +++ b/syntax/snippets.vim @@ -5,6 +5,8 @@ if exists("b:current_syntax") finish endif +" Embedded Syntaxes {{{1 + syntax include @Python syntax/python.vim unlet b:current_syntax syntax include @Viml syntax/vim.vim @@ -12,10 +14,15 @@ unlet b:current_syntax syntax include @Shell syntax/sh.vim unlet b:current_syntax -" global matches +" Syntax definitions {{{1 + +" Comments {{{2 + syn match snipComment "^#.*" contains=snipTODO syn keyword snipTODO FIXME NOTE NOTES TODO XXX contained +" Miscellaneous {{{2 + syn match snipDocString '"[^"]*"$' syn match snipString '"[^"]*"' syn match snipTabsOnly "^\t\+$" @@ -23,33 +30,47 @@ syn match snipLeadingSpaces "^\t* \+" syn match snipKeyword "\(\<\(end\)\?\(snippet\|global\)\>\)\|extends\|clearsnippets\|priority" contained -" extends definitions +" Extends {{{2 + syn match snipExtends "^extends.*" contains=snipKeyword -" snippet definitions +" Definitions {{{2 + +" snippet {{{3 + +syn region snipSnippet fold keepend start="^snippet" end="^endsnippet" contains=snipStart,snipEnd,snipTabsOnly,snipLeadingSpaces,snipCommand,snipVarExpansion,snipVar,snipVisual + syn match snipStart "^snippet.*" contained contains=snipKeyword,snipDocString syn match snipEnd "^endsnippet" contained contains=snipKeyword +" Command substitution {{{4 + syn region snipCommand keepend matchgroup=snipCommandDelim start="`" skip="\\[{}\\$`]" end="`" contains=snipPythonCommand,snipVimLCommand,snipShellCommand 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 +" Variables {{{4 + syn match snipVar "\$\d*" contained syn region snipVisual matchgroup=Define start="\${VISUAL" end="}" contained syn region snipVarExpansion matchgroup=Define start="\${\d*" end="}" contained contains=snipVar,snipVarExpansion,snipCommand -syn region snippet fold keepend start="^snippet" end="^endsnippet" contains=snipStart,snipEnd,snipTabsOnly,snipLeadingSpaces,snipCommand,snipVarExpansion,snipVar,snipVisual -" global definitions +" global {{{3 + syn match snipGlobalStart "^global.*" contained contains=snipKeyword,snipString syn match snipGlobalEnd "^endglobal" contained contains=snipKeyword syn region snipGlobal fold keepend start="^global" end="^endglobal" contains=snipGlobalStart,snipGlobalEnd,snipLeadingSpaces,snipTabsOnly,snipCommand,snipVarExpansion,snipVar,@Python -" snippet clearing -syn match snipClear "^clearsnippets" +" priority {{{3 + syn match snipPriority "^priority" -" highlighting rules +" Snippt Clearing {{{2 + +syn match snipClear "^clearsnippets" + +" Highlight groups {{{1 hi def link snipComment Comment hi def link snipLeadingSpaces Error @@ -75,7 +96,7 @@ hi def link snipVimLCommandV PreProc hi def link snipVar StorageClass hi def link snipVarExpansion Normal hi def link snipVisual Normal -hi def link snippet Normal +hi def link snipSnippet Normal hi def link snipGlobalStart Statement hi def link snipGlobalEnd Statement @@ -84,4 +105,6 @@ hi def link snipGlobal Normal hi def link snipClear Statement hi def link snipPriority Statement +" }}}1 + let b:current_syntax = "snippets" From b82759b2509a727bda9b6e4acfe255aaa7e3ec92 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Sun, 29 Jun 2014 23:11:11 -0700 Subject: [PATCH 07/21] Rewrite extends/priority/clearsnippets --- syntax/snippets.vim | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/syntax/snippets.vim b/syntax/snippets.vim index 4ce3d23..d4203a0 100644 --- a/syntax/snippets.vim +++ b/syntax/snippets.vim @@ -32,7 +32,8 @@ syn match snipKeyword "\(\<\(end\)\?\(snippet\|global\)\>\)\|extends\|clearsnipp " Extends {{{2 -syn match snipExtends "^extends.*" contains=snipKeyword +syn match snipExtends "^extends\%(\s.*\|$\)" contains=snipExtendsKeyword +syn match snipExtendsKeyword "^extends" contained " Definitions {{{2 @@ -64,11 +65,14 @@ syn region snipGlobal fold keepend start="^global" end="^endglobal" contains=sni " priority {{{3 -syn match snipPriority "^priority" +syn match snipPriority "^priority\%(\s.*\|$\)" contains=snipPriorityKeyword +syn match snipPriorityKeyword "^priority" contained nextgroup=snipPriorityValue skipwhite +syn match snipPriorityValue "-\?\d\+" contained " Snippt Clearing {{{2 -syn match snipClear "^clearsnippets" +syn match snipClear "^clearsnippets\%(\s.*\|$\)" contains=snipClearKeyword +syn match snipClearKeyword "^clearsnippets" contained " Highlight groups {{{1 @@ -80,7 +84,7 @@ hi def link snipTabsOnly Error hi def link snipKeyword Keyword -hi def link snipExtends Statement +hi def link snipExtendsKeyword Keyword hi def link snipStart Statement hi def link snipEnd snipStart @@ -102,8 +106,10 @@ hi def link snipGlobalStart Statement hi def link snipGlobalEnd Statement hi def link snipGlobal Normal -hi def link snipClear Statement -hi def link snipPriority Statement +hi def link snipPriorityKeyword Keyword +hi def link snipPriorityValue Number + +hi def link snipClearKeyword Keyword " }}}1 From 5937cea081d2c26ead8191bc9304ee951e3bb9b0 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Sun, 29 Jun 2014 23:22:53 -0700 Subject: [PATCH 08/21] Mark up syntax items with 'display' as appropriate --- syntax/snippets.vim | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/syntax/snippets.vim b/syntax/snippets.vim index d4203a0..33161f3 100644 --- a/syntax/snippets.vim +++ b/syntax/snippets.vim @@ -18,8 +18,8 @@ unlet b:current_syntax " Comments {{{2 -syn match snipComment "^#.*" contains=snipTODO -syn keyword snipTODO FIXME NOTE NOTES TODO XXX contained +syn match snipComment "^#.*" contains=snipTODO display +syn keyword snipTODO contained display FIXME NOTE NOTES TODO XXX " Miscellaneous {{{2 @@ -32,8 +32,8 @@ syn match snipKeyword "\(\<\(end\)\?\(snippet\|global\)\>\)\|extends\|clearsnipp " Extends {{{2 -syn match snipExtends "^extends\%(\s.*\|$\)" contains=snipExtendsKeyword -syn match snipExtendsKeyword "^extends" contained +syn match snipExtends "^extends\%(\s.*\|$\)" contains=snipExtendsKeyword display +syn match snipExtendsKeyword "^extends" contained display " Definitions {{{2 @@ -65,14 +65,14 @@ syn region snipGlobal fold keepend start="^global" end="^endglobal" contains=sni " priority {{{3 -syn match snipPriority "^priority\%(\s.*\|$\)" contains=snipPriorityKeyword -syn match snipPriorityKeyword "^priority" contained nextgroup=snipPriorityValue skipwhite -syn match snipPriorityValue "-\?\d\+" contained +syn match snipPriority "^priority\%(\s.*\|$\)" contains=snipPriorityKeyword display +syn match snipPriorityKeyword "^priority" contained nextgroup=snipPriorityValue skipwhite display +syn match snipPriorityValue "-\?\d\+" contained display " Snippt Clearing {{{2 -syn match snipClear "^clearsnippets\%(\s.*\|$\)" contains=snipClearKeyword -syn match snipClearKeyword "^clearsnippets" contained +syn match snipClear "^clearsnippets\%(\s.*\|$\)" contains=snipClearKeyword display +syn match snipClearKeyword "^clearsnippets" contained display " Highlight groups {{{1 From cb2905c178ddf5f2c7677ed40c1c777c3d2a347c Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Sun, 29 Jun 2014 23:33:36 -0700 Subject: [PATCH 09/21] Rewrite syntax matching for `snippet` --- syntax/snippets.vim | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/syntax/snippets.vim b/syntax/snippets.vim index 33161f3..1d3cb16 100644 --- a/syntax/snippets.vim +++ b/syntax/snippets.vim @@ -39,10 +39,12 @@ syn match snipExtendsKeyword "^extends" contained display " snippet {{{3 -syn region snipSnippet fold keepend start="^snippet" end="^endsnippet" contains=snipStart,snipEnd,snipTabsOnly,snipLeadingSpaces,snipCommand,snipVarExpansion,snipVar,snipVisual - -syn match snipStart "^snippet.*" contained contains=snipKeyword,snipDocString -syn match snipEnd "^endsnippet" contained contains=snipKeyword +syn region snipSnippet start="^snippet\_s" end="^endsnippet\s*$" contains=snipSnippetHeader fold keepend +syn match snipSnippetHeader "^.*$" nextgroup=snipSnippetBody skipnl contained contains=snipSnippetHeaderKeyword +syn match snipSnippetHeaderKeyword "^snippet" contained nextgroup=snipSnippetTrigger +syn region snipSnippetBody start="\_." end="^\zeendsnippet\s*$" contained contains=snipTabsOnly,snipLeadingSpaces,snipCommand,snipVarExpansion,snipVar,snipVisual nextgroup=snipSnippetFooter +syn match snipSnippetFooter "^endsnippet.*" contained contains=snipSnippetFooterKeyword +syn match snipSnippetFooterKeyword "^endsnippet" contained " Command substitution {{{4 @@ -86,6 +88,9 @@ hi def link snipKeyword Keyword hi def link snipExtendsKeyword Keyword +hi def link snipSnippetHeaderKeyword snipKeyword +hi def link snipSnippetFooterKeyword snipKeyword + hi def link snipStart Statement hi def link snipEnd snipStart From d239402b7fabe7cdbf69d84a02dc23dafd63c863 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Sun, 29 Jun 2014 23:44:22 -0700 Subject: [PATCH 10/21] Rewrite syntax matching for `global` The body of a global now only has Python syntax coloring if the trigger is !p. This matches the actual behavior of UltiSnips. AFAIK right now globals with other triggers are useless, but this opens the door to proper syntax coloring for those if they ever gain a use. --- syntax/snippets.vim | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/syntax/snippets.vim b/syntax/snippets.vim index 1d3cb16..649e841 100644 --- a/syntax/snippets.vim +++ b/syntax/snippets.vim @@ -61,9 +61,19 @@ syn region snipVarExpansion matchgroup=Define start="\${\d*" end="}" contained c " global {{{3 -syn match snipGlobalStart "^global.*" contained contains=snipKeyword,snipString -syn match snipGlobalEnd "^endglobal" contained contains=snipKeyword -syn region snipGlobal fold keepend start="^global" end="^endglobal" contains=snipGlobalStart,snipGlobalEnd,snipLeadingSpaces,snipTabsOnly,snipCommand,snipVarExpansion,snipVar,@Python +" Generic (non-Python) {{{4 +syn region snipGlobal start="^global\_s" end="^endglobal\s*$" contains=snipGlobalHeader fold keepend +syn match snipGlobalHeader "^.*$" nextgroup=snipGlobalBody skipnl contained contains=snipGlobalHeaderKeyword +syn match snipGlobalHeaderKeyword "^global" contained nextgroup=snipSnippetTrigger +syn region snipGlobalBody start="\_." end="^\zeendglobal\s*$" contained contains=snipTabsOnly,snipLeadingSpaces nextgroup=snipGlobalFooter +syn match snipGlobalFooter "^endglobal.*" contained contains=snipGlobalFooterKeyword +syn match snipGlobalFooterKeyword "^endglobal" contained + +" Python (!p) {{{4 + +syn region snipGlobal start="^global\s\+!p\_s\@=" end="^endglobal\s*$" contains=snipGlobalPHeader fold keepend +syn match snipGlobalPHeader "^.*$" nextgroup=snipGlobalPBody skipnl contained contains=snipGlobalHeaderKeyword +syn region snipGlobalPBody start="\_." end="^\zeendglobal\s*$" contained contains=snipTabsOnly,snipLeadingSpaces,@Python nextgroup=snipGlobalFooter " priority {{{3 @@ -86,13 +96,13 @@ hi def link snipTabsOnly Error hi def link snipKeyword Keyword -hi def link snipExtendsKeyword Keyword +hi def link snipExtendsKeyword snipKeyword hi def link snipSnippetHeaderKeyword snipKeyword hi def link snipSnippetFooterKeyword snipKeyword -hi def link snipStart Statement -hi def link snipEnd snipStart +hi def link snipGlobalHeaderKeyword snipKeyword +hi def link snipGlobalFooterKeyword snipKeyword hi def link snipCommand Special hi def link snipCommandDelim snipCommand @@ -107,10 +117,6 @@ hi def link snipVarExpansion Normal hi def link snipVisual Normal hi def link snipSnippet Normal -hi def link snipGlobalStart Statement -hi def link snipGlobalEnd Statement -hi def link snipGlobal Normal - hi def link snipPriorityKeyword Keyword hi def link snipPriorityValue Number From 5760eb4033ba2303fda1d2c660f8b16d047e5684 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Mon, 30 Jun 2014 00:00:20 -0700 Subject: [PATCH 11/21] Fix empty snippets/globals --- syntax/snippets.vim | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/syntax/snippets.vim b/syntax/snippets.vim index 649e841..75e2db1 100644 --- a/syntax/snippets.vim +++ b/syntax/snippets.vim @@ -40,8 +40,8 @@ syn match snipExtendsKeyword "^extends" contained display " snippet {{{3 syn region snipSnippet start="^snippet\_s" end="^endsnippet\s*$" contains=snipSnippetHeader fold keepend -syn match snipSnippetHeader "^.*$" nextgroup=snipSnippetBody skipnl contained contains=snipSnippetHeaderKeyword -syn match snipSnippetHeaderKeyword "^snippet" contained nextgroup=snipSnippetTrigger +syn match snipSnippetHeader "^.*$" nextgroup=snipSnippetBody,snipSnippetFooter skipnl contained contains=snipSnippetHeaderKeyword +syn match snipSnippetHeaderKeyword "^snippet" contained nextgroup=snipSnippetTrigger skipwhite syn region snipSnippetBody start="\_." end="^\zeendsnippet\s*$" contained contains=snipTabsOnly,snipLeadingSpaces,snipCommand,snipVarExpansion,snipVar,snipVisual nextgroup=snipSnippetFooter syn match snipSnippetFooter "^endsnippet.*" contained contains=snipSnippetFooterKeyword syn match snipSnippetFooterKeyword "^endsnippet" contained @@ -62,19 +62,23 @@ syn region snipVarExpansion matchgroup=Define start="\${\d*" end="}" contained c " global {{{3 " Generic (non-Python) {{{4 + syn region snipGlobal start="^global\_s" end="^endglobal\s*$" contains=snipGlobalHeader fold keepend -syn match snipGlobalHeader "^.*$" nextgroup=snipGlobalBody skipnl contained contains=snipGlobalHeaderKeyword -syn match snipGlobalHeaderKeyword "^global" contained nextgroup=snipSnippetTrigger +syn match snipGlobalHeader "^.*$" nextgroup=snipGlobalBody,snipGlobalFooter skipnl contained contains=snipGlobalHeaderKeyword syn region snipGlobalBody start="\_." end="^\zeendglobal\s*$" contained contains=snipTabsOnly,snipLeadingSpaces nextgroup=snipGlobalFooter -syn match snipGlobalFooter "^endglobal.*" contained contains=snipGlobalFooterKeyword -syn match snipGlobalFooterKeyword "^endglobal" contained " Python (!p) {{{4 syn region snipGlobal start="^global\s\+!p\_s\@=" end="^endglobal\s*$" contains=snipGlobalPHeader fold keepend -syn match snipGlobalPHeader "^.*$" nextgroup=snipGlobalPBody skipnl contained contains=snipGlobalHeaderKeyword +syn match snipGlobalPHeader "^.*$" nextgroup=snipGlobalPBody,snipGlobalFooter skipnl contained contains=snipGlobalHeaderKeyword +syn match snipGlobalHeaderKeyword "^global" contained nextgroup=snipSnippetTrigger skipwhite syn region snipGlobalPBody start="\_." end="^\zeendglobal\s*$" contained contains=snipTabsOnly,snipLeadingSpaces,@Python nextgroup=snipGlobalFooter +" Common {{{4 + +syn match snipGlobalFooter "^endglobal.*" contained contains=snipGlobalFooterKeyword +syn match snipGlobalFooterKeyword "^endglobal" contained + " priority {{{3 syn match snipPriority "^priority\%(\s.*\|$\)" contains=snipPriorityKeyword display From acc79747c9f373378597b713826ac6bcbfe8a101 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Mon, 30 Jun 2014 13:38:58 -0700 Subject: [PATCH 12/21] Syntax highlight the snippet trigger properly This supports multiword triggers, docstrings, options, and even highlights invalid multiword triggers as errors. --- syntax/snippets.vim | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/syntax/snippets.vim b/syntax/snippets.vim index 75e2db1..2637ac2 100644 --- a/syntax/snippets.vim +++ b/syntax/snippets.vim @@ -46,6 +46,32 @@ syn region snipSnippetBody start="\_." end="^\zeendsnippet\s*$" contained contai syn match snipSnippetFooter "^endsnippet.*" contained contains=snipSnippetFooterKeyword syn match snipSnippetFooterKeyword "^endsnippet" contained +" 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 + " Command substitution {{{4 syn region snipCommand keepend matchgroup=snipCommandDelim start="`" skip="\\[{}\\$`]" end="`" contains=snipPythonCommand,snipVimLCommand,snipShellCommand @@ -69,7 +95,7 @@ syn region snipGlobalBody start="\_." end="^\zeendglobal\s*$" contained contains " Python (!p) {{{4 -syn region snipGlobal start="^global\s\+!p\_s\@=" end="^endglobal\s*$" contains=snipGlobalPHeader fold keepend +syn region snipGlobal start=,^global\s\+!p\%(\s\+"[^"]*\%("\s\+[^"[:space:]]\+\|"\)\=\)\=\s*$, end=,^endglobal\s*$, contains=snipGlobalPHeader fold keepend syn match snipGlobalPHeader "^.*$" nextgroup=snipGlobalPBody,snipGlobalFooter skipnl contained contains=snipGlobalHeaderKeyword syn match snipGlobalHeaderKeyword "^global" contained nextgroup=snipSnippetTrigger skipwhite syn region snipGlobalPBody start="\_." end="^\zeendglobal\s*$" contained contains=snipTabsOnly,snipLeadingSpaces,@Python nextgroup=snipGlobalFooter @@ -105,6 +131,11 @@ hi def link snipExtendsKeyword snipKeyword hi def link snipSnippetHeaderKeyword snipKeyword hi def link snipSnippetFooterKeyword snipKeyword +hi def link snipSnippetTrigger Identifier +hi def link snipSnippetTriggerInvalid Error +hi def link snipSnippetDocString String +hi def link snipSnippetOptionFlag Special + hi def link snipGlobalHeaderKeyword snipKeyword hi def link snipGlobalFooterKeyword snipKeyword From 0dba6503e1c55efa8b52446c6444fe5029bc07ae Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Mon, 30 Jun 2014 15:41:35 -0700 Subject: [PATCH 13/21] Clean up miscellaneous syntax items Remove a few obsolete items. Remove the snipTabsOnly item. A tab-only line is not necessarily an error. Color leading spaces with a red background, because the default Error coloring doesn't affect the display of spaces. --- syntax/snippets.vim | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/syntax/snippets.vim b/syntax/snippets.vim index 2637ac2..80000d6 100644 --- a/syntax/snippets.vim +++ b/syntax/snippets.vim @@ -21,14 +21,9 @@ unlet b:current_syntax syn match snipComment "^#.*" contains=snipTODO display syn keyword snipTODO contained display FIXME NOTE NOTES TODO XXX -" Miscellaneous {{{2 +" Errors {{{2 -syn match snipDocString '"[^"]*"$' -syn match snipString '"[^"]*"' -syn match snipTabsOnly "^\t\+$" -syn match snipLeadingSpaces "^\t* \+" - -syn match snipKeyword "\(\<\(end\)\?\(snippet\|global\)\>\)\|extends\|clearsnippets\|priority" contained +syn match snipLeadingSpaces "^\t* \+" contained " Extends {{{2 @@ -42,7 +37,7 @@ syn match snipExtendsKeyword "^extends" contained display syn region snipSnippet start="^snippet\_s" end="^endsnippet\s*$" contains=snipSnippetHeader fold keepend syn match snipSnippetHeader "^.*$" nextgroup=snipSnippetBody,snipSnippetFooter skipnl contained contains=snipSnippetHeaderKeyword syn match snipSnippetHeaderKeyword "^snippet" contained nextgroup=snipSnippetTrigger skipwhite -syn region snipSnippetBody start="\_." end="^\zeendsnippet\s*$" contained contains=snipTabsOnly,snipLeadingSpaces,snipCommand,snipVarExpansion,snipVar,snipVisual nextgroup=snipSnippetFooter +syn region snipSnippetBody start="\_." end="^\zeendsnippet\s*$" contained contains=snipLeadingSpaces,snipCommand,snipVarExpansion,snipVar,snipVisual nextgroup=snipSnippetFooter syn match snipSnippetFooter "^endsnippet.*" contained contains=snipSnippetFooterKeyword syn match snipSnippetFooterKeyword "^endsnippet" contained @@ -91,14 +86,14 @@ syn region snipVarExpansion matchgroup=Define start="\${\d*" end="}" contained c syn region snipGlobal start="^global\_s" end="^endglobal\s*$" contains=snipGlobalHeader fold keepend syn match snipGlobalHeader "^.*$" nextgroup=snipGlobalBody,snipGlobalFooter skipnl contained contains=snipGlobalHeaderKeyword -syn region snipGlobalBody start="\_." end="^\zeendglobal\s*$" contained contains=snipTabsOnly,snipLeadingSpaces nextgroup=snipGlobalFooter +syn region snipGlobalBody start="\_." end="^\zeendglobal\s*$" contained contains=snipLeadingSpaces nextgroup=snipGlobalFooter " Python (!p) {{{4 syn region snipGlobal start=,^global\s\+!p\%(\s\+"[^"]*\%("\s\+[^"[:space:]]\+\|"\)\=\)\=\s*$, end=,^endglobal\s*$, contains=snipGlobalPHeader fold keepend syn match snipGlobalPHeader "^.*$" nextgroup=snipGlobalPBody,snipGlobalFooter skipnl contained contains=snipGlobalHeaderKeyword syn match snipGlobalHeaderKeyword "^global" contained nextgroup=snipSnippetTrigger skipwhite -syn region snipGlobalPBody start="\_." end="^\zeendglobal\s*$" contained contains=snipTabsOnly,snipLeadingSpaces,@Python nextgroup=snipGlobalFooter +syn region snipGlobalPBody start="\_." end="^\zeendglobal\s*$" contained contains=@Python nextgroup=snipGlobalFooter " Common {{{4 @@ -119,10 +114,9 @@ syn match snipClearKeyword "^clearsnippets" contained display " Highlight groups {{{1 hi def link snipComment Comment -hi def link snipLeadingSpaces Error +hi def snipLeadingSpaces term=reverse ctermfg=15 ctermbg=4 gui=reverse guifg=#dc322f hi def link snipString String hi def link snipDocString String -hi def link snipTabsOnly Error hi def link snipKeyword Keyword From 4b73864b74d6e2f6740ee7ecca837975d85fb702 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Mon, 30 Jun 2014 15:56:13 -0700 Subject: [PATCH 14/21] Fix the docstring for ShellCodeToken It's not vim-syntax-related, but it was bugging me. --- pythonx/UltiSnips/snippet/parsing/_lexer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pythonx/UltiSnips/snippet/parsing/_lexer.py b/pythonx/UltiSnips/snippet/parsing/_lexer.py index 5233e31..1c5794f 100644 --- a/pythonx/UltiSnips/snippet/parsing/_lexer.py +++ b/pythonx/UltiSnips/snippet/parsing/_lexer.py @@ -253,7 +253,7 @@ class EscapeCharToken(Token): ) class ShellCodeToken(Token): - """`! echo "hi"`""" + """`echo "hi"`""" @classmethod def starts_here(cls, stream): """Returns true if this token starts at the current position in From 5fa39faa9243aea79d0de23372764ce19bbd51e0 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Mon, 30 Jun 2014 18:38:50 -0700 Subject: [PATCH 15/21] fixup! Clean up miscellaneous syntax items --- syntax/snippets.vim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/syntax/snippets.vim b/syntax/snippets.vim index 80000d6..276440e 100644 --- a/syntax/snippets.vim +++ b/syntax/snippets.vim @@ -114,9 +114,8 @@ syn match snipClearKeyword "^clearsnippets" contained display " Highlight groups {{{1 hi def link snipComment Comment +hi def link snipTODO Todo hi def snipLeadingSpaces term=reverse ctermfg=15 ctermbg=4 gui=reverse guifg=#dc322f -hi def link snipString String -hi def link snipDocString String hi def link snipKeyword Keyword From 30ecd1d1b0373ab47d4f80a6033a4cfd5ef3a89d Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Mon, 30 Jun 2014 19:15:56 -0700 Subject: [PATCH 16/21] Rewrite parsing for tab stops --- syntax/snippets.vim | 47 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/syntax/snippets.vim b/syntax/snippets.vim index 276440e..17ebd13 100644 --- a/syntax/snippets.vim +++ b/syntax/snippets.vim @@ -37,7 +37,7 @@ syn match snipExtendsKeyword "^extends" contained display syn region snipSnippet start="^snippet\_s" end="^endsnippet\s*$" contains=snipSnippetHeader fold keepend syn match snipSnippetHeader "^.*$" nextgroup=snipSnippetBody,snipSnippetFooter skipnl contained contains=snipSnippetHeaderKeyword syn match snipSnippetHeaderKeyword "^snippet" contained nextgroup=snipSnippetTrigger skipwhite -syn region snipSnippetBody start="\_." end="^\zeendsnippet\s*$" contained contains=snipLeadingSpaces,snipCommand,snipVarExpansion,snipVar,snipVisual nextgroup=snipSnippetFooter +syn region snipSnippetBody start="\_." end="^\zeendsnippet\s*$" contained contains=snipLeadingSpaces,@snipTokens nextgroup=snipSnippetFooter syn match snipSnippetFooter "^endsnippet.*" contained contains=snipSnippetFooterKeyword syn match snipSnippetFooterKeyword "^endsnippet" contained @@ -73,12 +73,32 @@ syn region snipCommand keepend matchgroup=snipCommandDelim start="`" skip="\\[{} 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 +syn cluster snipTokens add=snipCommand -" Variables {{{4 +" Tab Stops {{{4 -syn match snipVar "\$\d*" contained -syn region snipVisual matchgroup=Define start="\${VISUAL" end="}" contained -syn region snipVarExpansion matchgroup=Define start="\${\d*" end="}" contained contains=snipVar,snipVarExpansion,snipCommand +syn match snipEscape "\\[{}\\$`]" contained +syn cluster snipTokens add=snipEscape + +syn match snipMirror "\$\d\+" contained +syn cluster snipTokens add=snipMirror + +syn region snipTabStop matchgroup=snipTabStop start="\${\d\+[:}]\@=" end="}" contained contains=snipTabStopDefault +syn region snipTabStopDefault matchgroup=snipTabStop start=":" end="\ze}" contained contains=snipTabStopEscape,snipTabStop,snipBalancedBraces +syn match snipTabStopEscape "\\[{}]" contained +syn region snipBalancedBraces start="{" end="}" contained transparent +syn cluster snipTokens add=snipTabStop + +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 + +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 " global {{{3 @@ -140,10 +160,19 @@ hi def link snipVimLCommand snipCommand hi def link snipPythonCommandP PreProc hi def link snipVimLCommandV PreProc -hi def link snipVar StorageClass -hi def link snipVarExpansion Normal -hi def link snipVisual Normal -hi def link snipSnippet Normal +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 hi def link snipPriorityKeyword Keyword hi def link snipPriorityValue Number From ebd62751e7864f196d8c62db845d74c056ed4b56 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Mon, 30 Jun 2014 19:26:28 -0700 Subject: [PATCH 17/21] Tweak snippet/global highlighting to always highlight the end The snippet/global regions were always ending correctly, but an unclosed contained region could cause the wrong highlighting to apply to the endsnippet/endglobal. Tweak the definitions such that the snippet/global regions actually end at the start of the line and the footer occurs outside the region. --- syntax/snippets.vim | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/syntax/snippets.vim b/syntax/snippets.vim index 17ebd13..3e3b9b7 100644 --- a/syntax/snippets.vim +++ b/syntax/snippets.vim @@ -34,10 +34,10 @@ syn match snipExtendsKeyword "^extends" contained display " snippet {{{3 -syn region snipSnippet start="^snippet\_s" end="^endsnippet\s*$" contains=snipSnippetHeader fold keepend +syn region snipSnippet start="^snippet\_s" end="^\zeendsnippet\s*$" contains=snipSnippetHeader nextgroup=snipSnippetFooter fold keepend syn match snipSnippetHeader "^.*$" nextgroup=snipSnippetBody,snipSnippetFooter skipnl contained contains=snipSnippetHeaderKeyword syn match snipSnippetHeaderKeyword "^snippet" contained nextgroup=snipSnippetTrigger skipwhite -syn region snipSnippetBody start="\_." end="^\zeendsnippet\s*$" contained contains=snipLeadingSpaces,@snipTokens nextgroup=snipSnippetFooter +syn region snipSnippetBody start="\_." end="^\zeendsnippet\s*$" contained contains=snipLeadingSpaces,@snipTokens syn match snipSnippetFooter "^endsnippet.*" contained contains=snipSnippetFooterKeyword syn match snipSnippetFooterKeyword "^endsnippet" contained @@ -104,16 +104,16 @@ syn cluster snipTokens add=snipTransformation " Generic (non-Python) {{{4 -syn region snipGlobal start="^global\_s" end="^endglobal\s*$" contains=snipGlobalHeader fold keepend +syn region snipGlobal start="^global\_s" end="^\zeendglobal\s*$" contains=snipGlobalHeader nextgroup=snipGlobalFooter fold keepend syn match snipGlobalHeader "^.*$" nextgroup=snipGlobalBody,snipGlobalFooter skipnl contained contains=snipGlobalHeaderKeyword -syn region snipGlobalBody start="\_." end="^\zeendglobal\s*$" contained contains=snipLeadingSpaces nextgroup=snipGlobalFooter +syn region snipGlobalBody start="\_." end="^\zeendglobal\s*$" contained contains=snipLeadingSpaces " Python (!p) {{{4 -syn region snipGlobal start=,^global\s\+!p\%(\s\+"[^"]*\%("\s\+[^"[:space:]]\+\|"\)\=\)\=\s*$, end=,^endglobal\s*$, contains=snipGlobalPHeader fold keepend +syn region snipGlobal start=,^global\s\+!p\%(\s\+"[^"]*\%("\s\+[^"[:space:]]\+\|"\)\=\)\=\s*$, end=,^\zeendglobal\s*$, contains=snipGlobalPHeader nextgroup=snipGlobalFooter fold keepend syn match snipGlobalPHeader "^.*$" nextgroup=snipGlobalPBody,snipGlobalFooter skipnl contained contains=snipGlobalHeaderKeyword syn match snipGlobalHeaderKeyword "^global" contained nextgroup=snipSnippetTrigger skipwhite -syn region snipGlobalPBody start="\_." end="^\zeendglobal\s*$" contained contains=@Python nextgroup=snipGlobalFooter +syn region snipGlobalPBody start="\_." end="^\zeendglobal\s*$" contained contains=@Python " Common {{{4 From 010e2c4facca8945ebee17a66d24f1db99195d50 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Mon, 30 Jun 2014 19:29:00 -0700 Subject: [PATCH 18/21] Remove the coloring for python commands Python commands tend to be longer than normal commands, and they already include embedded python syntax coloring, so coloring them red like shell commands is a bit overwhelming. Preferably there would be some subtle background color we could apply, but I don't see any pre-existing group name for that, and defining our own would not play well with colorschemes. --- syntax/snippets.vim | 1 - 1 file changed, 1 deletion(-) diff --git a/syntax/snippets.vim b/syntax/snippets.vim index 3e3b9b7..4416b64 100644 --- a/syntax/snippets.vim +++ b/syntax/snippets.vim @@ -155,7 +155,6 @@ hi def link snipGlobalFooterKeyword snipKeyword hi def link snipCommand Special hi def link snipCommandDelim snipCommand hi def link snipShellCommand snipCommand -hi def link snipPythonCommand snipCommand hi def link snipVimLCommand snipCommand hi def link snipPythonCommandP PreProc hi def link snipVimLCommandV PreProc From 40145103b61e8048bf96b0fa76756f6a88414285 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Mon, 30 Jun 2014 20:10:42 -0700 Subject: [PATCH 19/21] Stop embedding python/viml/sh if the `` includes { In order to handle brace balancing properly, we need our own region to match the {/} pairs, which unfortunately means that if a { occurs in a command substitution, we have to disable the embedded language highlighting. --- syntax/snippets.vim | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/syntax/snippets.vim b/syntax/snippets.vim index 4416b64..055b5d2 100644 --- a/syntax/snippets.vim +++ b/syntax/snippets.vim @@ -69,12 +69,18 @@ syn match snipSnippetOptionFlag ,[biwrts], contained " Command substitution {{{4 -syn region snipCommand keepend matchgroup=snipCommandDelim start="`" skip="\\[{}\\$`]" end="`" contains=snipPythonCommand,snipVimLCommand,snipShellCommand +syn region snipCommand keepend matchgroup=snipCommandDelim start="`" skip="\\[{}\\$`]" end="`" contains=snipPythonCommand,snipVimLCommand,snipShellCommand,snipCommandSyntaxOverride 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 syn cluster snipTokens add=snipCommand +" 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 + " Tab Stops {{{4 syn match snipEscape "\\[{}\\$`]" contained @@ -84,9 +90,9 @@ syn match snipMirror "\$\d\+" contained syn cluster snipTokens add=snipMirror syn region snipTabStop matchgroup=snipTabStop start="\${\d\+[:}]\@=" end="}" contained contains=snipTabStopDefault -syn region snipTabStopDefault matchgroup=snipTabStop start=":" end="\ze}" contained contains=snipTabStopEscape,snipTabStop,snipBalancedBraces +syn region snipTabStopDefault matchgroup=snipTabStop start=":" skip="\\[{}]" end="\ze}" contained contains=snipTabStopEscape,snipBalancedBraces,@snipTokens keepend syn match snipTabStopEscape "\\[{}]" contained -syn region snipBalancedBraces start="{" end="}" contained transparent +syn region snipBalancedBraces start="{" end="}" contained transparent extend syn cluster snipTokens add=snipTabStop syn region snipVisual matchgroup=snipVisual start="\${VISUAL[:}/]\@=" end="}" contained contains=snipVisualDefault,snipTransformationPattern From 67c7422ae2c556bf2ad8081c26fcc60e98545606 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Mon, 30 Jun 2014 21:14:55 -0700 Subject: [PATCH 20/21] Set up basic highlighting for snipmate files Try to detect a snipmate-formatted file by looking at the directory name and searching for endsnippet. If we think it's a snipmate file, switch over to an alternative syntax highlighting variant. --- syntax/snippets.vim | 19 +++++++++++++-- syntax/snippets_snipmate.vim | 47 ++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 syntax/snippets_snipmate.vim diff --git a/syntax/snippets.vim b/syntax/snippets.vim index 055b5d2..19a9da1 100644 --- a/syntax/snippets.vim +++ b/syntax/snippets.vim @@ -5,6 +5,15 @@ if exists("b:current_syntax") finish endif +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 :h/snippets_snipmate.vim + finish +endif + " Embedded Syntaxes {{{1 syntax include @Python syntax/python.vim @@ -69,11 +78,12 @@ syn match snipSnippetOptionFlag ,[biwrts], contained " Command substitution {{{4 -syn region snipCommand keepend matchgroup=snipCommandDelim start="`" skip="\\[{}\\$`]" end="`" contains=snipPythonCommand,snipVimLCommand,snipShellCommand,snipCommandSyntaxOverride +syn region snipCommand keepend matchgroup=snipCommandDelim start="`" skip="\\[{}\\$`]" end="`" contained contains=snipPythonCommand,snipVimLCommand,snipShellCommand,snipCommandSyntaxOverride 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 syn cluster snipTokens add=snipCommand +syn cluster snipTabStopTokens add=snipCommand " unfortunately due to the balanced braces parsing of commands, if a { occurs " in the command, we need to prevent the embedded syntax highlighting. @@ -85,19 +95,23 @@ syn region snipCommandSyntaxOverride start="\%(\\[{}\\$`]\|\_[^`"{]\)*\ze{" skip syn match snipEscape "\\[{}\\$`]" contained syn cluster snipTokens add=snipEscape +syn cluster snipTabStopTokens add=snipEscape syn match snipMirror "\$\d\+" contained syn cluster snipTokens add=snipMirror +syn cluster snipTabStopTokens add=snipMirror syn region snipTabStop matchgroup=snipTabStop start="\${\d\+[:}]\@=" end="}" contained contains=snipTabStopDefault -syn region snipTabStopDefault matchgroup=snipTabStop start=":" skip="\\[{}]" end="\ze}" contained contains=snipTabStopEscape,snipBalancedBraces,@snipTokens keepend +syn region snipTabStopDefault matchgroup=snipTabStop start=":" skip="\\[{}]" end="\ze}" contained contains=snipTabStopEscape,snipBalancedBraces,@snipTabStopTokens keepend syn match snipTabStopEscape "\\[{}]" contained syn region snipBalancedBraces start="{" end="}" contained transparent extend syn cluster snipTokens add=snipTabStop +syn cluster snipTabStopTokens add=snipTabStop 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 +syn cluster snipTabStopTokens add=snipVisual 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 @@ -105,6 +119,7 @@ syn region snipTransformationReplace matchgroup=snipTransformationPatternDelim s syn region snipTransformationOptions start="\ze[^}]" end="\ze}" contained contains=snipTabStopEscape syn match snipTransformationEscape "\\/" contained syn cluster snipTokens add=snipTransformation +syn cluster snipTabStopTokens add=snipTransformation " global {{{3 diff --git a/syntax/snippets_snipmate.vim b/syntax/snippets_snipmate.vim new file mode 100644 index 0000000..aa55c1f --- /dev/null +++ b/syntax/snippets_snipmate.vim @@ -0,0 +1,47 @@ +" Syntax highlighting variant used for snipmate snippets files +" The snippets.vim file sources this if it wants snipmate mode + +if exists("b:current_syntax") + finish +endif + +" Embedded syntaxes {{{1 + +" Re-include the original file so we can share some of its definitions +let b:ultisnips_override_snipmate = 1 +syn include :h/snippets.vim +unlet b:current_syntax +unlet b:ultisnips_override_snipmate + +syn cluster snipTokens contains=snipEscape,snipVisual,snipTabStop,snipMirror,snipmateCommand +syn cluster snipTabStopTokens contains=snipVisual,snipMirror,snipEscape,snipmateCommand + +" Syntax definitions {{{1 + +syn match snipmateComment "^#.*" + +syn match snipmateExtends "^extends\%(\s.*\|$\)" contains=snipExtendsKeyword display + +syn region snipmateSnippet start="^snippet\ze\%(\s\|$\)" end="^\ze[^[:tab:]]" contains=snipmateSnippetHeader keepend +syn match snipmateSnippetHeader "^.*" contained contains=snipmateKeyword nextgroup=snipmateSnippetBody skipnl skipempty +syn match snipmateKeyword "^snippet\ze\%(\s\|$\)" contained nextgroup=snipmateTrigger skipwhite +syn match snipmateTrigger "\S\+" contained nextgroup=snipmateDescription skipwhite +syn match snipmateDescription "\S.*" contained +syn region snipmateSnippetBody start="^\t" end="^\ze[^[:tab:]]" contained contains=@snipTokens + +syn region snipmateCommand keepend matchgroup=snipCommandDelim start="`" skip="\\[{}\\$`]" end="`" contained contains=snipCommandSyntaxOverride,@Viml + +" Highlight groups {{{1 + +hi def link snipmateComment snipComment + +hi def link snipmateSnippet snipSnippet +hi def link snipmateKeyword snipKeyword +hi def link snipmateTrigger snipSnippetTrigger +hi def link snipmateDescription snipSnippetDocString + +hi def link snipmateCommand snipCommand + +" }}}1 + +let b:current_syntax = "snippets" From b10b62ae6d8721b197a074f73c30351aea35c29b Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Mon, 30 Jun 2014 21:17:52 -0700 Subject: [PATCH 21/21] Twiddle indentation settings We just want autoindent, no need for smartindent/etc that may be set by the user's vimrc. --- ftplugin/snippets.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/ftplugin/snippets.vim b/ftplugin/snippets.vim index 134fe01..69e1abf 100644 --- a/ftplugin/snippets.vim +++ b/ftplugin/snippets.vim @@ -7,6 +7,7 @@ setlocal foldlevel=99 setlocal commentstring=#%s setlocal noexpandtab +setlocal autoindent nosmartindent nocindent " Define match words for use with matchit plugin " http://www.vim.org/scripts/script.php?script_id=39