1 To: vim_dev@googlegroups.com
4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: "} else" causes following lines to be indented too much. (Rouben
13 Solution: Better detection for the "else". (Lech Lorens)
14 Files: src/misc1.c, src/testdir/test3.in, src/testdir/test3.ok
17 *** ../vim-7.3.194/src/misc1.c 2011-05-10 16:41:13.000000000 +0200
18 --- src/misc1.c 2011-05-19 16:30:28.000000000 +0200
21 * Recognize a line that starts with '{' or '}', or ends with ';', ',', '{' or
23 * Don't consider "} else" a terminated line.
24 ! * Don't consider a line where there are unmatched opening braces before '}',
25 ! * ';' or ',' a terminated line.
26 * Return the character terminating the line (ending char's have precedence if
27 * both apply in order to determine initializations).
30 * Recognize a line that starts with '{' or '}', or ends with ';', ',', '{' or
32 * Don't consider "} else" a terminated line.
33 ! * If a line begins with an "else", only consider it terminated if no unmatched
34 ! * opening braces follow (handle "else { foo();" correctly).
35 * Return the character terminating the line (ending char's have precedence if
36 * both apply in order to determine initializations).
40 int incl_open; /* include '{' at the end as terminator */
41 int incl_comma; /* recognize a trailing comma */
43 ! char_u found_start = 0;
44 ! unsigned n_open = 0;
46 s = cin_skipcomment(s);
48 if (*s == '{' || (*s == '}' && !cin_iselse(s)))
53 /* skip over comments, "" strings and 'c'haracters */
54 s = skip_string(cin_skipcomment(s));
55 if (*s == '}' && n_open > 0)
58 && (*s == ';' || *s == '}' || (incl_comma && *s == ','))
62 int incl_open; /* include '{' at the end as terminator */
63 int incl_comma; /* recognize a trailing comma */
65 ! char_u found_start = 0;
66 ! unsigned n_open = 0;
67 ! int is_else = FALSE;
69 s = cin_skipcomment(s);
71 if (*s == '{' || (*s == '}' && !cin_iselse(s)))
75 + is_else = cin_iselse(s);
79 /* skip over comments, "" strings and 'c'haracters */
80 s = skip_string(cin_skipcomment(s));
81 if (*s == '}' && n_open > 0)
83 ! if ((!is_else || n_open == 0)
84 && (*s == ';' || *s == '}' || (incl_comma && *s == ','))
87 *** ../vim-7.3.194/src/testdir/test3.in 2011-05-10 13:38:23.000000000 +0200
88 --- src/testdir/test3.in 2011-05-19 16:29:01.000000000 +0200
114 + char* tab[] = {"foo", "bar",
116 + "this line used", "to be indented incorrectly"};
127 + printf("This line used to be indented incorrectly.\n");
137 + printf("Don't you dare indent this line incorrectly!\n);
143 *** ../vim-7.3.194/src/testdir/test3.ok 2011-05-10 13:38:23.000000000 +0200
144 --- src/testdir/test3.ok 2011-05-19 16:29:01.000000000 +0200
153 + char* tab[] = {"foo", "bar",
155 + "this line used", "to be indented incorrectly"};
166 + printf("This line used to be indented incorrectly.\n");
176 + printf("Don't you dare indent this line incorrectly!\n);
182 *** ../vim-7.3.194/src/version.c 2011-05-19 14:59:07.000000000 +0200
183 --- src/version.c 2011-05-19 16:34:16.000000000 +0200
187 { /* Add new patch number below this line */
194 ...for the taxes that I pay because it means that I am employed.
196 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
197 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
198 \\\ an exciting new programming language -- http://www.Zimbu.org ///
199 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///