Mercurial > vim
comparison src/misc1.c @ 3454:214c7ec1c8f9 v7.3.492
updated for version 7.3.492
Problem: Can't indent conditions separately from function arguments.
Solution: Add the 'k' flag in 'cino. (Lech Lorens)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Thu, 05 Apr 2012 17:17:42 +0200 |
parents | 4a2744311b3f |
children | bf5960ec2532 |
comparison
equal
deleted
inserted
replaced
3453:f2ce0c2b95b7 | 3454:214c7ec1c8f9 |
---|---|
5769 } | 5769 } |
5770 return retval; | 5770 return retval; |
5771 } | 5771 } |
5772 | 5772 |
5773 /* | 5773 /* |
5774 * Check whether in "p" there is an "if", "for" or "while" before offset. | |
5775 * Return 0 if there is none. | |
5776 * Otherwise return !0 and update "*poffset" to point to the place where the | |
5777 * string was found. | |
5778 */ | |
5779 static int | |
5780 cin_is_if_for_while_before_offset(line, offset, poffset) | |
5781 char_u *line; | |
5782 size_t offset; | |
5783 int *poffset; | |
5784 { | |
5785 | |
5786 if (offset-- < 2) | |
5787 return 0; | |
5788 while (offset > 2 && vim_iswhite(line[offset])) | |
5789 --offset; | |
5790 | |
5791 offset -= 1; | |
5792 if (!STRNCMP(line + offset, "if", 2)) | |
5793 goto probablyFound; | |
5794 | |
5795 if (offset >= 1) | |
5796 { | |
5797 offset -= 1; | |
5798 if (!STRNCMP(line + offset, "for", 3)) | |
5799 goto probablyFound; | |
5800 | |
5801 if (offset >= 2) | |
5802 { | |
5803 offset -= 2; | |
5804 if (!STRNCMP(line + offset, "while", 5)) | |
5805 goto probablyFound; | |
5806 } | |
5807 } | |
5808 | |
5809 return 0; | |
5810 probablyFound: | |
5811 if (!offset || !vim_isIDc(line[offset - 1])) | |
5812 { | |
5813 *poffset = offset; | |
5814 return 1; | |
5815 } | |
5816 return 0; | |
5817 } | |
5818 | |
5819 /* | |
5774 * Return TRUE if we are at the end of a do-while. | 5820 * Return TRUE if we are at the end of a do-while. |
5775 * do | 5821 * do |
5776 * nothing; | 5822 * nothing; |
5777 * while (foo | 5823 * while (foo |
5778 * && bar); <-- here | 5824 * && bar); <-- here |
6122 return trypos; | 6168 return trypos; |
6123 } | 6169 } |
6124 | 6170 |
6125 /* | 6171 /* |
6126 * Find the matching '(', failing if it is in a comment. | 6172 * Find the matching '(', failing if it is in a comment. |
6127 * Return NULL of no match found. | 6173 * Return NULL if no match found. |
6128 */ | 6174 */ |
6129 static pos_T * | 6175 static pos_T * |
6130 find_match_paren(ind_maxparen, ind_maxcomment) /* XXX */ | 6176 find_match_paren(ind_maxparen, ind_maxcomment) /* XXX */ |
6131 int ind_maxparen; | 6177 int ind_maxparen; |
6132 int ind_maxcomment; | 6178 int ind_maxcomment; |
6390 | 6436 |
6391 /* | 6437 /* |
6392 * handle C++ namespace | 6438 * handle C++ namespace |
6393 */ | 6439 */ |
6394 int ind_cpp_namespace = 0; | 6440 int ind_cpp_namespace = 0; |
6441 | |
6442 /* | |
6443 * handle continuation lines containing conditions of if(), for() and | |
6444 * while() | |
6445 */ | |
6446 int ind_if_for_while = 0; | |
6395 | 6447 |
6396 pos_T cur_curpos; | 6448 pos_T cur_curpos; |
6397 int amount; | 6449 int amount; |
6398 int scope_amount; | 6450 int scope_amount; |
6399 int cur_amount = MAXCOL; | 6451 int cur_amount = MAXCOL; |
6435 int lookfor_break; | 6487 int lookfor_break; |
6436 int lookfor_cpp_namespace = FALSE; | 6488 int lookfor_cpp_namespace = FALSE; |
6437 int cont_amount = 0; /* amount for continuation line */ | 6489 int cont_amount = 0; /* amount for continuation line */ |
6438 int original_line_islabel; | 6490 int original_line_islabel; |
6439 int added_to_amount = 0; | 6491 int added_to_amount = 0; |
6492 int is_if_for_while = 0; | |
6440 | 6493 |
6441 for (options = curbuf->b_p_cino; *options; ) | 6494 for (options = curbuf->b_p_cino; *options; ) |
6442 { | 6495 { |
6443 l = options++; | 6496 l = options++; |
6444 if (*options == '-') | 6497 if (*options == '-') |
6507 case 'j': ind_java = n; break; | 6560 case 'j': ind_java = n; break; |
6508 case 'J': ind_js = n; break; | 6561 case 'J': ind_js = n; break; |
6509 case 'l': ind_keep_case_label = n; break; | 6562 case 'l': ind_keep_case_label = n; break; |
6510 case '#': ind_hash_comment = n; break; | 6563 case '#': ind_hash_comment = n; break; |
6511 case 'N': ind_cpp_namespace = n; break; | 6564 case 'N': ind_cpp_namespace = n; break; |
6565 case 'k': ind_if_for_while = n; break; | |
6512 } | 6566 } |
6513 if (*options == ',') | 6567 if (*options == ',') |
6514 ++options; | 6568 ++options; |
6515 } | 6569 } |
6516 | 6570 |
6810 * parentheses is zero, line up with the unclosed parentheses. | 6864 * parentheses is zero, line up with the unclosed parentheses. |
6811 */ | 6865 */ |
6812 if (amount == -1) | 6866 if (amount == -1) |
6813 { | 6867 { |
6814 int ignore_paren_col = 0; | 6868 int ignore_paren_col = 0; |
6869 int is_if_for_while = 0; | |
6870 | |
6871 if (ind_if_for_while) | |
6872 { | |
6873 /* Look for the outermost opening parenthesis on this line | |
6874 * and check whether it belongs to an "if", "for" or "while". */ | |
6875 | |
6876 pos_T cursor_save = curwin->w_cursor; | |
6877 pos_T outermost; | |
6878 char_u *line; | |
6879 int look_col; | |
6880 | |
6881 trypos = &our_paren_pos; | |
6882 do { | |
6883 outermost = *trypos; | |
6884 curwin->w_cursor.lnum = outermost.lnum; | |
6885 curwin->w_cursor.col = outermost.col; | |
6886 | |
6887 trypos = find_match_paren(ind_maxparen, ind_maxcomment); | |
6888 } while (trypos && trypos->lnum == outermost.lnum); | |
6889 | |
6890 curwin->w_cursor = cursor_save; | |
6891 | |
6892 line = ml_get(outermost.lnum); | |
6893 | |
6894 is_if_for_while = | |
6895 cin_is_if_for_while_before_offset(line, outermost.col, | |
6896 &outermost.col); | |
6897 } | |
6815 | 6898 |
6816 amount = skip_label(our_paren_pos.lnum, &look, ind_maxcomment); | 6899 amount = skip_label(our_paren_pos.lnum, &look, ind_maxcomment); |
6817 look = skipwhite(look); | 6900 look = skipwhite(look); |
6818 if (*look == '(') | 6901 if (*look == '(') |
6819 { | 6902 { |
6834 ignore_paren_col = trypos->col + 1; | 6917 ignore_paren_col = trypos->col + 1; |
6835 | 6918 |
6836 curwin->w_cursor.lnum = save_lnum; | 6919 curwin->w_cursor.lnum = save_lnum; |
6837 look = ml_get(our_paren_pos.lnum) + look_col; | 6920 look = ml_get(our_paren_pos.lnum) + look_col; |
6838 } | 6921 } |
6839 if (theline[0] == ')' || ind_unclosed == 0 | 6922 if (theline[0] == ')' || (ind_unclosed == 0 && is_if_for_while == 0) |
6840 || (!ind_unclosed_noignore && *look == '(' | 6923 || (!ind_unclosed_noignore && *look == '(' |
6841 && ignore_paren_col == 0)) | 6924 && ignore_paren_col == 0)) |
6842 { | 6925 { |
6843 /* | 6926 /* |
6844 * If we're looking at a close paren, line up right there; | 6927 * If we're looking at a close paren, line up right there; |
6905 | 6988 |
6906 if (theline[0] == ')' && ind_matching_paren) | 6989 if (theline[0] == ')' && ind_matching_paren) |
6907 { | 6990 { |
6908 /* Line up with the start of the matching paren line. */ | 6991 /* Line up with the start of the matching paren line. */ |
6909 } | 6992 } |
6910 else if (ind_unclosed == 0 || (!ind_unclosed_noignore | 6993 else if ((ind_unclosed == 0 && is_if_for_while == 0) |
6994 || (!ind_unclosed_noignore | |
6911 && *look == '(' && ignore_paren_col == 0)) | 6995 && *look == '(' && ignore_paren_col == 0)) |
6912 { | 6996 { |
6913 if (cur_amount != MAXCOL) | 6997 if (cur_amount != MAXCOL) |
6914 amount = cur_amount; | 6998 amount = cur_amount; |
6915 } | 6999 } |
6941 curwin->w_cursor.lnum = our_paren_pos.lnum; | 7025 curwin->w_cursor.lnum = our_paren_pos.lnum; |
6942 curwin->w_cursor.col = col; | 7026 curwin->w_cursor.col = col; |
6943 if (find_match_paren(ind_maxparen, ind_maxcomment) != NULL) | 7027 if (find_match_paren(ind_maxparen, ind_maxcomment) != NULL) |
6944 amount += ind_unclosed2; | 7028 amount += ind_unclosed2; |
6945 else | 7029 else |
6946 amount += ind_unclosed; | 7030 { |
7031 if (is_if_for_while) | |
7032 amount += ind_if_for_while; | |
7033 else | |
7034 amount += ind_unclosed; | |
7035 } | |
6947 } | 7036 } |
6948 /* | 7037 /* |
6949 * For a line starting with ')' use the minimum of the two | 7038 * For a line starting with ')' use the minimum of the two |
6950 * positions, to avoid giving it more indent than the previous | 7039 * positions, to avoid giving it more indent than the previous |
6951 * lines: | 7040 * lines: |