1
0
mirror of https://github.com/gryf/snipmate.vim.git synced 2025-12-23 22:52:27 +01:00

some more refactoring

This commit is contained in:
Michael Sanders
2009-02-25 16:24:45 -05:00
parent 1d7f242ce5
commit 979da19541

View File

@@ -114,26 +114,26 @@ fun! TriggerSnippet()
call feedkeys("\<esc>a", 'n') | call s:UpdateChangedSnip(0) call feedkeys("\<esc>a", 'n') | call s:UpdateChangedSnip(0)
endif endif
if !exists('s:snipPos') " don't expand snippets within snippets if exists('s:snipPos')
if !exists('s:sid') && exists('g:SuperTabMappingForward') return s:JumpTabStop()
\ && g:SuperTabMappingForward == "<tab>"
call s:GetSuperTabSID()
endif
let word = s:GetSnippet()
if exists('s:snippet')
if s:snippet == ''
return unl s:snippet " if user cancelled multi snippet, quit
endif
let col = col('.')-len(word)
" if word is a trigger for a snippet, delete the trigger & expand
" the snippet
exe 'sil s/'.word.'\%#//'
return s:ExpandSnippet(col)
endif
return exists('s:sid') ? {s:sid}_SuperTab('n') : "\<tab>"
endif endif
return s:JumpTabStop()
if !exists('s:sid') && exists('g:SuperTabMappingForward')
\ && g:SuperTabMappingForward == "<tab>"
call s:GetSuperTabSID()
endif
let word = s:GetSnippet()
" if word is a trigger for a snippet, delete the trigger & expand the snippet
if exists('s:snippet')
if s:snippet == ''
return unl s:snippet " if user cancelled multi snippet, quit
endif
let col = col('.')-len(word)
sil exe 's/'.word.'\%#//'
return s:ExpandSnippet(col)
endif
return exists('s:sid') ? {s:sid}_SuperTab('n') : "\<tab>"
endf endf
" Check if word under cursor is snippet trigger; if it isn't, try checking if " Check if word under cursor is snippet trigger; if it isn't, try checking if
@@ -171,6 +171,12 @@ fun s:ExpandSnippet(col)
sil exe 's/\%'.col.'c.*//' sil exe 's/\%'.col.'c.*//'
else | let afterCursor = '' | endif else | let afterCursor = '' | endif
" for some reason the cursor needs to move one right after this
let line = getline(lnum)
if line != '' && col == 1 && afterCursor == '' && &ve !~ 'all\|onemore'
let col += 1
endif
call s:ProcessSnippet() call s:ProcessSnippet()
if s:snippet == '' if s:snippet == ''
return unl s:snippet " avoid an error if the snippet is now empty return unl s:snippet " avoid an error if the snippet is now empty
@@ -178,20 +184,11 @@ fun s:ExpandSnippet(col)
let snip = split(substitute(s:snippet, '$\d\|${\d.\{-}}', '', 'g'), "\n", 1) let snip = split(substitute(s:snippet, '$\d\|${\d.\{-}}', '', 'g'), "\n", 1)
if afterCursor != '' | let snip[-1] .= afterCursor | endif if afterCursor != '' | let snip[-1] .= afterCursor | endif
let line = getline(lnum)
call setline(lnum, line.snip[0]) call setline(lnum, line.snip[0])
" for some reason the cursor needs to move one right after this
if line != '' && col == 1 && afterCursor == '' && &ve !~ 'all\|onemore'
let col += 1
endif
" autoindent snippet according to previous indentation " autoindent snippet according to previous indentation
let indent = matchend(line, '^.\{-}\ze\(\S\|$\)')+1 let indent = matchend(line, '^.\{-}\ze\(\S\|$\)')+1
if !indent call append(lnum, map(snip[1:], "'".strpart(line, 0, indent-1)."'.v:val"))
call append(lnum, snip[1:])
else
call append(lnum, map(snip[1:], "'".strpart(line, 0, indent-1)."'.v:val"))
endif
let snipLen = s:BuildTabStops(lnum, col-indent, indent) let snipLen = s:BuildTabStops(lnum, col-indent, indent)
unl s:snippet unl s:snippet
@@ -242,6 +239,7 @@ fun s:ProcessSnippet()
endif endif
let i += 1 let i += 1
endw endw
if &et " expand tabs to spaces if 'expandtab' is set if &et " expand tabs to spaces if 'expandtab' is set
let s:snippet = substitute(s:snippet, '\t', let s:snippet = substitute(s:snippet, '\t',
\ repeat(' ', &sts ? &sts : &sw), 'g') \ repeat(' ', &sts ? &sts : &sw), 'g')
@@ -317,7 +315,8 @@ fun s:JumpTabStop()
let changeLine = s:endSnipLine - s:snipPos[s:curPos][0] let changeLine = s:endSnipLine - s:snipPos[s:curPos][0]
let changeCol = s:endSnip - s:snipPos[s:curPos][1] let changeCol = 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
endif endif