diff options
author | Bram Moolenaar <Bram@vim.org> | 2011-05-19 16:35:09 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2011-05-19 16:35:09 +0200 |
commit | 496f9517cb2630cd902be85e51e3ab395a194e85 (patch) | |
tree | 2a8397bda1a6256b31a362d4a31571d037501608 /src/misc1.c | |
parent | 1385c3ee7f8715796c87d9bb020326ecc681e95d (diff) | |
download | vim-git-496f9517cb2630cd902be85e51e3ab395a194e85.tar.gz |
updated for version 7.3.195v7.3.195
Problem: "} else" causes following lines to be indented too much. (Rouben
Rostamian)
Solution: Better detection for the "else". (Lech Lorens)
Diffstat (limited to 'src/misc1.c')
-rw-r--r-- | src/misc1.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/misc1.c b/src/misc1.c index f1ab84879..0959e2a24 100644 --- a/src/misc1.c +++ b/src/misc1.c @@ -5482,8 +5482,8 @@ cin_islinecomment(p) * Recognize a line that starts with '{' or '}', or ends with ';', ',', '{' or * '}'. * Don't consider "} else" a terminated line. - * Don't consider a line where there are unmatched opening braces before '}', - * ';' or ',' a terminated line. + * If a line begins with an "else", only consider it terminated if no unmatched + * opening braces follow (handle "else { foo();" correctly). * Return the character terminating the line (ending char's have precedence if * both apply in order to determine initializations). */ @@ -5493,21 +5493,25 @@ cin_isterminated(s, incl_open, incl_comma) int incl_open; /* include '{' at the end as terminator */ int incl_comma; /* recognize a trailing comma */ { - char_u found_start = 0; - unsigned n_open = 0; + char_u found_start = 0; + unsigned n_open = 0; + int is_else = FALSE; s = cin_skipcomment(s); if (*s == '{' || (*s == '}' && !cin_iselse(s))) found_start = *s; + if (!found_start) + is_else = cin_iselse(s); + while (*s) { /* skip over comments, "" strings and 'c'haracters */ s = skip_string(cin_skipcomment(s)); if (*s == '}' && n_open > 0) --n_open; - if (n_open == 0 + if ((!is_else || n_open == 0) && (*s == ';' || *s == '}' || (incl_comma && *s == ',')) && cin_nocode(s + 1)) return *s; |