mirror of
https://github.com/gryf/snipmate.vim.git
synced 2026-01-08 15:14:11 +01:00
fixed bug with numbers in placeholders, and cleaned up the code a bit
This commit is contained in:
@@ -61,7 +61,7 @@ fun s:ProcessSnippet(snip)
|
|||||||
" Evaluate eval (`...`) expressions.
|
" Evaluate eval (`...`) expressions.
|
||||||
" 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
|
||||||
wh match(snippet, '`.\{-}`') != -1
|
while match(snippet, '`.\{-}`') != -1
|
||||||
let snippet = substitute(snippet, '`.\{-}`',
|
let snippet = substitute(snippet, '`.\{-}`',
|
||||||
\ substitute(eval(matchstr(snippet, '`\zs.\{-}\ze`')),
|
\ substitute(eval(matchstr(snippet, '`\zs.\{-}\ze`')),
|
||||||
\ "\n\\%$", '', ''), '')
|
\ "\n\\%$", '', ''), '')
|
||||||
@@ -78,10 +78,10 @@ fun s:ProcessSnippet(snip)
|
|||||||
" the colon in their associated ${#}.
|
" the colon in their associated ${#}.
|
||||||
" (e.g. "${1:foo}" turns all "$1"'s into "foo")
|
" (e.g. "${1:foo}" turns all "$1"'s into "foo")
|
||||||
let i = 1
|
let i = 1
|
||||||
wh stridx(snippet, '${'.i) != -1
|
while stridx(snippet, '${'.i) != -1
|
||||||
let s = matchstr(snippet, '${'.i.':\zs.\{-}\ze}')
|
let s = matchstr(snippet, '${'.i.':\zs.\{-}\ze}')
|
||||||
if s != ''
|
if s != ''
|
||||||
let snippet = substitute(snippet, '$'.i, '&'.s, 'g')
|
let snippet = substitute(snippet, '$'.i, s.'&', 'g')
|
||||||
endif
|
endif
|
||||||
let i += 1
|
let i += 1
|
||||||
endw
|
endw
|
||||||
@@ -95,7 +95,7 @@ endf
|
|||||||
fun s:Count(haystack, needle)
|
fun s:Count(haystack, needle)
|
||||||
let counter = 0
|
let counter = 0
|
||||||
let index = stridx(a:haystack, a:needle)
|
let index = stridx(a:haystack, a:needle)
|
||||||
wh index != -1
|
while index != -1
|
||||||
let index = stridx(a:haystack, a:needle, index+1)
|
let index = stridx(a:haystack, a:needle, index+1)
|
||||||
let counter += 1
|
let counter += 1
|
||||||
endw
|
endw
|
||||||
@@ -118,29 +118,29 @@ fun s:BuildTabStops(snip, lnum, col, indent)
|
|||||||
let snipPos = []
|
let snipPos = []
|
||||||
let i = 1
|
let i = 1
|
||||||
let withoutVars = substitute(a:snip, '$\d\+', '', 'g')
|
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 beforeTabStop = matchstr(withoutVars, '^.*\ze${'.i.'\D')
|
||||||
let withoutOthers = substitute(withoutVars, '${'.i.'\@!\d\+.\{-}}', '', 'g')
|
let withoutOthers = substitute(withoutVars, '${'.i.'\@!\d\+.\{-}}', '', 'g')
|
||||||
let snipPos += [[a:lnum + s:Count(beforeTabStop, "\n"),
|
|
||||||
\ a:indent + len(matchstr(withoutOthers,
|
let j = i - 1
|
||||||
\ "^.*\\(\n\\|^\\)\\zs.*\\ze${".i.'\D')), -1]]
|
call add(snipPos, [0, 0, -1])
|
||||||
if snipPos[i-1][0] == a:lnum
|
let snipPos[j][0] = a:lnum + s:Count(beforeTabStop, "\n")
|
||||||
let snipPos[i-1][1] += a:col
|
let snipPos[j][1] = a:indent + len(matchstr(withoutOthers, '.*\(\n\|^\)\zs.*\ze${'.i.'\D'))
|
||||||
endif
|
if snipPos[j][0] == a:lnum | let snipPos[j][1] += a:col | endif
|
||||||
|
|
||||||
" Get all $# matches in another list, if ${#:name} is given
|
" Get all $# matches in another list, if ${#:name} is given
|
||||||
if stridx(withoutVars, '${'.i.':') != -1
|
if stridx(withoutVars, '${'.i.':') != -1
|
||||||
let j = i - 1
|
|
||||||
let snipPos[j][2] = len(matchstr(withoutVars, '${'.i.':\zs.\{-}\ze}'))
|
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')
|
let withoutOthers = substitute(a:snip, '${\d\+.\{-}}\|$'.i.'\@!\d\+', '', 'g')
|
||||||
wh match(withoutOthers, '$'.i.'\D') != -1
|
while match(withoutOthers, '$'.i.'\D') != -1
|
||||||
let beforeMark = matchstr(withoutOthers, '^.\{-}\ze$'.i.'\D')
|
let beforeMark = matchstr(withoutOthers, '^.\{-}\ze'.dots.'$'.i.'\D')
|
||||||
let linecount = a:lnum + s:Count(beforeMark, "\n")
|
call add(snipPos[j][3], [0, 0])
|
||||||
let snipPos[j][3] += [[linecount,
|
let snipPos[j][3][-1][0] = a:lnum + s:Count(beforeMark, "\n")
|
||||||
\ a:indent + (linecount > a:lnum
|
let snipPos[j][3][-1][1] = a:indent + (snipPos[j][3][-1][0] > a:lnum
|
||||||
\ ? len(matchstr(beforeMark, "^.*\n\\zs.*"))
|
\ ? len(matchstr(beforeMark, '.*\n\zs.*'))
|
||||||
\ : a:col + len(beforeMark))]]
|
\ : a:col + len(beforeMark))
|
||||||
let withoutOthers = substitute(withoutOthers, '$'.i.'\ze\D', '', '')
|
let withoutOthers = substitute(withoutOthers, '$'.i.'\ze\D', '', '')
|
||||||
endw
|
endw
|
||||||
endif
|
endif
|
||||||
|
|||||||
Reference in New Issue
Block a user