comparison src/misc1.c @ 2843:8dbea5adc937 v7.3.195

updated for version 7.3.195 Problem: "} else" causes following lines to be indented too much. (Rouben Rostamian) Solution: Better detection for the "else". (Lech Lorens)
author Bram Moolenaar <bram@vim.org>
date Thu, 19 May 2011 16:35:09 +0200
parents 8bd38abda314
children 78859ef2982b
comparison
equal deleted inserted replaced
2842:d26e38796007 2843:8dbea5adc937
5480 5480
5481 /* 5481 /*
5482 * Recognize a line that starts with '{' or '}', or ends with ';', ',', '{' or 5482 * Recognize a line that starts with '{' or '}', or ends with ';', ',', '{' or
5483 * '}'. 5483 * '}'.
5484 * Don't consider "} else" a terminated line. 5484 * Don't consider "} else" a terminated line.
5485 * Don't consider a line where there are unmatched opening braces before '}', 5485 * If a line begins with an "else", only consider it terminated if no unmatched
5486 * ';' or ',' a terminated line. 5486 * opening braces follow (handle "else { foo();" correctly).
5487 * Return the character terminating the line (ending char's have precedence if 5487 * Return the character terminating the line (ending char's have precedence if
5488 * both apply in order to determine initializations). 5488 * both apply in order to determine initializations).
5489 */ 5489 */
5490 static int 5490 static int
5491 cin_isterminated(s, incl_open, incl_comma) 5491 cin_isterminated(s, incl_open, incl_comma)
5492 char_u *s; 5492 char_u *s;
5493 int incl_open; /* include '{' at the end as terminator */ 5493 int incl_open; /* include '{' at the end as terminator */
5494 int incl_comma; /* recognize a trailing comma */ 5494 int incl_comma; /* recognize a trailing comma */
5495 { 5495 {
5496 char_u found_start = 0; 5496 char_u found_start = 0;
5497 unsigned n_open = 0; 5497 unsigned n_open = 0;
5498 int is_else = FALSE;
5498 5499
5499 s = cin_skipcomment(s); 5500 s = cin_skipcomment(s);
5500 5501
5501 if (*s == '{' || (*s == '}' && !cin_iselse(s))) 5502 if (*s == '{' || (*s == '}' && !cin_iselse(s)))
5502 found_start = *s; 5503 found_start = *s;
5504
5505 if (!found_start)
5506 is_else = cin_iselse(s);
5503 5507
5504 while (*s) 5508 while (*s)
5505 { 5509 {
5506 /* skip over comments, "" strings and 'c'haracters */ 5510 /* skip over comments, "" strings and 'c'haracters */
5507 s = skip_string(cin_skipcomment(s)); 5511 s = skip_string(cin_skipcomment(s));
5508 if (*s == '}' && n_open > 0) 5512 if (*s == '}' && n_open > 0)
5509 --n_open; 5513 --n_open;
5510 if (n_open == 0 5514 if ((!is_else || n_open == 0)
5511 && (*s == ';' || *s == '}' || (incl_comma && *s == ',')) 5515 && (*s == ';' || *s == '}' || (incl_comma && *s == ','))
5512 && cin_nocode(s + 1)) 5516 && cin_nocode(s + 1))
5513 return *s; 5517 return *s;
5514 else if (*s == '{') 5518 else if (*s == '{')
5515 { 5519 {