1
0
mirror of https://github.com/gryf/snipmate.vim.git synced 2026-01-03 04:14:13 +01:00

fixed bug with numbers in placeholders, and cleaned up the code a bit

This commit is contained in:
Michael Sanders
2009-06-06 13:37:19 -04:00
parent 31d03ef467
commit 2fed6ad159

View File

@@ -61,7 +61,7 @@ fun s:ProcessSnippet(snip)
" Evaluate eval (`...`) expressions.
" Using a loop here instead of a regex fixes a bug with nested "\=".
if stridx(snippet, '`') != -1
wh match(snippet, '`.\{-}`') != -1
while match(snippet, '`.\{-}`') != -1
let snippet = substitute(snippet, '`.\{-}`',
\ substitute(eval(matchstr(snippet, '`\zs.\{-}\ze`')),
\ "\n\\%$", '', ''), '')
@@ -78,10 +78,10 @@ fun s:ProcessSnippet(snip)
" the colon in their associated ${#}.
" (e.g. "${1:foo}" turns all "$1"'s into "foo")
let i = 1
wh stridx(snippet, '${'.i) != -1
while stridx(snippet, '${'.i) != -1
let s = matchstr(snippet, '${'.i.':\zs.\{-}\ze}')
if s != ''
let snippet = substitute(snippet, '$'.i, '&'.s, 'g')
let snippet = substitute(snippet, '$'.i, s.'&', 'g')
endif
let i += 1
endw
@@ -95,7 +95,7 @@ endf
fun s:Count(haystack, needle)
let counter = 0
let index = stridx(a:haystack, a:needle)
wh index != -1
while index != -1
let index = stridx(a:haystack, a:needle, index+1)
let counter += 1
endw
@@ -118,29 +118,29 @@ fun s:BuildTabStops(snip, lnum, col, indent)
let snipPos = []
let i = 1
let withoutVars = substitute(a:snip, '$\d\+', '', 'g')
wh stridx(a:snip, '${'.i) != -1
while stridx(a:snip, '${'.i) != -1
let beforeTabStop = matchstr(withoutVars, '^.*\ze${'.i.'\D')
let withoutOthers = substitute(withoutVars, '${'.i.'\@!\d\+.\{-}}', '', 'g')
let snipPos += [[a:lnum + s:Count(beforeTabStop, "\n"),
\ a:indent + len(matchstr(withoutOthers,
\ "^.*\\(\n\\|^\\)\\zs.*\\ze${".i.'\D')), -1]]
if snipPos[i-1][0] == a:lnum
let snipPos[i-1][1] += a:col
endif
let j = i - 1
call add(snipPos, [0, 0, -1])
let snipPos[j][0] = a:lnum + s:Count(beforeTabStop, "\n")
let snipPos[j][1] = a:indent + len(matchstr(withoutOthers, '.*\(\n\|^\)\zs.*\ze${'.i.'\D'))
if snipPos[j][0] == a:lnum | let snipPos[j][1] += a:col | endif
" Get all $# matches in another list, if ${#:name} is given
if stridx(withoutVars, '${'.i.':') != -1
let j = i - 1
let snipPos[j][2] = len(matchstr(withoutVars, '${'.i.':\zs.\{-}\ze}'))
let snipPos[j] += [[]]
let dots = repeat('.', snipPos[j][2])
call add(snipPos[j], [])
let withoutOthers = substitute(a:snip, '${\d\+.\{-}}\|$'.i.'\@!\d\+', '', 'g')
wh match(withoutOthers, '$'.i.'\D') != -1
let beforeMark = matchstr(withoutOthers, '^.\{-}\ze$'.i.'\D')
let linecount = a:lnum + s:Count(beforeMark, "\n")
let snipPos[j][3] += [[linecount,
\ a:indent + (linecount > a:lnum
\ ? len(matchstr(beforeMark, "^.*\n\\zs.*"))
\ : a:col + len(beforeMark))]]
while match(withoutOthers, '$'.i.'\D') != -1
let beforeMark = matchstr(withoutOthers, '^.\{-}\ze'.dots.'$'.i.'\D')
call add(snipPos[j][3], [0, 0])
let snipPos[j][3][-1][0] = a:lnum + s:Count(beforeMark, "\n")
let snipPos[j][3][-1][1] = a:indent + (snipPos[j][3][-1][0] > a:lnum
\ ? len(matchstr(beforeMark, '.*\n\zs.*'))
\ : a:col + len(beforeMark))
let withoutOthers = substitute(withoutOthers, '$'.i.'\ze\D', '', '')
endw
endif