Skip to content

Commit

Permalink
Fix expand_cr behavior with 'smartindent'
Browse files Browse the repository at this point in the history
When indentation is controlled by 'smartindent', the expand_cr behavior
doesn't end up producing the same results that you would get without
delimitMate. The following behavior results instead:

Before: {|}
After: {
		|
	}

The expected behavior is to produce the following:

Before: {|}
After: {
	|
}

To that end, detect when indentation is controlled by 'smartindent' and
adjust the indentation of the close line to match.
  • Loading branch information
lilyball authored and blueyed committed Jun 15, 2014
1 parent 21072cf commit 5e96f61
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion autoload/delimitMate.vim
Expand Up @@ -484,10 +484,21 @@ function! delimitMate#ExpandReturn() "{{{
\ && (delimitMate#WithinEmptyMatchpair()
\ || expand_right_matchpair
\ || 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:
" XXX zv prevents breaking expansion with syntax folding enabled by
" InsertLeave.
return "\<Esc>a\<CR>\<Esc>zvO"
let val .= "\<Esc>zvO"
return val
else
return "\<CR>"
endif
Expand Down

0 comments on commit 5e96f61

Please sign in to comment.