- Improved indent snippet behavior.

This commit is contained in:
Shougo Matsushita 2012-10-06 16:22:36 +09:00
commit 88821a7d9b
3 changed files with 33 additions and 25 deletions

View File

@ -1,7 +1,7 @@
"============================================================================= "=============================================================================
" FILE: snippets_complete.vim " FILE: snippets_complete.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com> " AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" Last Modified: 04 Oct 2012. " Last Modified: 06 Oct 2012.
" License: MIT license {{{ " License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining " Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the " a copy of this software and associated documentation files (the

View File

@ -1,7 +1,7 @@
"============================================================================= "=============================================================================
" FILE: neosnippet.vim " FILE: neosnippet.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com> " AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" Last Modified: 04 Oct 2012. " Last Modified: 06 Oct 2012.
" License: MIT license {{{ " License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining " Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the " a copy of this software and associated documentation files (the
@ -568,34 +568,39 @@ function! neosnippet#expand(cur_text, col, trigger_name)"{{{
endfunction"}}} endfunction"}}}
function! s:indent_snippet(begin, end)"{{{ function! s:indent_snippet(begin, end)"{{{
let equalprg = &l:equalprg let equalprg = &l:equalprg
setlocal equalprg=
let pos = getpos('.') let pos = getpos('.')
let base_indent = matchstr(getline(a:begin), '^\s\+') try
for line_nr in range(a:begin+1, a:end) setlocal equalprg=
call cursor(line_nr, 0)
if getline('.') =~ '^\t\+' " Indent begin line.
" Delete head tab character. call cursor(a:begin, 0)
let current_line = substitute(getline('.'), '^\t', '', '') silent normal! ==
if &l:expandtab && current_line =~ '^\t\+' let base_indent = matchstr(getline(a:begin), '^\s\+')
" Expand tab. for line_nr in range(a:begin+1, a:end)
cal setline('.', substitute(current_line, call cursor(line_nr, 0)
\ '^\t\+', base_indent . repeat(' ', &shiftwidth *
\ len(matchstr(current_line, '^\t\+'))), '')) if getline('.') =~ '^\t\+'
elseif line_nr != a:begin " Delete head tab character.
call setline('.', base_indent . current_line) let current_line = substitute(getline('.'), '^\t', '', '')
if &l:expandtab && current_line =~ '^\t\+'
" Expand tab.
cal setline('.', substitute(current_line,
\ '^\t\+', base_indent . repeat(' ', &shiftwidth *
\ len(matchstr(current_line, '^\t\+'))), ''))
elseif line_nr != a:begin
call setline('.', base_indent . current_line)
endif
else
silent normal! ==
endif endif
else endfor
silent normal! == finally
endif let &l:equalprg = equalprg
endfor call setpos('.', pos)
endtry
call setpos('.', pos)
let &l:equalprg = equalprg
endfunction"}}} endfunction"}}}
function! s:get_snippet_range(begin_line, begin_patterns, end_line, end_patterns)"{{{ function! s:get_snippet_range(begin_line, begin_patterns, end_line, end_patterns)"{{{

View File

@ -407,6 +407,9 @@ snippet *neosnippet-unite-action-snippet*
============================================================================== ==============================================================================
CHANGELOG *neosnippet-changelog* CHANGELOG *neosnippet-changelog*
2012-10-06
- Improved indent snippet behavior.
2012-10-04 2012-10-04
- Refactored snippets filter. - Refactored snippets filter.
- Changed :NeoSnippetEdit behavior. - Changed :NeoSnippetEdit behavior.