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: C-indenting wrong for a function header.
12 Solution: Skip to the start paren. (Lech Lorens)
13 Files: src/misc1.c, src/testdir/test3.in, src/testdir/test3.ok
16 *** ../vim-7.3.379/src/misc1.c 2011-12-14 20:05:17.000000000 +0100
17 --- src/misc1.c 2011-12-14 20:16:43.000000000 +0100
20 static int cin_islinecomment __ARGS((char_u *));
21 static int cin_isterminated __ARGS((char_u *, int, int));
22 static int cin_isinit __ARGS((void));
23 ! static int cin_isfuncdecl __ARGS((char_u **, linenr_T));
24 static int cin_isif __ARGS((char_u *));
25 static int cin_iselse __ARGS((char_u *));
26 static int cin_isdo __ARGS((char_u *));
28 static int cin_islinecomment __ARGS((char_u *));
29 static int cin_isterminated __ARGS((char_u *, int, int));
30 static int cin_isinit __ARGS((void));
31 ! static int cin_isfuncdecl __ARGS((char_u **, linenr_T, linenr_T, int, int));
32 static int cin_isif __ARGS((char_u *));
33 static int cin_iselse __ARGS((char_u *));
34 static int cin_isdo __ARGS((char_u *));
37 * "sp" points to a string with the line. When looking at other lines it must
38 * be restored to the line. When it's NULL fetch lines here.
39 * "lnum" is where we start looking.
42 ! cin_isfuncdecl(sp, first_lnum)
47 linenr_T lnum = first_lnum;
55 /* Ignore line starting with #. */
59 * "sp" points to a string with the line. When looking at other lines it must
60 * be restored to the line. When it's NULL fetch lines here.
61 * "lnum" is where we start looking.
62 + * "min_lnum" is the line before which we will not be looking.
65 ! cin_isfuncdecl(sp, first_lnum, min_lnum, ind_maxparen, ind_maxcomment)
73 linenr_T lnum = first_lnum;
76 + int just_started = TRUE;
83 + if (find_last_paren(s, '(', ')')
84 + && (trypos = find_match_paren(ind_maxparen, ind_maxcomment)) != NULL)
86 + lnum = trypos->lnum;
87 + if (lnum < min_lnum)
93 /* Ignore line starting with #. */
98 /* Require a comma at end of the line or a comma or ')' at the
99 * start of next line. */
101 ! if (!comma && *s != ',' && *s != ')')
104 else if (cin_iscomment(s)) /* ignore comments */
105 s = cin_skipcomment(s);
112 /* Require a comma at end of the line or a comma or ')' at the
113 * start of next line. */
115 ! if (!just_started && (!comma && *s != ',' && *s != ')'))
117 + just_started = FALSE;
119 else if (cin_iscomment(s)) /* ignore comments */
120 s = cin_skipcomment(s);
124 + just_started = FALSE;
131 * (it's a variable declaration).
133 if (start_brace != BRACE_IN_COL0
134 ! || !cin_isfuncdecl(&l, curwin->w_cursor.lnum))
136 /* if the line is terminated with another ','
137 * it is a continued variable initialization.
139 * (it's a variable declaration).
141 if (start_brace != BRACE_IN_COL0
142 ! || !cin_isfuncdecl(&l, curwin->w_cursor.lnum,
143 ! 0, ind_maxparen, ind_maxcomment))
145 /* if the line is terminated with another ','
146 * it is a continued variable initialization.
149 && vim_strchr(theline, '}') == NULL
150 && !cin_ends_in(theline, (char_u *)":", NULL)
151 && !cin_ends_in(theline, (char_u *)",", NULL)
152 ! && cin_isfuncdecl(NULL, cur_curpos.lnum + 1)
153 && !cin_isterminated(theline, FALSE, TRUE))
155 amount = ind_func_type;
157 && vim_strchr(theline, '}') == NULL
158 && !cin_ends_in(theline, (char_u *)":", NULL)
159 && !cin_ends_in(theline, (char_u *)",", NULL)
160 ! && cin_isfuncdecl(NULL, cur_curpos.lnum + 1,
161 ! cur_curpos.lnum + 1,
162 ! ind_maxparen, ind_maxcomment)
163 && !cin_isterminated(theline, FALSE, TRUE))
165 amount = ind_func_type;
168 * If the line looks like a function declaration, and we're
169 * not in a comment, put it the left margin.
171 ! if (cin_isfuncdecl(NULL, cur_curpos.lnum)) /* XXX */
173 l = ml_get_curline();
176 * If the line looks like a function declaration, and we're
177 * not in a comment, put it the left margin.
179 ! if (cin_isfuncdecl(NULL, cur_curpos.lnum, 0,
180 ! ind_maxparen, ind_maxcomment)) /* XXX */
182 l = ml_get_curline();
186 * line (and the ones that follow) needs to be indented as
189 ! if (cin_isfuncdecl(&l, curwin->w_cursor.lnum))
194 * line (and the ones that follow) needs to be indented as
197 ! if (cin_isfuncdecl(&l, curwin->w_cursor.lnum, 0,
198 ! ind_maxparen, ind_maxcomment))
202 *** ../vim-7.3.379/src/testdir/test3.in 2011-12-14 20:05:17.000000000 +0100
203 --- src/testdir/test3.in 2011-12-14 20:11:24.000000000 +0100
226 ! printf("Don't you dare indent this line incorrectly!\n);
234 ! printf("Don't you dare indent this line incorrectly!\n");
260 *** ../vim-7.3.379/src/testdir/test3.ok 2011-12-14 20:05:17.000000000 +0100
261 --- src/testdir/test3.ok 2011-12-14 20:11:24.000000000 +0100
267 ! printf("Don't you dare indent this line incorrectly!\n);
275 ! printf("Don't you dare indent this line incorrectly!\n");
301 *** ../vim-7.3.379/src/version.c 2011-12-14 20:05:17.000000000 +0100
302 --- src/version.c 2011-12-14 20:20:50.000000000 +0100
306 { /* Add new patch number below this line */
312 "Intelligence has much less practical application than you'd think."
313 -- Scott Adams, Dilbert.
315 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
316 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
317 \\\ an exciting new programming language -- http://www.Zimbu.org ///
318 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///