On 14-May-2011 Lech Lorens <lech.lor...@gmail.com> wrote: [...] I updated the previously sent patch with a more verbose comment. Attaching the updated patch.
-- Cheers, Lech -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php
diff --git a/runtime/doc/todo.txt b/runtime/doc/todo.txt index b96f255..bd48de9 100644 --- a/runtime/doc/todo.txt +++ b/runtime/doc/todo.txt @@ -3801,8 +3801,6 @@ Insert mode: 'cindent', 'smartindent': -9 "} else" causes following lines to be indented too much. (Rouben - Rostamian, 2008 Aug 30) 9 Wrapping a variable initialization should have extra indent: char * veryLongName = "very long string" diff --git a/src/misc1.c b/src/misc1.c index f1ab848..039fe3c 100644 --- a/src/misc1.c +++ b/src/misc1.c @@ -7542,12 +7542,19 @@ get_c_indent() * If whilelevel != 0 continue looking for a "do {". */ if (cin_iselse(l) - && whilelevel == 0 - && ((trypos = find_start_brace(ind_maxcomment)) - == NULL + && whilelevel == 0) + { + /* If we're looking at "} else", let's make sure we + * find the opening brace of the enclosing scope, + * not the one from "if () {". */ + if ('}' == *l) + curwin->w_cursor.col = 1 + (l - ml_get_curline()); + + if ((trypos = find_start_brace(ind_maxcomment)) == NULL || find_match(LOOKFOR_IF, trypos->lnum, - ind_maxparen, ind_maxcomment) == FAIL)) - break; + ind_maxparen, ind_maxcomment) == FAIL) + break; + } } /* diff --git a/src/testdir/test3.in b/src/testdir/test3.in index 56a1dc8..3678c41 100644 --- a/src/testdir/test3.in +++ b/src/testdir/test3.in @@ -1385,6 +1385,21 @@ void func(void) } STARTTEST +:set cino& +2kdd=][ +ENDTEST + +void func(void) +{ + for (int i = 0; i < 10; ++i) + if (i & 1) { + foo(1); + } else + foo(0); +baz(); +} + +STARTTEST :g/^STARTTEST/.,/^ENDTEST/d :1;/start of AUTO/,$wq! test.out ENDTEST diff --git a/src/testdir/test3.ok b/src/testdir/test3.ok index 656b16e..0fee544 100644 --- a/src/testdir/test3.ok +++ b/src/testdir/test3.ok @@ -1234,3 +1234,14 @@ void func(void) foo(); } + +void func(void) +{ + for (int i = 0; i < 10; ++i) + if (i & 1) { + foo(1); + } else + foo(0); + baz(); +} +