Merge pull request #180 from kballard/fix_expand_cr_smartindent

Fix expand_cr behavior with 'smartindent'
This commit is contained in:
Israel Chauca Fuentes
2014-11-27 02:45:59 -05:00

View File

@@ -488,10 +488,21 @@ function! delimitMate#ExpandReturn() "{{{
\ && (delimitMate#WithinEmptyMatchpair() \ && (delimitMate#WithinEmptyMatchpair()
\ || expand_right_matchpair \ || expand_right_matchpair
\ || expand_inside_quotes) \ || expand_inside_quotes)
let val = "\<Esc>a\<CR>"
if &smartindent && !&cindent && !&indentexpr
\ && delimitMate#GetCharFromCursor(0) == '}'
" indentation is controlled by 'smartindent', and the first character on
" the new line is '}'. If this were typed manually it would reindent to
" match the current line. Let's reproduce that behavior.
let shifts = indent('.') / &sw
let spaces = indent('.') - (shifts * &sw)
let val .= "^\<C-D>".repeat("\<C-T>", shifts).repeat(' ', spaces)
endif
" Expand: " Expand:
" XXX zv prevents breaking expansion with syntax folding enabled by " XXX zv prevents breaking expansion with syntax folding enabled by
" InsertLeave. " InsertLeave.
return "\<Esc>a\<CR>\<Esc>zvO" let val .= "\<Esc>zvO"
return val
else else
return "\<CR>" return "\<CR>"
endif endif