annotate src/indent.c @ 17447:c8bdaff91140

Added tag v8.1.1721 for changeset dcc4120f841294dfadbc2c59e479a669410474b5
author Bram Moolenaar <Bram@vim.org>
date Sat, 20 Jul 2019 19:15:05 +0200
parents ef00b6bc186b
children 0f7ae8010787
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * indent.c: Indentation related functions
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 #include "vim.h"
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 #if defined(FEAT_CINDENT) || defined(FEAT_SMARTINDENT)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 * Return TRUE if the string "line" starts with a word from 'cinwords'.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 cin_is_cinword(char_u *line)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 char_u *cinw;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 char_u *cinw_buf;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 int cinw_len;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 int retval = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 int len;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 cinw_len = (int)STRLEN(curbuf->b_p_cinw) + 1;
16764
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
31 cinw_buf = alloc(cinw_len);
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 if (cinw_buf != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 line = skipwhite(line);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 for (cinw = curbuf->b_p_cinw; *cinw; )
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 len = copy_option_part(&cinw, cinw_buf, cinw_len, ",");
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 if (STRNCMP(line, cinw_buf, len) == 0
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 && (!vim_iswordc(line[len]) || !vim_iswordc(line[len - 1])))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 retval = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 vim_free(cinw_buf);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 return retval;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 #endif
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 #if defined(FEAT_CINDENT) || defined(FEAT_SYN_HL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 static char_u *skip_string(char_u *p);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 static pos_T *find_start_rawstring(int ind_maxcomment);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 * Find the start of a comment, not knowing if we are in a comment right now.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 * Search starts at w_cursor.lnum and goes backwards.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 * Return NULL when not inside a comment.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 static pos_T *
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
62 ind_find_start_comment(void) // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 return find_start_comment(curbuf->b_ind_maxcomment);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 pos_T *
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
68 find_start_comment(int ind_maxcomment) // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 pos_T *pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 char_u *line;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 char_u *p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 int cur_maxcomment = ind_maxcomment;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 for (;;)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 pos = findmatchlimit(NULL, '*', FM_BACKWARD, cur_maxcomment);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 if (pos == NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
81 // Check if the comment start we found is inside a string.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
82 // If it is then restrict the search to below this line and try again.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 line = ml_get(pos->lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 for (p = line; *p && (colnr_T)(p - line) < pos->col; ++p)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 p = skip_string(p);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 if ((colnr_T)(p - line) <= pos->col)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 cur_maxcomment = curwin->w_cursor.lnum - pos->lnum - 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 if (cur_maxcomment <= 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 pos = NULL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 return pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 * Find the start of a comment or raw string, not knowing if we are in a
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 * comment or raw string right now.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 * Search starts at w_cursor.lnum and goes backwards.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 * If is_raw is given and returns start of raw_string, sets it to true.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 * Return NULL when not inside a comment or raw string.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 * "CORS" -> Comment Or Raw String
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 static pos_T *
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
107 ind_find_start_CORS(linenr_T *is_raw) // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 static pos_T comment_pos_copy;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 pos_T *comment_pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 pos_T *rs_pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 comment_pos = find_start_comment(curbuf->b_ind_maxcomment);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 if (comment_pos != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
116 // Need to make a copy of the static pos in findmatchlimit(),
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
117 // calling find_start_rawstring() may change it.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 comment_pos_copy = *comment_pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 comment_pos = &comment_pos_copy;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 rs_pos = find_start_rawstring(curbuf->b_ind_maxcomment);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
123 // If comment_pos is before rs_pos the raw string is inside the comment.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
124 // If rs_pos is before comment_pos the comment is inside the raw string.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 if (comment_pos == NULL || (rs_pos != NULL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 && LT_POS(*rs_pos, *comment_pos)))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 if (is_raw != NULL && rs_pos != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 *is_raw = rs_pos->lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 return rs_pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 return comment_pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 * Find the start of a raw string, not knowing if we are in one right now.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 * Search starts at w_cursor.lnum and goes backwards.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 * Return NULL when not inside a raw string.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 static pos_T *
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
141 find_start_rawstring(int ind_maxcomment) // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 pos_T *pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 char_u *line;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 char_u *p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 int cur_maxcomment = ind_maxcomment;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 for (;;)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 pos = findmatchlimit(NULL, 'R', FM_BACKWARD, cur_maxcomment);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 if (pos == NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
154 // Check if the raw string start we found is inside a string.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
155 // If it is then restrict the search to below this line and try again.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 line = ml_get(pos->lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 for (p = line; *p && (colnr_T)(p - line) < pos->col; ++p)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 p = skip_string(p);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 if ((colnr_T)(p - line) <= pos->col)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 cur_maxcomment = curwin->w_cursor.lnum - pos->lnum - 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 if (cur_maxcomment <= 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 pos = NULL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 return pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 * Skip to the end of a "string" and a 'c' character.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 * If there is no string or character, return argument unmodified.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 static char_u *
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 skip_string(char_u *p)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 int i;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
180 // We loop, because strings may be concatenated: "date""time".
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 for ( ; ; ++p)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
183 if (p[0] == '\'') // 'c' or '\n' or '\000'
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
185 if (!p[1]) // ' at end of line
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 i = 2;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
188 if (p[1] == '\\') // '\n' or '\000'
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 ++i;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
191 while (vim_isdigit(p[i - 1])) // '\000'
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 ++i;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 }
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
194 if (p[i] == '\'') // check for trailing '
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 p += i;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 }
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
200 else if (p[0] == '"') // start of string
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 for (++p; p[0]; ++p)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 if (p[0] == '\\' && p[1] != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 ++p;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
206 else if (p[0] == '"') // end of string
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 if (p[0] == '"')
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
210 continue; // continue for another string
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 else if (p[0] == 'R' && p[1] == '"')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
214 // Raw string: R"[delim](...)[delim]"
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 char_u *delim = p + 2;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 char_u *paren = vim_strchr(delim, '(');
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 if (paren != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 size_t delim_len = paren - delim;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 for (p += 3; *p; ++p)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 if (p[0] == ')' && STRNCMP(p + 1, delim, delim_len) == 0
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 && p[delim_len + 1] == '"')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 p += delim_len + 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 if (p[0] == '"')
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
230 continue; // continue for another string
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 }
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
233 break; // no string found
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 if (!*p)
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
236 --p; // backup from NUL
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 return p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 }
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
239 #endif // FEAT_CINDENT || FEAT_SYN_HL
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 #if defined(FEAT_CINDENT) || defined(PROTO)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 * Return TRUE if C-indenting is on.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 cindent_on(void)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 return (!p_paste && (curbuf->b_p_cin
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 # ifdef FEAT_EVAL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 || *curbuf->b_p_inde != NUL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 # endif
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 ));
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
256 // Find result cache for cpp_baseclass
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 typedef struct {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 int found;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 lpos_T lpos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260 } cpp_baseclass_cache_T;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 * Functions for C-indenting.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 * Most of this originally comes from Eric Fischer.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 * Below "XXX" means that this function may unlock the current line.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 static int cin_isdefault(char_u *);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 static int cin_ispreproc(char_u *);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 static int cin_iscomment(char_u *);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 static int cin_islinecomment(char_u *);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 static int cin_isterminated(char_u *, int, int);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 static int cin_iselse(char_u *);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 static int cin_ends_in(char_u *, char_u *, char_u *);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 static int cin_starts_with(char_u *s, char *word);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 static pos_T *find_match_paren(int);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 static pos_T *find_match_char(int c, int ind_maxparen);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 static int find_last_paren(char_u *l, int start, int end);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 static int find_match(int lookfor, linenr_T ourscope);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 * Skip over white space and C comments within the line.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 * Also skip over Perl/shell comments if desired.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 static char_u *
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 cin_skipcomment(char_u *s)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 while (*s)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292 char_u *prev_s = s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 s = skipwhite(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
296 // Perl/shell # comment comment continues until eol. Require a space
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
297 // before # to avoid recognizing $#array.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298 if (curbuf->b_ind_hash_comment != 0 && s != prev_s && *s == '#')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 s += STRLEN(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 if (*s != '/')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 ++s;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
306 if (*s == '/') // slash-slash comment continues till eol
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308 s += STRLEN(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 if (*s != '*')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 break;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
313 for (++s; *s; ++s) // skip slash-star comment
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 if (s[0] == '*' && s[1] == '/')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 s += 2;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 return s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 * Return TRUE if there is no code at *s. White space and comments are
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 * not considered code.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 cin_nocode(char_u *s)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 return *cin_skipcomment(s) == NUL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 * Check previous lines for a "//" line comment, skipping over blank lines.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336 static pos_T *
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
337 find_line_comment(void) // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 static pos_T pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340 char_u *line;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 char_u *p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 pos = curwin->w_cursor;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 while (--pos.lnum > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 line = ml_get(pos.lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 p = skipwhite(line);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 if (cin_islinecomment(p))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 pos.col = (int)(p - line);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 return &pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 if (*p != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 return NULL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 * Return TRUE if "text" starts with "key:".
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 cin_has_js_key(char_u *text)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 char_u *s = skipwhite(text);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 int quote = -1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 if (*s == '\'' || *s == '"')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
370 // can be 'key': or "key":
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 quote = *s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 ++s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 }
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
374 if (!vim_isIDc(*s)) // need at least one ID character
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 while (vim_isIDc(*s))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 ++s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 if (*s == quote)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 ++s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 s = cin_skipcomment(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
384 // "::" is not a label, it's C++
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 return (*s == ':' && s[1] != ':');
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 * Check if string matches "label:"; move to character after ':' if true.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 * "*s" must point to the start of the label, if there is one.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 cin_islabel_skip(char_u **s)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
395 if (!vim_isIDc(**s)) // need at least one ID character
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 while (vim_isIDc(**s))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 (*s)++;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 *s = cin_skipcomment(*s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
403 // "::" is not a label, it's C++
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 return (**s == ':' && *++*s != ':');
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 * Recognize a label: "label:".
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409 * Note: curwin->w_cursor must be where we are looking for the label.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 int
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
412 cin_islabel(void) // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414 char_u *s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 s = cin_skipcomment(ml_get_curline());
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
418 // Exclude "default" from labels, since it should be indented
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
419 // like a switch label. Same for C++ scope declarations.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 if (cin_isdefault(s))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 if (cin_isscopedecl(s))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 if (cin_islabel_skip(&s))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
427 // Only accept a label if the previous line is terminated or is a case
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
428 // label.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 pos_T cursor_save;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 pos_T *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 char_u *line;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 cursor_save = curwin->w_cursor;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 while (curwin->w_cursor.lnum > 1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 --curwin->w_cursor.lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
438 // If we're in a comment or raw string now, skip to the start of
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
439 // it.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 curwin->w_cursor.col = 0;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
441 if ((trypos = ind_find_start_CORS(NULL)) != NULL) // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 curwin->w_cursor = *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 line = ml_get_curline();
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
445 if (cin_ispreproc(line)) // ignore #defines, #if, etc.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 if (*(line = cin_skipcomment(line)) == NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 curwin->w_cursor = cursor_save;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 if (cin_isterminated(line, TRUE, FALSE)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 || cin_isscopedecl(line)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 || cin_iscase(line, TRUE)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 || (cin_islabel_skip(&line) && cin_nocode(line)))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 curwin->w_cursor = cursor_save;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
459 return TRUE; // label at start of file???
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 * Recognize structure initialization and enumerations:
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 * "[typedef] [static|public|protected|private] enum"
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 * "[typedef] [static|public|protected|private] = {"
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 cin_isinit(void)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 char_u *s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 static char *skip[] = {"static", "public", "protected", "private"};
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 s = cin_skipcomment(ml_get_curline());
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 if (cin_starts_with(s, "typedef"))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478 s = cin_skipcomment(s + 7);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 for (;;)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 int i, l;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 for (i = 0; i < (int)(sizeof(skip) / sizeof(char *)); ++i)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486 l = (int)strlen(skip[i]);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 if (cin_starts_with(s, skip[i]))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 s = cin_skipcomment(s + l);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 l = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 if (l != 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 if (cin_starts_with(s, "enum"))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
501 if (cin_ends_in(s, (char_u *)"=", (char_u *)"{"))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
502 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 * Recognize a switch label: "case .*:" or "default:".
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 cin_iscase(
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 char_u *s,
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
513 int strict) // Allow relaxed check of case statement for JS
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 s = cin_skipcomment(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 if (cin_starts_with(s, "case"))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 for (s += 4; *s; ++s)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 s = cin_skipcomment(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 if (*s == ':')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
523 if (s[1] == ':') // skip over "::" for C++
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 ++s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 if (*s == '\'' && s[1] && s[2] == '\'')
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
529 s += 2; // skip over ':'
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 else if (*s == '/' && (s[1] == '*' || s[1] == '/'))
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
531 return FALSE; // stop at comment
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 else if (*s == '"')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
534 // JS etc.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 if (strict)
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
536 return FALSE; // stop at string
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 if (cin_isdefault(s))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 * Recognize a "default" switch label.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 cin_isdefault(char_u *s)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 return (STRNCMP(s, "default", 7) == 0
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 && *(s = cin_skipcomment(s + 7)) == ':'
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 && s[1] != ':');
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 * Recognize a "public/private/protected" scope declaration label.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 cin_isscopedecl(char_u *s)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 int i;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 s = cin_skipcomment(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 if (STRNCMP(s, "public", 6) == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 i = 6;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 else if (STRNCMP(s, "protected", 9) == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 i = 9;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 else if (STRNCMP(s, "private", 7) == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 i = 7;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 return (*(s = cin_skipcomment(s + i)) == ':' && s[1] != ':');
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
580 // Maximum number of lines to search back for a "namespace" line.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 #define FIND_NAMESPACE_LIM 20
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 * Recognize a "namespace" scope declaration.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 cin_is_cpp_namespace(char_u *s)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 char_u *p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 int has_name = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 int has_name_start = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 s = cin_skipcomment(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 if (STRNCMP(s, "namespace", 9) == 0 && (s[9] == NUL || !vim_iswordc(s[9])))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596 p = cin_skipcomment(skipwhite(s + 9));
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 while (*p != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 if (VIM_ISWHITE(*p))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
601 has_name = TRUE; // found end of a name
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 p = cin_skipcomment(skipwhite(p));
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 else if (*p == '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 else if (vim_iswordc(*p))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 has_name_start = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 if (has_name)
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
612 return FALSE; // word character after skipping past name
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 ++p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 else if (p[0] == ':' && p[1] == ':' && vim_iswordc(p[2]))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 if (!has_name_start || has_name)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618 return FALSE;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
619 // C++ 17 nested namespace
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 p += 3;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 * Recognize a `extern "C"` or `extern "C++"` linkage specifications.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 cin_is_cpp_extern_c(char_u *s)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 char_u *p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 int has_string_literal = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 s = cin_skipcomment(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 if (STRNCMP(s, "extern", 6) == 0 && (s[6] == NUL || !vim_iswordc(s[6])))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 p = cin_skipcomment(skipwhite(s + 6));
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 while (*p != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 if (VIM_ISWHITE(*p))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 p = cin_skipcomment(skipwhite(p));
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 else if (*p == '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 else if (p[0] == '"' && p[1] == 'C' && p[2] == '"')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 if (has_string_literal)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 has_string_literal = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 p += 3;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 else if (p[0] == '"' && p[1] == 'C' && p[2] == '+' && p[3] == '+'
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 && p[4] == '"')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 if (has_string_literal)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 has_string_literal = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 p += 5;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 return has_string_literal ? TRUE : FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 * Return a pointer to the first non-empty non-comment character after a ':'.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 * Return NULL if not found.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 * case 234: a = b;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 * ^
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 static char_u *
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 after_label(char_u *l)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 for ( ; *l; ++l)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 if (*l == ':')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
693 if (l[1] == ':') // skip over "::" for C++
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694 ++l;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 else if (!cin_iscase(l + 1, FALSE))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 else if (*l == '\'' && l[1] && l[2] == '\'')
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
699 l += 2; // skip over 'x'
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 if (*l == NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 return NULL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 l = cin_skipcomment(l + 1);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 if (*l == NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 return NULL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 return l;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 * Get indent of line "lnum", skipping a label.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 * Return 0 if there is nothing after the label.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 static int
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
714 get_indent_nolabel (linenr_T lnum) // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 char_u *l;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 pos_T fp;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 colnr_T col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 char_u *p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 l = ml_get(lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 p = after_label(l);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 if (p == NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 return 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 fp.col = (colnr_T)(p - l);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 fp.lnum = lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 getvcol(curwin, &fp, &col, NULL, NULL);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 return (int)col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733 * Find indent for line "lnum", ignoring any case or jump label.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734 * Also return a pointer to the text (after the label) in "pp".
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 * label: if (asdf && asdfasdf)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 * ^
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739 skip_label(linenr_T lnum, char_u **pp)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 char_u *l;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 int amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 pos_T cursor_save;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 cursor_save = curwin->w_cursor;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 curwin->w_cursor.lnum = lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 l = ml_get_curline();
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
748 // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 if (cin_iscase(l, FALSE) || cin_isscopedecl(l) || cin_islabel())
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 amount = get_indent_nolabel(lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 l = after_label(ml_get_curline());
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
753 if (l == NULL) // just in case
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 amount = get_indent();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 *pp = l;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 curwin->w_cursor = cursor_save;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 return amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 * Return the indent of the first variable name after a type in a declaration.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 * int a, indent of "a"
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 * static struct foo b, indent of "b"
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 * enum bla c, indent of "c"
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 * Returns zero when it doesn't look like a declaration.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 cin_first_id_amount(void)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 char_u *line, *p, *s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 int len;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 pos_T fp;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 colnr_T col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 line = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 p = skipwhite(line);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 len = (int)(skiptowhite(p) - p);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 if (len == 6 && STRNCMP(p, "static", 6) == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 p = skipwhite(p + 6);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 len = (int)(skiptowhite(p) - p);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 if (len == 6 && STRNCMP(p, "struct", 6) == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 p = skipwhite(p + 6);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 else if (len == 4 && STRNCMP(p, "enum", 4) == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 p = skipwhite(p + 4);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 else if ((len == 8 && STRNCMP(p, "unsigned", 8) == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 || (len == 6 && STRNCMP(p, "signed", 6) == 0))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 s = skipwhite(p + len);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 if ((STRNCMP(s, "int", 3) == 0 && VIM_ISWHITE(s[3]))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 || (STRNCMP(s, "long", 4) == 0 && VIM_ISWHITE(s[4]))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 || (STRNCMP(s, "short", 5) == 0 && VIM_ISWHITE(s[5]))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
801 || (STRNCMP(s, "char", 4) == 0 && VIM_ISWHITE(s[4])))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 p = s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 for (len = 0; vim_isIDc(p[len]); ++len)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
805 ;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 if (len == 0 || !VIM_ISWHITE(p[len]) || cin_nocode(p))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 return 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809 p = skipwhite(p + len);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810 fp.lnum = curwin->w_cursor.lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
811 fp.col = (colnr_T)(p - line);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812 getvcol(curwin, &fp, &col, NULL, NULL);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 return (int)col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 * Return the indent of the first non-blank after an equal sign.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 * char *foo = "here";
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
819 * Return zero if no (useful) equal sign found.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 * Return -1 if the line above "lnum" ends in a backslash.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821 * foo = "asdf\
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 * asdf\
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 * here";
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 cin_get_equal_amount(linenr_T lnum)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828 char_u *line;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 char_u *s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830 colnr_T col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831 pos_T fp;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833 if (lnum > 1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835 line = ml_get(lnum - 1);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836 if (*line != NUL && line[STRLEN(line) - 1] == '\\')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 return -1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 line = s = ml_get(lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841 while (*s != NUL && vim_strchr((char_u *)"=;{}\"'", *s) == NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
843 if (cin_iscomment(s)) // ignore comments
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844 s = cin_skipcomment(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 ++s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 if (*s != '=')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 return 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851 s = skipwhite(s + 1);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 if (cin_nocode(s))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853 return 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
855 if (*s == '"') // nice alignment for continued strings
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 ++s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858 fp.lnum = lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859 fp.col = (colnr_T)(s - line);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860 getvcol(curwin, &fp, &col, NULL, NULL);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861 return (int)col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 * Recognize a preprocessor statement: Any line that starts with '#'.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868 cin_ispreproc(char_u *s)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 if (*skipwhite(s) == '#')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 * Return TRUE if line "*pp" at "*lnump" is a preprocessor statement or a
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 * continuation line of a preprocessor statement. Decrease "*lnump" to the
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878 * start and return the line in "*pp".
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879 * Put the amount of indent in "*amount".
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 cin_ispreproc_cont(char_u **pp, linenr_T *lnump, int *amount)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884 char_u *line = *pp;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 linenr_T lnum = *lnump;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886 int retval = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 int candidate_amount = *amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 if (*line != NUL && line[STRLEN(line) - 1] == '\\')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 candidate_amount = get_indent_lnum(lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
891
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892 for (;;)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 if (cin_ispreproc(line))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
896 retval = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897 *lnump = lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900 if (lnum == 1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 line = ml_get(--lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903 if (*line == NUL || line[STRLEN(line) - 1] != '\\')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 if (lnum != *lnump)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908 *pp = ml_get(*lnump);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
909 if (retval)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 *amount = candidate_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911 return retval;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 * Recognize the start of a C or C++ comment.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
917 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918 cin_iscomment(char_u *p)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920 return (p[0] == '/' && (p[1] == '*' || p[1] == '/'));
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
921 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924 * Recognize the start of a "//" comment.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 cin_islinecomment(char_u *p)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 return (p[0] == '/' && p[1] == '/');
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933 * Recognize a line that starts with '{' or '}', or ends with ';', ',', '{' or
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 * '}'.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 * Don't consider "} else" a terminated line.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 * If a line begins with an "else", only consider it terminated if no unmatched
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 * opening braces follow (handle "else { foo();" correctly).
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 * Return the character terminating the line (ending char's have precedence if
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939 * both apply in order to determine initializations).
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 cin_isterminated(
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 char_u *s,
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
944 int incl_open, // include '{' at the end as terminator
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
945 int incl_comma) // recognize a trailing comma
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 char_u found_start = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 unsigned n_open = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949 int is_else = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
951 s = cin_skipcomment(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 if (*s == '{' || (*s == '}' && !cin_iselse(s)))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954 found_start = *s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956 if (!found_start)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957 is_else = cin_iselse(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
959 while (*s)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
960 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
961 // skip over comments, "" strings and 'c'haracters
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962 s = skip_string(cin_skipcomment(s));
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 if (*s == '}' && n_open > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964 --n_open;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965 if ((!is_else || n_open == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966 && (*s == ';' || *s == '}' || (incl_comma && *s == ','))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 && cin_nocode(s + 1))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968 return *s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
969 else if (*s == '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
971 if (incl_open && cin_nocode(s + 1))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 return *s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974 ++n_open;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 if (*s)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 s++;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 return found_start;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984 * Recognize the basic picture of a function declaration -- it needs to
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 * have an open paren somewhere and a close paren at the end of the line and
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 * no semicolons anywhere.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 * When a line ends in a comma we continue looking in the next line.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 * "sp" points to a string with the line. When looking at other lines it must
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
989 * be restored to the line. When it's NULL fetch lines here.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
990 * "first_lnum" is where we start looking.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991 * "min_lnum" is the line before which we will not be looking.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 cin_isfuncdecl(
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995 char_u **sp,
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 linenr_T first_lnum,
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 linenr_T min_lnum)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 char_u *s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000 linenr_T lnum = first_lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001 linenr_T save_lnum = curwin->w_cursor.lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 int retval = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003 pos_T *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004 int just_started = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 if (sp == NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007 s = ml_get(lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009 s = *sp;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011 curwin->w_cursor.lnum = lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1012 if (find_last_paren(s, '(', ')')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013 && (trypos = find_match_paren(curbuf->b_ind_maxparen)) != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015 lnum = trypos->lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016 if (lnum < min_lnum)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 curwin->w_cursor.lnum = save_lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1020 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1021
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 s = ml_get(lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1024 curwin->w_cursor.lnum = save_lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1026 // Ignore line starting with #.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027 if (cin_ispreproc(s))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1028 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1030 while (*s && *s != '(' && *s != ';' && *s != '\'' && *s != '"')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1032 if (cin_iscomment(s)) // ignore comments
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033 s = cin_skipcomment(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1034 else if (*s == ':')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036 if (*(s + 1) == ':')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 s += 2;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038 else
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1039 // To avoid a mistake in the following situation:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1040 // A::A(int a, int b)
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1041 // : a(0) // <--not a function decl
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1042 // , b(0)
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1043 // {...
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1044 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1045 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 ++s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049 if (*s != '(')
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1050 return FALSE; // ';', ' or " before any () or no '('
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052 while (*s && *s != ';' && *s != '\'' && *s != '"')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 if (*s == ')' && cin_nocode(s + 1))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1056 /*
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1057 * ')' at the end: may have found a match
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058 * Check for he previous line not to end in a backslash:
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 * #if defined(x) && \
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060 * defined(y)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1062 lnum = first_lnum - 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1063 s = ml_get(lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1064 if (*s == NUL || s[STRLEN(s) - 1] != '\\')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1065 retval = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1066 goto done;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1068 if ((*s == ',' && cin_nocode(s + 1)) || s[1] == NUL || cin_nocode(s))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070 int comma = (*s == ',');
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1071
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1072 // ',' at the end: continue looking in the next line.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1073 // At the end: check for ',' in the next line, for this style:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1074 // func(arg1
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1075 // , arg2)
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 for (;;)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078 if (lnum >= curbuf->b_ml.ml_line_count)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 s = ml_get(++lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 if (!cin_ispreproc(s))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 if (lnum >= curbuf->b_ml.ml_line_count)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1085 break;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1086 // Require a comma at end of the line or a comma or ')' at the
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1087 // start of next line.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1088 s = skipwhite(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 if (!just_started && (!comma && *s != ',' && *s != ')'))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1091 just_started = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092 }
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1093 else if (cin_iscomment(s)) // ignore comments
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1094 s = cin_skipcomment(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1095 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1096 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1097 ++s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 just_started = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1099 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1100 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102 done:
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103 if (lnum != first_lnum && sp != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1104 *sp = ml_get(first_lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106 return retval;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1109 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 cin_isif(char_u *p)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1111 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112 return (STRNCMP(p, "if", 2) == 0 && !vim_isIDc(p[2]));
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1113 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1115 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1116 cin_iselse(
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 char_u *p)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1118 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1119 if (*p == '}') // accept "} else"
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 p = cin_skipcomment(p + 1);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 return (STRNCMP(p, "else", 4) == 0 && !vim_isIDc(p[4]));
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1125 cin_isdo(char_u *p)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1126 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 return (STRNCMP(p, "do", 2) == 0 && !vim_isIDc(p[2]));
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1129
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1131 * Check if this is a "while" that should have a matching "do".
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1132 * We only accept a "while (condition) ;", with only white space between the
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1133 * ')' and ';'. The condition may be spread over several lines.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1134 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1135 static int
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1136 cin_iswhileofdo (char_u *p, linenr_T lnum) // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1137 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 pos_T cursor_save;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 pos_T *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140 int retval = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142 p = cin_skipcomment(p);
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1143 if (*p == '}') // accept "} while (cond);"
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 p = cin_skipcomment(p + 1);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1145 if (cin_starts_with(p, "while"))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1147 cursor_save = curwin->w_cursor;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 curwin->w_cursor.lnum = lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1150 p = ml_get_curline();
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1151 while (*p && *p != 'w') // skip any '}', until the 'w' of the "while"
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1152 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1153 ++p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1154 ++curwin->w_cursor.col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1155 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1156 if ((trypos = findmatchlimit(NULL, 0, 0,
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1157 curbuf->b_ind_maxparen)) != NULL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1158 && *cin_skipcomment(ml_get_pos(trypos) + 1) == ';')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159 retval = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1160 curwin->w_cursor = cursor_save;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1161 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1162 return retval;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1166 * Check whether in "p" there is an "if", "for" or "while" before "*poffset".
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1167 * Return 0 if there is none.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1168 * Otherwise return !0 and update "*poffset" to point to the place where the
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169 * string was found.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1170 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1171 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1172 cin_is_if_for_while_before_offset(char_u *line, int *poffset)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1173 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174 int offset = *poffset;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176 if (offset-- < 2)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1177 return 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178 while (offset > 2 && VIM_ISWHITE(line[offset]))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1179 --offset;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1180
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1181 offset -= 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1182 if (!STRNCMP(line + offset, "if", 2))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183 goto probablyFound;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 if (offset >= 1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1186 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187 offset -= 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1188 if (!STRNCMP(line + offset, "for", 3))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1189 goto probablyFound;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1190
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1191 if (offset >= 2)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1192 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1193 offset -= 2;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1194 if (!STRNCMP(line + offset, "while", 5))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1195 goto probablyFound;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1196 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1197 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1198 return 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1199
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1200 probablyFound:
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1201 if (!offset || !vim_isIDc(line[offset - 1]))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1202 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1203 *poffset = offset;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1204 return 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1205 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1206 return 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1207 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1208
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1209 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1210 * Return TRUE if we are at the end of a do-while.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1211 * do
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1212 * nothing;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1213 * while (foo
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1214 * && bar); <-- here
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1215 * Adjust the cursor to the line with "while".
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1216 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1217 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1218 cin_iswhileofdo_end(int terminated)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1219 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1220 char_u *line;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1221 char_u *p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1222 char_u *s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1223 pos_T *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1224 int i;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1225
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1226 if (terminated != ';') // there must be a ';' at the end
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1227 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1228
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1229 p = line = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1230 while (*p != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1231 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1232 p = cin_skipcomment(p);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1233 if (*p == ')')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1234 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1235 s = skipwhite(p + 1);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1236 if (*s == ';' && cin_nocode(s + 1))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1238 // Found ");" at end of the line, now check there is "while"
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1239 // before the matching '('. XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1240 i = (int)(p - line);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1241 curwin->w_cursor.col = i;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1242 trypos = find_match_paren(curbuf->b_ind_maxparen);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1243 if (trypos != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1244 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1245 s = cin_skipcomment(ml_get(trypos->lnum));
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1246 if (*s == '}') // accept "} while (cond);"
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1247 s = cin_skipcomment(s + 1);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1248 if (cin_starts_with(s, "while"))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1249 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1250 curwin->w_cursor.lnum = trypos->lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1251 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1252 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1253 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1254
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1255 // Searching may have made "line" invalid, get it again.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1256 line = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1257 p = line + i;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1258 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1259 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1260 if (*p != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1261 ++p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1262 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1263 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1264 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1265
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1266 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1267 cin_isbreak(char_u *p)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1268 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1269 return (STRNCMP(p, "break", 5) == 0 && !vim_isIDc(p[5]));
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1270 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1271
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1272 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1273 * Find the position of a C++ base-class declaration or
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1274 * constructor-initialization. eg:
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1275 *
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1276 * class MyClass :
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1277 * baseClass <-- here
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1278 * class MyClass : public baseClass,
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1279 * anotherBaseClass <-- here (should probably lineup ??)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1280 * MyClass::MyClass(...) :
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1281 * baseClass(...) <-- here (constructor-initialization)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1282 *
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1283 * This is a lot of guessing. Watch out for "cond ? func() : foo".
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1284 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1285 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1286 cin_is_cpp_baseclass(
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1287 cpp_baseclass_cache_T *cached) // input and output
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1288 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1289 lpos_T *pos = &cached->lpos; // find position
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1290 char_u *s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1291 int class_or_struct, lookfor_ctor_init, cpp_base_class;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1292 linenr_T lnum = curwin->w_cursor.lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1293 char_u *line = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1294
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1295 if (pos->lnum <= lnum)
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1296 return cached->found; // Use the cached result
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1297
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1298 pos->col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1299
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1300 s = skipwhite(line);
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1301 if (*s == '#') // skip #define FOO x ? (x) : x
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1302 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1303 s = cin_skipcomment(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1304 if (*s == NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1305 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1306
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1307 cpp_base_class = lookfor_ctor_init = class_or_struct = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1308
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1309 // Search for a line starting with '#', empty, ending in ';' or containing
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1310 // '{' or '}' and start below it. This handles the following situations:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1311 // a = cond ?
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1312 // func() :
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1313 // asdf;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1314 // func::foo()
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1315 // : something
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1316 // {}
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1317 // Foo::Foo (int one, int two)
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1318 // : something(4),
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1319 // somethingelse(3)
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1320 // {}
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1321 while (lnum > 1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1322 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1323 line = ml_get(lnum - 1);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1324 s = skipwhite(line);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1325 if (*s == '#' || *s == NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1326 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1327 while (*s != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1328 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1329 s = cin_skipcomment(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1330 if (*s == '{' || *s == '}'
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1331 || (*s == ';' && cin_nocode(s + 1)))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1332 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1333 if (*s != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1334 ++s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1335 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1336 if (*s != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1337 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1338 --lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1339 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1340
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1341 pos->lnum = lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1342 line = ml_get(lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1343 s = line;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1344 for (;;)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1345 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1346 if (*s == NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1347 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1348 if (lnum == curwin->w_cursor.lnum)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1349 break;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1350 // Continue in the cursor line.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1351 line = ml_get(++lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1352 s = line;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1353 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1354 if (s == line)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1355 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1356 // don't recognize "case (foo):" as a baseclass
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1357 if (cin_iscase(s, FALSE))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1358 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1359 s = cin_skipcomment(line);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1360 if (*s == NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1361 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1362 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1363
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1364 if (s[0] == '"' || (s[0] == 'R' && s[1] == '"'))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1365 s = skip_string(s) + 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1366 else if (s[0] == ':')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1367 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1368 if (s[1] == ':')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1369 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1370 // skip double colon. It can't be a constructor
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1371 // initialization any more
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1372 lookfor_ctor_init = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1373 s = cin_skipcomment(s + 2);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1374 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1375 else if (lookfor_ctor_init || class_or_struct)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1376 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1377 // we have something found, that looks like the start of
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1378 // cpp-base-class-declaration or constructor-initialization
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1379 cpp_base_class = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1380 lookfor_ctor_init = class_or_struct = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1381 pos->col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1382 s = cin_skipcomment(s + 1);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1383 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1384 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1385 s = cin_skipcomment(s + 1);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1386 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1387 else if ((STRNCMP(s, "class", 5) == 0 && !vim_isIDc(s[5]))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1388 || (STRNCMP(s, "struct", 6) == 0 && !vim_isIDc(s[6])))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1389 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1390 class_or_struct = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1391 lookfor_ctor_init = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1392
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1393 if (*s == 'c')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1394 s = cin_skipcomment(s + 5);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1395 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1396 s = cin_skipcomment(s + 6);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1397 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1398 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1399 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1400 if (s[0] == '{' || s[0] == '}' || s[0] == ';')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1401 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1402 cpp_base_class = lookfor_ctor_init = class_or_struct = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1403 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1404 else if (s[0] == ')')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1405 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1406 // Constructor-initialization is assumed if we come across
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1407 // something like "):"
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1408 class_or_struct = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1409 lookfor_ctor_init = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1410 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1411 else if (s[0] == '?')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1412 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1413 // Avoid seeing '() :' after '?' as constructor init.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1414 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1415 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1416 else if (!vim_isIDc(s[0]))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1417 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1418 // if it is not an identifier, we are wrong
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1419 class_or_struct = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1420 lookfor_ctor_init = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1421 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1422 else if (pos->col == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1423 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1424 // it can't be a constructor-initialization any more
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1425 lookfor_ctor_init = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1426
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1427 // the first statement starts here: lineup with this one...
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1428 if (cpp_base_class)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1429 pos->col = (colnr_T)(s - line);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1430 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1431
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1432 // When the line ends in a comma don't align with it.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1433 if (lnum == curwin->w_cursor.lnum && *s == ',' && cin_nocode(s + 1))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1434 pos->col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1435
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1436 s = cin_skipcomment(s + 1);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1437 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1438 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1439
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1440 cached->found = cpp_base_class;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1441 if (cpp_base_class)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1442 pos->lnum = lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1443 return cpp_base_class;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1444 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1445
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1446 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1447 get_baseclass_amount(int col)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1448 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1449 int amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1450 colnr_T vcol;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1451 pos_T *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1452
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1453 if (col == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1454 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1455 amount = get_indent();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1456 if (find_last_paren(ml_get_curline(), '(', ')')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1457 && (trypos = find_match_paren(curbuf->b_ind_maxparen)) != NULL)
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1458 amount = get_indent_lnum(trypos->lnum); // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1459 if (!cin_ends_in(ml_get_curline(), (char_u *)",", NULL))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1460 amount += curbuf->b_ind_cpp_baseclass;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1461 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1462 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1463 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1464 curwin->w_cursor.col = col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1465 getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1466 amount = (int)vcol;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1467 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1468 if (amount < curbuf->b_ind_cpp_baseclass)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1469 amount = curbuf->b_ind_cpp_baseclass;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1470 return amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1471 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1472
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1473 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1474 * Return TRUE if string "s" ends with the string "find", possibly followed by
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1475 * white space and comments. Skip strings and comments.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1476 * Ignore "ignore" after "find" if it's not NULL.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1477 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1478 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1479 cin_ends_in(char_u *s, char_u *find, char_u *ignore)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1480 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1481 char_u *p = s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1482 char_u *r;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1483 int len = (int)STRLEN(find);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1484
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1485 while (*p != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1486 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1487 p = cin_skipcomment(p);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1488 if (STRNCMP(p, find, len) == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1489 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1490 r = skipwhite(p + len);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1491 if (ignore != NULL && STRNCMP(r, ignore, STRLEN(ignore)) == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1492 r = skipwhite(r + STRLEN(ignore));
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1493 if (cin_nocode(r))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1494 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1495 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1496 if (*p != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1497 ++p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1498 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1499 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1500 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1501
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1502 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1503 * Return TRUE when "s" starts with "word" and then a non-ID character.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1504 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1505 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1506 cin_starts_with(char_u *s, char *word)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1507 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1508 int l = (int)STRLEN(word);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1509
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1510 return (STRNCMP(s, word, l) == 0 && !vim_isIDc(s[l]));
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1511 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1512
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1513 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1514 * Skip strings, chars and comments until at or past "trypos".
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1515 * Return the column found.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1516 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1517 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1518 cin_skip2pos(pos_T *trypos)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1519 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1520 char_u *line;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1521 char_u *p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1522 char_u *new_p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1523
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1524 p = line = ml_get(trypos->lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1525 while (*p && (colnr_T)(p - line) < trypos->col)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1526 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1527 if (cin_iscomment(p))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1528 p = cin_skipcomment(p);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1529 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1530 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1531 new_p = skip_string(p);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1532 if (new_p == p)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1533 ++p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1534 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1535 p = new_p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1536 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1537 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1538 return (int)(p - line);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1539 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1540
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1541 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1542 * Find the '{' at the start of the block we are in.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1543 * Return NULL if no match found.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1544 * Ignore a '{' that is in a comment, makes indenting the next three lines
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1545 * work.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1546 */
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1547 /* foo() */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1548 /* { */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1549 /* } */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1550
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1551 static pos_T *
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1552 find_start_brace(void) // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1553 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1554 pos_T cursor_save;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1555 pos_T *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1556 pos_T *pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1557 static pos_T pos_copy;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1558
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1559 cursor_save = curwin->w_cursor;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1560 while ((trypos = findmatchlimit(NULL, '{', FM_BLOCKSTOP, 0)) != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1561 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1562 pos_copy = *trypos; // copy pos_T, next findmatch will change it
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1563 trypos = &pos_copy;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1564 curwin->w_cursor = *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1565 pos = NULL;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1566 // ignore the { if it's in a // or / * * / comment
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1567 if ((colnr_T)cin_skip2pos(trypos) == trypos->col
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1568 && (pos = ind_find_start_CORS(NULL)) == NULL) // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1569 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1570 if (pos != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1571 curwin->w_cursor.lnum = pos->lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1572 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1573 curwin->w_cursor = cursor_save;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1574 return trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1575 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1576
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1577 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1578 * Find the matching '(', ignoring it if it is in a comment.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1579 * Return NULL if no match found.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1580 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1581 static pos_T *
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1582 find_match_paren(int ind_maxparen) // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1583 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1584 return find_match_char('(', ind_maxparen);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1585 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1586
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1587 static pos_T *
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1588 find_match_char(int c, int ind_maxparen) // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1589 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1590 pos_T cursor_save;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1591 pos_T *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1592 static pos_T pos_copy;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1593 int ind_maxp_wk;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1594
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1595 cursor_save = curwin->w_cursor;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1596 ind_maxp_wk = ind_maxparen;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1597 retry:
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1598 if ((trypos = findmatchlimit(NULL, c, 0, ind_maxp_wk)) != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1599 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1600 // check if the ( is in a // comment
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1601 if ((colnr_T)cin_skip2pos(trypos) > trypos->col)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1602 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1603 ind_maxp_wk = ind_maxparen - (int)(cursor_save.lnum - trypos->lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1604 if (ind_maxp_wk > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1605 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1606 curwin->w_cursor = *trypos;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1607 curwin->w_cursor.col = 0; // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1608 goto retry;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1609 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1610 trypos = NULL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1611 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1612 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1613 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1614 pos_T *trypos_wk;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1615
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1616 pos_copy = *trypos; // copy trypos, findmatch will change it
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1617 trypos = &pos_copy;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1618 curwin->w_cursor = *trypos;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1619 if ((trypos_wk = ind_find_start_CORS(NULL)) != NULL) // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1620 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1621 ind_maxp_wk = ind_maxparen - (int)(cursor_save.lnum
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1622 - trypos_wk->lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1623 if (ind_maxp_wk > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1624 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1625 curwin->w_cursor = *trypos_wk;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1626 goto retry;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1627 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1628 trypos = NULL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1629 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1630 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1631 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1632 curwin->w_cursor = cursor_save;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1633 return trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1634 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1635
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1636 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1637 * Find the matching '(', ignoring it if it is in a comment or before an
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1638 * unmatched {.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1639 * Return NULL if no match found.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1640 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1641 static pos_T *
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1642 find_match_paren_after_brace (int ind_maxparen) // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1643 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1644 pos_T *trypos = find_match_paren(ind_maxparen);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1645
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1646 if (trypos != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1647 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1648 pos_T *tryposBrace = find_start_brace();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1649
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1650 // If both an unmatched '(' and '{' is found. Ignore the '('
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1651 // position if the '{' is further down.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1652 if (tryposBrace != NULL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1653 && (trypos->lnum != tryposBrace->lnum
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1654 ? trypos->lnum < tryposBrace->lnum
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1655 : trypos->col < tryposBrace->col))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1656 trypos = NULL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1657 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1658 return trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1659 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1660
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1661 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1662 * Return ind_maxparen corrected for the difference in line number between the
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1663 * cursor position and "startpos". This makes sure that searching for a
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1664 * matching paren above the cursor line doesn't find a match because of
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1665 * looking a few lines further.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1666 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1667 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1668 corr_ind_maxparen(pos_T *startpos)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1669 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1670 long n = (long)startpos->lnum - (long)curwin->w_cursor.lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1671
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1672 if (n > 0 && n < curbuf->b_ind_maxparen / 2)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1673 return curbuf->b_ind_maxparen - (int)n;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1674 return curbuf->b_ind_maxparen;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1675 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1676
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1677 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1678 * Set w_cursor.col to the column number of the last unmatched ')' or '{' in
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1679 * line "l". "l" must point to the start of the line.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1680 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1681 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1682 find_last_paren(char_u *l, int start, int end)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1683 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1684 int i;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1685 int retval = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1686 int open_count = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1687
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1688 curwin->w_cursor.col = 0; // default is start of line
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1689
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1690 for (i = 0; l[i] != NUL; i++)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1691 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1692 i = (int)(cin_skipcomment(l + i) - l); // ignore parens in comments
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1693 i = (int)(skip_string(l + i) - l); // ignore parens in quotes
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1694 if (l[i] == start)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1695 ++open_count;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1696 else if (l[i] == end)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1697 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1698 if (open_count > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1699 --open_count;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1700 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1701 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1702 curwin->w_cursor.col = i;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1703 retval = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1704 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1705 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1706 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1707 return retval;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1708 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1709
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1710 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1711 * Parse 'cinoptions' and set the values in "curbuf".
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1712 * Must be called when 'cinoptions', 'shiftwidth' and/or 'tabstop' changes.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1713 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1714 void
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1715 parse_cino(buf_T *buf)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1716 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1717 char_u *p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1718 char_u *l;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1719 char_u *digits;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1720 int n;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1721 int divider;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1722 int fraction = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1723 int sw = (int)get_sw_value(buf);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1724
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1725 // Set the default values.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1726
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1727 // Spaces from a block's opening brace the prevailing indent for that
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1728 // block should be.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1729 buf->b_ind_level = sw;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1730
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1731 // Spaces from the edge of the line an open brace that's at the end of a
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1732 // line is imagined to be.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1733 buf->b_ind_open_imag = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1734
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1735 // Spaces from the prevailing indent for a line that is not preceded by
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1736 // an opening brace.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1737 buf->b_ind_no_brace = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1738
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1739 // Column where the first { of a function should be located }.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1740 buf->b_ind_first_open = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1741
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1742 // Spaces from the prevailing indent a leftmost open brace should be
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1743 // located.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1744 buf->b_ind_open_extra = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1745
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1746 // Spaces from the matching open brace (real location for one at the left
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1747 // edge; imaginary location from one that ends a line) the matching close
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1748 // brace should be located.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1749 buf->b_ind_close_extra = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1750
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1751 // Spaces from the edge of the line an open brace sitting in the leftmost
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1752 // column is imagined to be.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1753 buf->b_ind_open_left_imag = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1754
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1755 // Spaces jump labels should be shifted to the left if N is non-negative,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1756 // otherwise the jump label will be put to column 1.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1757 buf->b_ind_jump_label = -1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1758
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1759 // Spaces from the switch() indent a "case xx" label should be located.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1760 buf->b_ind_case = sw;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1761
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1762 // Spaces from the "case xx:" code after a switch() should be located.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1763 buf->b_ind_case_code = sw;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1764
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1765 // Lineup break at end of case in switch() with case label.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1766 buf->b_ind_case_break = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1767
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1768 // Spaces from the class declaration indent a scope declaration label
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1769 // should be located.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1770 buf->b_ind_scopedecl = sw;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1771
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1772 // Spaces from the scope declaration label code should be located.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1773 buf->b_ind_scopedecl_code = sw;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1774
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1775 // Amount K&R-style parameters should be indented.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1776 buf->b_ind_param = sw;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1777
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1778 // Amount a function type spec should be indented.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1779 buf->b_ind_func_type = sw;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1780
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1781 // Amount a cpp base class declaration or constructor initialization
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1782 // should be indented.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1783 buf->b_ind_cpp_baseclass = sw;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1784
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1785 // additional spaces beyond the prevailing indent a continuation line
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1786 // should be located.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1787 buf->b_ind_continuation = sw;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1788
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1789 // Spaces from the indent of the line with an unclosed parentheses.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1790 buf->b_ind_unclosed = sw * 2;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1791
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1792 // Spaces from the indent of the line with an unclosed parentheses, which
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1793 // itself is also unclosed.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1794 buf->b_ind_unclosed2 = sw;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1795
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1796 // Suppress ignoring spaces from the indent of a line starting with an
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1797 // unclosed parentheses.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1798 buf->b_ind_unclosed_noignore = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1799
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1800 // If the opening paren is the last nonwhite character on the line, and
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1801 // b_ind_unclosed_wrapped is nonzero, use this indent relative to the outer
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1802 // context (for very long lines).
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1803 buf->b_ind_unclosed_wrapped = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1804
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1805 // Suppress ignoring white space when lining up with the character after
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1806 // an unclosed parentheses.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1807 buf->b_ind_unclosed_whiteok = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1808
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1809 // Indent a closing parentheses under the line start of the matching
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1810 // opening parentheses.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1811 buf->b_ind_matching_paren = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1812
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1813 // Indent a closing parentheses under the previous line.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1814 buf->b_ind_paren_prev = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1815
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1816 // Extra indent for comments.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1817 buf->b_ind_comment = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1818
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1819 // Spaces from the comment opener when there is nothing after it.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1820 buf->b_ind_in_comment = 3;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1821
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1822 // Boolean: if non-zero, use b_ind_in_comment even if there is something
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1823 // after the comment opener.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1824 buf->b_ind_in_comment2 = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1825
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1826 // Max lines to search for an open paren.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1827 buf->b_ind_maxparen = 20;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1828
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1829 // Max lines to search for an open comment.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1830 buf->b_ind_maxcomment = 70;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1831
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1832 // Handle braces for java code.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1833 buf->b_ind_java = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1834
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1835 // Not to confuse JS object properties with labels.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1836 buf->b_ind_js = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1837
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1838 // Handle blocked cases correctly.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1839 buf->b_ind_keep_case_label = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1840
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1841 // Handle C++ namespace.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1842 buf->b_ind_cpp_namespace = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1843
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1844 // Handle continuation lines containing conditions of if(), for() and
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1845 // while().
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1846 buf->b_ind_if_for_while = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1847
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1848 // indentation for # comments
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1849 buf->b_ind_hash_comment = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1850
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1851 // Handle C++ extern "C" or "C++"
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1852 buf->b_ind_cpp_extern_c = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1853
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1854 for (p = buf->b_p_cino; *p; )
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1855 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1856 l = p++;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1857 if (*p == '-')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1858 ++p;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1859 digits = p; // remember where the digits start
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1860 n = getdigits(&p);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1861 divider = 0;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1862 if (*p == '.') // ".5s" means a fraction
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1863 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1864 fraction = atol((char *)++p);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1865 while (VIM_ISDIGIT(*p))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1866 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1867 ++p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1868 if (divider)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1869 divider *= 10;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1870 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1871 divider = 10;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1872 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1873 }
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1874 if (*p == 's') // "2s" means two times 'shiftwidth'
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1875 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1876 if (p == digits)
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1877 n = sw; // just "s" is one 'shiftwidth'
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1878 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1879 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1880 n *= sw;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1881 if (divider)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1882 n += (sw * fraction + divider / 2) / divider;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1883 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1884 ++p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1885 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1886 if (l[1] == '-')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1887 n = -n;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1888
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1889 // When adding an entry here, also update the default 'cinoptions' in
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1890 // doc/indent.txt, and add explanation for it!
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1891 switch (*l)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1892 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1893 case '>': buf->b_ind_level = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1894 case 'e': buf->b_ind_open_imag = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1895 case 'n': buf->b_ind_no_brace = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1896 case 'f': buf->b_ind_first_open = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1897 case '{': buf->b_ind_open_extra = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1898 case '}': buf->b_ind_close_extra = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1899 case '^': buf->b_ind_open_left_imag = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1900 case 'L': buf->b_ind_jump_label = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1901 case ':': buf->b_ind_case = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1902 case '=': buf->b_ind_case_code = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1903 case 'b': buf->b_ind_case_break = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1904 case 'p': buf->b_ind_param = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1905 case 't': buf->b_ind_func_type = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1906 case '/': buf->b_ind_comment = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1907 case 'c': buf->b_ind_in_comment = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1908 case 'C': buf->b_ind_in_comment2 = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1909 case 'i': buf->b_ind_cpp_baseclass = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1910 case '+': buf->b_ind_continuation = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1911 case '(': buf->b_ind_unclosed = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1912 case 'u': buf->b_ind_unclosed2 = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1913 case 'U': buf->b_ind_unclosed_noignore = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1914 case 'W': buf->b_ind_unclosed_wrapped = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1915 case 'w': buf->b_ind_unclosed_whiteok = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1916 case 'm': buf->b_ind_matching_paren = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1917 case 'M': buf->b_ind_paren_prev = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1918 case ')': buf->b_ind_maxparen = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1919 case '*': buf->b_ind_maxcomment = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1920 case 'g': buf->b_ind_scopedecl = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1921 case 'h': buf->b_ind_scopedecl_code = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1922 case 'j': buf->b_ind_java = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1923 case 'J': buf->b_ind_js = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1924 case 'l': buf->b_ind_keep_case_label = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1925 case '#': buf->b_ind_hash_comment = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1926 case 'N': buf->b_ind_cpp_namespace = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1927 case 'k': buf->b_ind_if_for_while = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1928 case 'E': buf->b_ind_cpp_extern_c = n; break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1929 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1930 if (*p == ',')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1931 ++p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1932 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1933 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1934
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1935 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1936 * Return the desired indent for C code.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1937 * Return -1 if the indent should be left alone (inside a raw string).
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1938 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1939 int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1940 get_c_indent(void)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1941 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1942 pos_T cur_curpos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1943 int amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1944 int scope_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1945 int cur_amount = MAXCOL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1946 colnr_T col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1947 char_u *theline;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1948 char_u *linecopy;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1949 pos_T *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1950 pos_T *comment_pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1951 pos_T *tryposBrace = NULL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1952 pos_T tryposCopy;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1953 pos_T our_paren_pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1954 char_u *start;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1955 int start_brace;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1956 #define BRACE_IN_COL0 1 // '{' is in column 0
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1957 #define BRACE_AT_START 2 // '{' is at start of line
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1958 #define BRACE_AT_END 3 // '{' is at end of line
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1959 linenr_T ourscope;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1960 char_u *l;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1961 char_u *look;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1962 char_u terminated;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1963 int lookfor;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1964 #define LOOKFOR_INITIAL 0
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1965 #define LOOKFOR_IF 1
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1966 #define LOOKFOR_DO 2
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1967 #define LOOKFOR_CASE 3
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1968 #define LOOKFOR_ANY 4
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1969 #define LOOKFOR_TERM 5
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1970 #define LOOKFOR_UNTERM 6
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1971 #define LOOKFOR_SCOPEDECL 7
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1972 #define LOOKFOR_NOBREAK 8
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1973 #define LOOKFOR_CPP_BASECLASS 9
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1974 #define LOOKFOR_ENUM_OR_INIT 10
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1975 #define LOOKFOR_JS_KEY 11
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1976 #define LOOKFOR_COMMA 12
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1977
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1978 int whilelevel;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1979 linenr_T lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1980 int n;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1981 int iscase;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1982 int lookfor_break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1983 int lookfor_cpp_namespace = FALSE;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1984 int cont_amount = 0; // amount for continuation line
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1985 int original_line_islabel;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1986 int added_to_amount = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1987 int js_cur_has_key = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1988 linenr_T raw_string_start = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1989 cpp_baseclass_cache_T cache_cpp_baseclass = { FALSE, { MAXLNUM, 0 } };
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1990
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1991 // make a copy, value is changed below
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1992 int ind_continuation = curbuf->b_ind_continuation;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1993
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1994 // remember where the cursor was when we started
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1995 cur_curpos = curwin->w_cursor;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1996
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1997 // if we are at line 1 zero indent is fine, right?
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1998 if (cur_curpos.lnum == 1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1999 return 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2000
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2001 // Get a copy of the current contents of the line.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2002 // This is required, because only the most recent line obtained with
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2003 // ml_get is valid!
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2004 linecopy = vim_strsave(ml_get(cur_curpos.lnum));
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2005 if (linecopy == NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2006 return 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2007
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2008 // In insert mode and the cursor is on a ')' truncate the line at the
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2009 // cursor position. We don't want to line up with the matching '(' when
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2010 // inserting new stuff.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2011 // For unknown reasons the cursor might be past the end of the line, thus
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2012 // check for that.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2013 if ((State & INSERT)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2014 && curwin->w_cursor.col < (colnr_T)STRLEN(linecopy)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2015 && linecopy[curwin->w_cursor.col] == ')')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2016 linecopy[curwin->w_cursor.col] = NUL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2017
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2018 theline = skipwhite(linecopy);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2019
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2020 // move the cursor to the start of the line
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2021
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2022 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2023
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2024 original_line_islabel = cin_islabel(); // XXX
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2025
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2026 // If we are inside a raw string don't change the indent.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2027 // Ignore a raw string inside a comment.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2028 comment_pos = ind_find_start_comment();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2029 if (comment_pos != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2030 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2031 // findmatchlimit() static pos is overwritten, make a copy
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2032 tryposCopy = *comment_pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2033 comment_pos = &tryposCopy;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2034 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2035 trypos = find_start_rawstring(curbuf->b_ind_maxcomment);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2036 if (trypos != NULL && (comment_pos == NULL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2037 || LT_POS(*trypos, *comment_pos)))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2038 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2039 amount = -1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2040 goto laterend;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2041 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2042
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2043 // #defines and so on always go at the left when included in 'cinkeys'.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2044 if (*theline == '#' && (*linecopy == '#' || in_cinkeys('#', ' ', TRUE)))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2045 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2046 amount = curbuf->b_ind_hash_comment;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2047 goto theend;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2048 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2049
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2050 // Is it a non-case label? Then that goes at the left margin too unless:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2051 // - JS flag is set.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2052 // - 'L' item has a positive value.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2053 if (original_line_islabel && !curbuf->b_ind_js
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2054 && curbuf->b_ind_jump_label < 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2055 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2056 amount = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2057 goto theend;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2058 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2059
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2060 // If we're inside a "//" comment and there is a "//" comment in a
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2061 // previous line, lineup with that one.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2062 if (cin_islinecomment(theline)
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2063 && (trypos = find_line_comment()) != NULL) // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2064 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2065 // find how indented the line beginning the comment is
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2066 getvcol(curwin, trypos, &col, NULL, NULL);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2067 amount = col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2068 goto theend;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2069 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2070
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2071 // If we're inside a comment and not looking at the start of the
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2072 // comment, try using the 'comments' option.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2073 if (!cin_iscomment(theline) && comment_pos != NULL) // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2074 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2075 int lead_start_len = 2;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2076 int lead_middle_len = 1;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2077 char_u lead_start[COM_MAX_LEN]; // start-comment string
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2078 char_u lead_middle[COM_MAX_LEN]; // middle-comment string
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2079 char_u lead_end[COM_MAX_LEN]; // end-comment string
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2080 char_u *p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2081 int start_align = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2082 int start_off = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2083 int done = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2084
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2085 // find how indented the line beginning the comment is
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2086 getvcol(curwin, comment_pos, &col, NULL, NULL);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2087 amount = col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2088 *lead_start = NUL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2089 *lead_middle = NUL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2090
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2091 p = curbuf->b_p_com;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2092 while (*p != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2093 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2094 int align = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2095 int off = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2096 int what = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2097
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2098 while (*p != NUL && *p != ':')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2099 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2100 if (*p == COM_START || *p == COM_END || *p == COM_MIDDLE)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2101 what = *p++;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2102 else if (*p == COM_LEFT || *p == COM_RIGHT)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2103 align = *p++;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2104 else if (VIM_ISDIGIT(*p) || *p == '-')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2105 off = getdigits(&p);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2106 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2107 ++p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2108 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2109
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2110 if (*p == ':')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2111 ++p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2112 (void)copy_option_part(&p, lead_end, COM_MAX_LEN, ",");
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2113 if (what == COM_START)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2114 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2115 STRCPY(lead_start, lead_end);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2116 lead_start_len = (int)STRLEN(lead_start);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2117 start_off = off;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2118 start_align = align;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2119 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2120 else if (what == COM_MIDDLE)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2121 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2122 STRCPY(lead_middle, lead_end);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2123 lead_middle_len = (int)STRLEN(lead_middle);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2124 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2125 else if (what == COM_END)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2126 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2127 // If our line starts with the middle comment string, line it
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2128 // up with the comment opener per the 'comments' option.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2129 if (STRNCMP(theline, lead_middle, lead_middle_len) == 0
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2130 && STRNCMP(theline, lead_end, STRLEN(lead_end)) != 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2131 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2132 done = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2133 if (curwin->w_cursor.lnum > 1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2134 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2135 // If the start comment string matches in the previous
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2136 // line, use the indent of that line plus offset. If
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2137 // the middle comment string matches in the previous
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2138 // line, use the indent of that line. XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2139 look = skipwhite(ml_get(curwin->w_cursor.lnum - 1));
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2140 if (STRNCMP(look, lead_start, lead_start_len) == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2141 amount = get_indent_lnum(curwin->w_cursor.lnum - 1);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2142 else if (STRNCMP(look, lead_middle,
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2143 lead_middle_len) == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2144 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2145 amount = get_indent_lnum(curwin->w_cursor.lnum - 1);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2146 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2147 }
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2148 // If the start comment string doesn't match with the
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2149 // start of the comment, skip this entry. XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2150 else if (STRNCMP(ml_get(comment_pos->lnum) + comment_pos->col,
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2151 lead_start, lead_start_len) != 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2152 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2153 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2154 if (start_off != 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2155 amount += start_off;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2156 else if (start_align == COM_RIGHT)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2157 amount += vim_strsize(lead_start)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2158 - vim_strsize(lead_middle);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2159 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2160 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2161
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2162 // If our line starts with the end comment string, line it up
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2163 // with the middle comment
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2164 if (STRNCMP(theline, lead_middle, lead_middle_len) != 0
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2165 && STRNCMP(theline, lead_end, STRLEN(lead_end)) == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2166 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2167 amount = get_indent_lnum(curwin->w_cursor.lnum - 1);
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2168 // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2169 if (off != 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2170 amount += off;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2171 else if (align == COM_RIGHT)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2172 amount += vim_strsize(lead_start)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2173 - vim_strsize(lead_middle);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2174 done = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2175 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2176 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2177 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2178 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2179
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2180 // If our line starts with an asterisk, line up with the
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2181 // asterisk in the comment opener; otherwise, line up
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2182 // with the first character of the comment text.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2183 if (done)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2184 ;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2185 else if (theline[0] == '*')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2186 amount += 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2187 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2188 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2189 // If we are more than one line away from the comment opener, take
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2190 // the indent of the previous non-empty line. If 'cino' has "CO"
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2191 // and we are just below the comment opener and there are any
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2192 // white characters after it line up with the text after it;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2193 // otherwise, add the amount specified by "c" in 'cino'
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2194 amount = -1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2195 for (lnum = cur_curpos.lnum - 1; lnum > comment_pos->lnum; --lnum)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2196 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2197 if (linewhite(lnum)) // skip blank lines
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2198 continue;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2199 amount = get_indent_lnum(lnum); // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2200 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2201 }
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2202 if (amount == -1) // use the comment opener
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2203 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2204 if (!curbuf->b_ind_in_comment2)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2205 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2206 start = ml_get(comment_pos->lnum);
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2207 look = start + comment_pos->col + 2; // skip / and *
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2208 if (*look != NUL) // if something after it
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2209 comment_pos->col = (colnr_T)(skipwhite(look) - start);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2210 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2211 getvcol(curwin, comment_pos, &col, NULL, NULL);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2212 amount = col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2213 if (curbuf->b_ind_in_comment2 || *look == NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2214 amount += curbuf->b_ind_in_comment;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2215 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2216 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2217 goto theend;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2218 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2219
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2220 // Are we looking at a ']' that has a match?
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2221 if (*skipwhite(theline) == ']'
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2222 && (trypos = find_match_char('[', curbuf->b_ind_maxparen)) != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2223 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2224 // align with the line containing the '['.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2225 amount = get_indent_lnum(trypos->lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2226 goto theend;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2227 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2228
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2229 // Are we inside parentheses or braces? XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2230 if (((trypos = find_match_paren(curbuf->b_ind_maxparen)) != NULL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2231 && curbuf->b_ind_java == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2232 || (tryposBrace = find_start_brace()) != NULL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2233 || trypos != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2234 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2235 if (trypos != NULL && tryposBrace != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2236 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2237 // Both an unmatched '(' and '{' is found. Use the one which is
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2238 // closer to the current cursor position, set the other to NULL.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2239 if (trypos->lnum != tryposBrace->lnum
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2240 ? trypos->lnum < tryposBrace->lnum
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2241 : trypos->col < tryposBrace->col)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2242 trypos = NULL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2243 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2244 tryposBrace = NULL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2245 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2246
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2247 if (trypos != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2248 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2249 // If the matching paren is more than one line away, use the indent of
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2250 // a previous non-empty line that matches the same paren.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2251 if (theline[0] == ')' && curbuf->b_ind_paren_prev)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2252 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2253 // Line up with the start of the matching paren line.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2254 amount = get_indent_lnum(curwin->w_cursor.lnum - 1); // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2255 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2256 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2257 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2258 amount = -1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2259 our_paren_pos = *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2260 for (lnum = cur_curpos.lnum - 1; lnum > our_paren_pos.lnum; --lnum)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2261 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2262 l = skipwhite(ml_get(lnum));
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2263 if (cin_nocode(l)) // skip comment lines
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2264 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2265 if (cin_ispreproc_cont(&l, &lnum, &amount))
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2266 continue; // ignore #define, #if, etc.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2267 curwin->w_cursor.lnum = lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2268
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2269 // Skip a comment or raw string. XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2270 if ((trypos = ind_find_start_CORS(NULL)) != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2271 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2272 lnum = trypos->lnum + 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2273 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2274 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2275
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2276 // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2277 if ((trypos = find_match_paren(
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2278 corr_ind_maxparen(&cur_curpos))) != NULL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2279 && trypos->lnum == our_paren_pos.lnum
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2280 && trypos->col == our_paren_pos.col)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2281 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2282 amount = get_indent_lnum(lnum); // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2283
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2284 if (theline[0] == ')')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2285 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2286 if (our_paren_pos.lnum != lnum
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2287 && cur_amount > amount)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2288 cur_amount = amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2289 amount = -1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2290 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2291 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2292 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2293 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2294 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2295
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2296 // Line up with line where the matching paren is. XXX
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2297 // If the line starts with a '(' or the indent for unclosed
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2298 // parentheses is zero, line up with the unclosed parentheses.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2299 if (amount == -1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2300 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2301 int ignore_paren_col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2302 int is_if_for_while = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2303
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2304 if (curbuf->b_ind_if_for_while)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2305 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2306 // Look for the outermost opening parenthesis on this line
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2307 // and check whether it belongs to an "if", "for" or "while".
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2308
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2309 pos_T cursor_save = curwin->w_cursor;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2310 pos_T outermost;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2311 char_u *line;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2312
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2313 trypos = &our_paren_pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2314 do {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2315 outermost = *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2316 curwin->w_cursor.lnum = outermost.lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2317 curwin->w_cursor.col = outermost.col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2318
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2319 trypos = find_match_paren(curbuf->b_ind_maxparen);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2320 } while (trypos && trypos->lnum == outermost.lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2321
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2322 curwin->w_cursor = cursor_save;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2323
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2324 line = ml_get(outermost.lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2325
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2326 is_if_for_while =
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2327 cin_is_if_for_while_before_offset(line, &outermost.col);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2328 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2329
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2330 amount = skip_label(our_paren_pos.lnum, &look);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2331 look = skipwhite(look);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2332 if (*look == '(')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2333 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2334 linenr_T save_lnum = curwin->w_cursor.lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2335 char_u *line;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2336 int look_col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2337
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2338 // Ignore a '(' in front of the line that has a match before
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2339 // our matching '('.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2340 curwin->w_cursor.lnum = our_paren_pos.lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2341 line = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2342 look_col = (int)(look - line);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2343 curwin->w_cursor.col = look_col + 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2344 if ((trypos = findmatchlimit(NULL, ')', 0,
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2345 curbuf->b_ind_maxparen))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2346 != NULL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2347 && trypos->lnum == our_paren_pos.lnum
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2348 && trypos->col < our_paren_pos.col)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2349 ignore_paren_col = trypos->col + 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2350
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2351 curwin->w_cursor.lnum = save_lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2352 look = ml_get(our_paren_pos.lnum) + look_col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2353 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2354 if (theline[0] == ')' || (curbuf->b_ind_unclosed == 0
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2355 && is_if_for_while == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2356 || (!curbuf->b_ind_unclosed_noignore && *look == '('
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2357 && ignore_paren_col == 0))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2358 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2359 // If we're looking at a close paren, line up right there;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2360 // otherwise, line up with the next (non-white) character.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2361 // When b_ind_unclosed_wrapped is set and the matching paren is
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2362 // the last nonwhite character of the line, use either the
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2363 // indent of the current line or the indentation of the next
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2364 // outer paren and add b_ind_unclosed_wrapped (for very long
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2365 // lines).
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2366 if (theline[0] != ')')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2367 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2368 cur_amount = MAXCOL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2369 l = ml_get(our_paren_pos.lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2370 if (curbuf->b_ind_unclosed_wrapped
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2371 && cin_ends_in(l, (char_u *)"(", NULL))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2372 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2373 // look for opening unmatched paren, indent one level
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2374 // for each additional level
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2375 n = 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2376 for (col = 0; col < our_paren_pos.col; ++col)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2377 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2378 switch (l[col])
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2379 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2380 case '(':
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2381 case '{': ++n;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2382 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2383
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2384 case ')':
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2385 case '}': if (n > 1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2386 --n;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2387 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2388 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2389 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2390
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2391 our_paren_pos.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2392 amount += n * curbuf->b_ind_unclosed_wrapped;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2393 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2394 else if (curbuf->b_ind_unclosed_whiteok)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2395 our_paren_pos.col++;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2396 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2397 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2398 col = our_paren_pos.col + 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2399 while (VIM_ISWHITE(l[col]))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2400 col++;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2401 if (l[col] != NUL) // In case of trailing space
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2402 our_paren_pos.col = col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2403 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2404 our_paren_pos.col++;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2405 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2406 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2407
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2408 // Find how indented the paren is, or the character after it
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2409 // if we did the above "if".
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2410 if (our_paren_pos.col > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2411 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2412 getvcol(curwin, &our_paren_pos, &col, NULL, NULL);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2413 if (cur_amount > (int)col)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2414 cur_amount = col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2415 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2416 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2417
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2418 if (theline[0] == ')' && curbuf->b_ind_matching_paren)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2419 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2420 // Line up with the start of the matching paren line.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2421 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2422 else if ((curbuf->b_ind_unclosed == 0 && is_if_for_while == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2423 || (!curbuf->b_ind_unclosed_noignore
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2424 && *look == '(' && ignore_paren_col == 0))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2425 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2426 if (cur_amount != MAXCOL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2427 amount = cur_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2428 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2429 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2430 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2431 // Add b_ind_unclosed2 for each '(' before our matching one,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2432 // but ignore (void) before the line (ignore_paren_col).
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2433 col = our_paren_pos.col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2434 while ((int)our_paren_pos.col > ignore_paren_col)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2435 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2436 --our_paren_pos.col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2437 switch (*ml_get_pos(&our_paren_pos))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2438 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2439 case '(': amount += curbuf->b_ind_unclosed2;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2440 col = our_paren_pos.col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2441 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2442 case ')': amount -= curbuf->b_ind_unclosed2;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2443 col = MAXCOL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2444 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2445 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2446 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2447
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2448 // Use b_ind_unclosed once, when the first '(' is not inside
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2449 // braces
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2450 if (col == MAXCOL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2451 amount += curbuf->b_ind_unclosed;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2452 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2453 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2454 curwin->w_cursor.lnum = our_paren_pos.lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2455 curwin->w_cursor.col = col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2456 if (find_match_paren_after_brace(curbuf->b_ind_maxparen)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2457 != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2458 amount += curbuf->b_ind_unclosed2;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2459 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2460 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2461 if (is_if_for_while)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2462 amount += curbuf->b_ind_if_for_while;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2463 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2464 amount += curbuf->b_ind_unclosed;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2465 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2466 }
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2467 // For a line starting with ')' use the minimum of the two
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2468 // positions, to avoid giving it more indent than the previous
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2469 // lines:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2470 // func_long_name( if (x
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2471 // arg && yy
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2472 // ) ^ not here ) ^ not here
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2473 if (cur_amount < amount)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2474 amount = cur_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2475 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2476 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2477
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2478 // add extra indent for a comment
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2479 if (cin_iscomment(theline))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2480 amount += curbuf->b_ind_comment;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2481 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2482 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2483 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2484 // We are inside braces, there is a { before this line at the position
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2485 // stored in tryposBrace.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2486 // Make a copy of tryposBrace, it may point to pos_copy inside
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2487 // find_start_brace(), which may be changed somewhere.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2488 tryposCopy = *tryposBrace;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2489 tryposBrace = &tryposCopy;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2490 trypos = tryposBrace;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2491 ourscope = trypos->lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2492 start = ml_get(ourscope);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2493
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2494 // Now figure out how indented the line is in general.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2495 // If the brace was at the start of the line, we use that;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2496 // otherwise, check out the indentation of the line as
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2497 // a whole and then add the "imaginary indent" to that.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2498 look = skipwhite(start);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2499 if (*look == '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2500 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2501 getvcol(curwin, trypos, &col, NULL, NULL);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2502 amount = col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2503 if (*start == '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2504 start_brace = BRACE_IN_COL0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2505 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2506 start_brace = BRACE_AT_START;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2507 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2508 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2509 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2510 // That opening brace might have been on a continuation
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2511 // line. if so, find the start of the line.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2512 curwin->w_cursor.lnum = ourscope;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2513
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2514 // Position the cursor over the rightmost paren, so that
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2515 // matching it will take us back to the start of the line.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2516 lnum = ourscope;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2517 if (find_last_paren(start, '(', ')')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2518 && (trypos = find_match_paren(curbuf->b_ind_maxparen))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2519 != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2520 lnum = trypos->lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2521
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2522 // It could have been something like
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2523 // case 1: if (asdf &&
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2524 // ldfd) {
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2525 // }
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2526 if ((curbuf->b_ind_js || curbuf->b_ind_keep_case_label)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2527 && cin_iscase(skipwhite(ml_get_curline()), FALSE))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2528 amount = get_indent();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2529 else if (curbuf->b_ind_js)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2530 amount = get_indent_lnum(lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2531 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2532 amount = skip_label(lnum, &l);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2533
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2534 start_brace = BRACE_AT_END;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2535 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2536
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2537 // For Javascript check if the line starts with "key:".
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2538 if (curbuf->b_ind_js)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2539 js_cur_has_key = cin_has_js_key(theline);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2540
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2541 // If we're looking at a closing brace, that's where
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2542 // we want to be. otherwise, add the amount of room
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2543 // that an indent is supposed to be.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2544 if (theline[0] == '}')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2545 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2546 // they may want closing braces to line up with something
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2547 // other than the open brace. indulge them, if so.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2548 amount += curbuf->b_ind_close_extra;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2549 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2550 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2551 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2552 // If we're looking at an "else", try to find an "if"
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2553 // to match it with.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2554 // If we're looking at a "while", try to find a "do"
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2555 // to match it with.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2556 lookfor = LOOKFOR_INITIAL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2557 if (cin_iselse(theline))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2558 lookfor = LOOKFOR_IF;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2559 else if (cin_iswhileofdo(theline, cur_curpos.lnum)) // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2560 lookfor = LOOKFOR_DO;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2561 if (lookfor != LOOKFOR_INITIAL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2562 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2563 curwin->w_cursor.lnum = cur_curpos.lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2564 if (find_match(lookfor, ourscope) == OK)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2565 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2566 amount = get_indent(); // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2567 goto theend;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2568 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2569 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2570
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2571 // We get here if we are not on an "while-of-do" or "else" (or
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2572 // failed to find a matching "if").
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2573 // Search backwards for something to line up with.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2574 // First set amount for when we don't find anything.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2575
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2576 // if the '{' is _really_ at the left margin, use the imaginary
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2577 // location of a left-margin brace. Otherwise, correct the
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2578 // location for b_ind_open_extra.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2579
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2580 if (start_brace == BRACE_IN_COL0) // '{' is in column 0
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2581 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2582 amount = curbuf->b_ind_open_left_imag;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2583 lookfor_cpp_namespace = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2584 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2585 else if (start_brace == BRACE_AT_START &&
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2586 lookfor_cpp_namespace) // '{' is at start
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2587 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2588
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2589 lookfor_cpp_namespace = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2590 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2591 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2592 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2593 if (start_brace == BRACE_AT_END) // '{' is at end of line
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2594 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2595 amount += curbuf->b_ind_open_imag;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2596
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2597 l = skipwhite(ml_get_curline());
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2598 if (cin_is_cpp_namespace(l))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2599 amount += curbuf->b_ind_cpp_namespace;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2600 else if (cin_is_cpp_extern_c(l))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2601 amount += curbuf->b_ind_cpp_extern_c;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2602 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2603 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2604 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2605 // Compensate for adding b_ind_open_extra later.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2606 amount -= curbuf->b_ind_open_extra;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2607 if (amount < 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2608 amount = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2609 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2610 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2611
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2612 lookfor_break = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2613
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2614 if (cin_iscase(theline, FALSE)) // it's a switch() label
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2615 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2616 lookfor = LOOKFOR_CASE; // find a previous switch() label
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2617 amount += curbuf->b_ind_case;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2618 }
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2619 else if (cin_isscopedecl(theline)) // private:, ...
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2620 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2621 lookfor = LOOKFOR_SCOPEDECL; // class decl is this block
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2622 amount += curbuf->b_ind_scopedecl;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2623 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2624 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2625 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2626 if (curbuf->b_ind_case_break && cin_isbreak(theline))
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2627 // break; ...
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2628 lookfor_break = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2629
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2630 lookfor = LOOKFOR_INITIAL;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2631 // b_ind_level from start of block
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2632 amount += curbuf->b_ind_level;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2633 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2634 scope_amount = amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2635 whilelevel = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2636
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2637 // Search backwards. If we find something we recognize, line up
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2638 // with that.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2639 //
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2640 // If we're looking at an open brace, indent
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2641 // the usual amount relative to the conditional
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2642 // that opens the block.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2643 curwin->w_cursor = cur_curpos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2644 for (;;)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2645 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2646 curwin->w_cursor.lnum--;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2647 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2648
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2649 // If we went all the way back to the start of our scope, line
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2650 // up with it.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2651 if (curwin->w_cursor.lnum <= ourscope)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2652 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2653 // We reached end of scope:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2654 // If looking for a enum or structure initialization
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2655 // go further back:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2656 // If it is an initializer (enum xxx or xxx =), then
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2657 // don't add ind_continuation, otherwise it is a variable
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2658 // declaration:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2659 // int x,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2660 // here; <-- add ind_continuation
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2661 if (lookfor == LOOKFOR_ENUM_OR_INIT)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2662 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2663 if (curwin->w_cursor.lnum == 0
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2664 || curwin->w_cursor.lnum
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2665 < ourscope - curbuf->b_ind_maxparen)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2666 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2667 // nothing found (abuse curbuf->b_ind_maxparen as
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2668 // limit) assume terminated line (i.e. a variable
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2669 // initialization)
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2670 if (cont_amount > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2671 amount = cont_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2672 else if (!curbuf->b_ind_js)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2673 amount += ind_continuation;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2674 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2675 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2676
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2677 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2678
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2679 // If we're in a comment or raw string now, skip to
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2680 // the start of it.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2681 trypos = ind_find_start_CORS(NULL);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2682 if (trypos != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2683 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2684 curwin->w_cursor.lnum = trypos->lnum + 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2685 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2686 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2687 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2688
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2689 // Skip preprocessor directives and blank lines.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2690 if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum,
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2691 &amount))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2692 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2693
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2694 if (cin_nocode(l))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2695 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2696
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2697 terminated = cin_isterminated(l, FALSE, TRUE);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2698
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2699 // If we are at top level and the line looks like a
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2700 // function declaration, we are done
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2701 // (it's a variable declaration).
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2702 if (start_brace != BRACE_IN_COL0
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2703 || !cin_isfuncdecl(&l, curwin->w_cursor.lnum, 0))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2704 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2705 // if the line is terminated with another ','
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2706 // it is a continued variable initialization.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2707 // don't add extra indent.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2708 // TODO: does not work, if a function
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2709 // declaration is split over multiple lines:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2710 // cin_isfuncdecl returns FALSE then.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2711 if (terminated == ',')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2712 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2713
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2714 // if it es a enum declaration or an assignment,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2715 // we are done.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2716 if (terminated != ';' && cin_isinit())
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2717 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2718
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2719 // nothing useful found
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2720 if (terminated == 0 || terminated == '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2721 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2722 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2723
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2724 if (terminated != ';')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2725 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2726 // Skip parens and braces. Position the cursor
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2727 // over the rightmost paren, so that matching it
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2728 // will take us back to the start of the line.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2729 // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2730 trypos = NULL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2731 if (find_last_paren(l, '(', ')'))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2732 trypos = find_match_paren(
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2733 curbuf->b_ind_maxparen);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2734
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2735 if (trypos == NULL && find_last_paren(l, '{', '}'))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2736 trypos = find_start_brace();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2737
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2738 if (trypos != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2739 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2740 curwin->w_cursor.lnum = trypos->lnum + 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2741 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2742 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2743 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2744 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2745
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2746 // it's a variable declaration, add indentation
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2747 // like in
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2748 // int a,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2749 // b;
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2750 if (cont_amount > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2751 amount = cont_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2752 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2753 amount += ind_continuation;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2754 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2755 else if (lookfor == LOOKFOR_UNTERM)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2756 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2757 if (cont_amount > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2758 amount = cont_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2759 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2760 amount += ind_continuation;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2761 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2762 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2763 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2764 if (lookfor != LOOKFOR_TERM
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2765 && lookfor != LOOKFOR_CPP_BASECLASS
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2766 && lookfor != LOOKFOR_COMMA)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2767 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2768 amount = scope_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2769 if (theline[0] == '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2770 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2771 amount += curbuf->b_ind_open_extra;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2772 added_to_amount = curbuf->b_ind_open_extra;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2773 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2774 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2775
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2776 if (lookfor_cpp_namespace)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2777 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2778 // Looking for C++ namespace, need to look further
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2779 // back.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2780 if (curwin->w_cursor.lnum == ourscope)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2781 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2782
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2783 if (curwin->w_cursor.lnum == 0
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2784 || curwin->w_cursor.lnum
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2785 < ourscope - FIND_NAMESPACE_LIM)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2786 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2787
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2788 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2789
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2790 // If we're in a comment or raw string now, skip
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2791 // to the start of it.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2792 trypos = ind_find_start_CORS(NULL);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2793 if (trypos != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2794 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2795 curwin->w_cursor.lnum = trypos->lnum + 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2796 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2797 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2798 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2799
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2800 // Skip preprocessor directives and blank lines.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2801 if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum,
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2802 &amount))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2803 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2804
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2805 // Finally the actual check for "namespace".
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2806 if (cin_is_cpp_namespace(l))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2807 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2808 amount += curbuf->b_ind_cpp_namespace
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2809 - added_to_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2810 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2811 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2812 else if (cin_is_cpp_extern_c(l))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2813 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2814 amount += curbuf->b_ind_cpp_extern_c
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2815 - added_to_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2816 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2817 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2818
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2819 if (cin_nocode(l))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2820 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2821 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2822 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2823 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2824 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2825
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2826 // If we're in a comment or raw string now, skip to the start
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2827 // of it. XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2828 if ((trypos = ind_find_start_CORS(&raw_string_start)) != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2829 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2830 curwin->w_cursor.lnum = trypos->lnum + 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2831 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2832 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2833 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2834
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2835 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2836
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2837 // If this is a switch() label, may line up relative to that.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2838 // If this is a C++ scope declaration, do the same.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2839 iscase = cin_iscase(l, FALSE);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2840 if (iscase || cin_isscopedecl(l))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2841 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2842 // we are only looking for cpp base class
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2843 // declaration/initialization any longer
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2844 if (lookfor == LOOKFOR_CPP_BASECLASS)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2845 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2846
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2847 // When looking for a "do" we are not interested in
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2848 // labels.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2849 if (whilelevel > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2850 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2851
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2852 // case xx:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2853 // c = 99 + <- this indent plus continuation
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2854 //-> here;
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2855 if (lookfor == LOOKFOR_UNTERM
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2856 || lookfor == LOOKFOR_ENUM_OR_INIT)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2857 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2858 if (cont_amount > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2859 amount = cont_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2860 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2861 amount += ind_continuation;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2862 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2863 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2864
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2865 // case xx: <- line up with this case
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2866 // x = 333;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2867 // case yy:
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2868 if ( (iscase && lookfor == LOOKFOR_CASE)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2869 || (iscase && lookfor_break)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2870 || (!iscase && lookfor == LOOKFOR_SCOPEDECL))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2871 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2872 // Check that this case label is not for another
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2873 // switch() XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2874 if ((trypos = find_start_brace()) == NULL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2875 || trypos->lnum == ourscope)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2876 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2877 amount = get_indent(); // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2878 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2879 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2880 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2881 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2882
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2883 n = get_indent_nolabel(curwin->w_cursor.lnum); // XXX
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2884
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2885 // case xx: if (cond) <- line up with this if
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2886 // y = y + 1;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2887 // -> s = 99;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2888 //
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2889 // case xx:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2890 // if (cond) <- line up with this line
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2891 // y = y + 1;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2892 // -> s = 99;
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2893 if (lookfor == LOOKFOR_TERM)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2894 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2895 if (n)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2896 amount = n;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2897
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2898 if (!lookfor_break)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2899 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2900 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2901
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2902 // case xx: x = x + 1; <- line up with this x
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2903 // -> y = y + 1;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2904 //
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2905 // case xx: if (cond) <- line up with this if
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2906 // -> y = y + 1;
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2907 if (n)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2908 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2909 amount = n;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2910 l = after_label(ml_get_curline());
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2911 if (l != NULL && cin_is_cinword(l))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2912 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2913 if (theline[0] == '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2914 amount += curbuf->b_ind_open_extra;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2915 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2916 amount += curbuf->b_ind_level
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2917 + curbuf->b_ind_no_brace;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2918 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2919 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2920 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2921
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2922 // Try to get the indent of a statement before the switch
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2923 // label. If nothing is found, line up relative to the
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2924 // switch label.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2925 // break; <- may line up with this line
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2926 // case xx:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2927 // -> y = 1;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2928 scope_amount = get_indent() + (iscase // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2929 ? curbuf->b_ind_case_code
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2930 : curbuf->b_ind_scopedecl_code);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2931 lookfor = curbuf->b_ind_case_break
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2932 ? LOOKFOR_NOBREAK : LOOKFOR_ANY;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2933 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2934 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2935
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2936 // Looking for a switch() label or C++ scope declaration,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2937 // ignore other lines, skip {}-blocks.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2938 if (lookfor == LOOKFOR_CASE || lookfor == LOOKFOR_SCOPEDECL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2939 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2940 if (find_last_paren(l, '{', '}')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2941 && (trypos = find_start_brace()) != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2942 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2943 curwin->w_cursor.lnum = trypos->lnum + 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2944 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2945 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2946 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2947 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2948
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2949 // Ignore jump labels with nothing after them.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2950 if (!curbuf->b_ind_js && cin_islabel())
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2951 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2952 l = after_label(ml_get_curline());
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2953 if (l == NULL || cin_nocode(l))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2954 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2955 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2956
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2957 // Ignore #defines, #if, etc.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2958 // Ignore comment and empty lines.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2959 // (need to get the line again, cin_islabel() may have
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2960 // unlocked it)
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2961 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2962 if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum, &amount)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2963 || cin_nocode(l))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2964 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2965
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2966 // Are we at the start of a cpp base class declaration or
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2967 // constructor initialization? XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2968 n = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2969 if (lookfor != LOOKFOR_TERM && curbuf->b_ind_cpp_baseclass > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2970 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2971 n = cin_is_cpp_baseclass(&cache_cpp_baseclass);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2972 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2973 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2974 if (n)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2975 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2976 if (lookfor == LOOKFOR_UNTERM)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2977 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2978 if (cont_amount > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2979 amount = cont_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2980 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2981 amount += ind_continuation;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2982 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2983 else if (theline[0] == '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2984 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2985 // Need to find start of the declaration.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2986 lookfor = LOOKFOR_UNTERM;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2987 ind_continuation = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2988 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2989 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2990 else
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2991 // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2992 amount = get_baseclass_amount(
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2993 cache_cpp_baseclass.lpos.col);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2994 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2995 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2996 else if (lookfor == LOOKFOR_CPP_BASECLASS)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2997 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2998 // only look, whether there is a cpp base class
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2999 // declaration or initialization before the opening brace.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3000 if (cin_isterminated(l, TRUE, FALSE))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3001 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3002 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3003 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3004 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3005
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3006 // What happens next depends on the line being terminated.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3007 // If terminated with a ',' only consider it terminating if
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3008 // there is another unterminated statement behind, eg:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3009 // 123,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3010 // sizeof
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3011 // here
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3012 // Otherwise check whether it is a enumeration or structure
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3013 // initialisation (not indented) or a variable declaration
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3014 // (indented).
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3015 terminated = cin_isterminated(l, FALSE, TRUE);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3016
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3017 if (js_cur_has_key)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3018 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3019 js_cur_has_key = 0; // only check the first line
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3020 if (curbuf->b_ind_js && terminated == ',')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3021 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3022 // For Javascript we might be inside an object:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3023 // key: something, <- align with this
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3024 // key: something
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3025 // or:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3026 // key: something + <- align with this
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3027 // something,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3028 // key: something
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3029 lookfor = LOOKFOR_JS_KEY;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3030 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3031 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3032 if (lookfor == LOOKFOR_JS_KEY && cin_has_js_key(l))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3033 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3034 amount = get_indent();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3035 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3036 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3037 if (lookfor == LOOKFOR_COMMA)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3038 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3039 if (tryposBrace != NULL && tryposBrace->lnum
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3040 >= curwin->w_cursor.lnum)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3041 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3042 if (terminated == ',')
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3043 // line below current line is the one that starts a
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3044 // (possibly broken) line ending in a comma.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3045 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3046 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3047 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3048 amount = get_indent();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3049 if (curwin->w_cursor.lnum - 1 == ourscope)
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3050 // line above is start of the scope, thus current
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3051 // line is the one that stars a (possibly broken)
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3052 // line ending in a comma.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3053 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3054 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3055 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3056
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3057 if (terminated == 0 || (lookfor != LOOKFOR_UNTERM
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3058 && terminated == ','))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3059 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3060 if (lookfor != LOOKFOR_ENUM_OR_INIT &&
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3061 (*skipwhite(l) == '[' || l[STRLEN(l) - 1] == '['))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3062 amount += ind_continuation;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3063 // if we're in the middle of a paren thing,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3064 // go back to the line that starts it so
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3065 // we can get the right prevailing indent
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3066 // if ( foo &&
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3067 // bar )
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3068
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3069 // Position the cursor over the rightmost paren, so that
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3070 // matching it will take us back to the start of the line.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3071 // Ignore a match before the start of the block.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3072 (void)find_last_paren(l, '(', ')');
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3073 trypos = find_match_paren(corr_ind_maxparen(&cur_curpos));
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3074 if (trypos != NULL && (trypos->lnum < tryposBrace->lnum
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3075 || (trypos->lnum == tryposBrace->lnum
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3076 && trypos->col < tryposBrace->col)))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3077 trypos = NULL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3078
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3079 // If we are looking for ',', we also look for matching
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3080 // braces.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3081 if (trypos == NULL && terminated == ','
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3082 && find_last_paren(l, '{', '}'))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3083 trypos = find_start_brace();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3084
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3085 if (trypos != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3086 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3087 // Check if we are on a case label now. This is
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3088 // handled above.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3089 // case xx: if ( asdf &&
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3090 // asdf)
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3091 curwin->w_cursor = *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3092 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3093 if (cin_iscase(l, FALSE) || cin_isscopedecl(l))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3094 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3095 ++curwin->w_cursor.lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3096 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3097 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3098 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3099 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3100
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3101 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3102 * Skip over continuation lines to find the one to get the
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3103 * indent from
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3104 * char *usethis = "bla\
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3105 * bla",
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3106 * here;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3107 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3108 if (terminated == ',')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3109 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3110 while (curwin->w_cursor.lnum > 1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3111 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3112 l = ml_get(curwin->w_cursor.lnum - 1);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3113 if (*l == NUL || l[STRLEN(l) - 1] != '\\')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3114 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3115 --curwin->w_cursor.lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3116 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3117 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3118 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3119
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3120 // Get indent and pointer to text for current line,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3121 // ignoring any jump label. XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3122 if (curbuf->b_ind_js)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3123 cur_amount = get_indent();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3124 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3125 cur_amount = skip_label(curwin->w_cursor.lnum, &l);
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3126 // If this is just above the line we are indenting, and it
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3127 // starts with a '{', line it up with this line.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3128 // while (not)
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3129 // -> {
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3130 // }
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3131 if (terminated != ',' && lookfor != LOOKFOR_TERM
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3132 && theline[0] == '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3133 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3134 amount = cur_amount;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3135 // Only add b_ind_open_extra when the current line
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3136 // doesn't start with a '{', which must have a match
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3137 // in the same line (scope is the same). Probably:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3138 // { 1, 2 },
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3139 // -> { 3, 4 }
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3140 if (*skipwhite(l) != '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3141 amount += curbuf->b_ind_open_extra;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3142
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3143 if (curbuf->b_ind_cpp_baseclass && !curbuf->b_ind_js)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3144 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3145 // have to look back, whether it is a cpp base
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3146 // class declaration or initialization
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3147 lookfor = LOOKFOR_CPP_BASECLASS;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3148 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3149 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3150 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3151 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3152
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3153 // Check if we are after an "if", "while", etc.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3154 // Also allow " } else".
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3155 if (cin_is_cinword(l) || cin_iselse(skipwhite(l)))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3156 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3157 // Found an unterminated line after an if (), line up
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3158 // with the last one.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3159 // if (cond)
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3160 // 100 +
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3161 // -> here;
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3162 if (lookfor == LOOKFOR_UNTERM
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3163 || lookfor == LOOKFOR_ENUM_OR_INIT)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3164 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3165 if (cont_amount > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3166 amount = cont_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3167 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3168 amount += ind_continuation;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3169 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3170 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3171
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3172 // If this is just above the line we are indenting, we
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3173 // are finished.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3174 // while (not)
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3175 // -> here;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3176 // Otherwise this indent can be used when the line
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3177 // before this is terminated.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3178 // yyy;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3179 // if (stat)
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3180 // while (not)
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3181 // xxx;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3182 // -> here;
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3183 amount = cur_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3184 if (theline[0] == '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3185 amount += curbuf->b_ind_open_extra;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3186 if (lookfor != LOOKFOR_TERM)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3187 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3188 amount += curbuf->b_ind_level
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3189 + curbuf->b_ind_no_brace;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3190 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3191 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3192
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3193 // Special trick: when expecting the while () after a
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3194 // do, line up with the while()
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3195 // do
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3196 // x = 1;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3197 // -> here
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3198 l = skipwhite(ml_get_curline());
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3199 if (cin_isdo(l))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3200 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3201 if (whilelevel == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3202 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3203 --whilelevel;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3204 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3205
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3206 // When searching for a terminated line, don't use the
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3207 // one between the "if" and the matching "else".
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3208 // Need to use the scope of this "else". XXX
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3209 // If whilelevel != 0 continue looking for a "do {".
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3210 if (cin_iselse(l) && whilelevel == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3211 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3212 // If we're looking at "} else", let's make sure we
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3213 // find the opening brace of the enclosing scope,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3214 // not the one from "if () {".
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3215 if (*l == '}')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3216 curwin->w_cursor.col =
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3217 (colnr_T)(l - ml_get_curline()) + 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3218
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3219 if ((trypos = find_start_brace()) == NULL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3220 || find_match(LOOKFOR_IF, trypos->lnum)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3221 == FAIL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3222 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3223 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3224 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3225
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3226 // If we're below an unterminated line that is not an
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3227 // "if" or something, we may line up with this line or
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3228 // add something for a continuation line, depending on
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3229 // the line before this one.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3230 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3231 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3232 // Found two unterminated lines on a row, line up with
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3233 // the last one.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3234 // c = 99 +
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3235 // 100 +
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3236 // -> here;
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3237 if (lookfor == LOOKFOR_UNTERM)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3238 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3239 // When line ends in a comma add extra indent
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3240 if (terminated == ',')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3241 amount += ind_continuation;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3242 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3243 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3244
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3245 if (lookfor == LOOKFOR_ENUM_OR_INIT)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3246 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3247 // Found two lines ending in ',', lineup with the
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3248 // lowest one, but check for cpp base class
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3249 // declaration/initialization, if it is an
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3250 // opening brace or we are looking just for
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3251 // enumerations/initializations.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3252 if (terminated == ',')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3253 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3254 if (curbuf->b_ind_cpp_baseclass == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3255 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3256
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3257 lookfor = LOOKFOR_CPP_BASECLASS;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3258 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3259 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3260
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3261 // Ignore unterminated lines in between, but
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3262 // reduce indent.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3263 if (amount > cur_amount)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3264 amount = cur_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3265 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3266 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3267 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3268 // Found first unterminated line on a row, may
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3269 // line up with this line, remember its indent
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3270 // 100 +
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3271 // -> here;
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3272 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3273 amount = cur_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3274
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3275 n = (int)STRLEN(l);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3276 if (terminated == ',' && (*skipwhite(l) == ']'
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3277 || (n >=2 && l[n - 2] == ']')))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3278 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3279
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3280 // If previous line ends in ',', check whether we
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3281 // are in an initialization or enum
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3282 // struct xxx =
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3283 // {
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3284 // sizeof a,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3285 // 124 };
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3286 // or a normal possible continuation line.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3287 // but only, of no other statement has been found
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3288 // yet.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3289 if (lookfor == LOOKFOR_INITIAL && terminated == ',')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3290 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3291 if (curbuf->b_ind_js)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3292 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3293 // Search for a line ending in a comma
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3294 // and line up with the line below it
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3295 // (could be the current line).
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3296 // some = [
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3297 // 1, <- line up here
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3298 // 2,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3299 // some = [
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3300 // 3 + <- line up here
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3301 // 4 *
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3302 // 5,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3303 // 6,
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3304 if (cin_iscomment(skipwhite(l)))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3305 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3306 lookfor = LOOKFOR_COMMA;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3307 trypos = find_match_char('[',
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3308 curbuf->b_ind_maxparen);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3309 if (trypos != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3310 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3311 if (trypos->lnum
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3312 == curwin->w_cursor.lnum - 1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3313 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3314 // Current line is first inside
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3315 // [], line up with it.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3316 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3317 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3318 ourscope = trypos->lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3319 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3320 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3321 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3322 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3323 lookfor = LOOKFOR_ENUM_OR_INIT;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3324 cont_amount = cin_first_id_amount();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3325 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3326 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3327 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3328 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3329 if (lookfor == LOOKFOR_INITIAL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3330 && *l != NUL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3331 && l[STRLEN(l) - 1] == '\\')
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3332 // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3333 cont_amount = cin_get_equal_amount(
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3334 curwin->w_cursor.lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3335 if (lookfor != LOOKFOR_TERM
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3336 && lookfor != LOOKFOR_JS_KEY
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3337 && lookfor != LOOKFOR_COMMA
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3338 && raw_string_start != curwin->w_cursor.lnum)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3339 lookfor = LOOKFOR_UNTERM;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3340 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3341 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3342 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3343 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3344
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3345 // Check if we are after a while (cond);
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3346 // If so: Ignore until the matching "do".
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3347 else if (cin_iswhileofdo_end(terminated)) // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3348 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3349 // Found an unterminated line after a while ();, line up
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3350 // with the last one.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3351 // while (cond);
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3352 // 100 + <- line up with this one
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3353 // -> here;
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3354 if (lookfor == LOOKFOR_UNTERM
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3355 || lookfor == LOOKFOR_ENUM_OR_INIT)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3356 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3357 if (cont_amount > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3358 amount = cont_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3359 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3360 amount += ind_continuation;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3361 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3362 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3363
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3364 if (whilelevel == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3365 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3366 lookfor = LOOKFOR_TERM;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3367 amount = get_indent(); // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3368 if (theline[0] == '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3369 amount += curbuf->b_ind_open_extra;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3370 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3371 ++whilelevel;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3372 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3373
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3374 // We are after a "normal" statement.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3375 // If we had another statement we can stop now and use the
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3376 // indent of that other statement.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3377 // Otherwise the indent of the current statement may be used,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3378 // search backwards for the next "normal" statement.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3379 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3380 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3381 // Skip single break line, if before a switch label. It
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3382 // may be lined up with the case label.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3383 if (lookfor == LOOKFOR_NOBREAK
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3384 && cin_isbreak(skipwhite(ml_get_curline())))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3385 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3386 lookfor = LOOKFOR_ANY;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3387 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3388 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3389
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3390 // Handle "do {" line.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3391 if (whilelevel > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3392 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3393 l = cin_skipcomment(ml_get_curline());
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3394 if (cin_isdo(l))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3395 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3396 amount = get_indent(); // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3397 --whilelevel;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3398 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3399 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3400 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3401
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3402 // Found a terminated line above an unterminated line. Add
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3403 // the amount for a continuation line.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3404 // x = 1;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3405 // y = foo +
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3406 // -> here;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3407 // or
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3408 // int x = 1;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3409 // int foo,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3410 // -> here;
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3411 if (lookfor == LOOKFOR_UNTERM
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3412 || lookfor == LOOKFOR_ENUM_OR_INIT)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3413 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3414 if (cont_amount > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3415 amount = cont_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3416 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3417 amount += ind_continuation;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3418 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3419 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3420
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3421 // Found a terminated line above a terminated line or "if"
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3422 // etc. line. Use the amount of the line below us.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3423 // x = 1; x = 1;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3424 // if (asdf) y = 2;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3425 // while (asdf) ->here;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3426 // here;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3427 // ->foo;
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3428 if (lookfor == LOOKFOR_TERM)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3429 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3430 if (!lookfor_break && whilelevel == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3431 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3432 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3433
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3434 // First line above the one we're indenting is terminated.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3435 // To know what needs to be done look further backward for
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3436 // a terminated line.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3437 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3438 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3439 // position the cursor over the rightmost paren, so
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3440 // that matching it will take us back to the start of
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3441 // the line. Helps for:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3442 // func(asdr,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3443 // asdfasdf);
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3444 // here;
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3445 term_again:
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3446 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3447 if (find_last_paren(l, '(', ')')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3448 && (trypos = find_match_paren(
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3449 curbuf->b_ind_maxparen)) != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3450 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3451 // Check if we are on a case label now. This is
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3452 // handled above.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3453 // case xx: if ( asdf &&
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3454 // asdf)
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3455 curwin->w_cursor = *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3456 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3457 if (cin_iscase(l, FALSE) || cin_isscopedecl(l))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3458 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3459 ++curwin->w_cursor.lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3460 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3461 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3462 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3463 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3464
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3465 // When aligning with the case statement, don't align
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3466 // with a statement after it.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3467 // case 1: { <-- don't use this { position
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3468 // stat;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3469 // }
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3470 // case 2:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3471 // stat;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3472 // }
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3473 iscase = (curbuf->b_ind_keep_case_label
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3474 && cin_iscase(l, FALSE));
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3475
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3476 // Get indent and pointer to text for current line,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3477 // ignoring any jump label.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3478 amount = skip_label(curwin->w_cursor.lnum, &l);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3479
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3480 if (theline[0] == '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3481 amount += curbuf->b_ind_open_extra;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3482 // See remark above: "Only add b_ind_open_extra.."
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3483 l = skipwhite(l);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3484 if (*l == '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3485 amount -= curbuf->b_ind_open_extra;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3486 lookfor = iscase ? LOOKFOR_ANY : LOOKFOR_TERM;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3487
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3488 // When a terminated line starts with "else" skip to
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3489 // the matching "if":
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3490 // else 3;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3491 // indent this;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3492 // Need to use the scope of this "else". XXX
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3493 // If whilelevel != 0 continue looking for a "do {".
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3494 if (lookfor == LOOKFOR_TERM
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3495 && *l != '}'
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3496 && cin_iselse(l)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3497 && whilelevel == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3498 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3499 if ((trypos = find_start_brace()) == NULL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3500 || find_match(LOOKFOR_IF, trypos->lnum)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3501 == FAIL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3502 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3503 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3504 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3505
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3506 // If we're at the end of a block, skip to the start of
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3507 // that block.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3508 l = ml_get_curline();
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3509 if (find_last_paren(l, '{', '}') // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3510 && (trypos = find_start_brace()) != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3511 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3512 curwin->w_cursor = *trypos;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3513 // if not "else {" check for terminated again
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3514 // but skip block for "} else {"
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3515 l = cin_skipcomment(ml_get_curline());
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3516 if (*l == '}' || !cin_iselse(l))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3517 goto term_again;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3518 ++curwin->w_cursor.lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3519 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3520 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3521 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3522 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3523 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3524 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3525 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3526
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3527 // add extra indent for a comment
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3528 if (cin_iscomment(theline))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3529 amount += curbuf->b_ind_comment;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3530
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3531 // subtract extra left-shift for jump labels
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3532 if (curbuf->b_ind_jump_label > 0 && original_line_islabel)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3533 amount -= curbuf->b_ind_jump_label;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3534
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3535 goto theend;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3536 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3537
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3538 // ok -- we're not inside any sort of structure at all!
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3539 //
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3540 // This means we're at the top level, and everything should
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3541 // basically just match where the previous line is, except
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3542 // for the lines immediately following a function declaration,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3543 // which are K&R-style parameters and need to be indented.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3544 //
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3545 // if our line starts with an open brace, forget about any
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3546 // prevailing indent and make sure it looks like the start
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3547 // of a function
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3548
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3549 if (theline[0] == '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3550 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3551 amount = curbuf->b_ind_first_open;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3552 goto theend;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3553 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3554
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3555 // If the NEXT line is a function declaration, the current
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3556 // line needs to be indented as a function type spec.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3557 // Don't do this if the current line looks like a comment or if the
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3558 // current line is terminated, ie. ends in ';', or if the current line
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3559 // contains { or }: "void f() {\n if (1)"
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3560 if (cur_curpos.lnum < curbuf->b_ml.ml_line_count
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3561 && !cin_nocode(theline)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3562 && vim_strchr(theline, '{') == NULL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3563 && vim_strchr(theline, '}') == NULL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3564 && !cin_ends_in(theline, (char_u *)":", NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3565 && !cin_ends_in(theline, (char_u *)",", NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3566 && cin_isfuncdecl(NULL, cur_curpos.lnum + 1,
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3567 cur_curpos.lnum + 1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3568 && !cin_isterminated(theline, FALSE, TRUE))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3569 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3570 amount = curbuf->b_ind_func_type;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3571 goto theend;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3572 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3573
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3574 // search backwards until we find something we recognize
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3575 amount = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3576 curwin->w_cursor = cur_curpos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3577 while (curwin->w_cursor.lnum > 1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3578 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3579 curwin->w_cursor.lnum--;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3580 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3581
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3582 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3583
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3584 // If we're in a comment or raw string now, skip to the start
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3585 // of it. XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3586 if ((trypos = ind_find_start_CORS(NULL)) != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3587 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3588 curwin->w_cursor.lnum = trypos->lnum + 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3589 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3590 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3591 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3592
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3593 // Are we at the start of a cpp base class declaration or
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3594 // constructor initialization? XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3595 n = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3596 if (curbuf->b_ind_cpp_baseclass != 0 && theline[0] != '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3597 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3598 n = cin_is_cpp_baseclass(&cache_cpp_baseclass);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3599 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3600 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3601 if (n)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3602 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3603 // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3604 amount = get_baseclass_amount(cache_cpp_baseclass.lpos.col);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3605 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3606 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3607
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3608 // Skip preprocessor directives and blank lines.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3609 if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum, &amount))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3610 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3611
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3612 if (cin_nocode(l))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3613 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3614
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3615 // If the previous line ends in ',', use one level of
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3616 // indentation:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3617 // int foo,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3618 // bar;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3619 // do this before checking for '}' in case of eg.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3620 // enum foobar
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3621 // {
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3622 // ...
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3623 // } foo,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3624 // bar;
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3625 n = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3626 if (cin_ends_in(l, (char_u *)",", NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3627 || (*l != NUL && (n = l[STRLEN(l) - 1]) == '\\'))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3628 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3629 // take us back to opening paren
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3630 if (find_last_paren(l, '(', ')')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3631 && (trypos = find_match_paren(
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3632 curbuf->b_ind_maxparen)) != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3633 curwin->w_cursor = *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3634
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3635 /*
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3636 * For a line ending in ',' that is a continuation line go
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3637 * back to the first line with a backslash:
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3638 * char *foo = "bla\
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3639 * bla",
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3640 * here;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3641 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3642 while (n == 0 && curwin->w_cursor.lnum > 1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3643 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3644 l = ml_get(curwin->w_cursor.lnum - 1);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3645 if (*l == NUL || l[STRLEN(l) - 1] != '\\')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3646 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3647 --curwin->w_cursor.lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3648 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3649 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3650
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3651 amount = get_indent(); // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3652
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3653 if (amount == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3654 amount = cin_first_id_amount();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3655 if (amount == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3656 amount = ind_continuation;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3657 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3658 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3659
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3660 // If the line looks like a function declaration, and we're
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3661 // not in a comment, put it the left margin.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3662 if (cin_isfuncdecl(NULL, cur_curpos.lnum, 0)) // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3663 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3664 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3665
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3666 // Finding the closing '}' of a previous function. Put
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3667 // current line at the left margin. For when 'cino' has "fs".
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3668 if (*skipwhite(l) == '}')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3669 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3670
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3671 // (matching {)
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3672 // If the previous line ends on '};' (maybe followed by
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3673 // comments) align at column 0. For example:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3674 // char *string_array[] = { "foo",
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3675 // / * x * / "b};ar" }; / * foobar * /
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3676 if (cin_ends_in(l, (char_u *)"};", NULL))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3677 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3678
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3679 // If the previous line ends on '[' we are probably in an
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3680 // array constant:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3681 // something = [
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3682 // 234, <- extra indent
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3683 if (cin_ends_in(l, (char_u *)"[", NULL))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3684 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3685 amount = get_indent() + ind_continuation;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3686 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3687 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3688
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3689 // Find a line only has a semicolon that belongs to a previous
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3690 // line ending in '}', e.g. before an #endif. Don't increase
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3691 // indent then.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3692 if (*(look = skipwhite(l)) == ';' && cin_nocode(look + 1))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3693 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3694 pos_T curpos_save = curwin->w_cursor;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3695
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3696 while (curwin->w_cursor.lnum > 1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3697 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3698 look = ml_get(--curwin->w_cursor.lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3699 if (!(cin_nocode(look) || cin_ispreproc_cont(
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3700 &look, &curwin->w_cursor.lnum, &amount)))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3701 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3702 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3703 if (curwin->w_cursor.lnum > 0
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3704 && cin_ends_in(look, (char_u *)"}", NULL))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3705 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3706
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3707 curwin->w_cursor = curpos_save;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3708 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3709
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3710 // If the PREVIOUS line is a function declaration, the current
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3711 // line (and the ones that follow) needs to be indented as
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3712 // parameters.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3713 if (cin_isfuncdecl(&l, curwin->w_cursor.lnum, 0))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3714 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3715 amount = curbuf->b_ind_param;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3716 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3717 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3718
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3719 // If the previous line ends in ';' and the line before the
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3720 // previous line ends in ',' or '\', ident to column zero:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3721 // int foo,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3722 // bar;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3723 // indent_to_0 here;
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3724 if (cin_ends_in(l, (char_u *)";", NULL))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3725 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3726 l = ml_get(curwin->w_cursor.lnum - 1);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3727 if (cin_ends_in(l, (char_u *)",", NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3728 || (*l != NUL && l[STRLEN(l) - 1] == '\\'))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3729 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3730 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3731 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3732
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3733 // Doesn't look like anything interesting -- so just
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3734 // use the indent of this line.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3735 //
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3736 // Position the cursor over the rightmost paren, so that
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3737 // matching it will take us back to the start of the line.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3738 find_last_paren(l, '(', ')');
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3739
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3740 if ((trypos = find_match_paren(curbuf->b_ind_maxparen)) != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3741 curwin->w_cursor = *trypos;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3742 amount = get_indent(); // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3743 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3744 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3745
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3746 // add extra indent for a comment
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3747 if (cin_iscomment(theline))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3748 amount += curbuf->b_ind_comment;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3749
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3750 /*
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3751 * add extra indent if the previous line ended in a backslash:
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3752 * "asdfasdf\
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3753 * here";
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3754 * char *foo = "asdf\
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3755 * here";
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3756 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3757 if (cur_curpos.lnum > 1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3758 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3759 l = ml_get(cur_curpos.lnum - 1);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3760 if (*l != NUL && l[STRLEN(l) - 1] == '\\')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3761 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3762 cur_amount = cin_get_equal_amount(cur_curpos.lnum - 1);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3763 if (cur_amount > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3764 amount = cur_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3765 else if (cur_amount == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3766 amount += ind_continuation;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3767 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3768 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3769
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3770 theend:
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3771 if (amount < 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3772 amount = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3773
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3774 laterend:
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3775 // put the cursor back where it belongs
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3776 curwin->w_cursor = cur_curpos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3777
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3778 vim_free(linecopy);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3779
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3780 return amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3781 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3782
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3783 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3784 find_match(int lookfor, linenr_T ourscope)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3785 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3786 char_u *look;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3787 pos_T *theirscope;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3788 char_u *mightbeif;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3789 int elselevel;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3790 int whilelevel;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3791
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3792 if (lookfor == LOOKFOR_IF)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3793 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3794 elselevel = 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3795 whilelevel = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3796 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3797 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3798 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3799 elselevel = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3800 whilelevel = 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3801 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3802
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3803 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3804
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3805 while (curwin->w_cursor.lnum > ourscope + 1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3806 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3807 curwin->w_cursor.lnum--;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3808 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3809
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3810 look = cin_skipcomment(ml_get_curline());
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3811 if (cin_iselse(look)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3812 || cin_isif(look)
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3813 || cin_isdo(look) // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3814 || cin_iswhileofdo(look, curwin->w_cursor.lnum))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3815 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3816 // if we've gone outside the braces entirely,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3817 // we must be out of scope...
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3818 theirscope = find_start_brace(); // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3819 if (theirscope == NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3820 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3821
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3822 // and if the brace enclosing this is further
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3823 // back than the one enclosing the else, we're
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3824 // out of luck too.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3825 if (theirscope->lnum < ourscope)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3826 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3827
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3828 // and if they're enclosed in a *deeper* brace,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3829 // then we can ignore it because it's in a
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3830 // different scope...
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3831 if (theirscope->lnum > ourscope)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3832 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3833
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3834 // if it was an "else" (that's not an "else if")
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3835 // then we need to go back to another if, so
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3836 // increment elselevel
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3837 look = cin_skipcomment(ml_get_curline());
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3838 if (cin_iselse(look))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3839 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3840 mightbeif = cin_skipcomment(look + 4);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3841 if (!cin_isif(mightbeif))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3842 ++elselevel;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3843 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3844 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3845
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3846 // if it was a "while" then we need to go back to
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3847 // another "do", so increment whilelevel. XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3848 if (cin_iswhileofdo(look, curwin->w_cursor.lnum))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3849 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3850 ++whilelevel;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3851 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3852 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3853
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3854 // If it's an "if" decrement elselevel
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3855 look = cin_skipcomment(ml_get_curline());
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3856 if (cin_isif(look))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3857 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3858 elselevel--;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3859 // When looking for an "if" ignore "while"s that
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3860 // get in the way.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3861 if (elselevel == 0 && lookfor == LOOKFOR_IF)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3862 whilelevel = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3863 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3864
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3865 // If it's a "do" decrement whilelevel
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3866 if (cin_isdo(look))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3867 whilelevel--;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3868
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3869 // if we've used up all the elses, then
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3870 // this must be the if that we want!
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3871 // match the indent level of that if.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3872 if (elselevel <= 0 && whilelevel <= 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3873 return OK;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3874 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3875 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3876 return FAIL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3877 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3878
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3879 # if defined(FEAT_EVAL) || defined(PROTO)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3880 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3881 * Get indent level from 'indentexpr'.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3882 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3883 int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3884 get_expr_indent(void)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3885 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3886 int indent = -1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3887 char_u *inde_copy;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3888 pos_T save_pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3889 colnr_T save_curswant;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3890 int save_set_curswant;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3891 int save_State;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3892 int use_sandbox = was_set_insecurely((char_u *)"indentexpr",
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3893 OPT_LOCAL);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3894
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3895 // Save and restore cursor position and curswant, in case it was changed
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3896 // via :normal commands
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3897 save_pos = curwin->w_cursor;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3898 save_curswant = curwin->w_curswant;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3899 save_set_curswant = curwin->w_set_curswant;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3900 set_vim_var_nr(VV_LNUM, curwin->w_cursor.lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3901 if (use_sandbox)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3902 ++sandbox;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3903 ++textlock;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3904
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3905 // Need to make a copy, the 'indentexpr' option could be changed while
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3906 // evaluating it.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3907 inde_copy = vim_strsave(curbuf->b_p_inde);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3908 if (inde_copy != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3909 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3910 indent = (int)eval_to_number(inde_copy);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3911 vim_free(inde_copy);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3912 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3913
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3914 if (use_sandbox)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3915 --sandbox;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3916 --textlock;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3917
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3918 // Restore the cursor position so that 'indentexpr' doesn't need to.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3919 // Pretend to be in Insert mode, allow cursor past end of line for "o"
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3920 // command.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3921 save_State = State;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3922 State = INSERT;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3923 curwin->w_cursor = save_pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3924 curwin->w_curswant = save_curswant;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3925 curwin->w_set_curswant = save_set_curswant;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3926 check_cursor();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3927 State = save_State;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3928
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3929 // If there is an error, just keep the current indent.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3930 if (indent < 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3931 indent = get_indent();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3932
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3933 return indent;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3934 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3935 # endif
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3936
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3937 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3938 * return TRUE if 'cinkeys' contains the key "keytyped",
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3939 * when == '*': Only if key is preceded with '*' (indent before insert)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3940 * when == '!': Only if key is preceded with '!' (don't insert)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3941 * when == ' ': Only if key is not preceded with '*'(indent afterwards)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3942 *
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3943 * "keytyped" can have a few special values:
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3944 * KEY_OPEN_FORW
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3945 * KEY_OPEN_BACK
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3946 * KEY_COMPLETE just finished completion.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3947 *
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3948 * If line_is_empty is TRUE accept keys with '0' before them.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3949 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3950 int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3951 in_cinkeys(
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3952 int keytyped,
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3953 int when,
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3954 int line_is_empty)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3955 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3956 char_u *look;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3957 int try_match;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3958 int try_match_word;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3959 char_u *p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3960 char_u *line;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3961 int icase;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3962 int i;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3963
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3964 if (keytyped == NUL)
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3965 // Can happen with CTRL-Y and CTRL-E on a short line.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3966 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3967
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3968 #ifdef FEAT_EVAL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3969 if (*curbuf->b_p_inde != NUL)
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3970 look = curbuf->b_p_indk; // 'indentexpr' set: use 'indentkeys'
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3971 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3972 #endif
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3973 look = curbuf->b_p_cink; // 'indentexpr' empty: use 'cinkeys'
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3974 while (*look)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3975 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3976 // Find out if we want to try a match with this key, depending on
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3977 // 'when' and a '*' or '!' before the key.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3978 switch (when)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3979 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3980 case '*': try_match = (*look == '*'); break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3981 case '!': try_match = (*look == '!'); break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3982 default: try_match = (*look != '*'); break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3983 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3984 if (*look == '*' || *look == '!')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3985 ++look;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3986
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3987 // If there is a '0', only accept a match if the line is empty.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3988 // But may still match when typing last char of a word.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3989 if (*look == '0')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3990 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3991 try_match_word = try_match;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3992 if (!line_is_empty)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3993 try_match = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3994 ++look;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3995 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3996 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3997 try_match_word = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3998
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3999 // does it look like a control character?
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4000 if (*look == '^'
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4001 #ifdef EBCDIC
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4002 && (Ctrl_chr(look[1]) != 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4003 #else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4004 && look[1] >= '?' && look[1] <= '_'
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4005 #endif
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4006 )
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4007 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4008 if (try_match && keytyped == Ctrl_chr(look[1]))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4009 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4010 look += 2;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4011 }
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4012 // 'o' means "o" command, open forward.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4013 // 'O' means "O" command, open backward.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4014 else if (*look == 'o')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4015 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4016 if (try_match && keytyped == KEY_OPEN_FORW)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4017 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4018 ++look;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4019 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4020 else if (*look == 'O')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4021 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4022 if (try_match && keytyped == KEY_OPEN_BACK)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4023 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4024 ++look;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4025 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4026
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4027 // 'e' means to check for "else" at start of line and just before the
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4028 // cursor.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4029 else if (*look == 'e')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4030 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4031 if (try_match && keytyped == 'e' && curwin->w_cursor.col >= 4)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4032 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4033 p = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4034 if (skipwhite(p) == p + curwin->w_cursor.col - 4 &&
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4035 STRNCMP(p + curwin->w_cursor.col - 4, "else", 4) == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4036 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4037 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4038 ++look;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4039 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4040
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4041 // ':' only causes an indent if it is at the end of a label or case
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4042 // statement, or when it was before typing the ':' (to fix
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4043 // class::method for C++).
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4044 else if (*look == ':')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4045 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4046 if (try_match && keytyped == ':')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4047 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4048 p = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4049 if (cin_iscase(p, FALSE) || cin_isscopedecl(p) || cin_islabel())
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4050 return TRUE;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4051 // Need to get the line again after cin_islabel().
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4052 p = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4053 if (curwin->w_cursor.col > 2
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4054 && p[curwin->w_cursor.col - 1] == ':'
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4055 && p[curwin->w_cursor.col - 2] == ':')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4056 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4057 p[curwin->w_cursor.col - 1] = ' ';
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4058 i = (cin_iscase(p, FALSE) || cin_isscopedecl(p)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4059 || cin_islabel());
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4060 p = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4061 p[curwin->w_cursor.col - 1] = ':';
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4062 if (i)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4063 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4064 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4065 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4066 ++look;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4067 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4068
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4069
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4070 // Is it a key in <>, maybe?
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4071 else if (*look == '<')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4072 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4073 if (try_match)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4074 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4075 // make up some named keys <o>, <O>, <e>, <0>, <>>, <<>, <*>,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4076 // <:> and <!> so that people can re-indent on o, O, e, 0, <,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4077 // >, *, : and ! keys if they really really want to.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4078 if (vim_strchr((char_u *)"<>!*oOe0:", look[1]) != NULL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4079 && keytyped == look[1])
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4080 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4081
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4082 if (keytyped == get_special_key_code(look + 1))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4083 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4084 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4085 while (*look && *look != '>')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4086 look++;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4087 while (*look == '>')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4088 look++;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4089 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4090
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4091 // Is it a word: "=word"?
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4092 else if (*look == '=' && look[1] != ',' && look[1] != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4093 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4094 ++look;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4095 if (*look == '~')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4096 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4097 icase = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4098 ++look;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4099 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4100 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4101 icase = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4102 p = vim_strchr(look, ',');
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4103 if (p == NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4104 p = look + STRLEN(look);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4105 if ((try_match || try_match_word)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4106 && curwin->w_cursor.col >= (colnr_T)(p - look))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4107 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4108 int match = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4109
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4110 #ifdef FEAT_INS_EXPAND
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4111 if (keytyped == KEY_COMPLETE)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4112 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4113 char_u *s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4114
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4115 // Just completed a word, check if it starts with "look".
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4116 // search back for the start of a word.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4117 line = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4118 if (has_mbyte)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4119 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4120 char_u *n;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4121
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4122 for (s = line + curwin->w_cursor.col; s > line; s = n)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4123 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4124 n = mb_prevptr(line, s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4125 if (!vim_iswordp(n))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4126 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4127 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4128 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4129 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4130 for (s = line + curwin->w_cursor.col; s > line; --s)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4131 if (!vim_iswordc(s[-1]))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4132 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4133 if (s + (p - look) <= line + curwin->w_cursor.col
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4134 && (icase
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4135 ? MB_STRNICMP(s, look, p - look)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4136 : STRNCMP(s, look, p - look)) == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4137 match = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4138 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4139 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4140 #endif
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4141 // TODO: multi-byte
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4142 if (keytyped == (int)p[-1] || (icase && keytyped < 256
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4143 && TOLOWER_LOC(keytyped) == TOLOWER_LOC((int)p[-1])))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4144 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4145 line = ml_get_cursor();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4146 if ((curwin->w_cursor.col == (colnr_T)(p - look)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4147 || !vim_iswordc(line[-(p - look) - 1]))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4148 && (icase
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4149 ? MB_STRNICMP(line - (p - look), look, p - look)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4150 : STRNCMP(line - (p - look), look, p - look))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4151 == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4152 match = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4153 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4154 if (match && try_match_word && !try_match)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4155 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4156 // "0=word": Check if there are only blanks before the
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4157 // word.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4158 if (getwhitecols_curline() !=
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4159 (int)(curwin->w_cursor.col - (p - look)))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4160 match = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4161 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4162 if (match)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4163 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4164 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4165 look = p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4166 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4167
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4168 // ok, it's a boring generic character.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4169 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4170 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4171 if (try_match && *look == keytyped)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4172 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4173 if (*look != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4174 ++look;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4175 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4176
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4177 // Skip over ", ".
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4178 look = skip_to_option_part(look);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4179 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4180 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4181 }
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4182 #endif // FEAT_CINDENT
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4183
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4184 #if defined(FEAT_LISP) || defined(PROTO)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4185
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4186 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4187 lisp_match(char_u *p)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4188 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4189 char_u buf[LSIZE];
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4190 int len;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4191 char_u *word = *curbuf->b_p_lw != NUL ? curbuf->b_p_lw : p_lispwords;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4192
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4193 while (*word != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4194 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4195 (void)copy_option_part(&word, buf, LSIZE, ",");
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4196 len = (int)STRLEN(buf);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4197 if (STRNCMP(buf, p, len) == 0 && p[len] == ' ')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4198 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4199 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4200 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4201 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4202
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4203 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4204 * When 'p' is present in 'cpoptions, a Vi compatible method is used.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4205 * The incompatible newer method is quite a bit better at indenting
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4206 * code in lisp-like languages than the traditional one; it's still
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4207 * mostly heuristics however -- Dirk van Deun, dirk@rave.org
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4208 *
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4209 * TODO:
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4210 * Findmatch() should be adapted for lisp, also to make showmatch
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4211 * work correctly: now (v5.3) it seems all C/C++ oriented:
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4212 * - it does not recognize the #\( and #\) notations as character literals
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4213 * - it doesn't know about comments starting with a semicolon
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4214 * - it incorrectly interprets '(' as a character literal
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4215 * All this messes up get_lisp_indent in some rare cases.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4216 * Update from Sergey Khorev:
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4217 * I tried to fix the first two issues.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4218 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4219 int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4220 get_lisp_indent(void)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4221 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4222 pos_T *pos, realpos, paren;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4223 int amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4224 char_u *that;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4225 colnr_T col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4226 colnr_T firsttry;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4227 int parencount, quotecount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4228 int vi_lisp;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4229
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4230 // Set vi_lisp to use the vi-compatible method
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4231 vi_lisp = (vim_strchr(p_cpo, CPO_LISP) != NULL);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4232
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4233 realpos = curwin->w_cursor;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4234 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4235
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4236 if ((pos = findmatch(NULL, '(')) == NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4237 pos = findmatch(NULL, '[');
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4238 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4239 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4240 paren = *pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4241 pos = findmatch(NULL, '[');
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4242 if (pos == NULL || LT_POSP(pos, &paren))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4243 pos = &paren;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4244 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4245 if (pos != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4246 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4247 // Extra trick: Take the indent of the first previous non-white
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4248 // line that is at the same () level.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4249 amount = -1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4250 parencount = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4251
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4252 while (--curwin->w_cursor.lnum >= pos->lnum)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4253 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4254 if (linewhite(curwin->w_cursor.lnum))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4255 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4256 for (that = ml_get_curline(); *that != NUL; ++that)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4257 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4258 if (*that == ';')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4259 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4260 while (*(that + 1) != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4261 ++that;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4262 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4263 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4264 if (*that == '\\')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4265 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4266 if (*(that + 1) != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4267 ++that;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4268 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4269 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4270 if (*that == '"' && *(that + 1) != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4271 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4272 while (*++that && *that != '"')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4273 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4274 // skipping escaped characters in the string
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4275 if (*that == '\\')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4276 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4277 if (*++that == NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4278 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4279 if (that[1] == NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4280 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4281 ++that;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4282 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4283 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4284 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4285 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4286 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4287 if (*that == '(' || *that == '[')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4288 ++parencount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4289 else if (*that == ')' || *that == ']')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4290 --parencount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4291 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4292 if (parencount == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4293 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4294 amount = get_indent();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4295 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4296 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4297 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4298
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4299 if (amount == -1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4300 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4301 curwin->w_cursor.lnum = pos->lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4302 curwin->w_cursor.col = pos->col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4303 col = pos->col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4304
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4305 that = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4306
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4307 if (vi_lisp && get_indent() == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4308 amount = 2;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4309 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4310 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4311 char_u *line = that;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4312
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4313 amount = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4314 while (*that && col)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4315 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4316 amount += lbr_chartabsize_adv(line, &that, (colnr_T)amount);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4317 col--;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4318 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4319
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4320 // Some keywords require "body" indenting rules (the
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4321 // non-standard-lisp ones are Scheme special forms):
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4322 //
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4323 // (let ((a 1)) instead (let ((a 1))
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4324 // (...)) of (...))
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4325
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4326 if (!vi_lisp && (*that == '(' || *that == '[')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4327 && lisp_match(that + 1))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4328 amount += 2;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4329 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4330 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4331 that++;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4332 amount++;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4333 firsttry = amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4334
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4335 while (VIM_ISWHITE(*that))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4336 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4337 amount += lbr_chartabsize(line, that, (colnr_T)amount);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4338 ++that;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4339 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4340
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4341 if (*that && *that != ';') // not a comment line
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4342 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4343 // test *that != '(' to accommodate first let/do
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4344 // argument if it is more than one line
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4345 if (!vi_lisp && *that != '(' && *that != '[')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4346 firsttry++;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4347
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4348 parencount = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4349 quotecount = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4350
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4351 if (vi_lisp
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4352 || (*that != '"'
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4353 && *that != '\''
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4354 && *that != '#'
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4355 && (*that < '0' || *that > '9')))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4356 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4357 while (*that
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4358 && (!VIM_ISWHITE(*that)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4359 || quotecount
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4360 || parencount)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4361 && (!((*that == '(' || *that == '[')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4362 && !quotecount
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4363 && !parencount
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4364 && vi_lisp)))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4365 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4366 if (*that == '"')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4367 quotecount = !quotecount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4368 if ((*that == '(' || *that == '[')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4369 && !quotecount)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4370 ++parencount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4371 if ((*that == ')' || *that == ']')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4372 && !quotecount)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4373 --parencount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4374 if (*that == '\\' && *(that+1) != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4375 amount += lbr_chartabsize_adv(
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4376 line, &that, (colnr_T)amount);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4377 amount += lbr_chartabsize_adv(
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4378 line, &that, (colnr_T)amount);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4379 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4380 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4381 while (VIM_ISWHITE(*that))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4382 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4383 amount += lbr_chartabsize(
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4384 line, that, (colnr_T)amount);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4385 that++;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4386 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4387 if (!*that || *that == ';')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4388 amount = firsttry;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4389 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4390 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4391 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4392 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4393 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4394 else
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4395 amount = 0; // no matching '(' or '[' found, use zero indent
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4396
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4397 curwin->w_cursor = realpos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4398
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4399 return amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4400 }
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4401 #endif // FEAT_LISP
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4402
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4403 #if defined(FEAT_CINDENT) || defined(PROTO)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4404 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4405 * Do C or expression indenting on the current line.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4406 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4407 void
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4408 do_c_expr_indent(void)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4409 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4410 # ifdef FEAT_EVAL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4411 if (*curbuf->b_p_inde != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4412 fixthisline(get_expr_indent);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4413 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4414 # endif
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4415 fixthisline(get_c_indent);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4416 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4417 #endif
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4418
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4419 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) || defined(PROTO)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4420 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4421 * Re-indent the current line, based on the current contents of it and the
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4422 * surrounding lines. Fixing the cursor position seems really easy -- I'm very
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4423 * confused what all the part that handles Control-T is doing that I'm not.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4424 * "get_the_indent" should be get_c_indent, get_expr_indent or get_lisp_indent.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4425 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4426
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4427 void
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4428 fixthisline(int (*get_the_indent)(void))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4429 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4430 int amount = get_the_indent();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4431
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4432 if (amount >= 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4433 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4434 change_indent(INDENT_SET, amount, FALSE, 0, TRUE);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4435 if (linewhite(curwin->w_cursor.lnum))
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4436 did_ai = TRUE; // delete the indent if the line stays empty
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4437 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4438 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4439
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4440 void
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4441 fix_indent(void)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4442 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4443 if (p_paste)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4444 return;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4445 # ifdef FEAT_LISP
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4446 if (curbuf->b_p_lisp && curbuf->b_p_ai)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4447 fixthisline(get_lisp_indent);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4448 # endif
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4449 # if defined(FEAT_LISP) && defined(FEAT_CINDENT)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4450 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4451 # endif
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4452 # ifdef FEAT_CINDENT
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4453 if (cindent_on())
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4454 do_c_expr_indent();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4455 # endif
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4456 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4457
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4458 #endif