1
0
mirror of https://github.com/gryf/snipmate.vim.git synced 2026-01-06 22:04:11 +01:00

fixed some bugs with expanding nested snippets

This commit is contained in:
Michael Sanders
2009-03-02 18:46:07 -05:00
parent 6fa780f53e
commit e18b44e640

View File

@@ -118,7 +118,9 @@ fun! TriggerSnippet()
call s:GetSuperTabSID() call s:GetSuperTabSID()
endif endif
if exists('s:update') | return s:JumpTabStop() | endif if exists('s:snipPos') && s:endSnip == s:snipPos[s:curPos][1]+s:snipPos[s:curPos][2]
return s:JumpTabStop() " don't treat placeholder text as a trigger
endif
let word = matchstr(getline('.'), '\S\+\%'.col('.').'c') let word = matchstr(getline('.'), '\S\+\%'.col('.').'c')
for filetype in split(&ft, '\.') + ['_'] " deal with dotted file-types for filetype in split(&ft, '\.') + ['_'] " deal with dotted file-types
@@ -131,7 +133,7 @@ fun! TriggerSnippet()
if s:snippet == '' " if user cancelled a multi snippet, quit if s:snippet == '' " if user cancelled a multi snippet, quit
return unl s:snippet return unl s:snippet
endif endif
let col = col('.')-len(trigger) let col = col('.') - len(trigger)
sil exe 's/'.escape(trigger, '.^$/\*[]').'\%#//' sil exe 's/'.escape(trigger, '.^$/\*[]').'\%#//'
return s:ExpandSnippet(col) return s:ExpandSnippet(col)
endif endif
@@ -190,7 +192,7 @@ fun s:ExpandSnippet(col)
let indent = matchend(line, '^.\{-}\ze\(\S\|$\)')+1 let indent = matchend(line, '^.\{-}\ze\(\S\|$\)')+1
call append(lnum, map(snip[1:], "'".strpart(line, 0, indent-1)."'.v:val")) call append(lnum, map(snip[1:], "'".strpart(line, 0, indent-1)."'.v:val"))
if exists('s:snipPos') " update tab stops if expanding nested snip if exists('s:snipPos') && stridx(s:snippet, '${1') != -1
if exists('s:update') if exists('s:update')
call s:UpdateSnip(len(snip[-1])-len(afterCursor)) call s:UpdateSnip(len(snip[-1])-len(afterCursor))
call s:UpdatePlaceholderTabStops() call s:UpdatePlaceholderTabStops()
@@ -327,15 +329,16 @@ endf
fun s:JumpTabStop() fun s:JumpTabStop()
if exists('s:update') if exists('s:update')
call s:UpdatePlaceholderTabStops() call s:UpdatePlaceholderTabStops()
let updated = 1 else
call s:UpdateTabStops()
endif endif
let s:curPos += 1 let s:curPos += 1
if s:curPos == s:snipLen if s:curPos == s:snipLen
let sMode = s:endSnip == s:snipPos[s:curPos-1][1]+s:snipPos[s:curPos-1][2] let sMode = s:endSnip == s:snipPos[s:curPos-1][1]+s:snipPos[s:curPos-1][2]
call s:RemoveSnippet() call s:RemoveSnippet()
return sMode ? "\<tab>" : TriggerSnippet() return sMode ? "\<tab>" : TriggerSnippet()
endif endif
if !exists('updated') | call s:UpdateTabStops() | endif
call cursor(s:snipPos[s:curPos][0], s:snipPos[s:curPos][1]) call cursor(s:snipPos[s:curPos][0], s:snipPos[s:curPos][1])
@@ -400,18 +403,18 @@ fun s:UpdatePlaceholderTabStops()
endf endf
fun s:UpdateTabStops(...) fun s:UpdateTabStops(...)
let changeLine = a:0 ? a:1 : s:endSnipLine - s:snipPos[s:curPos-1][0] let changeLine = a:0 ? a:1 : s:endSnipLine - s:snipPos[s:curPos][0]
let changeCol = a:0 > 1 ? a:2 : s:endSnip - s:snipPos[s:curPos-1][1] let changeCol = a:0 > 1 ? a:2 : s:endSnip - s:snipPos[s:curPos][1]
if exists('s:origWordLen') if exists('s:origWordLen')
let changeCol -= s:origWordLen | unl s:origWordLen let changeCol -= s:origWordLen | unl s:origWordLen
endif endif
" there's probably a more efficient way to do this as well... " there's probably a more efficient way to do this as well...
let lnum = s:snipPos[s:curPos-1][0] let lnum = s:snipPos[s:curPos][0]
let col = s:snipPos[s:curPos-1][1] let col = s:snipPos[s:curPos][1]
" update the line number of all proceeding tab stops if <cr> has " update the line number of all proceeding tab stops if <cr> has
" been inserted " been inserted
if changeLine != 0 if changeLine != 0
for pos in s:snipPos[(s:curPos):] for pos in s:snipPos[(s:curPos+1):]
if pos[0] >= lnum if pos[0] >= lnum
if pos[0] == lnum if pos[0] == lnum
let pos[1] += changeCol let pos[1] += changeCol
@@ -432,7 +435,7 @@ fun s:UpdateTabStops(...)
elseif changeCol != 0 elseif changeCol != 0
" update the column of all proceeding tab stops if text has " update the column of all proceeding tab stops if text has
" been inserted/deleted in the current line " been inserted/deleted in the current line
for pos in s:snipPos[(s:curPos):] for pos in s:snipPos[(s:curPos+1):]
if pos[1] >= col && pos[0] == lnum if pos[1] >= col && pos[0] == lnum
let pos[1] += changeCol let pos[1] += changeCol
endif endif