]> git.pld-linux.org Git - packages/vim.git/blame - 7.3.380
- new
[packages/vim.git] / 7.3.380
CommitLineData
d034a75d
AG
1To: vim_dev@googlegroups.com
2Subject: Patch 7.3.380
3Fcc: outbox
4From: Bram Moolenaar <Bram@moolenaar.net>
5Mime-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8------------
9
10Patch 7.3.380
11Problem: C-indenting wrong for a function header.
12Solution: Skip to the start paren. (Lech Lorens)
13Files: src/misc1.c, src/testdir/test3.in, src/testdir/test3.ok
14
15
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
18***************
19*** 4943,4949 ****
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 *));
27--- 4943,4949 ----
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 *));
35***************
36*** 5585,5605 ****
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.
40 */
41 static int
42! cin_isfuncdecl(sp, first_lnum)
43 char_u **sp;
44 linenr_T first_lnum;
45 {
46 char_u *s;
47 linenr_T lnum = first_lnum;
48 int retval = FALSE;
49
50 if (sp == NULL)
51 s = ml_get(lnum);
52 else
53 s = *sp;
54
55 /* Ignore line starting with #. */
56 if (cin_ispreproc(s))
57 return FALSE;
58--- 5585,5621 ----
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.
63 */
64 static int
65! cin_isfuncdecl(sp, first_lnum, min_lnum, ind_maxparen, ind_maxcomment)
66 char_u **sp;
67 linenr_T first_lnum;
68+ linenr_T min_lnum;
69+ int ind_maxparen;
70+ int ind_maxcomment;
71 {
72 char_u *s;
73 linenr_T lnum = first_lnum;
74 int retval = FALSE;
75+ pos_T *trypos;
76+ int just_started = TRUE;
77
78 if (sp == NULL)
79 s = ml_get(lnum);
80 else
81 s = *sp;
82
83+ if (find_last_paren(s, '(', ')')
84+ && (trypos = find_match_paren(ind_maxparen, ind_maxcomment)) != NULL)
85+ {
86+ lnum = trypos->lnum;
87+ if (lnum < min_lnum)
88+ return FALSE;
89+
90+ s = ml_get(lnum);
91+ }
92+
93 /* Ignore line starting with #. */
94 if (cin_ispreproc(s))
95 return FALSE;
96***************
97*** 5650,5662 ****
98 /* Require a comma at end of the line or a comma or ')' at the
99 * start of next line. */
100 s = skipwhite(s);
101! if (!comma && *s != ',' && *s != ')')
102 break;
103 }
104 else if (cin_iscomment(s)) /* ignore comments */
105 s = cin_skipcomment(s);
106 else
107 ++s;
108 }
109
110 done:
111--- 5666,5682 ----
112 /* Require a comma at end of the line or a comma or ')' at the
113 * start of next line. */
114 s = skipwhite(s);
115! if (!just_started && (!comma && *s != ',' && *s != ')'))
116 break;
117+ just_started = FALSE;
118 }
119 else if (cin_iscomment(s)) /* ignore comments */
120 s = cin_skipcomment(s);
121 else
122+ {
123 ++s;
124+ just_started = FALSE;
125+ }
126 }
127
128 done:
129***************
130*** 7158,7164 ****
131 * (it's a variable declaration).
132 */
133 if (start_brace != BRACE_IN_COL0
134! || !cin_isfuncdecl(&l, curwin->w_cursor.lnum))
135 {
136 /* if the line is terminated with another ','
137 * it is a continued variable initialization.
138--- 7178,7185 ----
139 * (it's a variable declaration).
140 */
141 if (start_brace != BRACE_IN_COL0
142! || !cin_isfuncdecl(&l, curwin->w_cursor.lnum,
143! 0, ind_maxparen, ind_maxcomment))
144 {
145 /* if the line is terminated with another ','
146 * it is a continued variable initialization.
147***************
148*** 8019,8025 ****
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))
154 {
155 amount = ind_func_type;
156--- 8040,8048 ----
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))
164 {
165 amount = ind_func_type;
166***************
167*** 8125,8131 ****
168 * If the line looks like a function declaration, and we're
169 * not in a comment, put it the left margin.
170 */
171! if (cin_isfuncdecl(NULL, cur_curpos.lnum)) /* XXX */
172 break;
173 l = ml_get_curline();
174
175--- 8148,8155 ----
176 * If the line looks like a function declaration, and we're
177 * not in a comment, put it the left margin.
178 */
179! if (cin_isfuncdecl(NULL, cur_curpos.lnum, 0,
180! ind_maxparen, ind_maxcomment)) /* XXX */
181 break;
182 l = ml_get_curline();
183
184***************
185*** 8173,8179 ****
186 * line (and the ones that follow) needs to be indented as
187 * parameters.
188 */
189! if (cin_isfuncdecl(&l, curwin->w_cursor.lnum))
190 {
191 amount = ind_param;
192 break;
193--- 8197,8204 ----
194 * line (and the ones that follow) needs to be indented as
195 * parameters.
196 */
197! if (cin_isfuncdecl(&l, curwin->w_cursor.lnum, 0,
198! ind_maxparen, ind_maxcomment))
199 {
200 amount = ind_param;
201 break;
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
204***************
205*** 1429,1435 ****
206
207 STARTTEST
208 :set cino&
209! 2kdd=4][
210 ENDTEST
211
212 void func(void)
213--- 1429,1435 ----
214
215 STARTTEST
216 :set cino&
217! 2kdd=7][
218 ENDTEST
219
220 void func(void)
221***************
222*** 1478,1484 ****
223 3, 4,
224 5, 6};
225
226! printf("Don't you dare indent this line incorrectly!\n);
227 }
228
229 STARTTEST
230--- 1478,1506 ----
231 3, 4,
232 5, 6};
233
234! printf("Don't you dare indent this line incorrectly!\n");
235! }
236!
237! void
238! func4(a, b,
239! c)
240! int a;
241! int b;
242! int c;
243! {
244! }
245!
246! void
247! func5(
248! int a,
249! int b)
250! {
251! }
252!
253! void
254! func6(
255! int a)
256! {
257 }
258
259 STARTTEST
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
262***************
263*** 1331,1337 ****
264 3, 4,
265 5, 6};
266
267! printf("Don't you dare indent this line incorrectly!\n);
268 }
269
270
271--- 1331,1359 ----
272 3, 4,
273 5, 6};
274
275! printf("Don't you dare indent this line incorrectly!\n");
276! }
277!
278! void
279! func4(a, b,
280! c)
281! int a;
282! int b;
283! int c;
284! {
285! }
286!
287! void
288! func5(
289! int a,
290! int b)
291! {
292! }
293!
294! void
295! func6(
296! int a)
297! {
298 }
299
300
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
303***************
304*** 716,717 ****
305--- 716,719 ----
306 { /* Add new patch number below this line */
307+ /**/
308+ 380,
309 /**/
310
311--
312"Intelligence has much less practical application than you'd think."
313 -- Scott Adams, Dilbert.
314
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 ///
This page took 0.06608 seconds and 4 git commands to generate.