annotate src/indent.c @ 17809:59f8948b7590 v8.1.1901

patch 8.1.1901: the +insert_expand feature is not always available Commit: https://github.com/vim/vim/commit/e2c453d38f6512ac4cff7cd26aa7780b4e2534d7 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Aug 21 14:37:09 2019 +0200 patch 8.1.1901: the +insert_expand feature is not always available Problem: The +insert_expand feature is not always available. Solution: Graduate the +insert_expand feature.
author Bram Moolenaar <Bram@vim.org>
date Wed, 21 Aug 2019 14:45:04 +0200
parents 0f7ae8010787
children 079e10a49ea1
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
17789
0f7ae8010787 patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents: 16764
diff changeset
18 static int cin_iscase(char_u *s, int strict);
0f7ae8010787 patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents: 16764
diff changeset
19 static int cin_isscopedecl(char_u *s);
0f7ae8010787 patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents: 16764
diff changeset
20
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 * 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
23 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 cin_is_cinword(char_u *line)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 char_u *cinw;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 char_u *cinw_buf;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 int cinw_len;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 int retval = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 int len;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 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
34 cinw_buf = alloc(cinw_len);
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 if (cinw_buf != NULL)
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 line = skipwhite(line);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 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
39 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 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
41 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
42 && (!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
43 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 retval = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 break;
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 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 vim_free(cinw_buf);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 return retval;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 #endif
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 #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
55
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 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
57 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
58
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 * 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
61 * 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
62 * 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
63 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 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
65 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
66 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 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
68 }
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 *
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
71 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
72 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 pos_T *pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 char_u *line;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 char_u *p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 int cur_maxcomment = ind_maxcomment;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 for (;;)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 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
81 if (pos == NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
84 // 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
85 // 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
86 line = ml_get(pos->lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 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
88 p = skip_string(p);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 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
90 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 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
92 if (cur_maxcomment <= 0)
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 pos = NULL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 break;
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 return pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 * 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
103 * comment or raw string right now.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 * 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
105 * 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
106 * 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
107 * "CORS" -> Comment Or Raw String
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 *
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
110 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
111 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 static pos_T comment_pos_copy;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 pos_T *comment_pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 pos_T *rs_pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 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
117 if (comment_pos != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
119 // 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
120 // 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
121 comment_pos_copy = *comment_pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 comment_pos = &comment_pos_copy;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 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
125
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
126 // 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
127 // 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
128 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
129 && LT_POS(*rs_pos, *comment_pos)))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 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
132 *is_raw = rs_pos->lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 return rs_pos;
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 return comment_pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 * 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
140 * 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
141 * 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
142 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 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
144 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
145 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 pos_T *pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 char_u *line;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 char_u *p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 int cur_maxcomment = ind_maxcomment;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 for (;;)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 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
154 if (pos == NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
157 // 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
158 // 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
159 line = ml_get(pos->lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 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
161 p = skip_string(p);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 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
163 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 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
165 if (cur_maxcomment <= 0)
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 pos = NULL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 break;
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 return pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173
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 * 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
176 * 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
177 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 static char_u *
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 skip_string(char_u *p)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 int i;
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 // 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
184 for ( ; ; ++p)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
186 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
187 {
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]) // ' at end of line
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 i = 2;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
191 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
192 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 ++i;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
194 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
195 ++i;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 }
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
197 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
198 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 p += i;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 continue;
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 }
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
203 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
204 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 for (++p; p[0]; ++p)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 if (p[0] == '\\' && p[1] != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 ++p;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
209 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
210 break;
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 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
213 continue; // continue for another string
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 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
216 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
217 // Raw string: R"[delim](...)[delim]"
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 char_u *delim = p + 2;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 char_u *paren = vim_strchr(delim, '(');
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 if (paren != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 size_t delim_len = paren - delim;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 for (p += 3; *p; ++p)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 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
227 && p[delim_len + 1] == '"')
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 p += delim_len + 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 break;
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 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
233 continue; // continue for another string
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 }
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
236 break; // no string found
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 if (!*p)
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
239 --p; // backup from NUL
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 return p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 }
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
242 #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
243
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 #if defined(FEAT_CINDENT) || defined(PROTO)
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 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 * 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
248 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 cindent_on(void)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 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
253 # ifdef FEAT_EVAL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 || *curbuf->b_p_inde != NUL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 # endif
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 ));
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
259 // 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
260 typedef struct {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 int found;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 lpos_T lpos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 } cpp_baseclass_cache_T;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264
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 * Functions for C-indenting.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 * 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
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 * 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
271 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 static int cin_isdefault(char_u *);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 static int cin_ispreproc(char_u *);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 static int cin_iscomment(char_u *);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 static int cin_islinecomment(char_u *);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 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
278 static int cin_iselse(char_u *);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 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
280 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
281 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
282 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
283 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
284 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
285
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 * 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
288 * 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
289 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 static char_u *
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 cin_skipcomment(char_u *s)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 while (*s)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295 char_u *prev_s = s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 s = skipwhite(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
299 // 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
300 // before # to avoid recognizing $#array.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 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
302 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 s += STRLEN(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 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306 if (*s != '/')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308 ++s;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
309 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
310 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 s += STRLEN(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 if (*s != '*')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315 break;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
316 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
317 if (s[0] == '*' && s[1] == '/')
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 s += 2;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 break;
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 return s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325
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 * 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
328 * not considered code.
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 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 cin_nocode(char_u *s)
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 return *cin_skipcomment(s) == NUL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 }
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 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 * 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
338 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 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
340 find_line_comment(void) // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 static pos_T pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 char_u *line;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 char_u *p;
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 pos = curwin->w_cursor;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 while (--pos.lnum > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349 line = ml_get(pos.lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 p = skipwhite(line);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 if (cin_islinecomment(p))
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 pos.col = (int)(p - line);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354 return &pos;
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 if (*p != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 break;
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 return NULL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 }
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 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 * 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
364 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 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
367 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 char_u *s = skipwhite(text);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 int quote = -1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 if (*s == '\'' || *s == '"')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
373 // can be 'key': or "key":
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 quote = *s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 ++s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 }
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
377 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
378 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 while (vim_isIDc(*s))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 ++s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 if (*s == quote)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 ++s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 s = cin_skipcomment(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
387 // "::" 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
388 return (*s == ':' && s[1] != ':');
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390
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 * 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
393 * "*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
394 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 cin_islabel_skip(char_u **s)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
398 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
399 return FALSE;
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 while (vim_isIDc(**s))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 (*s)++;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 *s = cin_skipcomment(*s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
406 // "::" 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
407 return (**s == ':' && *++*s != ':');
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409
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 * Recognize a label: "label:".
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412 * 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
413 */
17789
0f7ae8010787 patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents: 16764
diff changeset
414 static int
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
415 cin_islabel(void) // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 char_u *s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 s = cin_skipcomment(ml_get_curline());
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
421 // 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
422 // 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
423 if (cin_isdefault(s))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 if (cin_isscopedecl(s))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 if (cin_islabel_skip(&s))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
430 // 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
431 // label.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 pos_T cursor_save;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 pos_T *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 char_u *line;
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 cursor_save = curwin->w_cursor;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 while (curwin->w_cursor.lnum > 1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 --curwin->w_cursor.lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
441 // 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
442 // it.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443 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
444 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
445 curwin->w_cursor = *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 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
448 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
449 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 if (*(line = cin_skipcomment(line)) == NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 curwin->w_cursor = cursor_save;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 if (cin_isterminated(line, TRUE, FALSE)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 || cin_isscopedecl(line)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 || cin_iscase(line, TRUE)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 || (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
458 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 return FALSE;
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 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
462 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
463 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 * Recognize structure initialization and enumerations:
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 * "[typedef] [static|public|protected|private] enum"
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 * "[typedef] [static|public|protected|private] = {"
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 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 cin_isinit(void)
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 char_u *s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 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
477
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478 s = cin_skipcomment(ml_get_curline());
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 if (cin_starts_with(s, "typedef"))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 s = cin_skipcomment(s + 7);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 for (;;)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 int i, l;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 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
488 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 l = (int)strlen(skip[i]);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 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
491 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 s = cin_skipcomment(s + l);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 l = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 }
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 if (l != 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 }
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_starts_with(s, "enum"))
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 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
505 return TRUE;
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 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 }
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 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 * 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
512 */
17789
0f7ae8010787 patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents: 16764
diff changeset
513 static int
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 cin_iscase(
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 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
516 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
517 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 s = cin_skipcomment(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 if (cin_starts_with(s, "case"))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 for (s += 4; *s; ++s)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 s = cin_skipcomment(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 if (*s == ':')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
526 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
527 ++s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 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
532 s += 2; // skip over ':'
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 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
534 return FALSE; // stop at comment
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 else if (*s == '"')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
537 // JS etc.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 if (strict)
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
539 return FALSE; // stop at string
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 return TRUE;
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 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 if (cin_isdefault(s))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 }
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 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 * Recognize a "default" switch label.
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 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 cin_isdefault(char_u *s)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 return (STRNCMP(s, "default", 7) == 0
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 && *(s = cin_skipcomment(s + 7)) == ':'
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 && s[1] != ':');
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 }
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 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 * 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
565 */
17789
0f7ae8010787 patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents: 16764
diff changeset
566 static int
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 cin_isscopedecl(char_u *s)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 int i;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 s = cin_skipcomment(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 if (STRNCMP(s, "public", 6) == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 i = 6;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 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
575 i = 9;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 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
577 i = 7;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 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
581 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
583 // 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
584 #define FIND_NAMESPACE_LIM 20
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 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 * Recognize a "namespace" scope declaration.
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 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 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
591 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 char_u *p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 int has_name = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 int has_name_start = FALSE;
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 s = cin_skipcomment(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 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
598 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 p = cin_skipcomment(skipwhite(s + 9));
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 while (*p != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 if (VIM_ISWHITE(*p))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
604 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
605 p = cin_skipcomment(skipwhite(p));
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 else if (*p == '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 else if (vim_iswordc(*p))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 has_name_start = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 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
615 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
616 ++p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618 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
619 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 if (!has_name_start || has_name)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 return FALSE;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
622 // C++ 17 nested namespace
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 p += 3;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 else
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 FALSE;
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 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 return TRUE;
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 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 }
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 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 * 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
637 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 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
640 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 char_u *p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 int has_string_literal = FALSE;
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 s = cin_skipcomment(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 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
646 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 p = cin_skipcomment(skipwhite(s + 6));
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 while (*p != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 if (VIM_ISWHITE(*p))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 p = cin_skipcomment(skipwhite(p));
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 else if (*p == '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 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
659 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 if (has_string_literal)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 has_string_literal = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 p += 3;
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 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
666 && p[4] == '"')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 if (has_string_literal)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 has_string_literal = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 p += 5;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 else
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 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 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 return has_string_literal ? TRUE : FALSE;
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 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 * 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
685 * Return NULL if not found.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 * case 234: a = b;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 * ^
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 static char_u *
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 after_label(char_u *l)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 for ( ; *l; ++l)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694 if (*l == ':')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
696 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
697 ++l;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 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
699 break;
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 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
702 l += 2; // skip over 'x'
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 }
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 l = cin_skipcomment(l + 1);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 if (*l == NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 return NULL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 return l;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711
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 * 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
714 * 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
715 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 static int
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
717 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
718 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 char_u *l;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 pos_T fp;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 colnr_T col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 char_u *p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 l = ml_get(lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 p = after_label(l);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 if (p == NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 return 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 fp.col = (colnr_T)(p - l);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 fp.lnum = lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 getvcol(curwin, &fp, &col, NULL, NULL);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 return (int)col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 * 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
737 * 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
738 * label: if (asdf && asdfasdf)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739 * ^
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 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 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
743 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 char_u *l;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 int amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 pos_T cursor_save;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 cursor_save = curwin->w_cursor;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 curwin->w_cursor.lnum = lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 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
751 // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 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
753 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 amount = get_indent_nolabel(lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 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
756 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
757 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 else
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 amount = get_indent();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 *pp = l;
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 curwin->w_cursor = cursor_save;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 return amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 * 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
772 * int a, indent of "a"
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 * 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
774 * enum bla c, indent of "c"
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 * 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
776 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 cin_first_id_amount(void)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 char_u *line, *p, *s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 int len;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 pos_T fp;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 colnr_T col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 line = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 p = skipwhite(line);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 len = (int)(skiptowhite(p) - p);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 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
789 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 p = skipwhite(p + 6);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 len = (int)(skiptowhite(p) - p);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 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
794 p = skipwhite(p + 6);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 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
796 p = skipwhite(p + 4);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 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
798 || (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
799 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 s = skipwhite(p + len);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
801 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
802 || (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
803 || (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
804 || (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
805 p = s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 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
808 ;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809 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
810 return 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
811
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812 p = skipwhite(p + len);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 fp.lnum = curwin->w_cursor.lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814 fp.col = (colnr_T)(p - line);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815 getvcol(curwin, &fp, &col, NULL, NULL);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 return (int)col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
819 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 * 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
821 * char *foo = "here";
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 * 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
823 * 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
824 * foo = "asdf\
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 * asdf\
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 * here";
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 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 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
830 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831 char_u *line;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 char_u *s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833 colnr_T col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834 pos_T fp;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836 if (lnum > 1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838 line = ml_get(lnum - 1);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 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
840 return -1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 line = s = ml_get(lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844 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
845 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
846 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
847 s = cin_skipcomment(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 ++s;
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 if (*s != '=')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 return 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 s = skipwhite(s + 1);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 if (cin_nocode(s))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 return 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
858 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
859 ++s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861 fp.lnum = lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862 fp.col = (colnr_T)(s - line);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 getvcol(curwin, &fp, &col, NULL, NULL);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 return (int)col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 }
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 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868 * 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
869 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 cin_ispreproc(char_u *s)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 if (*skipwhite(s) == '#')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879 * 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
880 * 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
881 * 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
882 * 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
883 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 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
886 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 char_u *line = *pp;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 linenr_T lnum = *lnump;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 int retval = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 int candidate_amount = *amount;
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 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
893 candidate_amount = get_indent_lnum(lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 for (;;)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
896 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897 if (cin_ispreproc(line))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899 retval = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900 *lnump = lnum;
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 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903 if (lnum == 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 line = ml_get(--lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906 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
907 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
909
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 if (lnum != *lnump)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911 *pp = ml_get(*lnump);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 if (retval)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913 *amount = candidate_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914 return retval;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 }
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 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918 * 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
919 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
921 cin_iscomment(char_u *p)
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 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
924 }
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 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 * Recognize the start of a "//" comment.
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 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930 cin_islinecomment(char_u *p)
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 return (p[0] == '/' && p[1] == '/');
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933 }
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 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 * 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
937 * '}'.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 * 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
939 * 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
940 * 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
941 * 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
942 * 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
943 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945 cin_isterminated(
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 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
947 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
948 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
949 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 char_u found_start = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
951 unsigned n_open = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952 int is_else = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954 s = cin_skipcomment(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 (*s == '{' || (*s == '}' && !cin_iselse(s)))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957 found_start = *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 if (!found_start)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
960 is_else = cin_iselse(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
961
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962 while (*s)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
964 // 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
965 s = skip_string(cin_skipcomment(s));
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966 if (*s == '}' && n_open > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 --n_open;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968 if ((!is_else || n_open == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
969 && (*s == ';' || *s == '}' || (incl_comma && *s == ','))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 && cin_nocode(s + 1))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
971 return *s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 else if (*s == '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974 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
975 return *s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 ++n_open;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 }
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 if (*s)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 s++;
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 return found_start;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 * 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
988 * 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
989 * no semicolons anywhere.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
990 * 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
991 * "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
992 * 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
993 * "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
994 * "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
995 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 cin_isfuncdecl(
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998 char_u **sp,
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 linenr_T first_lnum,
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000 linenr_T min_lnum)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 char_u *s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003 linenr_T lnum = first_lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004 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
1005 int retval = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 pos_T *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007 int just_started = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009 if (sp == NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 s = ml_get(lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1012 s = *sp;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014 curwin->w_cursor.lnum = lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015 if (find_last_paren(s, '(', ')')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016 && (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
1017 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 lnum = trypos->lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 if (lnum < min_lnum)
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 curwin->w_cursor.lnum = save_lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 return FALSE;
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
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025 s = ml_get(lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027 curwin->w_cursor.lnum = save_lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1028
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1029 // Ignore line starting with #.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1030 if (cin_ispreproc(s))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1032
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033 while (*s && *s != '(' && *s != ';' && *s != '\'' && *s != '"')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1034 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1035 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
1036 s = cin_skipcomment(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 else if (*s == ':')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 if (*(s + 1) == ':')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1040 s += 2;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041 else
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1042 // 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
1043 // 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
1044 // : 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
1045 // , b(0)
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1046 // {...
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 return FALSE;
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 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 ++s;
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 if (*s != '(')
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1053 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
1054
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055 while (*s && *s != ';' && *s != '\'' && *s != '"')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 if (*s == ')' && cin_nocode(s + 1))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1059 /*
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1060 * ')' 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
1061 * 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
1062 * #if defined(x) && \
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1063 * defined(y)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1064 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1065 lnum = first_lnum - 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1066 s = ml_get(lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 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
1068 retval = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069 goto done;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1071 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
1072 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1073 int comma = (*s == ',');
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1074
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1075 // ',' 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
1076 // 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
1077 // func(arg1
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1078 // , arg2)
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 for (;;)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 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
1082 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083 s = ml_get(++lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 if (!cin_ispreproc(s))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1085 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1087 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
1088 break;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1089 // 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
1090 // start of next line.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1091 s = skipwhite(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092 if (!just_started && (!comma && *s != ',' && *s != ')'))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1094 just_started = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1095 }
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1096 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
1097 s = cin_skipcomment(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 else
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 ++s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101 just_started = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1104
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105 done:
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106 if (lnum != first_lnum && sp != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107 *sp = ml_get(first_lnum);
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 return retval;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 }
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 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1113 cin_isif(char_u *p)
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 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
1116 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1118 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119 cin_iselse(
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 char_u *p)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1122 if (*p == '}') // accept "} else"
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123 p = cin_skipcomment(p + 1);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 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
1125 }
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 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 cin_isdo(char_u *p)
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 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
1131 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1132
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1133 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1134 * 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
1135 * 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
1136 * ')' 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
1137 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 static int
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1139 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
1140 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141 pos_T cursor_save;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142 pos_T *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1143 int retval = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1145 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
1146 if (*p == '}') // accept "} while (cond);"
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1147 p = cin_skipcomment(p + 1);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 if (cin_starts_with(p, "while"))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1150 cursor_save = curwin->w_cursor;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1151 curwin->w_cursor.lnum = lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1152 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1153 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
1154 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
1155 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1156 ++p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1157 ++curwin->w_cursor.col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1158 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159 if ((trypos = findmatchlimit(NULL, 0, 0,
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1160 curbuf->b_ind_maxparen)) != NULL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1161 && *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
1162 retval = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163 curwin->w_cursor = cursor_save;
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 return retval;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1166 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1167
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1168 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169 * 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
1170 * Return 0 if there is none.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1171 * 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
1172 * string was found.
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 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175 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
1176 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1177 int offset = *poffset;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1179 if (offset-- < 2)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1180 return 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1181 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
1182 --offset;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184 offset -= 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 if (!STRNCMP(line + offset, "if", 2))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1186 goto probablyFound;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1188 if (offset >= 1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1189 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1190 offset -= 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1191 if (!STRNCMP(line + offset, "for", 3))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1192 goto probablyFound;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1193
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1194 if (offset >= 2)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1195 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1196 offset -= 2;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1197 if (!STRNCMP(line + offset, "while", 5))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1198 goto probablyFound;
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 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1201 return 0;
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 probablyFound:
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1204 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
1205 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1206 *poffset = offset;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1207 return 1;
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 return 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1210 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1211
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1212 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1213 * 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
1214 * do
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1215 * nothing;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1216 * while (foo
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1217 * && bar); <-- here
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1218 * 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
1219 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1220 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1221 cin_iswhileofdo_end(int terminated)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1222 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1223 char_u *line;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1224 char_u *p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1225 char_u *s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1226 pos_T *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1227 int i;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1228
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1229 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
1230 return FALSE;
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 = line = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1233 while (*p != NUL)
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 p = cin_skipcomment(p);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1236 if (*p == ')')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1238 s = skipwhite(p + 1);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1239 if (*s == ';' && cin_nocode(s + 1))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1240 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1241 // 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
1242 // before the matching '('. XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1243 i = (int)(p - line);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1244 curwin->w_cursor.col = i;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1245 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
1246 if (trypos != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1247 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1248 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
1249 if (*s == '}') // accept "} while (cond);"
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1250 s = cin_skipcomment(s + 1);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1251 if (cin_starts_with(s, "while"))
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 curwin->w_cursor.lnum = trypos->lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1254 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1255 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1256 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1257
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1258 // 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
1259 line = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1260 p = line + i;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1261 }
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 if (*p != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1264 ++p;
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 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1267 }
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 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1270 cin_isbreak(char_u *p)
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 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
1273 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1274
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 * 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
1277 * constructor-initialization. eg:
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1278 *
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1279 * class MyClass :
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1280 * baseClass <-- here
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1281 * class MyClass : public baseClass,
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1282 * anotherBaseClass <-- here (should probably lineup ??)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1283 * MyClass::MyClass(...) :
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1284 * baseClass(...) <-- here (constructor-initialization)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1285 *
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1286 * 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
1287 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1288 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1289 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
1290 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
1291 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1292 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
1293 char_u *s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1294 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
1295 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
1296 char_u *line = ml_get_curline();
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 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
1299 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
1300
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1301 pos->col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1302
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1303 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
1304 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
1305 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1306 s = cin_skipcomment(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1307 if (*s == NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1308 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1309
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1310 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
1311
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1312 // 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
1313 // '{' 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
1314 // a = cond ?
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1315 // func() :
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1316 // asdf;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1317 // func::foo()
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1318 // : something
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1319 // {}
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1320 // 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
1321 // : something(4),
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1322 // somethingelse(3)
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1323 // {}
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1324 while (lnum > 1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1325 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1326 line = ml_get(lnum - 1);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1327 s = skipwhite(line);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1328 if (*s == '#' || *s == NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1329 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1330 while (*s != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1331 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1332 s = cin_skipcomment(s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1333 if (*s == '{' || *s == '}'
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1334 || (*s == ';' && cin_nocode(s + 1)))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1335 break;
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 ++s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1338 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1339 if (*s != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1340 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1341 --lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1342 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1343
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1344 pos->lnum = lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1345 line = ml_get(lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1346 s = line;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1347 for (;;)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1348 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1349 if (*s == NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1350 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1351 if (lnum == curwin->w_cursor.lnum)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1352 break;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1353 // Continue in the cursor line.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1354 line = ml_get(++lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1355 s = line;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1356 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1357 if (s == line)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1358 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1359 // 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
1360 if (cin_iscase(s, FALSE))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1361 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1362 s = cin_skipcomment(line);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1363 if (*s == NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1364 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1365 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1366
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1367 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
1368 s = skip_string(s) + 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1369 else if (s[0] == ':')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1370 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1371 if (s[1] == ':')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1372 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1373 // 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
1374 // initialization any more
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1375 lookfor_ctor_init = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1376 s = cin_skipcomment(s + 2);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1377 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1378 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
1379 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1380 // 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
1381 // 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
1382 cpp_base_class = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1383 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
1384 pos->col = 0;
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
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1388 s = cin_skipcomment(s + 1);
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 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
1391 || (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
1392 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1393 class_or_struct = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1394 lookfor_ctor_init = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1395
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1396 if (*s == 'c')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1397 s = cin_skipcomment(s + 5);
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 s = cin_skipcomment(s + 6);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1400 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1401 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1402 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1403 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
1404 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1405 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
1406 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1407 else if (s[0] == ')')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1408 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1409 // 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
1410 // something like "):"
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1411 class_or_struct = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1412 lookfor_ctor_init = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1413 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1414 else if (s[0] == '?')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1415 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1416 // 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
1417 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1418 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1419 else if (!vim_isIDc(s[0]))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1420 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1421 // 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
1422 class_or_struct = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1423 lookfor_ctor_init = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1424 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1425 else if (pos->col == 0)
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 // 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
1428 lookfor_ctor_init = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1429
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1430 // 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
1431 if (cpp_base_class)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1432 pos->col = (colnr_T)(s - line);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1433 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1434
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1435 // 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
1436 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
1437 pos->col = 0;
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 s = cin_skipcomment(s + 1);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1440 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1441 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1442
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1443 cached->found = cpp_base_class;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1444 if (cpp_base_class)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1445 pos->lnum = lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1446 return cpp_base_class;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1447 }
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 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1450 get_baseclass_amount(int col)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1451 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1452 int amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1453 colnr_T vcol;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1454 pos_T *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1455
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1456 if (col == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1457 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1458 amount = get_indent();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1459 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
1460 && (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
1461 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
1462 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
1463 amount += curbuf->b_ind_cpp_baseclass;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1464 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1465 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1466 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1467 curwin->w_cursor.col = col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1468 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
1469 amount = (int)vcol;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1470 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1471 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
1472 amount = curbuf->b_ind_cpp_baseclass;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1473 return amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1474 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1475
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1476 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1477 * 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
1478 * 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
1479 * 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
1480 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1481 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1482 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
1483 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1484 char_u *p = s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1485 char_u *r;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1486 int len = (int)STRLEN(find);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1487
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1488 while (*p != NUL)
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 p = cin_skipcomment(p);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1491 if (STRNCMP(p, find, len) == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1492 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1493 r = skipwhite(p + len);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1494 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
1495 r = skipwhite(r + STRLEN(ignore));
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1496 if (cin_nocode(r))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1497 return TRUE;
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 if (*p != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1500 ++p;
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 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1503 }
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 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1506 * 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
1507 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1508 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1509 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
1510 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1511 int l = (int)STRLEN(word);
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 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
1514 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1515
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 * 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
1518 * Return the column found.
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 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1521 cin_skip2pos(pos_T *trypos)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1522 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1523 char_u *line;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1524 char_u *p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1525 char_u *new_p;
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 p = line = ml_get(trypos->lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1528 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
1529 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1530 if (cin_iscomment(p))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1531 p = cin_skipcomment(p);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1532 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1533 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1534 new_p = skip_string(p);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1535 if (new_p == p)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1536 ++p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1537 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1538 p = new_p;
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 return (int)(p - line);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1542 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1543
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1544 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1545 * 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
1546 * Return NULL if no match found.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1547 * 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
1548 * work.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1549 */
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1550 /* foo() */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1551 /* { */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1552 /* } */
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 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
1555 find_start_brace(void) // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1556 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1557 pos_T cursor_save;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1558 pos_T *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1559 pos_T *pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1560 static pos_T pos_copy;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1561
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1562 cursor_save = curwin->w_cursor;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1563 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
1564 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1565 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
1566 trypos = &pos_copy;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1567 curwin->w_cursor = *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1568 pos = NULL;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1569 // 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
1570 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
1571 && (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
1572 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1573 if (pos != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1574 curwin->w_cursor.lnum = pos->lnum;
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 curwin->w_cursor = cursor_save;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1577 return trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1578 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1579
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 * 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
1582 * Return NULL if no match found.
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 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
1585 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
1586 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1587 return find_match_char('(', ind_maxparen);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1588 }
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 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
1591 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
1592 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1593 pos_T cursor_save;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1594 pos_T *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1595 static pos_T pos_copy;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1596 int ind_maxp_wk;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1597
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1598 cursor_save = curwin->w_cursor;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1599 ind_maxp_wk = ind_maxparen;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1600 retry:
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1601 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
1602 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1603 // 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
1604 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
1605 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1606 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
1607 if (ind_maxp_wk > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1608 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1609 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
1610 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
1611 goto retry;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1612 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1613 trypos = NULL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1614 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1615 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1616 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1617 pos_T *trypos_wk;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1618
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1619 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
1620 trypos = &pos_copy;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1621 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
1622 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
1623 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1624 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
1625 - trypos_wk->lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1626 if (ind_maxp_wk > 0)
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 curwin->w_cursor = *trypos_wk;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1629 goto retry;
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 trypos = NULL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1632 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1633 }
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 curwin->w_cursor = cursor_save;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1636 return trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1637 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1638
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1639 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1640 * 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
1641 * unmatched {.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1642 * Return NULL if no match found.
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 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
1645 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
1646 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1647 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
1648
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1649 if (trypos != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1650 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1651 pos_T *tryposBrace = find_start_brace();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1652
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1653 // 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
1654 // 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
1655 if (tryposBrace != NULL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1656 && (trypos->lnum != tryposBrace->lnum
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1657 ? trypos->lnum < tryposBrace->lnum
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1658 : trypos->col < tryposBrace->col))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1659 trypos = NULL;
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 return trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1662 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1663
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1664 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1665 * 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
1666 * 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
1667 * 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
1668 * looking a few lines further.
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 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1671 corr_ind_maxparen(pos_T *startpos)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1672 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1673 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
1674
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1675 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
1676 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
1677 return curbuf->b_ind_maxparen;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1678 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1679
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 * 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
1682 * 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
1683 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1684 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1685 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
1686 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1687 int i;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1688 int retval = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1689 int open_count = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1690
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1691 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
1692
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1693 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
1694 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1695 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
1696 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
1697 if (l[i] == start)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1698 ++open_count;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1699 else if (l[i] == end)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1700 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1701 if (open_count > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1702 --open_count;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1703 else
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 curwin->w_cursor.col = i;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1706 retval = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1707 }
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 return retval;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1711 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1712
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 * 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
1715 * 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
1716 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1717 void
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1718 parse_cino(buf_T *buf)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1719 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1720 char_u *p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1721 char_u *l;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1722 char_u *digits;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1723 int n;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1724 int divider;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1725 int fraction = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1726 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
1727
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1728 // 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
1729
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1730 // 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
1731 // block should be.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1732 buf->b_ind_level = sw;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1733
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1734 // 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
1735 // line is imagined to be.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1736 buf->b_ind_open_imag = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1737
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1738 // 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
1739 // an opening brace.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1740 buf->b_ind_no_brace = 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 // 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
1743 buf->b_ind_first_open = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1744
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1745 // 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
1746 // located.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1747 buf->b_ind_open_extra = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1748
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1749 // 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
1750 // 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
1751 // brace should be located.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1752 buf->b_ind_close_extra = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1753
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1754 // 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
1755 // column is imagined to be.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1756 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
1757
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1758 // 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
1759 // 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
1760 buf->b_ind_jump_label = -1;
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 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
1763 buf->b_ind_case = 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 // 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
1766 buf->b_ind_case_code = sw;
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 // 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
1769 buf->b_ind_case_break = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1770
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1771 // 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
1772 // 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 = 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 // 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
1776 buf->b_ind_scopedecl_code = 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 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
1779 buf->b_ind_param = 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 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
1782 buf->b_ind_func_type = sw;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1783
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1784 // 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
1785 // should be indented.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1786 buf->b_ind_cpp_baseclass = sw;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1787
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1788 // 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
1789 // should be located.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1790 buf->b_ind_continuation = sw;
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.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1793 buf->b_ind_unclosed = sw * 2;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1794
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1795 // 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
1796 // itself is also unclosed.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1797 buf->b_ind_unclosed2 = sw;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1798
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1799 // 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
1800 // unclosed parentheses.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1801 buf->b_ind_unclosed_noignore = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1802
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1803 // 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
1804 // 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
1805 // context (for very long lines).
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1806 buf->b_ind_unclosed_wrapped = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1807
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1808 // 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
1809 // an unclosed parentheses.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1810 buf->b_ind_unclosed_whiteok = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1811
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1812 // 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
1813 // opening parentheses.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1814 buf->b_ind_matching_paren = 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 // 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
1817 buf->b_ind_paren_prev = 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 // Extra indent for comments.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1820 buf->b_ind_comment = 0;
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 // 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
1823 buf->b_ind_in_comment = 3;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1824
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1825 // 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
1826 // after the comment opener.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1827 buf->b_ind_in_comment2 = 0;
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 paren.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1830 buf->b_ind_maxparen = 20;
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 // 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
1833 buf->b_ind_maxcomment = 70;
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 // Handle braces for java code.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1836 buf->b_ind_java = 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 // 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
1839 buf->b_ind_js = 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 blocked cases correctly.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1842 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
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 C++ namespace.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1845 buf->b_ind_cpp_namespace = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1846
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1847 // 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
1848 // while().
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1849 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
1850
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1851 // indentation for # comments
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1852 buf->b_ind_hash_comment = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1853
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1854 // 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
1855 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
1856
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1857 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
1858 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1859 l = p++;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1860 if (*p == '-')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1861 ++p;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1862 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
1863 n = getdigits(&p);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1864 divider = 0;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1865 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
1866 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1867 fraction = atol((char *)++p);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1868 while (VIM_ISDIGIT(*p))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1869 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1870 ++p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1871 if (divider)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1872 divider *= 10;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1873 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1874 divider = 10;
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 }
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1877 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
1878 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1879 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
1880 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
1881 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1882 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1883 n *= sw;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1884 if (divider)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1885 n += (sw * fraction + divider / 2) / divider;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1886 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1887 ++p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1888 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1889 if (l[1] == '-')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1890 n = -n;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1891
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1892 // 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
1893 // 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
1894 switch (*l)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1895 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1896 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
1897 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
1898 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
1899 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
1900 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
1901 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
1902 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
1903 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
1904 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
1905 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
1906 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
1907 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
1908 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
1909 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
1910 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
1911 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
1912 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
1913 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
1914 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
1915 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
1916 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
1917 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
1918 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
1919 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
1920 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
1921 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
1922 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
1923 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
1924 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
1925 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
1926 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
1927 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
1928 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
1929 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
1930 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
1931 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
1932 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1933 if (*p == ',')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1934 ++p;
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 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1937
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 * 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
1940 * 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
1941 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1942 int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1943 get_c_indent(void)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1944 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1945 pos_T cur_curpos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1946 int amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1947 int scope_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1948 int cur_amount = MAXCOL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1949 colnr_T col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1950 char_u *theline;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1951 char_u *linecopy;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1952 pos_T *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1953 pos_T *comment_pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1954 pos_T *tryposBrace = NULL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1955 pos_T tryposCopy;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1956 pos_T our_paren_pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1957 char_u *start;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1958 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
1959 #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
1960 #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
1961 #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
1962 linenr_T ourscope;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1963 char_u *l;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1964 char_u *look;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1965 char_u terminated;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1966 int lookfor;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1967 #define LOOKFOR_INITIAL 0
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1968 #define LOOKFOR_IF 1
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1969 #define LOOKFOR_DO 2
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1970 #define LOOKFOR_CASE 3
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1971 #define LOOKFOR_ANY 4
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1972 #define LOOKFOR_TERM 5
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1973 #define LOOKFOR_UNTERM 6
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1974 #define LOOKFOR_SCOPEDECL 7
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1975 #define LOOKFOR_NOBREAK 8
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1976 #define LOOKFOR_CPP_BASECLASS 9
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1977 #define LOOKFOR_ENUM_OR_INIT 10
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1978 #define LOOKFOR_JS_KEY 11
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1979 #define LOOKFOR_COMMA 12
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1980
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1981 int whilelevel;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1982 linenr_T lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1983 int n;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1984 int iscase;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1985 int lookfor_break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1986 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
1987 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
1988 int original_line_islabel;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1989 int added_to_amount = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1990 int js_cur_has_key = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1991 linenr_T raw_string_start = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1992 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
1993
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1994 // 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
1995 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
1996
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
1997 // 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
1998 cur_curpos = curwin->w_cursor;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1999
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2000 // 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
2001 if (cur_curpos.lnum == 1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2002 return 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2003
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2004 // 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
2005 // 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
2006 // ml_get is valid!
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2007 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
2008 if (linecopy == NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2009 return 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2010
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2011 // 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
2012 // 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
2013 // inserting new stuff.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2014 // 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
2015 // check for that.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2016 if ((State & INSERT)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2017 && 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
2018 && linecopy[curwin->w_cursor.col] == ')')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2019 linecopy[curwin->w_cursor.col] = NUL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2020
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2021 theline = skipwhite(linecopy);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2022
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2023 // 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
2024
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2025 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2026
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2027 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
2028
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2029 // 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
2030 // 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
2031 comment_pos = ind_find_start_comment();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2032 if (comment_pos != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2033 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2034 // 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
2035 tryposCopy = *comment_pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2036 comment_pos = &tryposCopy;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2037 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2038 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
2039 if (trypos != NULL && (comment_pos == NULL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2040 || LT_POS(*trypos, *comment_pos)))
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 amount = -1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2043 goto laterend;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2044 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2045
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2046 // #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
2047 if (*theline == '#' && (*linecopy == '#' || in_cinkeys('#', ' ', TRUE)))
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 amount = curbuf->b_ind_hash_comment;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2050 goto theend;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2051 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2052
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2053 // 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
2054 // - 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
2055 // - '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
2056 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
2057 && curbuf->b_ind_jump_label < 0)
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 amount = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2060 goto theend;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2061 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2062
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2063 // 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
2064 // 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
2065 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
2066 && (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
2067 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2068 // 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
2069 getvcol(curwin, trypos, &col, NULL, NULL);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2070 amount = col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2071 goto theend;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2072 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2073
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2074 // 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
2075 // 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
2076 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
2077 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2078 int lead_start_len = 2;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2079 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
2080 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
2081 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
2082 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
2083 char_u *p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2084 int start_align = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2085 int start_off = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2086 int done = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2087
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2088 // 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
2089 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
2090 amount = col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2091 *lead_start = NUL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2092 *lead_middle = 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 p = curbuf->b_p_com;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2095 while (*p != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2096 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2097 int align = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2098 int off = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2099 int what = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2100
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2101 while (*p != NUL && *p != ':')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2102 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2103 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
2104 what = *p++;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2105 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
2106 align = *p++;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2107 else if (VIM_ISDIGIT(*p) || *p == '-')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2108 off = getdigits(&p);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2109 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2110 ++p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2111 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2112
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2113 if (*p == ':')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2114 ++p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2115 (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
2116 if (what == COM_START)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2117 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2118 STRCPY(lead_start, lead_end);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2119 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
2120 start_off = off;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2121 start_align = align;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2122 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2123 else if (what == COM_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 STRCPY(lead_middle, lead_end);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2126 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
2127 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2128 else if (what == COM_END)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2129 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2130 // 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
2131 // 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
2132 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
2133 && 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
2134 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2135 done = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2136 if (curwin->w_cursor.lnum > 1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2137 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2138 // 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
2139 // 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
2140 // 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
2141 // 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
2142 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
2143 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
2144 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
2145 else if (STRNCMP(look, lead_middle,
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2146 lead_middle_len) == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2147 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2148 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
2149 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2150 }
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2151 // 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
2152 // 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
2153 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
2154 lead_start, lead_start_len) != 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2155 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2156 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2157 if (start_off != 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2158 amount += start_off;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2159 else if (start_align == COM_RIGHT)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2160 amount += vim_strsize(lead_start)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2161 - vim_strsize(lead_middle);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2162 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2163 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2164
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2165 // 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
2166 // with the middle comment
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2167 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
2168 && 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
2169 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2170 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
2171 // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2172 if (off != 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2173 amount += off;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2174 else if (align == COM_RIGHT)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2175 amount += vim_strsize(lead_start)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2176 - vim_strsize(lead_middle);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2177 done = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2178 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2179 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2180 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2181 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2182
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2183 // 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
2184 // 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
2185 // 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
2186 if (done)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2187 ;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2188 else if (theline[0] == '*')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2189 amount += 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2190 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2191 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2192 // 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
2193 // 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
2194 // 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
2195 // 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
2196 // 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
2197 amount = -1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2198 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
2199 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2200 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
2201 continue;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2202 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
2203 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2204 }
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2205 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
2206 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2207 if (!curbuf->b_ind_in_comment2)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2208 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2209 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
2210 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
2211 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
2212 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
2213 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2214 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
2215 amount = col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2216 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
2217 amount += curbuf->b_ind_in_comment;
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 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2220 goto theend;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2221 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2222
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2223 // 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
2224 if (*skipwhite(theline) == ']'
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2225 && (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
2226 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2227 // 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
2228 amount = get_indent_lnum(trypos->lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2229 goto theend;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2230 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2231
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2232 // 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
2233 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
2234 && curbuf->b_ind_java == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2235 || (tryposBrace = find_start_brace()) != NULL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2236 || trypos != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2237 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2238 if (trypos != NULL && tryposBrace != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2239 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2240 // 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
2241 // 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
2242 if (trypos->lnum != tryposBrace->lnum
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2243 ? trypos->lnum < tryposBrace->lnum
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2244 : trypos->col < tryposBrace->col)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2245 trypos = NULL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2246 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2247 tryposBrace = NULL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2248 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2249
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2250 if (trypos != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2251 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2252 // 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
2253 // 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
2254 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
2255 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2256 // 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
2257 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
2258 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2259 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2260 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2261 amount = -1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2262 our_paren_pos = *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2263 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
2264 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2265 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
2266 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
2267 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2268 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
2269 continue; // ignore #define, #if, etc.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2270 curwin->w_cursor.lnum = lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2271
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2272 // 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
2273 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
2274 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2275 lnum = trypos->lnum + 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2276 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2277 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2278
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2279 // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2280 if ((trypos = find_match_paren(
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2281 corr_ind_maxparen(&cur_curpos))) != NULL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2282 && trypos->lnum == our_paren_pos.lnum
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2283 && trypos->col == our_paren_pos.col)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2284 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2285 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
2286
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2287 if (theline[0] == ')')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2288 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2289 if (our_paren_pos.lnum != lnum
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2290 && cur_amount > amount)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2291 cur_amount = amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2292 amount = -1;
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 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2295 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2296 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2297 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2298
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2299 // 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
2300 // 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
2301 // 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
2302 if (amount == -1)
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 int ignore_paren_col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2305 int is_if_for_while = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2306
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2307 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
2308 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2309 // 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
2310 // 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
2311
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2312 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
2313 pos_T outermost;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2314 char_u *line;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2315
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2316 trypos = &our_paren_pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2317 do {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2318 outermost = *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2319 curwin->w_cursor.lnum = outermost.lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2320 curwin->w_cursor.col = outermost.col;
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 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
2323 } while (trypos && trypos->lnum == outermost.lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2324
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2325 curwin->w_cursor = cursor_save;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2326
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2327 line = ml_get(outermost.lnum);
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 is_if_for_while =
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2330 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
2331 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2332
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2333 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
2334 look = skipwhite(look);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2335 if (*look == '(')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2336 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2337 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
2338 char_u *line;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2339 int look_col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2340
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2341 // 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
2342 // our matching '('.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2343 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
2344 line = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2345 look_col = (int)(look - line);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2346 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
2347 if ((trypos = findmatchlimit(NULL, ')', 0,
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2348 curbuf->b_ind_maxparen))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2349 != NULL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2350 && trypos->lnum == our_paren_pos.lnum
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2351 && trypos->col < our_paren_pos.col)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2352 ignore_paren_col = trypos->col + 1;
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 curwin->w_cursor.lnum = save_lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2355 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
2356 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2357 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
2358 && is_if_for_while == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2359 || (!curbuf->b_ind_unclosed_noignore && *look == '('
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2360 && ignore_paren_col == 0))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2361 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2362 // 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
2363 // 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
2364 // 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
2365 // 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
2366 // 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
2367 // 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
2368 // lines).
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2369 if (theline[0] != ')')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2370 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2371 cur_amount = MAXCOL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2372 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
2373 if (curbuf->b_ind_unclosed_wrapped
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2374 && 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
2375 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2376 // 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
2377 // for each additional level
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2378 n = 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2379 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
2380 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2381 switch (l[col])
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2382 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2383 case '(':
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2384 case '{': ++n;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2385 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2386
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2387 case ')':
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2388 case '}': if (n > 1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2389 --n;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2390 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2391 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2392 }
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 our_paren_pos.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2395 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
2396 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2397 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
2398 our_paren_pos.col++;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2399 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2400 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2401 col = our_paren_pos.col + 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2402 while (VIM_ISWHITE(l[col]))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2403 col++;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2404 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
2405 our_paren_pos.col = col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2406 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2407 our_paren_pos.col++;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2408 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2409 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2410
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2411 // 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
2412 // 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
2413 if (our_paren_pos.col > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2414 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2415 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
2416 if (cur_amount > (int)col)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2417 cur_amount = col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2418 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2419 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2420
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2421 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
2422 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2423 // 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
2424 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2425 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
2426 || (!curbuf->b_ind_unclosed_noignore
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2427 && *look == '(' && ignore_paren_col == 0))
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 if (cur_amount != MAXCOL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2430 amount = cur_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2431 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2432 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2433 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2434 // 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
2435 // 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
2436 col = our_paren_pos.col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2437 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
2438 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2439 --our_paren_pos.col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2440 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
2441 {
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 = our_paren_pos.col;
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 case ')': amount -= curbuf->b_ind_unclosed2;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2446 col = MAXCOL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2447 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2448 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2449 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2450
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2451 // 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
2452 // braces
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2453 if (col == MAXCOL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2454 amount += curbuf->b_ind_unclosed;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2455 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2456 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2457 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
2458 curwin->w_cursor.col = col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2459 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
2460 != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2461 amount += curbuf->b_ind_unclosed2;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2462 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2463 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2464 if (is_if_for_while)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2465 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
2466 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2467 amount += curbuf->b_ind_unclosed;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2468 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2469 }
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2470 // 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
2471 // 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
2472 // lines:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2473 // 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
2474 // arg && yy
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2475 // ) ^ not here ) ^ not here
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2476 if (cur_amount < amount)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2477 amount = cur_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2478 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2479 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2480
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2481 // 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
2482 if (cin_iscomment(theline))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2483 amount += curbuf->b_ind_comment;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2484 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2485 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2486 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2487 // 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
2488 // stored in tryposBrace.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2489 // 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
2490 // 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
2491 tryposCopy = *tryposBrace;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2492 tryposBrace = &tryposCopy;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2493 trypos = tryposBrace;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2494 ourscope = trypos->lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2495 start = ml_get(ourscope);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2496
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2497 // 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
2498 // 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
2499 // 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
2500 // 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
2501 look = skipwhite(start);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2502 if (*look == '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2503 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2504 getvcol(curwin, trypos, &col, NULL, NULL);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2505 amount = col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2506 if (*start == '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2507 start_brace = BRACE_IN_COL0;
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 start_brace = BRACE_AT_START;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2510 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2511 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2512 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2513 // 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
2514 // 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
2515 curwin->w_cursor.lnum = ourscope;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2516
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2517 // 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
2518 // 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
2519 lnum = ourscope;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2520 if (find_last_paren(start, '(', ')')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2521 && (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
2522 != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2523 lnum = trypos->lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2524
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2525 // 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
2526 // 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
2527 // ldfd) {
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2528 // }
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2529 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
2530 && 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
2531 amount = get_indent();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2532 else if (curbuf->b_ind_js)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2533 amount = get_indent_lnum(lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2534 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2535 amount = skip_label(lnum, &l);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2536
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2537 start_brace = BRACE_AT_END;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2538 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2539
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2540 // 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
2541 if (curbuf->b_ind_js)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2542 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
2543
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2544 // 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
2545 // 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
2546 // 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
2547 if (theline[0] == '}')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2548 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2549 // 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
2550 // 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
2551 amount += curbuf->b_ind_close_extra;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2552 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2553 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2554 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2555 // 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
2556 // 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
2557 // 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
2558 // to match it with.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2559 lookfor = LOOKFOR_INITIAL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2560 if (cin_iselse(theline))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2561 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
2562 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
2563 lookfor = LOOKFOR_DO;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2564 if (lookfor != LOOKFOR_INITIAL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2565 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2566 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
2567 if (find_match(lookfor, ourscope) == OK)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2568 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2569 amount = get_indent(); // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2570 goto theend;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2571 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2572 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2573
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2574 // 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
2575 // 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
2576 // 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
2577 // 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
2578
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2579 // 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
2580 // 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
2581 // 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
2582
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2583 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
2584 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2585 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
2586 lookfor_cpp_namespace = TRUE;
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 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
2589 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
2590 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2591
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2592 lookfor_cpp_namespace = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2593 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2594 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2595 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2596 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
2597 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2598 amount += curbuf->b_ind_open_imag;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2599
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2600 l = skipwhite(ml_get_curline());
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2601 if (cin_is_cpp_namespace(l))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2602 amount += curbuf->b_ind_cpp_namespace;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2603 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
2604 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
2605 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2606 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2607 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2608 // 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
2609 amount -= curbuf->b_ind_open_extra;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2610 if (amount < 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2611 amount = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2612 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2613 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2614
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2615 lookfor_break = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2616
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2617 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
2618 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2619 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
2620 amount += curbuf->b_ind_case;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2621 }
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2622 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
2623 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2624 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
2625 amount += curbuf->b_ind_scopedecl;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2626 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2627 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2628 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2629 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
2630 // break; ...
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2631 lookfor_break = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2632
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2633 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
2634 // 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
2635 amount += curbuf->b_ind_level;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2636 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2637 scope_amount = amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2638 whilelevel = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2639
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2640 // 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
2641 // with that.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2642 //
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2643 // 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
2644 // 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
2645 // that opens the block.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2646 curwin->w_cursor = cur_curpos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2647 for (;;)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2648 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2649 curwin->w_cursor.lnum--;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2650 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2651
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2652 // 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
2653 // up with it.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2654 if (curwin->w_cursor.lnum <= ourscope)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2655 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2656 // 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
2657 // 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
2658 // go further back:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2659 // 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
2660 // 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
2661 // declaration:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2662 // int x,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2663 // here; <-- add ind_continuation
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2664 if (lookfor == LOOKFOR_ENUM_OR_INIT)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2665 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2666 if (curwin->w_cursor.lnum == 0
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2667 || curwin->w_cursor.lnum
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2668 < ourscope - curbuf->b_ind_maxparen)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2669 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2670 // 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
2671 // 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
2672 // initialization)
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2673 if (cont_amount > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2674 amount = cont_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2675 else if (!curbuf->b_ind_js)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2676 amount += ind_continuation;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2677 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2678 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2679
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2680 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2681
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2682 // 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
2683 // the start of it.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2684 trypos = ind_find_start_CORS(NULL);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2685 if (trypos != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2686 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2687 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
2688 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2689 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2690 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2691
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2692 // 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
2693 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
2694 &amount))
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 if (cin_nocode(l))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2698 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2700 terminated = cin_isterminated(l, FALSE, TRUE);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2701
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2702 // 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
2703 // 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
2704 // (it's a variable declaration).
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2705 if (start_brace != BRACE_IN_COL0
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2706 || !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
2707 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2708 // 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
2709 // 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
2710 // 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
2711 // 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
2712 // 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
2713 // cin_isfuncdecl returns FALSE then.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2714 if (terminated == ',')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2715 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2716
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2717 // 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
2718 // we are done.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2719 if (terminated != ';' && cin_isinit())
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2720 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2721
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2722 // nothing useful found
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2723 if (terminated == 0 || terminated == '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2724 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2725 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2726
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2727 if (terminated != ';')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2728 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2729 // 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
2730 // 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
2731 // 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
2732 // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2733 trypos = NULL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2734 if (find_last_paren(l, '(', ')'))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2735 trypos = find_match_paren(
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2736 curbuf->b_ind_maxparen);
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 && find_last_paren(l, '{', '}'))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2739 trypos = find_start_brace();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2740
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2741 if (trypos != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2742 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2743 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
2744 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2745 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2746 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2747 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2748
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2749 // 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
2750 // like in
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2751 // int a,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2752 // b;
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2753 if (cont_amount > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2754 amount = cont_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2755 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2756 amount += ind_continuation;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2757 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2758 else if (lookfor == LOOKFOR_UNTERM)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2759 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2760 if (cont_amount > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2761 amount = cont_amount;
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 amount += ind_continuation;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2764 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2765 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2766 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2767 if (lookfor != LOOKFOR_TERM
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2768 && lookfor != LOOKFOR_CPP_BASECLASS
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2769 && lookfor != LOOKFOR_COMMA)
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 = scope_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2772 if (theline[0] == '{')
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 amount += curbuf->b_ind_open_extra;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2775 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
2776 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2777 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2778
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2779 if (lookfor_cpp_namespace)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2780 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2781 // 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
2782 // back.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2783 if (curwin->w_cursor.lnum == ourscope)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2784 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2785
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2786 if (curwin->w_cursor.lnum == 0
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2787 || curwin->w_cursor.lnum
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2788 < ourscope - FIND_NAMESPACE_LIM)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2789 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2790
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2791 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2792
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2793 // 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
2794 // to the start of it.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2795 trypos = ind_find_start_CORS(NULL);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2796 if (trypos != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2797 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2798 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
2799 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2800 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2801 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2802
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2803 // 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
2804 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
2805 &amount))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2806 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2807
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2808 // 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
2809 if (cin_is_cpp_namespace(l))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2810 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2811 amount += curbuf->b_ind_cpp_namespace
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2812 - added_to_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2813 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2814 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2815 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
2816 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2817 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
2818 - added_to_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2819 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2820 }
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 if (cin_nocode(l))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2823 continue;
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 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2826 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2827 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2828
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2829 // 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
2830 // of it. XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2831 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
2832 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2833 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
2834 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2835 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2836 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2837
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2838 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2839
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2840 // 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
2841 // 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
2842 iscase = cin_iscase(l, FALSE);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2843 if (iscase || cin_isscopedecl(l))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2844 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2845 // 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
2846 // declaration/initialization any longer
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2847 if (lookfor == LOOKFOR_CPP_BASECLASS)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2848 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2849
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2850 // 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
2851 // labels.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2852 if (whilelevel > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2853 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2854
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2855 // case xx:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2856 // 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
2857 //-> here;
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2858 if (lookfor == LOOKFOR_UNTERM
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2859 || lookfor == LOOKFOR_ENUM_OR_INIT)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2860 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2861 if (cont_amount > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2862 amount = cont_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2863 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2864 amount += ind_continuation;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2865 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2866 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2867
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2868 // 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
2869 // x = 333;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2870 // case yy:
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2871 if ( (iscase && lookfor == LOOKFOR_CASE)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2872 || (iscase && lookfor_break)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2873 || (!iscase && lookfor == LOOKFOR_SCOPEDECL))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2874 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2875 // 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
2876 // switch() XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2877 if ((trypos = find_start_brace()) == NULL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2878 || trypos->lnum == ourscope)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2879 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2880 amount = get_indent(); // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2881 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2882 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2883 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2884 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2885
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2886 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
2887
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2888 // 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
2889 // y = y + 1;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2890 // -> s = 99;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2891 //
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2892 // case xx:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2893 // 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
2894 // y = y + 1;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2895 // -> s = 99;
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2896 if (lookfor == LOOKFOR_TERM)
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 (n)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2899 amount = n;
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 if (!lookfor_break)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2902 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2903 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2904
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2905 // 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
2906 // -> y = y + 1;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2907 //
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2908 // 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
2909 // -> y = y + 1;
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2910 if (n)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2911 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2912 amount = n;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2913 l = after_label(ml_get_curline());
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2914 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
2915 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2916 if (theline[0] == '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2917 amount += curbuf->b_ind_open_extra;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2918 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2919 amount += curbuf->b_ind_level
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2920 + curbuf->b_ind_no_brace;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2921 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2922 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2923 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2924
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2925 // 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
2926 // 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
2927 // switch label.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2928 // 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
2929 // case xx:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2930 // -> y = 1;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2931 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
2932 ? curbuf->b_ind_case_code
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2933 : curbuf->b_ind_scopedecl_code);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2934 lookfor = curbuf->b_ind_case_break
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2935 ? LOOKFOR_NOBREAK : LOOKFOR_ANY;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2936 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2937 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2938
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2939 // 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
2940 // ignore other lines, skip {}-blocks.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2941 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
2942 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2943 if (find_last_paren(l, '{', '}')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2944 && (trypos = find_start_brace()) != NULL)
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 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
2947 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2948 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2949 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2950 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2951
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2952 // 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
2953 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
2954 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2955 l = after_label(ml_get_curline());
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2956 if (l == NULL || cin_nocode(l))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2957 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2958 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2959
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2960 // 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
2961 // 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
2962 // (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
2963 // unlocked it)
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2964 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2965 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
2966 || cin_nocode(l))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2967 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2968
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2969 // 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
2970 // constructor initialization? XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2971 n = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2972 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
2973 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2974 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
2975 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2976 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2977 if (n)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2978 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2979 if (lookfor == LOOKFOR_UNTERM)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2980 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2981 if (cont_amount > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2982 amount = cont_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2983 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2984 amount += ind_continuation;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2985 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2986 else if (theline[0] == '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2987 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2988 // 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
2989 lookfor = LOOKFOR_UNTERM;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2990 ind_continuation = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2991 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2992 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2993 else
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
2994 // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2995 amount = get_baseclass_amount(
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2996 cache_cpp_baseclass.lpos.col);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2997 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2998 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2999 else if (lookfor == LOOKFOR_CPP_BASECLASS)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3000 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3001 // 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
3002 // 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
3003 if (cin_isterminated(l, TRUE, FALSE))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3004 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3005 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3006 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3007 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3008
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3009 // 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
3010 // 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
3011 // 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
3012 // 123,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3013 // sizeof
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3014 // here
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3015 // 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
3016 // 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
3017 // (indented).
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3018 terminated = cin_isterminated(l, FALSE, TRUE);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3019
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3020 if (js_cur_has_key)
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 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
3023 if (curbuf->b_ind_js && terminated == ',')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3024 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3025 // 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
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 // key: something
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3028 // or:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3029 // 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
3030 // something,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3031 // key: something
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3032 lookfor = LOOKFOR_JS_KEY;
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 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3035 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
3036 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3037 amount = get_indent();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3038 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3039 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3040 if (lookfor == LOOKFOR_COMMA)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3041 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3042 if (tryposBrace != NULL && tryposBrace->lnum
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3043 >= curwin->w_cursor.lnum)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3044 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3045 if (terminated == ',')
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3046 // 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
3047 // (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
3048 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3049 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3050 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3051 amount = get_indent();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3052 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
3053 // 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
3054 // 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
3055 // line ending in a comma.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3056 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3057 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3058 }
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 (terminated == 0 || (lookfor != LOOKFOR_UNTERM
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3061 && terminated == ','))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3062 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3063 if (lookfor != LOOKFOR_ENUM_OR_INIT &&
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3064 (*skipwhite(l) == '[' || l[STRLEN(l) - 1] == '['))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3065 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
3066 // 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
3067 // 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
3068 // 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
3069 // if ( foo &&
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3070 // bar )
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3071
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3072 // 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
3073 // 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
3074 // 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
3075 (void)find_last_paren(l, '(', ')');
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3076 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
3077 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
3078 || (trypos->lnum == tryposBrace->lnum
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3079 && trypos->col < tryposBrace->col)))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3080 trypos = NULL;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3081
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3082 // 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
3083 // braces.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3084 if (trypos == NULL && terminated == ','
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3085 && find_last_paren(l, '{', '}'))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3086 trypos = find_start_brace();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3087
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3088 if (trypos != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3089 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3090 // 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
3091 // handled above.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3092 // 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
3093 // asdf)
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3094 curwin->w_cursor = *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3095 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3096 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
3097 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3098 ++curwin->w_cursor.lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3099 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3100 continue;
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 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3103
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3104 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3105 * 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
3106 * indent from
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3107 * char *usethis = "bla\
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3108 * bla",
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3109 * here;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3110 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3111 if (terminated == ',')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3112 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3113 while (curwin->w_cursor.lnum > 1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3114 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3115 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
3116 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
3117 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3118 --curwin->w_cursor.lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3119 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3120 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3121 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3122
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3123 // 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
3124 // ignoring any jump label. XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3125 if (curbuf->b_ind_js)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3126 cur_amount = get_indent();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3127 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3128 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
3129 // 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
3130 // 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
3131 // while (not)
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3132 // -> {
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3133 // }
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3134 if (terminated != ',' && lookfor != LOOKFOR_TERM
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3135 && theline[0] == '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3136 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3137 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
3138 // 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
3139 // 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
3140 // 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
3141 // { 1, 2 },
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3142 // -> { 3, 4 }
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3143 if (*skipwhite(l) != '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3144 amount += curbuf->b_ind_open_extra;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3145
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3146 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
3147 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3148 // 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
3149 // class declaration or initialization
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3150 lookfor = LOOKFOR_CPP_BASECLASS;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3151 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3152 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3153 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3154 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3155
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3156 // 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
3157 // Also allow " } else".
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3158 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
3159 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3160 // 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
3161 // 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
3162 // if (cond)
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3163 // 100 +
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3164 // -> here;
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3165 if (lookfor == LOOKFOR_UNTERM
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3166 || lookfor == LOOKFOR_ENUM_OR_INIT)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3167 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3168 if (cont_amount > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3169 amount = cont_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3170 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3171 amount += ind_continuation;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3172 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3173 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3174
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3175 // 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
3176 // are finished.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3177 // while (not)
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3178 // -> here;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3179 // 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
3180 // 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
3181 // yyy;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3182 // if (stat)
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3183 // while (not)
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3184 // xxx;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3185 // -> here;
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3186 amount = cur_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3187 if (theline[0] == '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3188 amount += curbuf->b_ind_open_extra;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3189 if (lookfor != LOOKFOR_TERM)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3190 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3191 amount += curbuf->b_ind_level
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3192 + curbuf->b_ind_no_brace;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3193 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3194 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3195
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3196 // 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
3197 // 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
3198 // do
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3199 // x = 1;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3200 // -> here
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3201 l = skipwhite(ml_get_curline());
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3202 if (cin_isdo(l))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3203 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3204 if (whilelevel == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3205 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3206 --whilelevel;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3207 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3208
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3209 // 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
3210 // 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
3211 // 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
3212 // 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
3213 if (cin_iselse(l) && whilelevel == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3214 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3215 // 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
3216 // 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
3217 // not the one from "if () {".
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3218 if (*l == '}')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3219 curwin->w_cursor.col =
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3220 (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
3221
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3222 if ((trypos = find_start_brace()) == NULL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3223 || find_match(LOOKFOR_IF, trypos->lnum)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3224 == FAIL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3225 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3226 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3227 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3228
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3229 // 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
3230 // "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
3231 // 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
3232 // the line before this one.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3233 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3234 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3235 // 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
3236 // the last one.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3237 // c = 99 +
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3238 // 100 +
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3239 // -> here;
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3240 if (lookfor == LOOKFOR_UNTERM)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3241 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3242 // 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
3243 if (terminated == ',')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3244 amount += ind_continuation;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3245 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3246 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3247
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3248 if (lookfor == LOOKFOR_ENUM_OR_INIT)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3249 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3250 // 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
3251 // 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
3252 // 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
3253 // 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
3254 // enumerations/initializations.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3255 if (terminated == ',')
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 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
3258 break;
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 lookfor = LOOKFOR_CPP_BASECLASS;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3261 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3262 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3263
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3264 // 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
3265 // reduce indent.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3266 if (amount > cur_amount)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3267 amount = cur_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3268 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3269 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3270 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3271 // 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
3272 // 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
3273 // 100 +
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3274 // -> here;
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3275 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3276 amount = cur_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3277
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3278 n = (int)STRLEN(l);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3279 if (terminated == ',' && (*skipwhite(l) == ']'
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3280 || (n >=2 && l[n - 2] == ']')))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3281 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3282
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3283 // 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
3284 // 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
3285 // struct xxx =
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3286 // {
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3287 // sizeof a,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3288 // 124 };
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3289 // 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
3290 // 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
3291 // yet.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3292 if (lookfor == LOOKFOR_INITIAL && terminated == ',')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3293 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3294 if (curbuf->b_ind_js)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3295 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3296 // 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
3297 // 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
3298 // (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
3299 // some = [
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3300 // 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
3301 // 2,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3302 // some = [
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3303 // 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
3304 // 4 *
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3305 // 5,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3306 // 6,
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3307 if (cin_iscomment(skipwhite(l)))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3308 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3309 lookfor = LOOKFOR_COMMA;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3310 trypos = find_match_char('[',
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3311 curbuf->b_ind_maxparen);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3312 if (trypos != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3313 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3314 if (trypos->lnum
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3315 == curwin->w_cursor.lnum - 1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3316 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3317 // 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
3318 // [], line up with it.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3319 break;
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 ourscope = trypos->lnum;
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 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3324 else
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 lookfor = LOOKFOR_ENUM_OR_INIT;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3327 cont_amount = cin_first_id_amount();
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 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3330 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3331 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3332 if (lookfor == LOOKFOR_INITIAL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3333 && *l != NUL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3334 && 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
3335 // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3336 cont_amount = cin_get_equal_amount(
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3337 curwin->w_cursor.lnum);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3338 if (lookfor != LOOKFOR_TERM
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3339 && lookfor != LOOKFOR_JS_KEY
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3340 && lookfor != LOOKFOR_COMMA
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3341 && 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
3342 lookfor = LOOKFOR_UNTERM;
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 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3345 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3346 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3347
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3348 // 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
3349 // 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
3350 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
3351 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3352 // 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
3353 // 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
3354 // while (cond);
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3355 // 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
3356 // -> here;
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3357 if (lookfor == LOOKFOR_UNTERM
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3358 || lookfor == LOOKFOR_ENUM_OR_INIT)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3359 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3360 if (cont_amount > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3361 amount = cont_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3362 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3363 amount += ind_continuation;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3364 break;
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
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3367 if (whilelevel == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3368 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3369 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
3370 amount = get_indent(); // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3371 if (theline[0] == '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3372 amount += curbuf->b_ind_open_extra;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3373 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3374 ++whilelevel;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3375 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3376
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3377 // 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
3378 // 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
3379 // 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
3380 // 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
3381 // 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
3382 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3383 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3384 // 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
3385 // 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
3386 if (lookfor == LOOKFOR_NOBREAK
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3387 && cin_isbreak(skipwhite(ml_get_curline())))
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 lookfor = LOOKFOR_ANY;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3390 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3391 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3392
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3393 // Handle "do {" line.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3394 if (whilelevel > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3395 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3396 l = cin_skipcomment(ml_get_curline());
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3397 if (cin_isdo(l))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3398 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3399 amount = get_indent(); // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3400 --whilelevel;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3401 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3402 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3403 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3404
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3405 // 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
3406 // 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
3407 // x = 1;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3408 // y = foo +
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3409 // -> here;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3410 // or
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3411 // int x = 1;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3412 // int foo,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3413 // -> here;
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3414 if (lookfor == LOOKFOR_UNTERM
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3415 || lookfor == LOOKFOR_ENUM_OR_INIT)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3416 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3417 if (cont_amount > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3418 amount = cont_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3419 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3420 amount += ind_continuation;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3421 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3422 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3423
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3424 // 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
3425 // 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
3426 // 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
3427 // 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
3428 // while (asdf) ->here;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3429 // here;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3430 // ->foo;
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3431 if (lookfor == LOOKFOR_TERM)
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 if (!lookfor_break && whilelevel == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3434 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3435 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3436
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3437 // 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
3438 // 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
3439 // a terminated line.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3440 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3441 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3442 // 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
3443 // 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
3444 // 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
3445 // func(asdr,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3446 // asdfasdf);
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3447 // here;
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3448 term_again:
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3449 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3450 if (find_last_paren(l, '(', ')')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3451 && (trypos = find_match_paren(
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3452 curbuf->b_ind_maxparen)) != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3453 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3454 // 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
3455 // handled above.
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3456 // 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
3457 // asdf)
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3458 curwin->w_cursor = *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3459 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3460 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
3461 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3462 ++curwin->w_cursor.lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3463 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3464 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3465 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3466 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3467
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3468 // 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
3469 // 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
3470 // 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
3471 // stat;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3472 // }
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3473 // case 2:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3474 // stat;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3475 // }
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3476 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
3477 && cin_iscase(l, FALSE));
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3478
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3479 // 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
3480 // ignoring any jump label.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3481 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
3482
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3483 if (theline[0] == '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3484 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
3485 // 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
3486 l = skipwhite(l);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3487 if (*l == '{')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3488 amount -= curbuf->b_ind_open_extra;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3489 lookfor = iscase ? LOOKFOR_ANY : LOOKFOR_TERM;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3490
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3491 // 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
3492 // the matching "if":
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3493 // else 3;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3494 // indent this;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3495 // 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
3496 // 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
3497 if (lookfor == LOOKFOR_TERM
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3498 && *l != '}'
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3499 && cin_iselse(l)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3500 && whilelevel == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3501 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3502 if ((trypos = find_start_brace()) == NULL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3503 || find_match(LOOKFOR_IF, trypos->lnum)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3504 == FAIL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3505 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3506 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3507 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3508
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3509 // 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
3510 // that block.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3511 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
3512 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
3513 && (trypos = find_start_brace()) != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3514 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3515 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
3516 // 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
3517 // but skip block for "} else {"
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3518 l = cin_skipcomment(ml_get_curline());
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3519 if (*l == '}' || !cin_iselse(l))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3520 goto term_again;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3521 ++curwin->w_cursor.lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3522 curwin->w_cursor.col = 0;
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 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3527 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3528 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3529
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3530 // 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
3531 if (cin_iscomment(theline))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3532 amount += curbuf->b_ind_comment;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3533
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3534 // 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
3535 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
3536 amount -= curbuf->b_ind_jump_label;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3537
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3538 goto theend;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3539 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3540
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3541 // 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
3542 //
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3543 // 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
3544 // 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
3545 // 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
3546 // 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
3547 //
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3548 // 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
3549 // 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
3550 // of a function
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3551
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3552 if (theline[0] == '{')
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 amount = curbuf->b_ind_first_open;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3555 goto theend;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3556 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3557
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3558 // 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
3559 // 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
3560 // 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
3561 // 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
3562 // 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
3563 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
3564 && !cin_nocode(theline)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3565 && vim_strchr(theline, '{') == NULL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3566 && vim_strchr(theline, '}') == NULL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3567 && !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
3568 && !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
3569 && 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
3570 cur_curpos.lnum + 1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3571 && !cin_isterminated(theline, FALSE, TRUE))
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 amount = curbuf->b_ind_func_type;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3574 goto theend;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3575 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3576
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3577 // 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
3578 amount = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3579 curwin->w_cursor = cur_curpos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3580 while (curwin->w_cursor.lnum > 1)
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 curwin->w_cursor.lnum--;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3583 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3584
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3585 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3586
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3587 // 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
3588 // of it. XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3589 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
3590 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3591 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
3592 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3593 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3594 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3595
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3596 // 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
3597 // constructor initialization? XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3598 n = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3599 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
3600 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3601 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
3602 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3603 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3604 if (n)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3605 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3606 // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3607 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
3608 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3609 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3610
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3611 // 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
3612 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
3613 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3614
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3615 if (cin_nocode(l))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3616 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3617
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3618 // 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
3619 // indentation:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3620 // int foo,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3621 // bar;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3622 // 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
3623 // enum foobar
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3624 // {
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3625 // ...
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3626 // } foo,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3627 // bar;
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3628 n = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3629 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
3630 || (*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
3631 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3632 // 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
3633 if (find_last_paren(l, '(', ')')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3634 && (trypos = find_match_paren(
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3635 curbuf->b_ind_maxparen)) != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3636 curwin->w_cursor = *trypos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3637
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3638 /*
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3639 * 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
3640 * 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
3641 * char *foo = "bla\
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3642 * bla",
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3643 * here;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3644 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3645 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
3646 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3647 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
3648 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
3649 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3650 --curwin->w_cursor.lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3651 curwin->w_cursor.col = 0;
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
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3654 amount = get_indent(); // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3655
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3656 if (amount == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3657 amount = cin_first_id_amount();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3658 if (amount == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3659 amount = ind_continuation;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3660 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3661 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3662
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3663 // 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
3664 // 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
3665 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
3666 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3667 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3668
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3669 // 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
3670 // 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
3671 if (*skipwhite(l) == '}')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3672 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3673
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3674 // (matching {)
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3675 // 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
3676 // 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
3677 // 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
3678 // / * x * / "b};ar" }; / * foobar * /
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3679 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
3680 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3681
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3682 // 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
3683 // array constant:
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3684 // something = [
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3685 // 234, <- extra indent
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3686 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
3687 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3688 amount = get_indent() + ind_continuation;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3689 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3690 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3691
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3692 // 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
3693 // 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
3694 // indent then.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3695 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
3696 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3697 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
3698
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3699 while (curwin->w_cursor.lnum > 1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3700 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3701 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
3702 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
3703 &look, &curwin->w_cursor.lnum, &amount)))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3704 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3705 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3706 if (curwin->w_cursor.lnum > 0
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3707 && 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
3708 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3709
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3710 curwin->w_cursor = curpos_save;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3711 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3712
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3713 // 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
3714 // 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
3715 // parameters.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3716 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
3717 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3718 amount = curbuf->b_ind_param;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3719 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3720 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3721
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3722 // 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
3723 // 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
3724 // int foo,
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3725 // bar;
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3726 // indent_to_0 here;
15699
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 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3729 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
3730 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
3731 || (*l != NUL && l[STRLEN(l) - 1] == '\\'))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3732 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3733 l = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3734 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3735
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3736 // 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
3737 // 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
3738 //
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3739 // 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
3740 // 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
3741 find_last_paren(l, '(', ')');
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3742
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3743 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
3744 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
3745 amount = get_indent(); // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3746 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3747 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3748
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3749 // 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
3750 if (cin_iscomment(theline))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3751 amount += curbuf->b_ind_comment;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3752
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3753 /*
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3754 * 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
3755 * "asdfasdf\
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3756 * here";
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3757 * char *foo = "asdf\
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3758 * here";
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3759 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3760 if (cur_curpos.lnum > 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 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
3763 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
3764 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3765 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
3766 if (cur_amount > 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3767 amount = cur_amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3768 else if (cur_amount == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3769 amount += ind_continuation;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3770 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3771 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3772
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3773 theend:
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3774 if (amount < 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3775 amount = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3776
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3777 laterend:
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3778 // 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
3779 curwin->w_cursor = cur_curpos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3780
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3781 vim_free(linecopy);
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 return amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3784 }
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 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3787 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
3788 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3789 char_u *look;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3790 pos_T *theirscope;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3791 char_u *mightbeif;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3792 int elselevel;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3793 int whilelevel;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3794
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3795 if (lookfor == LOOKFOR_IF)
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 elselevel = 1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3798 whilelevel = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3799 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3800 else
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 elselevel = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3803 whilelevel = 1;
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
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3806 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3807
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3808 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
3809 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3810 curwin->w_cursor.lnum--;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3811 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3812
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3813 look = cin_skipcomment(ml_get_curline());
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3814 if (cin_iselse(look)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3815 || 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
3816 || cin_isdo(look) // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3817 || 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
3818 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3819 // 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
3820 // 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
3821 theirscope = find_start_brace(); // XXX
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3822 if (theirscope == NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3823 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3824
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3825 // 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
3826 // 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
3827 // out of luck too.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3828 if (theirscope->lnum < ourscope)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3829 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3830
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3831 // 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
3832 // 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
3833 // different scope...
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3834 if (theirscope->lnum > ourscope)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3835 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3836
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3837 // 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
3838 // 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
3839 // increment elselevel
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3840 look = cin_skipcomment(ml_get_curline());
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3841 if (cin_iselse(look))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3842 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3843 mightbeif = cin_skipcomment(look + 4);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3844 if (!cin_isif(mightbeif))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3845 ++elselevel;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3846 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3847 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3848
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3849 // 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
3850 // 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
3851 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
3852 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3853 ++whilelevel;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3854 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3855 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3856
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3857 // 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
3858 look = cin_skipcomment(ml_get_curline());
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3859 if (cin_isif(look))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3860 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3861 elselevel--;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3862 // 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
3863 // get in the way.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3864 if (elselevel == 0 && lookfor == LOOKFOR_IF)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3865 whilelevel = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3866 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3867
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3868 // 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
3869 if (cin_isdo(look))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3870 whilelevel--;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3871
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3872 // 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
3873 // 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
3874 // 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
3875 if (elselevel <= 0 && whilelevel <= 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3876 return OK;
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 return FAIL;
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
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3882 # if defined(FEAT_EVAL) || defined(PROTO)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3883 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3884 * Get indent level from 'indentexpr'.
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
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3887 get_expr_indent(void)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3888 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3889 int indent = -1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3890 char_u *inde_copy;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3891 pos_T save_pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3892 colnr_T save_curswant;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3893 int save_set_curswant;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3894 int save_State;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3895 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
3896 OPT_LOCAL);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3897
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3898 // 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
3899 // via :normal commands
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3900 save_pos = curwin->w_cursor;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3901 save_curswant = curwin->w_curswant;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3902 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
3903 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
3904 if (use_sandbox)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3905 ++sandbox;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3906 ++textlock;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3907
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3908 // 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
3909 // evaluating it.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3910 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
3911 if (inde_copy != NULL)
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 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
3914 vim_free(inde_copy);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3915 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3916
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3917 if (use_sandbox)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3918 --sandbox;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3919 --textlock;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3920
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3921 // 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
3922 // 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
3923 // command.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3924 save_State = State;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3925 State = INSERT;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3926 curwin->w_cursor = save_pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3927 curwin->w_curswant = save_curswant;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3928 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
3929 check_cursor();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3930 State = save_State;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3931
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3932 // 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
3933 if (indent < 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3934 indent = get_indent();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3935
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3936 return indent;
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 # endif
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3939
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3940 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3941 * 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
3942 * 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
3943 * 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
3944 * 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
3945 *
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3946 * "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
3947 * KEY_OPEN_FORW
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3948 * KEY_OPEN_BACK
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3949 * KEY_COMPLETE just finished completion.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3950 *
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3951 * 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
3952 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3953 int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3954 in_cinkeys(
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3955 int keytyped,
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3956 int when,
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3957 int line_is_empty)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3958 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3959 char_u *look;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3960 int try_match;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3961 int try_match_word;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3962 char_u *p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3963 char_u *line;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3964 int icase;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3965 int i;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3966
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3967 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
3968 // 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
3969 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3970
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3971 #ifdef FEAT_EVAL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3972 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
3973 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
3974 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3975 #endif
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3976 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
3977 while (*look)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3978 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3979 // 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
3980 // '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
3981 switch (when)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3982 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3983 case '*': try_match = (*look == '*'); break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3984 case '!': try_match = (*look == '!'); break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3985 default: try_match = (*look != '*'); break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3986 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3987 if (*look == '*' || *look == '!')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3988 ++look;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3989
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
3990 // 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
3991 // 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
3992 if (*look == '0')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3993 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3994 try_match_word = try_match;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3995 if (!line_is_empty)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3996 try_match = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3997 ++look;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3998 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3999 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4000 try_match_word = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4001
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4002 // 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
4003 if (*look == '^'
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4004 #ifdef EBCDIC
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4005 && (Ctrl_chr(look[1]) != 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4006 #else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4007 && look[1] >= '?' && look[1] <= '_'
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4008 #endif
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4009 )
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4010 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4011 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
4012 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4013 look += 2;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4014 }
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4015 // '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
4016 // '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
4017 else if (*look == 'o')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4018 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4019 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
4020 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4021 ++look;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4022 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4023 else if (*look == 'O')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4024 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4025 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
4026 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4027 ++look;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4028 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4029
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4030 // '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
4031 // cursor.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4032 else if (*look == 'e')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4033 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4034 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
4035 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4036 p = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4037 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
4038 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
4039 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4040 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4041 ++look;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4042 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4043
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4044 // ':' 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
4045 // 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
4046 // class::method for C++).
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4047 else if (*look == ':')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4048 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4049 if (try_match && keytyped == ':')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4050 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4051 p = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4052 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
4053 return TRUE;
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4054 // 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
4055 p = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4056 if (curwin->w_cursor.col > 2
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 && p[curwin->w_cursor.col - 2] == ':')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4059 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4060 p[curwin->w_cursor.col - 1] = ' ';
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4061 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
4062 || cin_islabel());
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4063 p = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4064 p[curwin->w_cursor.col - 1] = ':';
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4065 if (i)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4066 return TRUE;
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 ++look;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4070 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4071
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4072
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4073 // 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
4074 else if (*look == '<')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4075 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4076 if (try_match)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4077 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4078 // 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
4079 // <:> 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
4080 // >, *, : 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
4081 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
4082 && keytyped == 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 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
4086 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4087 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4088 while (*look && *look != '>')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4089 look++;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4090 while (*look == '>')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4091 look++;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4092 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4093
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4094 // Is it a word: "=word"?
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4095 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
4096 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4097 ++look;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4098 if (*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 icase = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4101 ++look;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4102 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4103 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4104 icase = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4105 p = vim_strchr(look, ',');
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4106 if (p == NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4107 p = look + STRLEN(look);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4108 if ((try_match || try_match_word)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4109 && 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
4110 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4111 int match = FALSE;
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 if (keytyped == KEY_COMPLETE)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4114 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4115 char_u *s;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4116
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4117 // 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
4118 // 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
4119 line = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4120 if (has_mbyte)
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 char_u *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 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
4125 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4126 n = mb_prevptr(line, s);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4127 if (!vim_iswordp(n))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4128 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4129 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4130 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4131 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4132 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
4133 if (!vim_iswordc(s[-1]))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4134 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4135 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
4136 && (icase
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4137 ? MB_STRNICMP(s, look, p - look)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4138 : STRNCMP(s, look, p - look)) == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4139 match = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4140 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4141 else
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4142 // TODO: multi-byte
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4143 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
4144 && 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
4145 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4146 line = ml_get_cursor();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4147 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
4148 || !vim_iswordc(line[-(p - look) - 1]))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4149 && (icase
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4150 ? 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
4151 : 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
4152 == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4153 match = TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4154 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4155 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
4156 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4157 // "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
4158 // word.
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4159 if (getwhitecols_curline() !=
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4160 (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
4161 match = FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4162 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4163 if (match)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4164 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4165 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4166 look = p;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4167 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4168
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4169 // 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
4170 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4171 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4172 if (try_match && *look == keytyped)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4173 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4174 if (*look != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4175 ++look;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4176 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4177
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4178 // Skip over ", ".
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4179 look = skip_to_option_part(look);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4180 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4181 return FALSE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4182 }
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4183 #endif // FEAT_CINDENT
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4184
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4185 #if defined(FEAT_LISP) || defined(PROTO)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4186
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4187 static int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4188 lisp_match(char_u *p)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4189 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4190 char_u buf[LSIZE];
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4191 int len;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4192 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
4193
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4194 while (*word != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4195 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4196 (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
4197 len = (int)STRLEN(buf);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4198 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
4199 return TRUE;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4200 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4201 return FALSE;
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 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4205 * 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
4206 * 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
4207 * 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
4208 * 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
4209 *
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4210 * TODO:
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4211 * 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
4212 * 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
4213 * - 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
4214 * - 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
4215 * - 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
4216 * 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
4217 * Update from Sergey Khorev:
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4218 * 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
4219 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4220 int
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4221 get_lisp_indent(void)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4222 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4223 pos_T *pos, realpos, paren;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4224 int amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4225 char_u *that;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4226 colnr_T col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4227 colnr_T firsttry;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4228 int parencount, quotecount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4229 int vi_lisp;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4230
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4231 // 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
4232 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
4233
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4234 realpos = curwin->w_cursor;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4235 curwin->w_cursor.col = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4236
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4237 if ((pos = findmatch(NULL, '(')) == NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4238 pos = findmatch(NULL, '[');
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4239 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4240 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4241 paren = *pos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4242 pos = findmatch(NULL, '[');
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4243 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
4244 pos = &paren;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4245 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4246 if (pos != NULL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4247 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4248 // 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
4249 // 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
4250 amount = -1;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4251 parencount = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4252
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4253 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
4254 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4255 if (linewhite(curwin->w_cursor.lnum))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4256 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4257 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
4258 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4259 if (*that == ';')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4260 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4261 while (*(that + 1) != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4262 ++that;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4263 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4264 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4265 if (*that == '\\')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4266 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4267 if (*(that + 1) != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4268 ++that;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4269 continue;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4270 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4271 if (*that == '"' && *(that + 1) != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4272 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4273 while (*++that && *that != '"')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4274 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4275 // 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
4276 if (*that == '\\')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4277 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4278 if (*++that == NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4279 break;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4280 if (that[1] == NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4281 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4282 ++that;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4283 break;
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 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4288 if (*that == '(' || *that == '[')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4289 ++parencount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4290 else if (*that == ')' || *that == ']')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4291 --parencount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4292 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4293 if (parencount == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4294 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4295 amount = get_indent();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4296 break;
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
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4300 if (amount == -1)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4301 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4302 curwin->w_cursor.lnum = pos->lnum;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4303 curwin->w_cursor.col = pos->col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4304 col = pos->col;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4305
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4306 that = ml_get_curline();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4307
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4308 if (vi_lisp && get_indent() == 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4309 amount = 2;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4310 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4311 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4312 char_u *line = that;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4313
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4314 amount = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4315 while (*that && col)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4316 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4317 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
4318 col--;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4319 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4320
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4321 // 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
4322 // 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
4323 //
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4324 // (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
4325 // (...)) of (...))
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4326
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4327 if (!vi_lisp && (*that == '(' || *that == '[')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4328 && lisp_match(that + 1))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4329 amount += 2;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4330 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4331 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4332 that++;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4333 amount++;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4334 firsttry = amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4335
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4336 while (VIM_ISWHITE(*that))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4337 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4338 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
4339 ++that;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4340 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4341
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4342 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
4343 {
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4344 // 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
4345 // 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
4346 if (!vi_lisp && *that != '(' && *that != '[')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4347 firsttry++;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4348
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4349 parencount = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4350 quotecount = 0;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4351
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4352 if (vi_lisp
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 != '#'
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4356 && (*that < '0' || *that > '9')))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4357 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4358 while (*that
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4359 && (!VIM_ISWHITE(*that)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4360 || quotecount
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4361 || parencount)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4362 && (!((*that == '(' || *that == '[')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4363 && !quotecount
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4364 && !parencount
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4365 && vi_lisp)))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4366 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4367 if (*that == '"')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4368 quotecount = !quotecount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4369 if ((*that == '(' || *that == '[')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4370 && !quotecount)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4371 ++parencount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4372 if ((*that == ')' || *that == ']')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4373 && !quotecount)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4374 --parencount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4375 if (*that == '\\' && *(that+1) != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4376 amount += lbr_chartabsize_adv(
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4377 line, &that, (colnr_T)amount);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4378 amount += lbr_chartabsize_adv(
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4379 line, &that, (colnr_T)amount);
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 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4382 while (VIM_ISWHITE(*that))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4383 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4384 amount += lbr_chartabsize(
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4385 line, that, (colnr_T)amount);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4386 that++;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4387 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4388 if (!*that || *that == ';')
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4389 amount = firsttry;
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 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4395 else
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4396 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
4397
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4398 curwin->w_cursor = realpos;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4399
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4400 return amount;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4401 }
15733
d2f0154a44f5 patch 8.1.0874: using old style comments in new file
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
4402 #endif // FEAT_LISP
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4403
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4404 #if defined(FEAT_CINDENT) || defined(PROTO)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4405 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4406 * 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
4407 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4408 void
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4409 do_c_expr_indent(void)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4410 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4411 # ifdef FEAT_EVAL
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4412 if (*curbuf->b_p_inde != NUL)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4413 fixthisline(get_expr_indent);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4414 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4415 # endif
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4416 fixthisline(get_c_indent);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4417 }
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4418 #endif
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4419
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4420 #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
4421 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4422 * 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
4423 * 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
4424 * 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
4425 * "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
4426 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4427
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4428 void
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4429 fixthisline(int (*get_the_indent)(void))
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4430 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4431 int amount = get_the_indent();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4432
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4433 if (amount >= 0)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4434 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4435 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
4436 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
4437 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
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
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4441 void
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4442 fix_indent(void)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4443 {
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4444 if (p_paste)
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4445 return;
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4446 # ifdef FEAT_LISP
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4447 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
4448 fixthisline(get_lisp_indent);
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4449 # endif
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4450 # 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
4451 else
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4452 # endif
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4453 # ifdef FEAT_CINDENT
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4454 if (cindent_on())
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4455 do_c_expr_indent();
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4456 # endif
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
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4459 #endif