Skip to content

Commit

Permalink
New way to eval ..., and escape \
Browse files Browse the repository at this point in the history
* \ is escaped as `
* the eval result in `substitute` may contain special chars,
  see |sub-replace-special|
* syntax update
  • Loading branch information
lilydjwg authored and garbas committed Feb 3, 2011
1 parent 08945cc commit 2a83172
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
21 changes: 15 additions & 6 deletions autoload/snipMate.vim
Expand Up @@ -77,15 +77,24 @@ fun s:ProcessSnippet(snip)
let snippet = a:snip let snippet = a:snip
" Evaluate eval (`...`) expressions. " Evaluate eval (`...`) expressions.
" Backquotes prefixed with a backslash "\" are ignored. " Backquotes prefixed with a backslash "\" are ignored.
" And backslash can be escaped by doubling it.
" Using a loop here instead of a regex fixes a bug with nested "\=". " Using a loop here instead of a regex fixes a bug with nested "\=".
if stridx(snippet, '`') != -1 if stridx(snippet, '`') != -1
while match(snippet, '\(^\|[^\\]\)`.\{-}[^\\]`') != -1 let new = []
let snippet = substitute(snippet, '\(^\|[^\\]\)\zs`.\{-}[^\\]`\ze', let snip = split(snippet, '\%(\\\@<!\%(\\\\\)*\)\@<=`', 1)
\ substitute(eval(matchstr(snippet, '\(^\|[^\\]\)`\zs.\{-}[^\\]\ze`')), let isexp = 0
\ "\n\\%$", '', ''), '') for i in snip
endw if isexp
call add(new, substitute(eval(i), "\n\\%$", '', ''))
else
call add(new, i)
endif
let isexp = !isexp
endfor
let snippet = join(new, '')
let snippet = substitute(snippet, "\r", "\n", 'g') let snippet = substitute(snippet, "\r", "\n", 'g')
let snippet = substitute(snippet, '\\`', '`', 'g') let snippet = substitute(snippet, '\\`', "`", 'g')
let snippet = substitute(snippet, '\\\\', "\\", 'g')
endif endif


" Place all text after a colon in a tab stop after the tab stop " Place all text after a colon in a tab stop after the tab stop
Expand Down
4 changes: 3 additions & 1 deletion syntax/snippet.vim
Expand Up @@ -3,7 +3,8 @@
syn match snipComment '^#.*' syn match snipComment '^#.*'
syn match placeHolder '\${\d\+\(:.\{-}\)\=}' contains=snipCommand syn match placeHolder '\${\d\+\(:.\{-}\)\=}' contains=snipCommand
syn match tabStop '\$\d\+' syn match tabStop '\$\d\+'
syn match snipCommand '[^\\]`.\{-}`' syn match snipEscape '\\\\\|\\`'
syn match snipCommand '\%(\\\@<!\%(\\\\\)*\)\@<=`.\{-}\%(\\\@<!\%(\\\\\)*\)\@<=`'
syn match snippet '^snippet.*' transparent contains=multiSnipText,snipKeyword syn match snippet '^snippet.*' transparent contains=multiSnipText,snipKeyword
syn match multiSnipText '\S\+ \zs.*' contained syn match multiSnipText '\S\+ \zs.*' contained
syn match snipKeyword '^snippet'me=s+8 contained syn match snipKeyword '^snippet'me=s+8 contained
Expand All @@ -12,6 +13,7 @@ syn match snipError "^[^#s\t].*$"
hi link snipComment Comment hi link snipComment Comment
hi link multiSnipText String hi link multiSnipText String
hi link snipKeyword Keyword hi link snipKeyword Keyword
hi link snipEscape SpecialChar
hi link snipComment Comment hi link snipComment Comment
hi link placeHolder Special hi link placeHolder Special
hi link tabStop Special hi link tabStop Special
Expand Down

0 comments on commit 2a83172

Please sign in to comment.