diff options
-rw-r--r-- | runtime/doc/indent.txt | 12 | ||||
-rw-r--r-- | src/buffer.c | 3 | ||||
-rw-r--r-- | src/edit.c | 6 | ||||
-rw-r--r-- | src/eval.c | 2 | ||||
-rw-r--r-- | src/ex_getln.c | 6 | ||||
-rw-r--r-- | src/fold.c | 2 | ||||
-rw-r--r-- | src/misc1.c | 726 | ||||
-rw-r--r-- | src/ops.c | 7 | ||||
-rw-r--r-- | src/option.c | 29 | ||||
-rw-r--r-- | src/proto/misc1.pro | 1 | ||||
-rw-r--r-- | src/proto/option.pro | 2 | ||||
-rw-r--r-- | src/structs.h | 39 | ||||
-rw-r--r-- | src/version.c | 2 |
13 files changed, 443 insertions, 394 deletions
diff --git a/runtime/doc/indent.txt b/runtime/doc/indent.txt index b700d15e33..3a2a208e85 100644 --- a/runtime/doc/indent.txt +++ b/runtime/doc/indent.txt @@ -545,10 +545,12 @@ The examples below assume a 'shiftwidth' of 4. (default 70 lines). *cino-#* - #N When N is non-zero recognize shell/Perl comments, starting with - '#'. Default N is zero: don't recognize '#' comments. Note - that lines starting with # will still be seen as preprocessor - lines. + #N When N is non-zero recognize shell/Perl comments starting with + '#', do not recognize preprocessor lines; allow right-shifting + lines that start with "#". + When N is zero (default): don't recognize '#' comments, do + recognize preprocessor lines; right-shifting lines that start + with "#" does not work. The defaults, spelled out in full, are: @@ -556,7 +558,7 @@ The defaults, spelled out in full, are: c3,C0,/0,(2s,us,U0,w0,W0,k0,m0,j0,J0,)20,*70,#0 Vim puts a line in column 1 if: -- It starts with '#' (preprocessor directives), if 'cinkeys' contains '#'. +- It starts with '#' (preprocessor directives), if 'cinkeys' contains '#0'. - It starts with a label (a keyword followed by ':', other than "case" and "default") and 'cinoptions' does not contain an 'L' entry with a positive value. diff --git a/src/buffer.c b/src/buffer.c index 7b02ddaf57..8973b42aae 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -211,7 +211,10 @@ open_buffer(read_stdin, eap, flags) /* if first time loading this buffer, init b_chartab[] */ if (curbuf->b_flags & BF_NEVERLOADED) + { (void)buf_init_chartab(curbuf, FALSE); + parse_cino(curbuf); + } /* * Set/reset the Changed flag first, autocmds may change the buffer. diff --git a/src/edit.c b/src/edit.c index 02d822524d..b4469e855a 100644 --- a/src/edit.c +++ b/src/edit.c @@ -8958,7 +8958,7 @@ ins_bs(c, mode, inserted_space_p) *inserted_space_p = FALSE; if (p_sta && in_indent) - ts = (int)get_sw_value(); + ts = (int)get_sw_value(curbuf); else ts = (int)get_sts_value(); /* Compute the virtual column where we want to be. Since @@ -9647,7 +9647,7 @@ ins_tab() * When nothing special, insert TAB like a normal character */ if (!curbuf->b_p_et - && !(p_sta && ind && curbuf->b_p_ts != get_sw_value()) + && !(p_sta && ind && curbuf->b_p_ts != get_sw_value(curbuf)) && get_sts_value() == 0) return TRUE; @@ -9663,7 +9663,7 @@ ins_tab() AppendToRedobuff((char_u *)"\t"); if (p_sta && ind) /* insert tab in indent, use 'shiftwidth' */ - temp = (int)get_sw_value(); + temp = (int)get_sw_value(curbuf); else if (curbuf->b_p_sts != 0) /* use 'softtabstop' when set */ temp = (int)get_sts_value(); else /* otherwise use 'tabstop' */ diff --git a/src/eval.c b/src/eval.c index 0468203cca..14ba4d8b2d 100644 --- a/src/eval.c +++ b/src/eval.c @@ -16934,7 +16934,7 @@ f_shiftwidth(argvars, rettv) typval_T *argvars UNUSED; typval_T *rettv; { - rettv->vval.v_number = get_sw_value(); + rettv->vval.v_number = get_sw_value(curbuf); } /* diff --git a/src/ex_getln.c b/src/ex_getln.c index cdd59def88..7ec47c7028 100644 --- a/src/ex_getln.c +++ b/src/ex_getln.c @@ -2280,7 +2280,7 @@ getexmodeline(promptc, cookie, indent) if (c1 == Ctrl_T) { - long sw = get_sw_value(); + long sw = get_sw_value(curbuf); p = (char_u *)line_ga.ga_data; p[line_ga.ga_len] = NUL; @@ -2337,7 +2337,7 @@ redraw: p[line_ga.ga_len] = NUL; indent = get_indent_str(p, 8); --indent; - indent -= indent % get_sw_value(); + indent -= indent % get_sw_value(curbuf); } while (get_indent_str(p, 8) > indent) { @@ -4178,7 +4178,7 @@ expand_showtail(xp) /* * Prepare a string for expansion. * When expanding file names: The string will be used with expand_wildcards(). - * Copy the file name into allocated memory and add a '*' at the end. + * Copy "fname[len]" into allocated memory and add a '*' at the end. * When expanding other names: The string will be used with regcomp(). Copy * the name into allocated memory and prepend "^". */ diff --git a/src/fold.c b/src/fold.c index a1671fe667..cd58c9153c 100644 --- a/src/fold.c +++ b/src/fold.c @@ -3052,7 +3052,7 @@ foldlevelIndent(flp) flp->lvl = -1; } else - flp->lvl = get_indent_buf(buf, lnum) / get_sw_value(); + flp->lvl = get_indent_buf(buf, lnum) / get_sw_value(curbuf); if (flp->lvl > flp->wp->w_p_fdn) { flp->lvl = flp->wp->w_p_fdn; diff --git a/src/misc1.c b/src/misc1.c index c349015ba0..fa43657a47 100644 --- a/src/misc1.c +++ b/src/misc1.c @@ -1405,7 +1405,7 @@ open_line(dir, flags, second_line_indent) #ifdef FEAT_SMARTINDENT if (did_si) { - int sw = (int)get_sw_value(); + int sw = (int)get_sw_value(curbuf); if (p_sr) newindent -= newindent % sw; @@ -5342,8 +5342,6 @@ static int find_last_paren __ARGS((char_u *l, int start, int end)); static int find_match __ARGS((int lookfor, linenr_T ourscope, int ind_maxparen, int ind_maxcomment)); static int cin_is_cpp_namespace __ARGS((char_u *)); -static int ind_hash_comment = 0; /* # starts a comment */ - /* * Skip over white space and C comments within the line. * Also skip over Perl/shell comments if desired. @@ -5360,7 +5358,7 @@ cin_skipcomment(s) /* Perl/shell # comment comment continues until eol. Require a space * before # to avoid recognizing $#array. */ - if (ind_hash_comment != 0 && s != prev_s && *s == '#') + if (curbuf->b_ind_hash_comment != 0 && s != prev_s && *s == '#') { s += STRLEN(s); break; @@ -6639,201 +6637,229 @@ find_last_paren(l, start, end) return retval; } - int -get_c_indent() +/* + * Parse 'cinoptions' and set the values in "curbuf". + * Must be called when 'cinoptions', 'shiftwidth' and/or 'tabstop' changes. + */ + void +parse_cino(buf) + buf_T *buf; { - int sw = (int)get_sw_value(); + char_u *p; + char_u *l; + char_u *digits; + int n; + int divider; + int fraction = 0; + int sw = (int)get_sw_value(buf); /* - * spaces from a block's opening brace the prevailing indent for that - * block should be + * Set the default values. */ + /* Spaces from a block's opening brace the prevailing indent for that + * block should be. */ + buf->b_ind_level = sw; - int ind_level = sw; + /* Spaces from the edge of the line an open brace that's at the end of a + * line is imagined to be. */ + buf->b_ind_open_imag = 0; - /* - * spaces from the edge of the line an open brace that's at the end of a - * line is imagined to be. - */ - int ind_open_imag = 0; + /* Spaces from the prevailing indent for a line that is not preceded by + * an opening brace. */ + buf->b_ind_no_brace = 0; - /* - * spaces from the prevailing indent for a line that is not preceded by - * an opening brace. - */ - int ind_no_brace = 0; - - /* - * column where the first { of a function should be located } - */ - int ind_first_open = 0; + /* Column where the first { of a function should be located }. */ + buf->b_ind_first_open = 0; - /* - * spaces from the prevailing indent a leftmost open brace should be - * located - */ - int ind_open_extra = 0; + /* Spaces from the prevailing indent a leftmost open brace should be + * located. */ + buf->b_ind_open_extra = 0; - /* - * spaces from the matching open brace (real location for one at the left + /* Spaces from the matching open brace (real location for one at the left * edge; imaginary location from one that ends a line) the matching close - * brace should be located - */ - int ind_close_extra = 0; + * brace should be located. */ + buf->b_ind_close_extra = 0; - /* - * spaces from the edge of the line an open brace sitting in the leftmost - * column is imagined to be - */ - int ind_open_left_imag = 0; + /* Spaces from the edge of the line an open brace sitting in the leftmost + * column is imagined to be. */ + buf->b_ind_open_left_imag = 0; - /* - * Spaces jump labels should be shifted to the left if N is non-negative, - * otherwise the jump label will be put to column 1. - */ - int ind_jump_label = -1; + /* Spaces jump labels should be shifted to the left if N is non-negative, + * otherwise the jump label will be put to column 1. */ + buf->b_ind_jump_label = -1; - /* - * spaces from the switch() indent a "case xx" label should be located - */ - int ind_case = sw; + /* Spaces from the switch() indent a "case xx" label should be located. */ + buf->b_ind_case = sw; - /* - * spaces from the "case xx:" code after a switch() should be located - */ - int ind_case_code = sw; + /* Spaces from the "case xx:" code after a switch() should be located. */ + buf->b_ind_case_code = sw; - /* - * lineup break at end of case in switch() with case label - */ - int ind_case_break = 0; + /* Lineup break at end of case in switch() with case label. */ + buf->b_ind_case_break = 0; - /* - * spaces from the class declaration indent a scope declaration label - * should be located - */ - int ind_scopedecl = sw; + /* Spaces from the class declaration indent a scope declaration label + * should be located. */ + buf->b_ind_scopedecl = sw; - /* - * spaces from the scope declaration label code should be located - */ - int ind_scopedecl_code = sw; + /* Spaces from the scope declaration label code should be located. */ + buf->b_ind_scopedecl_code = sw; - /* - * amount K&R-style parameters should be indented - */ - int ind_param = sw; + /* Amount K&R-style parameters should be indented. */ + buf->b_ind_param = sw; - /* - * amount a function type spec should be indented - */ - int ind_func_type = sw; + /* Amount a function type spec should be indented. */ + buf->b_ind_func_type = sw; - /* - * amount a cpp base class declaration or constructor initialization - * should be indented - */ - int ind_cpp_baseclass = sw; + /* Amount a cpp base class declaration or constructor initialization + * should be indented. */ + buf->b_ind_cpp_baseclass = sw; - /* - * additional spaces beyond the prevailing indent a continuation line - * should be located - */ - int ind_continuation = sw; + /* additional spaces beyond the prevailing indent a continuation line + * should be located. */ + buf->b_ind_continuation = sw; - /* - * spaces from the indent of the line with an unclosed parentheses - */ - int ind_unclosed = sw * 2; + /* Spaces from the indent of the line with an unclosed parentheses. */ + buf->b_ind_unclosed = sw * 2; - /* - * spaces from the indent of the line with an unclosed parentheses, which - * itself is also unclosed - */ - int ind_unclosed2 = sw; + /* Spaces from the indent of the line with an unclosed parentheses, which + * itself is also unclosed. */ + buf->b_ind_unclosed2 = sw; - /* - * suppress ignoring spaces from the indent of a line starting with an - * unclosed parentheses. - */ - int ind_unclosed_noignore = 0; + /* Suppress ignoring spaces from the indent of a line starting with an + * unclosed parentheses. */ + buf->b_ind_unclosed_noignore = 0; - /* - * If the opening paren is the last nonwhite character on the line, and - * ind_unclosed_wrapped is nonzero, use this indent relative to the outer - * context (for very long lines). - */ - int ind_unclosed_wrapped = 0; + /* If the opening paren is the last nonwhite character on the line, and + * b_ind_unclosed_wrapped is nonzero, use this indent relative to the outer + * context (for very long lines). */ + buf->b_ind_unclosed_wrapped = 0; - /* - * suppress ignoring white space when lining up with the character after - * an unclosed parentheses. - */ - int ind_unclosed_whiteok = 0; + /* Suppress ignoring white space when lining up with the character after + * an unclosed parentheses. */ + buf->b_ind_unclosed_whiteok = 0; - /* - * indent a closing parentheses under the line start of the matching - * opening parentheses. - */ - int ind_matching_paren = 0; + /* Indent a closing parentheses under the line start of the matching + * opening parentheses. */ + buf->b_ind_matching_paren = 0; - /* - * indent a closing parentheses under the previous line. - */ - int ind_paren_prev = 0; + /* Indent a closing parentheses under the previous line. */ + buf->b_ind_paren_prev = 0; - /* - * Extra indent for comments. - */ - int ind_comment = 0; + /* Extra indent for comments. */ + buf->b_ind_comment = 0; - /* - * spaces from the comment opener when there is nothing after it. - */ - int ind_in_comment = 3; + /* Spaces from the comment opener when there is nothing after it. */ + buf->b_ind_in_comment = 3; - /* - * boolean: if non-zero, use ind_in_comment even if there is something - * after the comment opener. - */ - int ind_in_comment2 = 0; + /* Boolean: if non-zero, use b_ind_in_comment even if there is something + * after the comment opener. */ + buf->b_ind_in_comment2 = 0; - /* - * max lines to search for an open paren - */ - int ind_maxparen = 20; + /* Max lines to search for an open paren. */ + buf->b_ind_maxparen = 20; - /* - * max lines to search for an open comment - */ - int ind_maxcomment = 70; + /* Max lines to search for an open comment. */ + buf->b_ind_maxcomment = 70; - /* - * handle braces for java code - */ - int ind_java = 0; + /* Handle braces for java code. */ + buf->b_ind_java = 0; - /* - * not to confuse JS object properties with labels - */ - int ind_js = 0; + /* Not to confuse JS object properties with labels. */ + buf->b_ind_js = 0; - /* - * handle blocked cases correctly - */ - int ind_keep_case_label = 0; + /* Handle blocked cases correctly. */ + buf->b_ind_keep_case_label = 0; - /* - * handle C++ namespace - */ - int ind_cpp_namespace = 0; + /* Handle C++ namespace. */ + buf->b_ind_cpp_namespace = 0; - /* - * handle continuation lines containing conditions of if(), for() and - * while() - */ - int ind_if_for_while = 0; + /* Handle continuation lines containing conditions of if(), for() and + * while(). */ + buf->b_ind_if_for_while = 0; + + for (p = buf->b_p_cino; *p; ) + { + l = p++; + if (*p == '-') + ++p; + digits = p; /* remember where the digits start */ + n = getdigits(&p); + divider = 0; + if (*p == '.') /* ".5s" means a fraction */ + { + fraction = atol((char *)++p); + while (VIM_ISDIGIT(*p)) + { + ++p; + if (divider) + divider *= 10; + else + divider = 10; + } + } + if (*p == 's') /* "2s" means two times 'shiftwidth' */ + { + if (p == digits) + n = sw; /* just "s" is one 'shiftwidth' */ + else + { + n *= sw; + if (divider) + n += (sw * fraction + divider / 2) / divider; + } + ++p; + } + if (l[1] == '-') + n = -n; + /* When adding an entry here, also update the default 'cinoptions' in + * doc/indent.txt, and add explanation for it! */ + switch (*l) + { + case '>': buf->b_ind_level = n; break; + case 'e': buf->b_ind_open_imag = n; break; + case 'n': buf->b_ind_no_brace = n; break; + case 'f': buf->b_ind_first_open = n; break; + case '{': buf->b_ind_open_extra = n; break; + case '}': buf->b_ind_close_extra = n; break; + case '^': buf->b_ind_open_left_imag = n; break; + case 'L': buf->b_ind_jump_label = n; break; + case ':': buf->b_ind_case = n; break; + case '=': buf->b_ind_case_code = n; break; + case 'b': buf->b_ind_case_break = n; break; + case 'p': buf->b_ind_param = n; break; + case 't': buf->b_ind_func_type = n; break; + case '/': buf->b_ind_comment = n; break; + case 'c': buf->b_ind_in_comment = n; break; + case 'C': buf->b_ind_in_comment2 = n; break; + case 'i': buf->b_ind_cpp_baseclass = n; break; + case '+': buf->b_ind_continuation = n; break; + case '(': buf->b_ind_unclosed = n; break; + case 'u': buf->b_ind_unclosed2 = n; break; + case 'U': buf->b_ind_unclosed_noignore = n; break; + case 'W': buf->b_ind_unclosed_wrapped = n; break; + case 'w': buf->b_ind_unclosed_whiteok = n; break; + case 'm': buf->b_ind_matching_paren = n; break; + case 'M': buf->b_ind_paren_prev = n; break; + case ')': buf->b_ind_maxparen = n; break; + case '*': buf->b_ind_maxcomment = n; break; + case 'g': buf->b_ind_scopedecl = n; break; + case 'h': buf->b_ind_scopedecl_code = n; break; + case 'j': buf->b_ind_java = n; break; + case 'J': buf->b_ind_js = n; break; + case 'l': buf->b_ind_keep_case_label = n; break; + case '#': buf->b_ind_hash_comment = n; break; + case 'N': buf->b_ind_cpp_namespace = n; break; + case 'k': buf->b_ind_if_for_while = n; break; + } + if (*p == ',') + ++p; + } +} + + int +get_c_indent() +{ pos_T cur_curpos; int amount; int scope_amount; @@ -6868,10 +6894,6 @@ get_c_indent() int whilelevel; linenr_T lnum; - char_u *options; - char_u *digits; - int fraction = 0; /* init for GCC */ - int divider; int n; int iscase; int lookfor_break; @@ -6880,83 +6902,8 @@ get_c_indent() int original_line_islabel; int added_to_amount = 0; - for (options = curbuf->b_p_cino; *options; ) - { - l = options++; - if (*options == '-') - ++options; - digits = options; /* remember where the digits start */ - n = getdigits(&options); - divider = 0; - if (*options == '.') /* ".5s" means a fraction */ - { - fraction = atol((char *)++options); - while (VIM_ISDIGIT(*options)) - { - ++options; - if (divider) - divider *= 10; - else - divider = 10; - } - } - if (*options == 's') /* "2s" means two times 'shiftwidth' */ - { - if (options == digits) - n = sw; /* just "s" is one 'shiftwidth' */ - else - { - n *= sw; - if (divider) - n += (sw * fraction + divider / 2) / divider; - } - ++options; - } - if (l[1] == '-') - n = -n; - /* When adding an entry here, also update the default 'cinoptions' in - * doc/indent.txt, and add explanation for it! */ - switch (*l) - { - case '>': ind_level = n; break; - case 'e': ind_open_imag = n; break; - case 'n': ind_no_brace = n; break; - case 'f': ind_first_open = n; break; - case '{': ind_open_extra = n; break; - case '}': ind_close_extra = n; break; - case '^': ind_open_left_imag = n; break; - case 'L': ind_jump_label = n; break; - case ':': ind_case = n; break; - case '=': ind_case_code = n; break; - case 'b': ind_case_break = n; break; - case 'p': ind_param = n; break; - case 't': ind_func_type = n; break; - case '/': ind_comment = n; break; - case 'c': ind_in_comment = n; break; - case 'C': ind_in_comment2 = n; break; - case 'i': ind_cpp_baseclass = n; break; - case '+': ind_continuation = n; break; - case '(': ind_unclosed = n; break; - case 'u': ind_unclosed2 = n; break; - case 'U': ind_unclosed_noignore = n; break; - case 'W': ind_unclosed_wrapped = n; break; - case 'w': ind_unclosed_whiteok = n; break; - case 'm': ind_matching_paren = n; break; - case 'M': ind_paren_prev = n; break; - case ')': ind_maxparen = n; break; - case '*': ind_maxcomment = n; break; - case 'g': ind_scopedecl = n; break; - case 'h': ind_scopedecl_code = n; break; - case 'j': ind_java = n; break; - case 'J': ind_js = n; break; - case 'l': ind_keep_case_label = n; break; - case '#': ind_hash_comment = n; break; - case 'N': ind_cpp_namespace = n; break; - case 'k': ind_if_for_while = n; break; - } - if (*options == ',') - ++options; - } + /* make a copy, value is changed below */ + int ind_continuation = curbuf->b_ind_continuation; /* remember where the cursor was when we started */ cur_curpos = curwin->w_cursor; @@ -6990,22 +6937,21 @@ get_c_indent() curwin->w_cursor.col = 0; - original_line_islabel = cin_islabel(ind_maxcomment); /* XXX */ + original_line_islabel = cin_islabel(curbuf->b_ind_maxcomment); /* XXX */ /* * #defines and so on always go at the left when included in 'cinkeys'. */ if (*theline == '#' && (*linecopy == '#' || in_cinkeys('#', ' ', TRUE))) - { - amount = 0; - } + amount = curbuf->b_ind_hash_comment; /* * Is it a non-case label? Then that goes at the left margin too unless: * - JS flag is set. * - 'L' item has a positive value. */ - else if (original_line_islabel && !ind_js && ind_jump_label < 0) + else if (original_line_islabel && !curbuf->b_ind_js + && curbuf->b_ind_jump_label < 0) { amount = 0; } @@ -7027,7 +6973,8 @@ get_c_indent() * comment, try using the 'comments' option. */ else if (!cin_iscomment(theline) - && (trypos = find_start_comment(ind_maxcomment)) != NULL) /* XXX */ + && (trypos = find_start_comment(curbuf->b_ind_maxcomment)) != NULL) + /* XXX */ { int lead_start_len = 2; int lead_middle_len = 1; @@ -7161,7 +7108,7 @@ get_c_indent() } if (amount == -1) /* use the comment opener */ { - if (!ind_in_comment2) + if (!curbuf->b_ind_in_comment2) { start = ml_get(trypos->lnum); look = start + trypos->col + 2; /* skip / and * */ @@ -7170,8 +7117,8 @@ get_c_indent() } getvcol(curwin, trypos, &col, NULL, NULL); amount = col; - if (ind_in_comment2 || *look == NUL) - amount += ind_in_comment; + if (curbuf->b_ind_in_comment2 || *look == NUL) + amount += curbuf->b_ind_in_comment; } } } @@ -7179,9 +7126,11 @@ get_c_indent() /* * Are we inside parentheses or braces? */ /* XXX */ - else if (((trypos = find_match_paren(ind_maxparen, ind_maxcomment)) != NULL - && ind_java == 0) - || (tryposBrace = find_start_brace(ind_maxcomment)) != NULL + else if (((trypos = find_match_paren(curbuf->b_ind_maxparen, + curbuf->b_ind_maxcomment)) != NULL + && curbuf->b_ind_java == 0) + || (tryposBrace = + find_start_brace(curbuf->b_ind_maxcomment)) != NULL || trypos != NULL) { if (trypos != NULL && tryposBrace != NULL) @@ -7202,7 +7151,7 @@ get_c_indent() * If the matching paren is more than one line away, use the indent of * a previous non-empty line that matches the same paren. */ - if (theline[0] == ')' && ind_paren_prev) + if (theline[0] == ')' && curbuf->b_ind_paren_prev) { /* Line up with the start of the matching paren line. */ amount = get_indent_lnum(curwin->w_cursor.lnum - 1); /* XXX */ @@ -7221,7 +7170,8 @@ get_c_indent() curwin->w_cursor.lnum = lnum; /* Skip a comment. XXX */ - if ((trypos = find_start_comment(ind_maxcomment)) != NULL) + if ((trypos = find_start_comment(curbuf->b_ind_maxcomment)) + != NULL) { lnum = trypos->lnum + 1; continue; @@ -7229,8 +7179,8 @@ get_c_indent() /* XXX */ if ((trypos = find_match_paren( - corr_ind_maxparen(ind_maxparen, &cur_curpos), - ind_maxcomment)) != NULL + corr_ind_maxparen(curbuf->b_ind_maxparen, &cur_curpos), + curbuf->b_ind_maxcomment)) != NULL && trypos->lnum == our_paren_pos.lnum && trypos->col == our_paren_pos.col) { @@ -7258,7 +7208,7 @@ get_c_indent() int ignore_paren_col = 0; int is_if_for_while = 0; - if (ind_if_for_while) + if (curbuf->b_ind_if_for_while) { /* Look for the outermost opening parenthesis on this line * and check whether it belongs to an "if", "for" or "while". */ @@ -7273,7 +7223,8 @@ get_c_indent() curwin->w_cursor.lnum = outermost.lnum; curwin->w_cursor.col = outermost.col; - trypos = find_match_paren(ind_maxparen, ind_maxcomment); + trypos = find_match_paren(curbuf->b_ind_maxparen, + curbuf->b_ind_maxcomment); } while (trypos && trypos->lnum == outermost.lnum); curwin->w_cursor = cursor_save; @@ -7284,7 +7235,8 @@ get_c_indent() cin_is_if_for_while_before_offset(line, &outermost.col); } - amount = skip_label(our_paren_pos.lnum, &look, ind_maxcomment); + amount = skip_label(our_paren_pos.lnum, &look, + curbuf->b_ind_maxcomment); look = skipwhite(look); if (*look == '(') { @@ -7298,7 +7250,8 @@ get_c_indent() line = ml_get_curline(); look_col = (int)(look - line); curwin->w_cursor.col = look_col + 1; - if ((trypos = findmatchlimit(NULL, ')', 0, ind_maxparen)) + if ((trypos = findmatchlimit(NULL, ')', 0, + curbuf->b_ind_maxparen)) != NULL && trypos->lnum == our_paren_pos.lnum && trypos->col < our_paren_pos.col) @@ -7307,24 +7260,25 @@ get_c_indent() curwin->w_cursor.lnum = save_lnum; look = ml_get(our_paren_pos.lnum) + look_col; } - if (theline[0] == ')' || (ind_unclosed == 0 && is_if_for_while == 0) - || (!ind_unclosed_noignore && *look == '(' + if (theline[0] == ')' || (curbuf->b_ind_unclosed == 0 + && is_if_for_while == 0) + || (!curbuf->b_ind_unclosed_noignore && *look == '(' && ignore_paren_col == 0)) { /* * If we're looking at a close paren, line up right there; * otherwise, line up with the next (non-white) character. - * When ind_unclosed_wrapped is set and the matching paren is + * When b_ind_unclosed_wrapped is set and the matching paren is * the last nonwhite character of the line, use either the * indent of the current line or the indentation of the next - * outer paren and add ind_unclosed_wrapped (for very long + * outer paren and add b_ind_unclosed_wrapped (for very long * lines). */ if (theline[0] != ')') { cur_amount = MAXCOL; l = ml_get(our_paren_pos.lnum); - if (ind_unclosed_wrapped + if (curbuf->b_ind_unclosed_wrapped && cin_ends_in(l, (char_u *)"(", NULL)) { /* look for opening unmatched paren, indent one level @@ -7346,9 +7300,9 @@ get_c_indent() } our_paren_pos.col = 0; - amount += n * ind_unclosed_wrapped; + amount += n * curbuf->b_ind_unclosed_wrapped; } - else if (ind_unclosed_whiteok) + else if (curbuf->b_ind_unclosed_whiteok) our_paren_pos.col++; else { @@ -7374,12 +7328,12 @@ get_c_indent() } } - if (theline[0] == ')' && ind_matching_paren) + if (theline[0] == ')' && curbuf->b_ind_matching_paren) { /* Line up with the start of the matching paren line. */ } - else if ((ind_unclosed == 0 && is_if_for_while == 0) - || (!ind_unclosed_noignore + else if ((curbuf->b_ind_unclosed == 0 && is_if_for_while == 0) + || (!curbuf->b_ind_unclosed_noignore && *look == '(' && ignore_paren_col == 0)) { if (cur_amount != MAXCOL) @@ -7387,39 +7341,40 @@ get_c_indent() } else { - /* Add ind_unclosed2 for each '(' before our matching one, but - * ignore (void) before the line (ignore_paren_col). */ + /* Add b_ind_unclosed2 for each '(' before our matching one, + * but ignore (void) before the line (ignore_paren_col). */ col = our_paren_pos.col; while ((int)our_paren_pos.col > ignore_paren_col) { --our_paren_pos.col; switch (*ml_get_pos(&our_paren_pos)) { - case '(': amount += ind_unclosed2; + case '(': amount += curbuf->b_ind_unclosed2; col = our_paren_pos.col; break; - case ')': amount -= ind_unclosed2; + case ')': amount -= curbuf->b_ind_unclosed2; col = MAXCOL; break; } } - /* Use ind_unclosed once, when the first '(' is not inside + /* Use b_ind_unclosed once, when the first '(' is not inside * braces */ if (col == MAXCOL) - amount += ind_unclosed; + amount += curbuf->b_ind_unclosed; else { curwin->w_cursor.lnum = our_paren_pos.lnum; curwin->w_cursor.col = col; - if (find_match_paren(ind_maxparen, ind_maxcomment) != NULL) - amount += ind_unclosed2; + if (find_match_paren(curbuf->b_ind_maxparen, + curbuf->b_ind_maxcomment) != NULL) + amount += curbuf->b_ind_unclosed2; else { if (is_if_for_while) - amount += ind_if_for_while; + amount += curbuf->b_ind_if_for_while; else - amount += ind_unclosed; + amount += curbuf->b_ind_unclosed; } } /* @@ -7437,7 +7392,7 @@ get_c_indent() /* add extra indent for a comment */ if (cin_iscomment(theline)) - amount += ind_comment; + amount += curbuf->b_ind_comment; } /* @@ -7480,8 +7435,8 @@ get_c_indent() */ lnum = ourscope; if (find_last_paren(start, '(', ')') - && (trypos = find_match_paren(ind_maxparen, - ind_maxcomment)) != NULL) + && (trypos = find_match_paren(curbuf->b_ind_maxparen, + curbuf->b_ind_maxcomment)) != NULL) lnum = trypos->lnum; /* @@ -7490,11 +7445,11 @@ get_c_indent() * ldfd) { * } */ - if (ind_js || (ind_keep_case_label + if (curbuf->b_ind_js || (curbuf->b_ind_keep_case_label && cin_iscase(skipwhite(ml_get_curline()), FALSE))) amount = get_indent(); else - amount = skip_label(lnum, &l, ind_maxcomment); + amount = skip_label(lnum, &l, curbuf->b_ind_maxcomment); start_brace = BRACE_AT_END; } @@ -7510,7 +7465,7 @@ get_c_indent() * they may want closing braces to line up with something * other than the open brace. indulge them, if so. */ - amount += ind_close_extra; + amount += curbuf->b_ind_close_extra; } else { @@ -7523,14 +7478,14 @@ get_c_indent() lookfor = LOOKFOR_INITIAL; if (cin_iselse(theline)) lookfor = LOOKFOR_IF; - else if (cin_iswhileofdo(theline, cur_curpos.lnum, ind_maxparen)) - /* XXX */ + else if (cin_iswhileofdo(theline, cur_curpos.lnum, + curbuf->b_ind_maxparen)) /* XXX */ lookfor = LOOKFOR_DO; if (lookfor != LOOKFOR_INITIAL) { curwin->w_cursor.lnum = cur_curpos.lnum; - if (find_match(lookfor, ourscope, ind_maxparen, - ind_maxcomment) == OK) + if (find_match(lookfor, ourscope, curbuf->b_ind_maxparen, + curbuf->b_ind_maxcomment) == OK) { amount = get_indent(); /* XXX */ goto theend; @@ -7547,12 +7502,12 @@ get_c_indent() /* * if the '{' is _really_ at the left margin, use the imaginary * location of a left-margin brace. Otherwise, correct the - * location for ind_open_extra. + * location for b_ind_open_extra. */ if (start_brace == BRACE_IN_COL0) /* '{' is in column 0 */ { - amount = ind_open_left_imag; + amount = curbuf->b_ind_open_left_imag; lookfor_cpp_namespace = TRUE; } else if (start_brace == BRACE_AT_START && @@ -7565,16 +7520,16 @@ get_c_indent() { if (start_brace == BRACE_AT_END) /* '{' is at end of line */ { - amount += ind_open_imag; + amount += curbuf->b_ind_open_imag; l = skipwhite(ml_get_curline()); if (cin_is_cpp_namespace(l)) - amount += ind_cpp_namespace; + amount += curbuf->b_ind_cpp_namespace; } else { - /* Compensate for adding ind_open_extra later. */ - amount -= ind_open_extra; + /* Compensate for adding b_ind_open_extra later. */ + amount -= curbuf->b_ind_open_extra; if (amount < 0) am |