From 4024181af23eec8a110c6c782bba25fbc8bfd116 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Tue, 3 Jun 2014 18:26:42 -0700 Subject: [PATCH] Fix expand_cr behavior with 'smartindent' 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. --- autoload/delimitMate.vim | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/autoload/delimitMate.vim b/autoload/delimitMate.vim index 035e558..dd3ac5b 100644 --- a/autoload/delimitMate.vim +++ b/autoload/delimitMate.vim @@ -484,10 +484,21 @@ function! delimitMate#ExpandReturn() "{{{ \ && (delimitMate#WithinEmptyMatchpair() \ || expand_right_matchpair \ || expand_inside_quotes) + let val = "\a\" + 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 .= "^\".repeat("\", shifts).repeat(' ', spaces) + endif " Expand: " XXX zv prevents breaking expansion with syntax folding enabled by " InsertLeave. - return "\a\\zvO" + let val .= "\zvO" + return val else return "\" endif