annotate src/cindent.c @ 32427:11bc7fa31c3b v9.0.1545

patch 9.0.1545: text not scrolled when cursor moved with "g0" and "h" Commit: https://github.com/vim/vim/commit/8667a5678f983ba899825b810ab849952d49bcb8 Author: Luuk van Baal <luukvbaal@gmail.com> Date: Fri May 12 15:47:25 2023 +0100 patch 9.0.1545: text not scrolled when cursor moved with "g0" and "h" Problem: Text not scrolled when cursor moved with "g0" and "h". Solution: Adjust w_skipcol when needed. (Luuk van Baal, closes https://github.com/vim/vim/issues/12387)
author Bram Moolenaar <Bram@vim.org>
date Fri, 12 May 2023 17:00:05 +0200
parents 2ed95122d59c
children 448aef880252
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * cindent.c: C indentation related functions
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 * Many of C-indenting functions originally come from Eric Fischer.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 * Below "XXX" means that this function may unlock the current line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 #include "vim.h"
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 // values for the "lookfor" state
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 #define LOOKFOR_INITIAL 0
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 #define LOOKFOR_IF 1
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 #define LOOKFOR_DO 2
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 #define LOOKFOR_CASE 3
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 #define LOOKFOR_ANY 4
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 #define LOOKFOR_TERM 5
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 #define LOOKFOR_UNTERM 6
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 #define LOOKFOR_SCOPEDECL 7
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 #define LOOKFOR_NOBREAK 8
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 #define LOOKFOR_CPP_BASECLASS 9
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 #define LOOKFOR_ENUM_OR_INIT 10
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 #define LOOKFOR_JS_KEY 11
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 #define LOOKFOR_COMMA 12
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 * Return TRUE if the string "line" starts with a word from 'cinwords'.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 cin_is_cinword(char_u *line)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 char_u *cinw;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 char_u *cinw_buf;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 int cinw_len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 int retval = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 int len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 cinw_len = (int)STRLEN(curbuf->b_p_cinw) + 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 cinw_buf = alloc(cinw_len);
31667
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
49 if (cinw_buf == NULL)
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
50 return FALSE;
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
51
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
52 line = skipwhite(line);
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
53 for (cinw = curbuf->b_p_cinw; *cinw; )
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 {
31667
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
55 len = copy_option_part(&cinw, cinw_buf, cinw_len, ",");
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
56 if (STRNCMP(line, cinw_buf, len) == 0
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
57 && (!vim_iswordc(line[len]) || !vim_iswordc(line[len - 1])))
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 {
31667
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
59 retval = TRUE;
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
60 break;
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 }
31667
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
63 vim_free(cinw_buf);
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 return retval;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 * Skip to the end of a "string" and a 'c' character.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 * If there is no string or character, return argument unmodified.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 static char_u *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 skip_string(char_u *p)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 int i;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 // We loop, because strings may be concatenated: "date""time".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 for ( ; ; ++p)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 if (p[0] == '\'') // 'c' or '\n' or '\000'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 {
25897
f2fb5d30cd16 patch 8.2.3482: reading beyond end of line ending in quote and backslash
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
81 if (p[1] == NUL) // ' at end of line
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 i = 2;
25897
f2fb5d30cd16 patch 8.2.3482: reading beyond end of line ending in quote and backslash
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
84 if (p[1] == '\\' && p[2] != NUL) // '\n' or '\000'
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 ++i;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 while (vim_isdigit(p[i - 1])) // '\000'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 ++i;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 }
28891
85c2bbee17d0 patch 8.2.4968: reading past end of the line when C-indenting
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
90 if (p[i - 1] != NUL && p[i] == '\'') // check for trailing '
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 p += i;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 else if (p[0] == '"') // start of string
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 for (++p; p[0]; ++p)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 if (p[0] == '\\' && p[1] != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 else if (p[0] == '"') // end of string
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 if (p[0] == '"')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 continue; // continue for another string
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 else if (p[0] == 'R' && p[1] == '"')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 // Raw string: R"[delim](...)[delim]"
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 char_u *delim = p + 2;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 char_u *paren = vim_strchr(delim, '(');
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 if (paren != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 size_t delim_len = paren - delim;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 for (p += 3; *p; ++p)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 if (p[0] == ')' && STRNCMP(p + 1, delim, delim_len) == 0
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 && p[delim_len + 1] == '"')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 p += delim_len + 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 if (p[0] == '"')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 continue; // continue for another string
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 break; // no string found
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 if (!*p)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 --p; // backup from NUL
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 return p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 /*
26819
0d798c7e1865 patch 8.2.3938: line comment start is also found in a string
Bram Moolenaar <Bram@vim.org>
parents: 26771
diff changeset
137 * Return TRUE if "line[col]" is inside a C string.
0d798c7e1865 patch 8.2.3938: line comment start is also found in a string
Bram Moolenaar <Bram@vim.org>
parents: 26771
diff changeset
138 */
0d798c7e1865 patch 8.2.3938: line comment start is also found in a string
Bram Moolenaar <Bram@vim.org>
parents: 26771
diff changeset
139 int
0d798c7e1865 patch 8.2.3938: line comment start is also found in a string
Bram Moolenaar <Bram@vim.org>
parents: 26771
diff changeset
140 is_pos_in_string(char_u *line, colnr_T col)
0d798c7e1865 patch 8.2.3938: line comment start is also found in a string
Bram Moolenaar <Bram@vim.org>
parents: 26771
diff changeset
141 {
0d798c7e1865 patch 8.2.3938: line comment start is also found in a string
Bram Moolenaar <Bram@vim.org>
parents: 26771
diff changeset
142 char_u *p;
0d798c7e1865 patch 8.2.3938: line comment start is also found in a string
Bram Moolenaar <Bram@vim.org>
parents: 26771
diff changeset
143
0d798c7e1865 patch 8.2.3938: line comment start is also found in a string
Bram Moolenaar <Bram@vim.org>
parents: 26771
diff changeset
144 for (p = line; *p && (colnr_T)(p - line) < col; ++p)
0d798c7e1865 patch 8.2.3938: line comment start is also found in a string
Bram Moolenaar <Bram@vim.org>
parents: 26771
diff changeset
145 p = skip_string(p);
0d798c7e1865 patch 8.2.3938: line comment start is also found in a string
Bram Moolenaar <Bram@vim.org>
parents: 26771
diff changeset
146 return !((colnr_T)(p - line) <= col);
0d798c7e1865 patch 8.2.3938: line comment start is also found in a string
Bram Moolenaar <Bram@vim.org>
parents: 26771
diff changeset
147 }
0d798c7e1865 patch 8.2.3938: line comment start is also found in a string
Bram Moolenaar <Bram@vim.org>
parents: 26771
diff changeset
148
0d798c7e1865 patch 8.2.3938: line comment start is also found in a string
Bram Moolenaar <Bram@vim.org>
parents: 26771
diff changeset
149 /*
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 * Find the start of a comment, not knowing if we are in a comment right now.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 * Search starts at w_cursor.lnum and goes backwards.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 * Return NULL when not inside a comment.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 static pos_T *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 ind_find_start_comment(void) // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 return find_start_comment(curbuf->b_ind_maxcomment);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 pos_T *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 find_start_comment(int ind_maxcomment) // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 pos_T *pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 int cur_maxcomment = ind_maxcomment;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 for (;;)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 pos = findmatchlimit(NULL, '*', FM_BACKWARD, cur_maxcomment);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 if (pos == NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 // Check if the comment start we found is inside a string.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 // If it is then restrict the search to below this line and try again.
26819
0d798c7e1865 patch 8.2.3938: line comment start is also found in a string
Bram Moolenaar <Bram@vim.org>
parents: 26771
diff changeset
174 if (!is_pos_in_string(ml_get(pos->lnum), pos->col))
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 cur_maxcomment = curwin->w_cursor.lnum - pos->lnum - 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 if (cur_maxcomment <= 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 pos = NULL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 return pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 * Find the start of a raw string, not knowing if we are in one right now.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 * Search starts at w_cursor.lnum and goes backwards.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 * Return NULL when not inside a raw string.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 static pos_T *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 find_start_rawstring(int ind_maxcomment) // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 pos_T *pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 int cur_maxcomment = ind_maxcomment;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 for (;;)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 pos = findmatchlimit(NULL, 'R', FM_BACKWARD, cur_maxcomment);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 if (pos == NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 // Check if the raw string start we found is inside a string.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 // If it is then restrict the search to below this line and try again.
26819
0d798c7e1865 patch 8.2.3938: line comment start is also found in a string
Bram Moolenaar <Bram@vim.org>
parents: 26771
diff changeset
205 if (!is_pos_in_string(ml_get(pos->lnum), pos->col))
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 cur_maxcomment = curwin->w_cursor.lnum - pos->lnum - 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 if (cur_maxcomment <= 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 pos = NULL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 return pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 * Find the start of a comment or raw string, not knowing if we are in a
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 * comment or raw string right now.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 * Search starts at w_cursor.lnum and goes backwards.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 * If is_raw is given and returns start of raw_string, sets it to true.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 * Return NULL when not inside a comment or raw string.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 * "CORS" -> Comment Or Raw String
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 static pos_T *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 ind_find_start_CORS(linenr_T *is_raw) // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 static pos_T comment_pos_copy;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 pos_T *comment_pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 pos_T *rs_pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 comment_pos = find_start_comment(curbuf->b_ind_maxcomment);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 if (comment_pos != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 // Need to make a copy of the static pos in findmatchlimit(),
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 // calling find_start_rawstring() may change it.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 comment_pos_copy = *comment_pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 comment_pos = &comment_pos_copy;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 rs_pos = find_start_rawstring(curbuf->b_ind_maxcomment);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 // If comment_pos is before rs_pos the raw string is inside the comment.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 // If rs_pos is before comment_pos the comment is inside the raw string.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 if (comment_pos == NULL || (rs_pos != NULL
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 && LT_POS(*rs_pos, *comment_pos)))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 if (is_raw != NULL && rs_pos != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 *is_raw = rs_pos->lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 return rs_pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 return comment_pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 }
28942
6cdf55afaae9 patch 8.2.4993: smart/C/lisp indenting is optional
Bram Moolenaar <Bram@vim.org>
parents: 28891
diff changeset
253
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 * Return TRUE if C-indenting is on.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 cindent_on(void)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 return (!p_paste && (curbuf->b_p_cin
28942
6cdf55afaae9 patch 8.2.4993: smart/C/lisp indenting is optional
Bram Moolenaar <Bram@vim.org>
parents: 28891
diff changeset
262 #ifdef FEAT_EVAL
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 || *curbuf->b_p_inde != NUL
28942
6cdf55afaae9 patch 8.2.4993: smart/C/lisp indenting is optional
Bram Moolenaar <Bram@vim.org>
parents: 28891
diff changeset
264 #endif
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 ));
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268 // Find result cache for cpp_baseclass
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 typedef struct {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 int found;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 lpos_T lpos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 } cpp_baseclass_cache_T;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 * Skip over white space and C comments within the line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 * Also skip over Perl/shell comments if desired.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 static char_u *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 cin_skipcomment(char_u *s)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 while (*s)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 char_u *prev_s = s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 s = skipwhite(s);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 // Perl/shell # comment comment continues until eol. Require a space
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 // before # to avoid recognizing $#array.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 if (curbuf->b_ind_hash_comment != 0 && s != prev_s && *s == '#')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 s += STRLEN(s);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 if (*s != '/')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296 ++s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 if (*s == '/') // slash-slash comment continues till eol
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 s += STRLEN(s);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302 if (*s != '*')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 for (++s; *s; ++s) // skip slash-star comment
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 if (s[0] == '*' && s[1] == '/')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 s += 2;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 return s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315 * Return TRUE if there is no code at *s. White space and comments are
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 * not considered code.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 cin_nocode(char_u *s)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 return *cin_skipcomment(s) == NUL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 * Recognize the start of a C or C++ comment.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 cin_iscomment(char_u *p)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 return (p[0] == '/' && (p[1] == '*' || p[1] == '/'));
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 * Recognize the start of a "//" comment.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 cin_islinecomment(char_u *p)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 return (p[0] == '/' && p[1] == '/');
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 * Check previous lines for a "//" line comment, skipping over blank lines.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 static pos_T *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 find_line_comment(void) // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 static pos_T pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349 char_u *line;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 char_u *p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 pos = curwin->w_cursor;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 while (--pos.lnum > 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 line = ml_get(pos.lnum);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 p = skipwhite(line);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 if (cin_islinecomment(p))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359 pos.col = (int)(p - line);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 return &pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362 if (*p != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 return NULL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 * Return TRUE if "text" starts with "key:".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 cin_has_js_key(char_u *text)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 char_u *s = skipwhite(text);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 int quote = -1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 if (*s == '\'' || *s == '"')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 // can be 'key': or "key":
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 quote = *s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 ++s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 if (!vim_isIDc(*s)) // need at least one ID character
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 while (vim_isIDc(*s))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 ++s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 if (*s == quote)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 ++s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 s = cin_skipcomment(s);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 // "::" is not a label, it's C++
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 return (*s == ':' && s[1] != ':');
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 * Check if string matches "label:"; move to character after ':' if true.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 * "*s" must point to the start of the label, if there is one.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 cin_islabel_skip(char_u **s)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 if (!vim_isIDc(**s)) // need at least one ID character
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 while (vim_isIDc(**s))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 (*s)++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 *s = cin_skipcomment(*s);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412 // "::" is not a label, it's C++
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 return (**s == ':' && *++*s != ':');
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 /*
28497
7c4a9e20c178 patch 8.2.4773: build failure without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents: 28355
diff changeset
417 * Recognize a scope declaration label from the 'cinscopedecls' option.
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 static int
28353
8bc8071928ed patch 8.2.4702: C++ scope labels are hard-coded
Bram Moolenaar <Bram@vim.org>
parents: 27490
diff changeset
420 cin_isscopedecl(char_u *p)
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 {
28355
f1a3df11d013 patch 8.2.4703: memory leak in handling 'cinscopedecls'
Bram Moolenaar <Bram@vim.org>
parents: 28353
diff changeset
422 size_t cinsd_len;
f1a3df11d013 patch 8.2.4703: memory leak in handling 'cinscopedecls'
Bram Moolenaar <Bram@vim.org>
parents: 28353
diff changeset
423 char_u *cinsd_buf;
f1a3df11d013 patch 8.2.4703: memory leak in handling 'cinscopedecls'
Bram Moolenaar <Bram@vim.org>
parents: 28353
diff changeset
424 char_u *cinsd;
f1a3df11d013 patch 8.2.4703: memory leak in handling 'cinscopedecls'
Bram Moolenaar <Bram@vim.org>
parents: 28353
diff changeset
425 size_t len;
f1a3df11d013 patch 8.2.4703: memory leak in handling 'cinscopedecls'
Bram Moolenaar <Bram@vim.org>
parents: 28353
diff changeset
426 char_u *skip;
f1a3df11d013 patch 8.2.4703: memory leak in handling 'cinscopedecls'
Bram Moolenaar <Bram@vim.org>
parents: 28353
diff changeset
427 char_u *s = cin_skipcomment(p);
f1a3df11d013 patch 8.2.4703: memory leak in handling 'cinscopedecls'
Bram Moolenaar <Bram@vim.org>
parents: 28353
diff changeset
428 int found = FALSE;
28353
8bc8071928ed patch 8.2.4702: C++ scope labels are hard-coded
Bram Moolenaar <Bram@vim.org>
parents: 27490
diff changeset
429
8bc8071928ed patch 8.2.4702: C++ scope labels are hard-coded
Bram Moolenaar <Bram@vim.org>
parents: 27490
diff changeset
430 cinsd_len = STRLEN(curbuf->b_p_cinsd) + 1;
8bc8071928ed patch 8.2.4702: C++ scope labels are hard-coded
Bram Moolenaar <Bram@vim.org>
parents: 27490
diff changeset
431 cinsd_buf = alloc(cinsd_len);
28355
f1a3df11d013 patch 8.2.4703: memory leak in handling 'cinscopedecls'
Bram Moolenaar <Bram@vim.org>
parents: 28353
diff changeset
432 if (cinsd_buf == NULL)
f1a3df11d013 patch 8.2.4703: memory leak in handling 'cinscopedecls'
Bram Moolenaar <Bram@vim.org>
parents: 28353
diff changeset
433 return FALSE;
f1a3df11d013 patch 8.2.4703: memory leak in handling 'cinscopedecls'
Bram Moolenaar <Bram@vim.org>
parents: 28353
diff changeset
434
f1a3df11d013 patch 8.2.4703: memory leak in handling 'cinscopedecls'
Bram Moolenaar <Bram@vim.org>
parents: 28353
diff changeset
435 for (cinsd = curbuf->b_p_cinsd; *cinsd; )
28353
8bc8071928ed patch 8.2.4702: C++ scope labels are hard-coded
Bram Moolenaar <Bram@vim.org>
parents: 27490
diff changeset
436 {
28497
7c4a9e20c178 patch 8.2.4773: build failure without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents: 28355
diff changeset
437 len = copy_option_part(&cinsd, cinsd_buf, (int)cinsd_len, ",");
28355
f1a3df11d013 patch 8.2.4703: memory leak in handling 'cinscopedecls'
Bram Moolenaar <Bram@vim.org>
parents: 28353
diff changeset
438 if (STRNCMP(s, cinsd_buf, len) == 0)
28353
8bc8071928ed patch 8.2.4702: C++ scope labels are hard-coded
Bram Moolenaar <Bram@vim.org>
parents: 27490
diff changeset
439 {
28355
f1a3df11d013 patch 8.2.4703: memory leak in handling 'cinscopedecls'
Bram Moolenaar <Bram@vim.org>
parents: 28353
diff changeset
440 skip = cin_skipcomment(s + len);
f1a3df11d013 patch 8.2.4703: memory leak in handling 'cinscopedecls'
Bram Moolenaar <Bram@vim.org>
parents: 28353
diff changeset
441 if (*skip == ':' && skip[1] != ':')
28353
8bc8071928ed patch 8.2.4702: C++ scope labels are hard-coded
Bram Moolenaar <Bram@vim.org>
parents: 27490
diff changeset
442 {
28355
f1a3df11d013 patch 8.2.4703: memory leak in handling 'cinscopedecls'
Bram Moolenaar <Bram@vim.org>
parents: 28353
diff changeset
443 found = TRUE;
f1a3df11d013 patch 8.2.4703: memory leak in handling 'cinscopedecls'
Bram Moolenaar <Bram@vim.org>
parents: 28353
diff changeset
444 break;
28353
8bc8071928ed patch 8.2.4702: C++ scope labels are hard-coded
Bram Moolenaar <Bram@vim.org>
parents: 27490
diff changeset
445 }
8bc8071928ed patch 8.2.4702: C++ scope labels are hard-coded
Bram Moolenaar <Bram@vim.org>
parents: 27490
diff changeset
446 }
8bc8071928ed patch 8.2.4702: C++ scope labels are hard-coded
Bram Moolenaar <Bram@vim.org>
parents: 27490
diff changeset
447 }
8bc8071928ed patch 8.2.4702: C++ scope labels are hard-coded
Bram Moolenaar <Bram@vim.org>
parents: 27490
diff changeset
448
28355
f1a3df11d013 patch 8.2.4703: memory leak in handling 'cinscopedecls'
Bram Moolenaar <Bram@vim.org>
parents: 28353
diff changeset
449 vim_free(cinsd_buf);
f1a3df11d013 patch 8.2.4703: memory leak in handling 'cinscopedecls'
Bram Moolenaar <Bram@vim.org>
parents: 28353
diff changeset
450 return found;
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 * Recognize a preprocessor statement: Any line that starts with '#'.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 cin_ispreproc(char_u *s)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 if (*skipwhite(s) == '#')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 * Return TRUE if line "*pp" at "*lnump" is a preprocessor statement or a
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 * continuation line of a preprocessor statement. Decrease "*lnump" to the
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 * start and return the line in "*pp".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 * Put the amount of indent in "*amount".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 cin_ispreproc_cont(char_u **pp, linenr_T *lnump, int *amount)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 char_u *line = *pp;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 linenr_T lnum = *lnump;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 int retval = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 int candidate_amount = *amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478 if (*line != NUL && line[STRLEN(line) - 1] == '\\')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479 candidate_amount = get_indent_lnum(lnum);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 for (;;)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 if (cin_ispreproc(line))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 retval = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486 *lnump = lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 if (lnum == 1)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 line = ml_get(--lnum);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 if (*line == NUL || line[STRLEN(line) - 1] != '\\')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 if (lnum != *lnump)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497 *pp = ml_get(*lnump);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 if (retval)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 *amount = candidate_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500 return retval;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
501 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
502
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 cin_iselse(
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 char_u *p)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 if (*p == '}') // accept "} else"
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 p = cin_skipcomment(p + 1);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 return (STRNCMP(p, "else", 4) == 0 && !vim_isIDc(p[4]));
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 * Recognize a line that starts with '{' or '}', or ends with ';', ',', '{' or
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 * '}'.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 * Don't consider "} else" a terminated line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 * If a line begins with an "else", only consider it terminated if no unmatched
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 * opening braces follow (handle "else { foo();" correctly).
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 * Return the character terminating the line (ending char's have precedence if
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 * both apply in order to determine initializations).
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 cin_isterminated(
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 char_u *s,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 int incl_open, // include '{' at the end as terminator
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 int incl_comma) // recognize a trailing comma
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527 char_u found_start = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 unsigned n_open = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 int is_else = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 s = cin_skipcomment(s);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 if (*s == '{' || (*s == '}' && !cin_iselse(s)))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534 found_start = *s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 if (!found_start)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 is_else = cin_iselse(s);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 while (*s)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 // skip over comments, "" strings and 'c'haracters
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542 s = skip_string(cin_skipcomment(s));
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543 if (*s == '}' && n_open > 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 --n_open;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 if ((!is_else || n_open == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 && (*s == ';' || *s == '}' || (incl_comma && *s == ','))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 && cin_nocode(s + 1))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 return *s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 else if (*s == '{')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 if (incl_open && cin_nocode(s + 1))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 return *s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 ++n_open;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 if (*s)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 s++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 return found_start;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 * Return TRUE when "s" starts with "word" and then a non-ID character.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 cin_starts_with(char_u *s, char *word)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 int l = (int)STRLEN(word);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 return (STRNCMP(s, word, l) == 0 && !vim_isIDc(s[l]));
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 * Recognize a "default" switch label.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 cin_isdefault(char_u *s)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 return (STRNCMP(s, "default", 7) == 0
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 && *(s = cin_skipcomment(s + 7)) == ':'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 && s[1] != ':');
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 * Recognize a switch label: "case .*:" or "default:".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 cin_iscase(
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 char_u *s,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 int strict) // Allow relaxed check of case statement for JS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 s = cin_skipcomment(s);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 if (cin_starts_with(s, "case"))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596 for (s += 4; *s; ++s)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 s = cin_skipcomment(s);
19104
9f4648953f1a patch 8.2.0112: illegal memory access when using 'cindent'
Bram Moolenaar <Bram@vim.org>
parents: 18757
diff changeset
599 if (*s == NUL)
9f4648953f1a patch 8.2.0112: illegal memory access when using 'cindent'
Bram Moolenaar <Bram@vim.org>
parents: 18757
diff changeset
600 break;
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601 if (*s == ':')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 if (s[1] == ':') // skip over "::" for C++
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 ++s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 if (*s == '\'' && s[1] && s[2] == '\'')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 s += 2; // skip over ':'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 else if (*s == '/' && (s[1] == '*' || s[1] == '/'))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 return FALSE; // stop at comment
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 else if (*s == '"')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 // JS etc.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 if (strict)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 return FALSE; // stop at string
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 if (cin_isdefault(s))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 * Recognize a label: "label:".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 * Note: curwin->w_cursor must be where we are looking for the label.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 cin_islabel(void) // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 char_u *s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 s = cin_skipcomment(ml_get_curline());
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 // Exclude "default" from labels, since it should be indented
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 // like a switch label. Same for C++ scope declarations.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 if (cin_isdefault(s))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 if (cin_isscopedecl(s))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646
31667
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
647 if (!cin_islabel_skip(&s))
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
648 return FALSE;
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
649
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
650 // Only accept a label if the previous line is terminated or is a case
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
651 // label.
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
652 pos_T cursor_save;
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
653 pos_T *trypos;
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
654 char_u *line;
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
655
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
656 cursor_save = curwin->w_cursor;
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
657 while (curwin->w_cursor.lnum > 1)
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 {
31667
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
659 --curwin->w_cursor.lnum;
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
660
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
661 // If we're in a comment or raw string now, skip to the start of
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
662 // it.
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
663 curwin->w_cursor.col = 0;
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
664 if ((trypos = ind_find_start_CORS(NULL)) != NULL) // XXX
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
665 curwin->w_cursor = *trypos;
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
666
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
667 line = ml_get_curline();
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
668 if (cin_ispreproc(line)) // ignore #defines, #if, etc.
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
669 continue;
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
670 if (*(line = cin_skipcomment(line)) == NUL)
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
671 continue;
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
672
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 curwin->w_cursor = cursor_save;
31667
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
674 if (cin_isterminated(line, TRUE, FALSE)
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
675 || cin_isscopedecl(line)
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
676 || cin_iscase(line, TRUE)
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
677 || (cin_islabel_skip(&line) && cin_nocode(line)))
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
678 return TRUE;
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
679 return FALSE;
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 }
31667
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
681 curwin->w_cursor = cursor_save;
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
682 return TRUE; // label at start of file???
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 * Return TRUE if string "s" ends with the string "find", possibly followed by
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 * white space and comments. Skip strings and comments.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 * Ignore "ignore" after "find" if it's not NULL.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 cin_ends_in(char_u *s, char_u *find, char_u *ignore)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 char_u *p = s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694 char_u *r;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 int len = (int)STRLEN(find);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 while (*p != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 p = cin_skipcomment(p);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 if (STRNCMP(p, find, len) == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 r = skipwhite(p + len);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 if (ignore != NULL && STRNCMP(r, ignore, STRLEN(ignore)) == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 r = skipwhite(r + STRLEN(ignore));
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 if (cin_nocode(r))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 if (*p != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 * Recognize structure initialization and enumerations:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 * "[typedef] [static|public|protected|private] enum"
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 * "[typedef] [static|public|protected|private] = {"
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 cin_isinit(void)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 char_u *s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 static char *skip[] = {"static", "public", "protected", "private"};
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 s = cin_skipcomment(ml_get_curline());
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 if (cin_starts_with(s, "typedef"))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 s = cin_skipcomment(s + 7);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 for (;;)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 int i, l;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733
24768
7334bf933510 patch 8.2.2922: computing array length is done in various ways
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
734 for (i = 0; i < (int)ARRAY_LENGTH(skip); ++i)
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 l = (int)strlen(skip[i]);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 if (cin_starts_with(s, skip[i]))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739 s = cin_skipcomment(s + l);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 l = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 if (l != 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 if (cin_starts_with(s, "enum"))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 if (cin_ends_in(s, (char_u *)"=", (char_u *)"{"))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 // Maximum number of lines to search back for a "namespace" line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 #define FIND_NAMESPACE_LIM 20
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 * Recognize a "namespace" scope declaration.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 cin_is_cpp_namespace(char_u *s)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 char_u *p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 int has_name = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 int has_name_start = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 s = cin_skipcomment(s);
26694
1095fd0dc362 patch 8.2.3876: 'cindent' does not recognize inline namespace
Bram Moolenaar <Bram@vim.org>
parents: 26516
diff changeset
771
32190
73489b6c4a02 patch 9.0.1426: indent wrong after "export namespace" in C++
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
772 // skip over "inline" and "export" in any order
73489b6c4a02 patch 9.0.1426: indent wrong after "export namespace" in C++
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
773 while ((STRNCMP(s, "inline", 6) == 0 || STRNCMP(s, "export", 6) == 0)
73489b6c4a02 patch 9.0.1426: indent wrong after "export namespace" in C++
Bram Moolenaar <Bram@vim.org>
parents: 31804
diff changeset
774 && (s[6] == NUL || !vim_iswordc(s[6])))
26694
1095fd0dc362 patch 8.2.3876: 'cindent' does not recognize inline namespace
Bram Moolenaar <Bram@vim.org>
parents: 26516
diff changeset
775 s = cin_skipcomment(skipwhite(s + 6));
1095fd0dc362 patch 8.2.3876: 'cindent' does not recognize inline namespace
Bram Moolenaar <Bram@vim.org>
parents: 26516
diff changeset
776
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 if (STRNCMP(s, "namespace", 9) == 0 && (s[9] == NUL || !vim_iswordc(s[9])))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 p = cin_skipcomment(skipwhite(s + 9));
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 while (*p != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 if (VIM_ISWHITE(*p))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 has_name = TRUE; // found end of a name
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 p = cin_skipcomment(skipwhite(p));
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 else if (*p == '{')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 else if (vim_iswordc(*p))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 has_name_start = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 if (has_name)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 return FALSE; // word character after skipping past name
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 else if (p[0] == ':' && p[1] == ':' && vim_iswordc(p[2]))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 if (!has_name_start || has_name)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
801 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 // C++ 17 nested namespace
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803 p += 3;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
805 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
811 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 * Recognize a `extern "C"` or `extern "C++"` linkage specifications.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
819 cin_is_cpp_extern_c(char_u *s)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821 char_u *p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 int has_string_literal = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 s = cin_skipcomment(s);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 if (STRNCMP(s, "extern", 6) == 0 && (s[6] == NUL || !vim_iswordc(s[6])))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 p = cin_skipcomment(skipwhite(s + 6));
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828 while (*p != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830 if (VIM_ISWHITE(*p))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 p = cin_skipcomment(skipwhite(p));
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834 else if (*p == '{')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838 else if (p[0] == '"' && p[1] == 'C' && p[2] == '"')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 if (has_string_literal)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 has_string_literal = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 p += 3;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 else if (p[0] == '"' && p[1] == 'C' && p[2] == '+' && p[3] == '+'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 && p[4] == '"')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 if (has_string_literal)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850 has_string_literal = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851 p += 5;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858 return has_string_literal ? TRUE : FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 * Return a pointer to the first non-empty non-comment character after a ':'.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 * Return NULL if not found.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866 * case 234: a = b;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 * ^
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 static char_u *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 after_label(char_u *l)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 for ( ; *l; ++l)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874 if (*l == ':')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 if (l[1] == ':') // skip over "::" for C++
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 ++l;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878 else if (!cin_iscase(l + 1, FALSE))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 else if (*l == '\'' && l[1] && l[2] == '\'')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 l += 2; // skip over 'x'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884 if (*l == NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 return NULL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886 l = cin_skipcomment(l + 1);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 if (*l == NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 return NULL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 return l;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
891
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893 * Get indent of line "lnum", skipping a label.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 * Return 0 if there is nothing after the label.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
896 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897 get_indent_nolabel (linenr_T lnum) // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899 char_u *l;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900 pos_T fp;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 colnr_T col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 char_u *p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 l = ml_get(lnum);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905 p = after_label(l);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906 if (p == NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 return 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
909 fp.col = (colnr_T)(p - l);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 fp.lnum = lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911 getvcol(curwin, &fp, &col, NULL, NULL);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 return (int)col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916 * Find indent for line "lnum", ignoring any case or jump label.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
917 * Also return a pointer to the text (after the label) in "pp".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918 * label: if (asdf && asdfasdf)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919 * ^
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
921 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922 skip_label(linenr_T lnum, char_u **pp)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924 char_u *l;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925 int amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 pos_T cursor_save;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 cursor_save = curwin->w_cursor;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 curwin->w_cursor.lnum = lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930 l = ml_get_curline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931 // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 if (cin_iscase(l, FALSE) || cin_isscopedecl(l) || cin_islabel())
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 amount = get_indent_nolabel(lnum);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 l = after_label(ml_get_curline());
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 if (l == NULL) // just in case
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 l = ml_get_curline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 amount = get_indent();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 l = ml_get_curline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 *pp = l;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 curwin->w_cursor = cursor_save;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 return amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
951 * Return the indent of the first variable name after a type in a declaration.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952 * int a, indent of "a"
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 * static struct foo b, indent of "b"
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954 * enum bla c, indent of "c"
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955 * Returns zero when it doesn't look like a declaration.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958 cin_first_id_amount(void)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
959 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
960 char_u *line, *p, *s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
961 int len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962 pos_T fp;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 colnr_T col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965 line = ml_get_curline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966 p = skipwhite(line);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 len = (int)(skiptowhite(p) - p);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968 if (len == 6 && STRNCMP(p, "static", 6) == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
969 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 p = skipwhite(p + 6);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
971 len = (int)(skiptowhite(p) - p);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 if (len == 6 && STRNCMP(p, "struct", 6) == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974 p = skipwhite(p + 6);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975 else if (len == 4 && STRNCMP(p, "enum", 4) == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976 p = skipwhite(p + 4);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 else if ((len == 8 && STRNCMP(p, "unsigned", 8) == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 || (len == 6 && STRNCMP(p, "signed", 6) == 0))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 s = skipwhite(p + len);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 if ((STRNCMP(s, "int", 3) == 0 && VIM_ISWHITE(s[3]))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982 || (STRNCMP(s, "long", 4) == 0 && VIM_ISWHITE(s[4]))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 || (STRNCMP(s, "short", 5) == 0 && VIM_ISWHITE(s[5]))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984 || (STRNCMP(s, "char", 4) == 0 && VIM_ISWHITE(s[4])))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 p = s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 for (len = 0; vim_isIDc(p[len]); ++len)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 ;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
989 if (len == 0 || !VIM_ISWHITE(p[len]) || cin_nocode(p))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
990 return 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 p = skipwhite(p + len);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 fp.lnum = curwin->w_cursor.lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 fp.col = (colnr_T)(p - line);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995 getvcol(curwin, &fp, &col, NULL, NULL);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 return (int)col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000 * Return the indent of the first non-blank after an equal sign.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001 * char *foo = "here";
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 * Return zero if no (useful) equal sign found.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003 * Return -1 if the line above "lnum" ends in a backslash.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004 * foo = "asdf\
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005 * asdf\
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 * here";
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009 cin_get_equal_amount(linenr_T lnum)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011 char_u *line;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1012 char_u *s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013 colnr_T col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014 pos_T fp;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016 if (lnum > 1)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 line = ml_get(lnum - 1);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 if (*line != NUL && line[STRLEN(line) - 1] == '\\')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1020 return -1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1021 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023 line = s = ml_get(lnum);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1024 while (*s != NUL && vim_strchr((char_u *)"=;{}\"'", *s) == NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026 if (cin_iscomment(s)) // ignore comments
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027 s = cin_skipcomment(s);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1028 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029 ++s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1030 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031 if (*s != '=')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1032 return 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1034 s = skipwhite(s + 1);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 if (cin_nocode(s))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036 return 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038 if (*s == '"') // nice alignment for continued strings
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 ++s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1040
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041 fp.lnum = lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1042 fp.col = (colnr_T)(s - line);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1043 getvcol(curwin, &fp, &col, NULL, NULL);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1044 return (int)col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1045 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 * Skip strings, chars and comments until at or past "trypos".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049 * Return the column found.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052 cin_skip2pos(pos_T *trypos)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 char_u *line;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055 char_u *p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056 char_u *new_p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058 p = line = ml_get(trypos->lnum);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 while (*p && (colnr_T)(p - line) < trypos->col)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061 if (cin_iscomment(p))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1062 p = cin_skipcomment(p);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1063 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1064 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1065 new_p = skip_string(p);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1066 if (new_p == p)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1068 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069 p = new_p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1071 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1072 return (int)(p - line);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1073 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1074
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075 static pos_T *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 find_match_char(int c, int ind_maxparen) // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078 pos_T cursor_save;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 pos_T *trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 static pos_T pos_copy;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 int ind_maxp_wk;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083 cursor_save = curwin->w_cursor;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 ind_maxp_wk = ind_maxparen;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1085 retry:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086 if ((trypos = findmatchlimit(NULL, c, 0, ind_maxp_wk)) != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1087 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1088 // check if the ( is in a // comment
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 if ((colnr_T)cin_skip2pos(trypos) > trypos->col)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1091 ind_maxp_wk = ind_maxparen - (int)(cursor_save.lnum - trypos->lnum);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092 if (ind_maxp_wk > 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1094 curwin->w_cursor = *trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1095 curwin->w_cursor.col = 0; // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1096 goto retry;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1097 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 trypos = NULL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1099 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1100 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102 pos_T *trypos_wk;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1104 pos_copy = *trypos; // copy trypos, findmatch will change it
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105 trypos = &pos_copy;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106 curwin->w_cursor = *trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107 if ((trypos_wk = ind_find_start_CORS(NULL)) != NULL) // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1109 ind_maxp_wk = ind_maxparen - (int)(cursor_save.lnum
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 - trypos_wk->lnum);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1111 if (ind_maxp_wk > 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1113 curwin->w_cursor = *trypos_wk;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114 goto retry;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1115 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1116 trypos = NULL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1118 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 curwin->w_cursor = cursor_save;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 return trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1125 * Find the matching '(', ignoring it if it is in a comment.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1126 * Return NULL if no match found.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 static pos_T *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1129 find_match_paren(int ind_maxparen) // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1131 return find_match_char('(', ind_maxparen);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1132 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1133
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1134 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1135 * Set w_cursor.col to the column number of the last unmatched ')' or '{' in
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1136 * line "l". "l" must point to the start of the line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1137 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 find_last_paren(char_u *l, int start, int end)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141 int i;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142 int retval = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1143 int open_count = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1145 curwin->w_cursor.col = 0; // default is start of line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1147 for (i = 0; l[i] != NUL; i++)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 i = (int)(cin_skipcomment(l + i) - l); // ignore parens in comments
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1150 i = (int)(skip_string(l + i) - l); // ignore parens in quotes
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1151 if (l[i] == start)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1152 ++open_count;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1153 else if (l[i] == end)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1154 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1155 if (open_count > 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1156 --open_count;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1157 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1158 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159 curwin->w_cursor.col = i;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1160 retval = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1161 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1162 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164 return retval;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1166
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1167 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1168 * Recognize the basic picture of a function declaration -- it needs to
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169 * have an open paren somewhere and a close paren at the end of the line and
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1170 * no semicolons anywhere.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1171 * When a line ends in a comma we continue looking in the next line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1172 * "sp" points to a string with the line. When looking at other lines it must
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1173 * be restored to the line. When it's NULL fetch lines here.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174 * "first_lnum" is where we start looking.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175 * "min_lnum" is the line before which we will not be looking.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1177 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178 cin_isfuncdecl(
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1179 char_u **sp,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1180 linenr_T first_lnum,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1181 linenr_T min_lnum)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1182 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183 char_u *s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184 linenr_T lnum = first_lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 linenr_T save_lnum = curwin->w_cursor.lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1186 int retval = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187 pos_T *trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1188 int just_started = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1189
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1190 if (sp == NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1191 s = ml_get(lnum);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1192 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1193 s = *sp;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1194
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1195 curwin->w_cursor.lnum = lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1196 if (find_last_paren(s, '(', ')')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1197 && (trypos = find_match_paren(curbuf->b_ind_maxparen)) != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1198 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1199 lnum = trypos->lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1200 if (lnum < min_lnum)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1201 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1202 curwin->w_cursor.lnum = save_lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1203 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1204 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1205
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1206 s = ml_get(lnum);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1207 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1208 curwin->w_cursor.lnum = save_lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1209
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1210 // Ignore line starting with #.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1211 if (cin_ispreproc(s))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1212 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1213
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1214 while (*s && *s != '(' && *s != ';' && *s != '\'' && *s != '"')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1215 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1216 if (cin_iscomment(s)) // ignore comments
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1217 s = cin_skipcomment(s);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1218 else if (*s == ':')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1219 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1220 if (*(s + 1) == ':')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1221 s += 2;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1222 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1223 // To avoid a mistake in the following situation:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1224 // A::A(int a, int b)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1225 // : a(0) // <--not a function decl
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1226 // , b(0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1227 // {...
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1228 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1229 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1230 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1231 ++s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1232 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1233 if (*s != '(')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1234 return FALSE; // ';', ' or " before any () or no '('
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1235
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1236 while (*s && *s != ';' && *s != '\'' && *s != '"')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1238 if (*s == ')' && cin_nocode(s + 1))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1239 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1240 // ')' at the end: may have found a match
26771
fc859aea8cec patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents: 26694
diff changeset
1241 // Check for the previous line not to end in a backslash:
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1242 // #if defined(x) && {backslash}
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1243 // defined(y)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1244 lnum = first_lnum - 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1245 s = ml_get(lnum);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1246 if (*s == NUL || s[STRLEN(s) - 1] != '\\')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1247 retval = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1248 goto done;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1249 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1250 if ((*s == ',' && cin_nocode(s + 1)) || s[1] == NUL || cin_nocode(s))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1251 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1252 int comma = (*s == ',');
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1253
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1254 // ',' at the end: continue looking in the next line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1255 // At the end: check for ',' in the next line, for this style:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1256 // func(arg1
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1257 // , arg2)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1258 for (;;)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1259 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1260 if (lnum >= curbuf->b_ml.ml_line_count)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1261 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1262 s = ml_get(++lnum);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1263 if (!cin_ispreproc(s))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1264 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1265 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1266 if (lnum >= curbuf->b_ml.ml_line_count)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1267 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1268 // Require a comma at end of the line or a comma or ')' at the
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1269 // start of next line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1270 s = skipwhite(s);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1271 if (!just_started && (!comma && *s != ',' && *s != ')'))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1272 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1273 just_started = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1274 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1275 else if (cin_iscomment(s)) // ignore comments
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1276 s = cin_skipcomment(s);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1277 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1278 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1279 ++s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1280 just_started = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1281 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1282 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1283
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1284 done:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1285 if (lnum != first_lnum && sp != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1286 *sp = ml_get(first_lnum);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1287
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1288 return retval;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1289 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1290
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1291 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1292 cin_isif(char_u *p)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1293 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1294 return (STRNCMP(p, "if", 2) == 0 && !vim_isIDc(p[2]));
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1295 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1296
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1297 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1298 cin_isdo(char_u *p)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1299 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1300 return (STRNCMP(p, "do", 2) == 0 && !vim_isIDc(p[2]));
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1301 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1302
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1303 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1304 * Check if this is a "while" that should have a matching "do".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1305 * We only accept a "while (condition) ;", with only white space between the
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1306 * ')' and ';'. The condition may be spread over several lines.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1307 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1308 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1309 cin_iswhileofdo (char_u *p, linenr_T lnum) // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1310 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1311 pos_T cursor_save;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1312 pos_T *trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1313 int retval = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1314
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1315 p = cin_skipcomment(p);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1316 if (*p == '}') // accept "} while (cond);"
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1317 p = cin_skipcomment(p + 1);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1318 if (cin_starts_with(p, "while"))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1319 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1320 cursor_save = curwin->w_cursor;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1321 curwin->w_cursor.lnum = lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1322 curwin->w_cursor.col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1323 p = ml_get_curline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1324 while (*p && *p != 'w') // skip any '}', until the 'w' of the "while"
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1325 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1326 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1327 ++curwin->w_cursor.col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1328 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1329 if ((trypos = findmatchlimit(NULL, 0, 0,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1330 curbuf->b_ind_maxparen)) != NULL
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1331 && *cin_skipcomment(ml_get_pos(trypos) + 1) == ';')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1332 retval = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1333 curwin->w_cursor = cursor_save;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1334 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1335 return retval;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1336 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1337
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1338 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1339 * Check whether in "p" there is an "if", "for" or "while" before "*poffset".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1340 * Return 0 if there is none.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1341 * Otherwise return !0 and update "*poffset" to point to the place where the
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1342 * string was found.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1343 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1344 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1345 cin_is_if_for_while_before_offset(char_u *line, int *poffset)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1346 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1347 int offset = *poffset;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1348
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1349 if (offset-- < 2)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1350 return 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1351 while (offset > 2 && VIM_ISWHITE(line[offset]))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1352 --offset;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1353
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1354 offset -= 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1355 if (!STRNCMP(line + offset, "if", 2))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1356 goto probablyFound;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1357
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1358 if (offset >= 1)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1359 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1360 offset -= 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1361 if (!STRNCMP(line + offset, "for", 3))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1362 goto probablyFound;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1363
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1364 if (offset >= 2)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1365 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1366 offset -= 2;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1367 if (!STRNCMP(line + offset, "while", 5))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1368 goto probablyFound;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1369 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1370 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1371 return 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1372
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1373 probablyFound:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1374 if (!offset || !vim_isIDc(line[offset - 1]))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1375 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1376 *poffset = offset;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1377 return 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1378 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1379 return 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1380 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1381
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1382 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1383 * Return TRUE if we are at the end of a do-while.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1384 * do
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1385 * nothing;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1386 * while (foo
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1387 * && bar); <-- here
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1388 * Adjust the cursor to the line with "while".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1389 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1390 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1391 cin_iswhileofdo_end(int terminated)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1392 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1393 char_u *line;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1394 char_u *p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1395 char_u *s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1396 pos_T *trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1397 int i;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1398
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1399 if (terminated != ';') // there must be a ';' at the end
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1400 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1401
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1402 p = line = ml_get_curline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1403 while (*p != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1404 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1405 p = cin_skipcomment(p);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1406 if (*p == ')')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1407 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1408 s = skipwhite(p + 1);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1409 if (*s == ';' && cin_nocode(s + 1))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1410 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1411 // Found ");" at end of the line, now check there is "while"
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1412 // before the matching '('. XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1413 i = (int)(p - line);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1414 curwin->w_cursor.col = i;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1415 trypos = find_match_paren(curbuf->b_ind_maxparen);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1416 if (trypos != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1417 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1418 s = cin_skipcomment(ml_get(trypos->lnum));
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1419 if (*s == '}') // accept "} while (cond);"
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1420 s = cin_skipcomment(s + 1);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1421 if (cin_starts_with(s, "while"))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1422 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1423 curwin->w_cursor.lnum = trypos->lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1424 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1425 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1426 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1427
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1428 // Searching may have made "line" invalid, get it again.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1429 line = ml_get_curline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1430 p = line + i;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1431 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1432 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1433 if (*p != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1434 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1435 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1436 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1437 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1438
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1439 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1440 cin_isbreak(char_u *p)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1441 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1442 return (STRNCMP(p, "break", 5) == 0 && !vim_isIDc(p[5]));
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1443 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1444
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1445 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1446 * Find the position of a C++ base-class declaration or
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1447 * constructor-initialization. eg:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1448 *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1449 * class MyClass :
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1450 * baseClass <-- here
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1451 * class MyClass : public baseClass,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1452 * anotherBaseClass <-- here (should probably lineup ??)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1453 * MyClass::MyClass(...) :
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1454 * baseClass(...) <-- here (constructor-initialization)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1455 *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1456 * This is a lot of guessing. Watch out for "cond ? func() : foo".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1457 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1458 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1459 cin_is_cpp_baseclass(
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1460 cpp_baseclass_cache_T *cached) // input and output
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1461 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1462 lpos_T *pos = &cached->lpos; // find position
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1463 char_u *s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1464 int class_or_struct, lookfor_ctor_init, cpp_base_class;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1465 linenr_T lnum = curwin->w_cursor.lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1466 char_u *line = ml_get_curline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1467
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1468 if (pos->lnum <= lnum)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1469 return cached->found; // Use the cached result
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1470
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1471 pos->col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1472
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1473 s = skipwhite(line);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1474 if (*s == '#') // skip #define FOO x ? (x) : x
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1475 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1476 s = cin_skipcomment(s);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1477 if (*s == NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1478 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1479
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1480 cpp_base_class = lookfor_ctor_init = class_or_struct = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1481
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1482 // Search for a line starting with '#', empty, ending in ';' or containing
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1483 // '{' or '}' and start below it. This handles the following situations:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1484 // a = cond ?
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1485 // func() :
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1486 // asdf;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1487 // func::foo()
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1488 // : something
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1489 // {}
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1490 // Foo::Foo (int one, int two)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1491 // : something(4),
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1492 // somethingelse(3)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1493 // {}
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1494 while (lnum > 1)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1495 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1496 line = ml_get(lnum - 1);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1497 s = skipwhite(line);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1498 if (*s == '#' || *s == NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1499 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1500 while (*s != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1501 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1502 s = cin_skipcomment(s);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1503 if (*s == '{' || *s == '}'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1504 || (*s == ';' && cin_nocode(s + 1)))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1505 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1506 if (*s != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1507 ++s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1508 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1509 if (*s != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1510 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1511 --lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1512 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1513
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1514 pos->lnum = lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1515 line = ml_get(lnum);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1516 s = line;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1517 for (;;)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1518 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1519 if (*s == NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1520 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1521 if (lnum == curwin->w_cursor.lnum)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1522 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1523 // Continue in the cursor line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1524 line = ml_get(++lnum);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1525 s = line;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1526 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1527 if (s == line)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1528 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1529 // don't recognize "case (foo):" as a baseclass
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1530 if (cin_iscase(s, FALSE))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1531 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1532 s = cin_skipcomment(line);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1533 if (*s == NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1534 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1535 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1536
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1537 if (s[0] == '"' || (s[0] == 'R' && s[1] == '"'))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1538 s = skip_string(s) + 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1539 else if (s[0] == ':')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1540 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1541 if (s[1] == ':')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1542 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1543 // skip double colon. It can't be a constructor
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1544 // initialization any more
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1545 lookfor_ctor_init = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1546 s = cin_skipcomment(s + 2);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1547 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1548 else if (lookfor_ctor_init || class_or_struct)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1549 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1550 // we have something found, that looks like the start of
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1551 // cpp-base-class-declaration or constructor-initialization
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1552 cpp_base_class = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1553 lookfor_ctor_init = class_or_struct = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1554 pos->col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1555 s = cin_skipcomment(s + 1);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1556 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1557 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1558 s = cin_skipcomment(s + 1);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1559 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1560 else if ((STRNCMP(s, "class", 5) == 0 && !vim_isIDc(s[5]))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1561 || (STRNCMP(s, "struct", 6) == 0 && !vim_isIDc(s[6])))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1562 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1563 class_or_struct = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1564 lookfor_ctor_init = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1565
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1566 if (*s == 'c')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1567 s = cin_skipcomment(s + 5);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1568 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1569 s = cin_skipcomment(s + 6);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1570 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1571 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1572 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1573 if (s[0] == '{' || s[0] == '}' || s[0] == ';')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1574 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1575 cpp_base_class = lookfor_ctor_init = class_or_struct = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1576 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1577 else if (s[0] == ')')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1578 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1579 // Constructor-initialization is assumed if we come across
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1580 // something like "):"
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1581 class_or_struct = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1582 lookfor_ctor_init = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1583 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1584 else if (s[0] == '?')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1585 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1586 // Avoid seeing '() :' after '?' as constructor init.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1587 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1588 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1589 else if (!vim_isIDc(s[0]))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1590 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1591 // if it is not an identifier, we are wrong
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1592 class_or_struct = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1593 lookfor_ctor_init = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1594 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1595 else if (pos->col == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1596 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1597 // it can't be a constructor-initialization any more
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1598 lookfor_ctor_init = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1599
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1600 // the first statement starts here: lineup with this one...
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1601 if (cpp_base_class)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1602 pos->col = (colnr_T)(s - line);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1603 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1604
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1605 // When the line ends in a comma don't align with it.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1606 if (lnum == curwin->w_cursor.lnum && *s == ',' && cin_nocode(s + 1))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1607 pos->col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1608
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1609 s = cin_skipcomment(s + 1);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1610 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1611 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1612
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1613 cached->found = cpp_base_class;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1614 if (cpp_base_class)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1615 pos->lnum = lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1616 return cpp_base_class;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1617 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1618
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1619 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1620 get_baseclass_amount(int col)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1621 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1622 int amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1623 colnr_T vcol;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1624 pos_T *trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1625
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1626 if (col == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1627 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1628 amount = get_indent();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1629 if (find_last_paren(ml_get_curline(), '(', ')')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1630 && (trypos = find_match_paren(curbuf->b_ind_maxparen)) != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1631 amount = get_indent_lnum(trypos->lnum); // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1632 if (!cin_ends_in(ml_get_curline(), (char_u *)",", NULL))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1633 amount += curbuf->b_ind_cpp_baseclass;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1634 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1635 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1636 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1637 curwin->w_cursor.col = col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1638 getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1639 amount = (int)vcol;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1640 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1641 if (amount < curbuf->b_ind_cpp_baseclass)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1642 amount = curbuf->b_ind_cpp_baseclass;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1643 return amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1644 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1645
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1646 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1647 * Find the '{' at the start of the block we are in.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1648 * Return NULL if no match found.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1649 * Ignore a '{' that is in a comment, makes indenting the next three lines
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1650 * work.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1651 */
18757
c469e1930456 patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18498
diff changeset
1652 // foo()
c469e1930456 patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18498
diff changeset
1653 // {
c469e1930456 patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18498
diff changeset
1654 // }
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1655
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1656 static pos_T *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1657 find_start_brace(void) // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1658 {
26187
8e92f01f7226 patch 8.2.3625: illegal memory access when C-indenting
Bram Moolenaar <Bram@vim.org>
parents: 25897
diff changeset
1659 pos_T cursor_save;
8e92f01f7226 patch 8.2.3625: illegal memory access when C-indenting
Bram Moolenaar <Bram@vim.org>
parents: 25897
diff changeset
1660 pos_T *trypos;
8e92f01f7226 patch 8.2.3625: illegal memory access when C-indenting
Bram Moolenaar <Bram@vim.org>
parents: 25897
diff changeset
1661 pos_T *pos;
8e92f01f7226 patch 8.2.3625: illegal memory access when C-indenting
Bram Moolenaar <Bram@vim.org>
parents: 25897
diff changeset
1662 static pos_T pos_copy;
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1663
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1664 cursor_save = curwin->w_cursor;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1665 while ((trypos = findmatchlimit(NULL, '{', FM_BLOCKSTOP, 0)) != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1666 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1667 pos_copy = *trypos; // copy pos_T, next findmatch will change it
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1668 trypos = &pos_copy;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1669 curwin->w_cursor = *trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1670 pos = NULL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1671 // ignore the { if it's in a // or / * * / comment
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1672 if ((colnr_T)cin_skip2pos(trypos) == trypos->col
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1673 && (pos = ind_find_start_CORS(NULL)) == NULL) // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1674 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1675 if (pos != NULL)
26187
8e92f01f7226 patch 8.2.3625: illegal memory access when C-indenting
Bram Moolenaar <Bram@vim.org>
parents: 25897
diff changeset
1676 curwin->w_cursor = *pos;
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1677 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1678 curwin->w_cursor = cursor_save;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1679 return trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1680 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1681
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1682 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1683 * Find the matching '(', ignoring it if it is in a comment or before an
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1684 * unmatched {.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1685 * Return NULL if no match found.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1686 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1687 static pos_T *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1688 find_match_paren_after_brace (int ind_maxparen) // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1689 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1690 pos_T *trypos = find_match_paren(ind_maxparen);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1691
31667
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
1692 if (trypos == NULL)
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
1693 return NULL;
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
1694
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
1695 pos_T *tryposBrace = find_start_brace();
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
1696
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
1697 // If both an unmatched '(' and '{' is found. Ignore the '('
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
1698 // position if the '{' is further down.
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
1699 if (tryposBrace != NULL
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
1700 && (trypos->lnum != tryposBrace->lnum
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
1701 ? trypos->lnum < tryposBrace->lnum
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
1702 : trypos->col < tryposBrace->col))
b89cfd86e18e patch 9.0.1166: code is indented more than necessary
Bram Moolenaar <Bram@vim.org>
parents: 31091
diff changeset
1703 trypos = NULL;
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1704 return trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1705 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1706
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1707 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1708 * Return ind_maxparen corrected for the difference in line number between the
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1709 * cursor position and "startpos". This makes sure that searching for a
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1710 * matching paren above the cursor line doesn't find a match because of
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1711 * looking a few lines further.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1712 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1713 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1714 corr_ind_maxparen(pos_T *startpos)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1715 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1716 long n = (long)startpos->lnum - (long)curwin->w_cursor.lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1717
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1718 if (n > 0 && n < curbuf->b_ind_maxparen / 2)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1719 return curbuf->b_ind_maxparen - (int)n;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1720 return curbuf->b_ind_maxparen;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1721 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1722
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1723 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1724 * Parse 'cinoptions' and set the values in "curbuf".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1725 * Must be called when 'cinoptions', 'shiftwidth' and/or 'tabstop' changes.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1726 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1727 void
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1728 parse_cino(buf_T *buf)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1729 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1730 char_u *p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1731 char_u *l;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1732 char_u *digits;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1733 int n;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1734 int divider;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1735 int fraction = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1736 int sw = (int)get_sw_value(buf);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1737
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1738 // Set the default values.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1739
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1740 // Spaces from a block's opening brace the prevailing indent for that
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1741 // block should be.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1742 buf->b_ind_level = sw;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1743
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1744 // Spaces from the edge of the line an open brace that's at the end of a
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1745 // line is imagined to be.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1746 buf->b_ind_open_imag = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1747
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1748 // Spaces from the prevailing indent for a line that is not preceded by
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1749 // an opening brace.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1750 buf->b_ind_no_brace = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1751
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1752 // Column where the first { of a function should be located }.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1753 buf->b_ind_first_open = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1754
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1755 // Spaces from the prevailing indent a leftmost open brace should be
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1756 // located.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1757 buf->b_ind_open_extra = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1758
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1759 // Spaces from the matching open brace (real location for one at the left
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1760 // edge; imaginary location from one that ends a line) the matching close
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1761 // brace should be located.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1762 buf->b_ind_close_extra = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1763
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1764 // Spaces from the edge of the line an open brace sitting in the leftmost
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1765 // column is imagined to be.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1766 buf->b_ind_open_left_imag = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1767
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1768 // Spaces jump labels should be shifted to the left if N is non-negative,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1769 // otherwise the jump label will be put to column 1.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1770 buf->b_ind_jump_label = -1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1771
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1772 // Spaces from the switch() indent a "case xx" label should be located.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1773 buf->b_ind_case = sw;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1774
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1775 // Spaces from the "case xx:" code after a switch() should be located.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1776 buf->b_ind_case_code = sw;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1777
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1778 // Lineup break at end of case in switch() with case label.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1779 buf->b_ind_case_break = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1780
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1781 // Spaces from the class declaration indent a scope declaration label
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1782 // should be located.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1783 buf->b_ind_scopedecl = sw;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1784
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1785 // Spaces from the scope declaration label code should be located.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1786 buf->b_ind_scopedecl_code = sw;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1787
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1788 // Amount K&R-style parameters should be indented.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1789 buf->b_ind_param = sw;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1790
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1791 // Amount a function type spec should be indented.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1792 buf->b_ind_func_type = sw;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1793
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1794 // Amount a cpp base class declaration or constructor initialization
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1795 // should be indented.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1796 buf->b_ind_cpp_baseclass = sw;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1797
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1798 // additional spaces beyond the prevailing indent a continuation line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1799 // should be located.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1800 buf->b_ind_continuation = sw;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1801
18498
9e6d5a4abb1c patch 8.1.2243: typos in comments
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
1802 // Spaces from the indent of the line with an unclosed parenthesis.
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1803 buf->b_ind_unclosed = sw * 2;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1804
18498
9e6d5a4abb1c patch 8.1.2243: typos in comments
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
1805 // Spaces from the indent of the line with an unclosed parenthesis, which
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1806 // itself is also unclosed.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1807 buf->b_ind_unclosed2 = sw;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1808
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1809 // Suppress ignoring spaces from the indent of a line starting with an
26771
fc859aea8cec patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents: 26694
diff changeset
1810 // unclosed parenthesis.
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1811 buf->b_ind_unclosed_noignore = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1812
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1813 // If the opening paren is the last nonwhite character on the line, and
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1814 // b_ind_unclosed_wrapped is nonzero, use this indent relative to the outer
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1815 // context (for very long lines).
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1816 buf->b_ind_unclosed_wrapped = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1817
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1818 // Suppress ignoring white space when lining up with the character after
18498
9e6d5a4abb1c patch 8.1.2243: typos in comments
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
1819 // an unclosed parenthesis.
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1820 buf->b_ind_unclosed_whiteok = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1821
26771
fc859aea8cec patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents: 26694
diff changeset
1822 // Indent a closing parenthesis under the line start of the matching
fc859aea8cec patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents: 26694
diff changeset
1823 // opening parenthesis.
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1824 buf->b_ind_matching_paren = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1825
26771
fc859aea8cec patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents: 26694
diff changeset
1826 // Indent a closing parenthesis under the previous line.
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1827 buf->b_ind_paren_prev = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1828
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1829 // Extra indent for comments.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1830 buf->b_ind_comment = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1831
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1832 // Spaces from the comment opener when there is nothing after it.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1833 buf->b_ind_in_comment = 3;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1834
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1835 // Boolean: if non-zero, use b_ind_in_comment even if there is something
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1836 // after the comment opener.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1837 buf->b_ind_in_comment2 = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1838
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1839 // Max lines to search for an open paren.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1840 buf->b_ind_maxparen = 20;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1841
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1842 // Max lines to search for an open comment.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1843 buf->b_ind_maxcomment = 70;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1844
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1845 // Handle braces for java code.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1846 buf->b_ind_java = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1847
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1848 // Not to confuse JS object properties with labels.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1849 buf->b_ind_js = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1850
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1851 // Handle blocked cases correctly.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1852 buf->b_ind_keep_case_label = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1853
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1854 // Handle C++ namespace.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1855 buf->b_ind_cpp_namespace = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1856
32395
2ed95122d59c patch 9.0.1529: code style test doesn't check for space after "if"
Bram Moolenaar <Bram@vim.org>
parents: 32190
diff changeset
1857 // Handle continuation lines containing conditions of if (), for () and
2ed95122d59c patch 9.0.1529: code style test doesn't check for space after "if"
Bram Moolenaar <Bram@vim.org>
parents: 32190
diff changeset
1858 // while ().
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1859 buf->b_ind_if_for_while = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1860
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1861 // indentation for # comments
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1862 buf->b_ind_hash_comment = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1863
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1864 // Handle C++ extern "C" or "C++"
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1865 buf->b_ind_cpp_extern_c = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1866
20621
d30b16692ce0 patch 8.2.0864: pragmas are indented all the way to the left
Bram Moolenaar <Bram@vim.org>
parents: 19104
diff changeset
1867 // Handle C #pragma directives
d30b16692ce0 patch 8.2.0864: pragmas are indented all the way to the left
Bram Moolenaar <Bram@vim.org>
parents: 19104
diff changeset
1868 buf->b_ind_pragma = 0;
d30b16692ce0 patch 8.2.0864: pragmas are indented all the way to the left
Bram Moolenaar <Bram@vim.org>
parents: 19104
diff changeset
1869
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1870 for (p = buf->b_p_cino; *p; )
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1871 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1872 l = p++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1873 if (*p == '-')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1874 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1875 digits = p; // remember where the digits start
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1876 n = getdigits(&p);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1877 divider = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1878 if (*p == '.') // ".5s" means a fraction
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1879 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1880 fraction = atol((char *)++p);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1881 while (VIM_ISDIGIT(*p))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1882 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1883 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1884 if (divider)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1885 divider *= 10;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1886 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1887 divider = 10;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1888 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1889 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1890 if (*p == 's') // "2s" means two times 'shiftwidth'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1891 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1892 if (p == digits)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1893 n = sw; // just "s" is one 'shiftwidth'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1894 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1895 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1896 n *= sw;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1897 if (divider)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1898 n += (sw * fraction + divider / 2) / divider;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1899 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1900 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1901 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1902 if (l[1] == '-')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1903 n = -n;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1904
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1905 // When adding an entry here, also update the default 'cinoptions' in
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1906 // doc/indent.txt, and add explanation for it!
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1907 switch (*l)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1908 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1909 case '>': buf->b_ind_level = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1910 case 'e': buf->b_ind_open_imag = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1911 case 'n': buf->b_ind_no_brace = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1912 case 'f': buf->b_ind_first_open = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1913 case '{': buf->b_ind_open_extra = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1914 case '}': buf->b_ind_close_extra = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1915 case '^': buf->b_ind_open_left_imag = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1916 case 'L': buf->b_ind_jump_label = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1917 case ':': buf->b_ind_case = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1918 case '=': buf->b_ind_case_code = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1919 case 'b': buf->b_ind_case_break = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1920 case 'p': buf->b_ind_param = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1921 case 't': buf->b_ind_func_type = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1922 case '/': buf->b_ind_comment = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1923 case 'c': buf->b_ind_in_comment = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1924 case 'C': buf->b_ind_in_comment2 = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1925 case 'i': buf->b_ind_cpp_baseclass = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1926 case '+': buf->b_ind_continuation = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1927 case '(': buf->b_ind_unclosed = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1928 case 'u': buf->b_ind_unclosed2 = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1929 case 'U': buf->b_ind_unclosed_noignore = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1930 case 'W': buf->b_ind_unclosed_wrapped = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1931 case 'w': buf->b_ind_unclosed_whiteok = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1932 case 'm': buf->b_ind_matching_paren = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1933 case 'M': buf->b_ind_paren_prev = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1934 case ')': buf->b_ind_maxparen = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1935 case '*': buf->b_ind_maxcomment = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1936 case 'g': buf->b_ind_scopedecl = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1937 case 'h': buf->b_ind_scopedecl_code = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1938 case 'j': buf->b_ind_java = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1939 case 'J': buf->b_ind_js = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1940 case 'l': buf->b_ind_keep_case_label = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1941 case '#': buf->b_ind_hash_comment = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1942 case 'N': buf->b_ind_cpp_namespace = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1943 case 'k': buf->b_ind_if_for_while = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1944 case 'E': buf->b_ind_cpp_extern_c = n; break;
20621
d30b16692ce0 patch 8.2.0864: pragmas are indented all the way to the left
Bram Moolenaar <Bram@vim.org>
parents: 19104
diff changeset
1945 case 'P': buf->b_ind_pragma = n; break;
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1946 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1947 if (*p == ',')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1948 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1949 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1950 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1951
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1952 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1953 find_match(int lookfor, linenr_T ourscope)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1954 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1955 char_u *look;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1956 pos_T *theirscope;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1957 char_u *mightbeif;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1958 int elselevel;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1959 int whilelevel;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1960
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1961 if (lookfor == LOOKFOR_IF)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1962 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1963 elselevel = 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1964 whilelevel = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1965 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1966 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1967 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1968 elselevel = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1969 whilelevel = 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1970 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1971
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1972 curwin->w_cursor.col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1973
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1974 while (curwin->w_cursor.lnum > ourscope + 1)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1975 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1976 curwin->w_cursor.lnum--;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1977 curwin->w_cursor.col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1978
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1979 look = cin_skipcomment(ml_get_curline());
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1980 if (cin_iselse(look)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1981 || cin_isif(look)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1982 || cin_isdo(look) // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1983 || cin_iswhileofdo(look, curwin->w_cursor.lnum))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1984 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1985 // if we've gone outside the braces entirely,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1986 // we must be out of scope...
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1987 theirscope = find_start_brace(); // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1988 if (theirscope == NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1989 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1990
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1991 // and if the brace enclosing this is further
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1992 // back than the one enclosing the else, we're
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1993 // out of luck too.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1994 if (theirscope->lnum < ourscope)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1995 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1996
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1997 // and if they're enclosed in a *deeper* brace,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1998 // then we can ignore it because it's in a
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1999 // different scope...
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2000 if (theirscope->lnum > ourscope)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2001 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2002
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2003 // if it was an "else" (that's not an "else if")
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2004 // then we need to go back to another if, so
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2005 // increment elselevel
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2006 look = cin_skipcomment(ml_get_curline());
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2007 if (cin_iselse(look))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2008 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2009 mightbeif = cin_skipcomment(look + 4);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2010 if (!cin_isif(mightbeif))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2011 ++elselevel;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2012 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2013 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2014
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2015 // if it was a "while" then we need to go back to
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2016 // another "do", so increment whilelevel. XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2017 if (cin_iswhileofdo(look, curwin->w_cursor.lnum))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2018 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2019 ++whilelevel;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2020 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2021 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2022
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2023 // If it's an "if" decrement elselevel
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2024 look = cin_skipcomment(ml_get_curline());
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2025 if (cin_isif(look))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2026 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2027 elselevel--;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2028 // When looking for an "if" ignore "while"s that
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2029 // get in the way.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2030 if (elselevel == 0 && lookfor == LOOKFOR_IF)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2031 whilelevel = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2032 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2033
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2034 // If it's a "do" decrement whilelevel
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2035 if (cin_isdo(look))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2036 whilelevel--;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2037
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2038 // if we've used up all the elses, then
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2039 // this must be the if that we want!
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2040 // match the indent level of that if.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2041 if (elselevel <= 0 && whilelevel <= 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2042 return OK;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2043 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2044 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2045 return FAIL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2046 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2047
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2048 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2049 * Return the desired indent for C code.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2050 * Return -1 if the indent should be left alone (inside a raw string).
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2051 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2052 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2053 get_c_indent(void)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2054 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2055 pos_T cur_curpos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2056 int amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2057 int scope_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2058 int cur_amount = MAXCOL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2059 colnr_T col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2060 char_u *theline;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2061 char_u *linecopy;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2062 pos_T *trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2063 pos_T *comment_pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2064 pos_T *tryposBrace = NULL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2065 pos_T tryposCopy;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2066 pos_T our_paren_pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2067 char_u *start;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2068 int start_brace;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2069 #define BRACE_IN_COL0 1 // '{' is in column 0
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2070 #define BRACE_AT_START 2 // '{' is at start of line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2071 #define BRACE_AT_END 3 // '{' is at end of line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2072 linenr_T ourscope;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2073 char_u *l;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2074 char_u *look;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2075 char_u terminated;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2076 int lookfor;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2077 int whilelevel;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2078 linenr_T lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2079 int n;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2080 int iscase;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2081 int lookfor_break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2082 int lookfor_cpp_namespace = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2083 int cont_amount = 0; // amount for continuation line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2084 int original_line_islabel;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2085 int added_to_amount = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2086 int js_cur_has_key = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2087 linenr_T raw_string_start = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2088 cpp_baseclass_cache_T cache_cpp_baseclass = { FALSE, { MAXLNUM, 0 } };
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2089
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2090 // make a copy, value is changed below
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2091 int ind_continuation = curbuf->b_ind_continuation;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2092
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2093 // remember where the cursor was when we started
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2094 cur_curpos = curwin->w_cursor;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2095
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2096 // if we are at line 1 zero indent is fine, right?
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2097 if (cur_curpos.lnum == 1)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2098 return 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2099
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2100 // Get a copy of the current contents of the line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2101 // This is required, because only the most recent line obtained with
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2102 // ml_get is valid!
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2103 linecopy = vim_strsave(ml_get(cur_curpos.lnum));
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2104 if (linecopy == NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2105 return 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2106
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2107 // In insert mode and the cursor is on a ')' truncate the line at the
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2108 // cursor position. We don't want to line up with the matching '(' when
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2109 // inserting new stuff.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2110 // For unknown reasons the cursor might be past the end of the line, thus
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2111 // check for that.
28773
d770568e6c98 patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents: 28497
diff changeset
2112 if ((State & MODE_INSERT)
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2113 && curwin->w_cursor.col < (colnr_T)STRLEN(linecopy)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2114 && linecopy[curwin->w_cursor.col] == ')')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2115 linecopy[curwin->w_cursor.col] = NUL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2116
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2117 theline = skipwhite(linecopy);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2118
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2119 // move the cursor to the start of the line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2120
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2121 curwin->w_cursor.col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2122
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2123 original_line_islabel = cin_islabel(); // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2124
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2125 // If we are inside a raw string don't change the indent.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2126 // Ignore a raw string inside a comment.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2127 comment_pos = ind_find_start_comment();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2128 if (comment_pos != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2129 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2130 // findmatchlimit() static pos is overwritten, make a copy
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2131 tryposCopy = *comment_pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2132 comment_pos = &tryposCopy;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2133 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2134 trypos = find_start_rawstring(curbuf->b_ind_maxcomment);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2135 if (trypos != NULL && (comment_pos == NULL
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2136 || LT_POS(*trypos, *comment_pos)))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2137 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2138 amount = -1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2139 goto laterend;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2140 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2141
20621
d30b16692ce0 patch 8.2.0864: pragmas are indented all the way to the left
Bram Moolenaar <Bram@vim.org>
parents: 19104
diff changeset
2142 // #defines and so on go at the left when included in 'cinkeys',
23229
b545334ae654 patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents: 20621
diff changeset
2143 // excluding pragmas when customized in 'cinoptions'
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2144 if (*theline == '#' && (*linecopy == '#' || in_cinkeys('#', ' ', TRUE)))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2145 {
20621
d30b16692ce0 patch 8.2.0864: pragmas are indented all the way to the left
Bram Moolenaar <Bram@vim.org>
parents: 19104
diff changeset
2146 char_u *directive = skipwhite(theline + 1);
d30b16692ce0 patch 8.2.0864: pragmas are indented all the way to the left
Bram Moolenaar <Bram@vim.org>
parents: 19104
diff changeset
2147 if (curbuf->b_ind_pragma == 0 || STRNCMP(directive, "pragma", 6) != 0)
d30b16692ce0 patch 8.2.0864: pragmas are indented all the way to the left
Bram Moolenaar <Bram@vim.org>
parents: 19104
diff changeset
2148 {
d30b16692ce0 patch 8.2.0864: pragmas are indented all the way to the left
Bram Moolenaar <Bram@vim.org>
parents: 19104
diff changeset
2149 amount = curbuf->b_ind_hash_comment;
d30b16692ce0 patch 8.2.0864: pragmas are indented all the way to the left
Bram Moolenaar <Bram@vim.org>
parents: 19104
diff changeset
2150 goto theend;
d30b16692ce0 patch 8.2.0864: pragmas are indented all the way to the left
Bram Moolenaar <Bram@vim.org>
parents: 19104
diff changeset
2151 }
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2152 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2153
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2154 // Is it a non-case label? Then that goes at the left margin too unless:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2155 // - JS flag is set.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2156 // - 'L' item has a positive value.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2157 if (original_line_islabel && !curbuf->b_ind_js
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2158 && curbuf->b_ind_jump_label < 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2159 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2160 amount = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2161 goto theend;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2162 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2163
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2164 // If we're inside a "//" comment and there is a "//" comment in a
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2165 // previous line, lineup with that one.
26516
9596c652420b patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents: 26187
diff changeset
2166 if (cin_islinecomment(theline))
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2167 {
26516
9596c652420b patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents: 26187
diff changeset
2168 pos_T linecomment_pos;
9596c652420b patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents: 26187
diff changeset
2169
9596c652420b patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents: 26187
diff changeset
2170 trypos = find_line_comment(); // XXX
9596c652420b patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents: 26187
diff changeset
2171 if (trypos == NULL && curwin->w_cursor.lnum > 1)
9596c652420b patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents: 26187
diff changeset
2172 {
9596c652420b patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents: 26187
diff changeset
2173 // There may be a statement before the comment, search from the end
9596c652420b patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents: 26187
diff changeset
2174 // of the line for a comment start.
9596c652420b patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents: 26187
diff changeset
2175 linecomment_pos.col =
9596c652420b patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents: 26187
diff changeset
2176 check_linecomment(ml_get(curwin->w_cursor.lnum - 1));
9596c652420b patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents: 26187
diff changeset
2177 if (linecomment_pos.col != MAXCOL)
9596c652420b patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents: 26187
diff changeset
2178 {
28809
d0241e74bfdb patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents: 28773
diff changeset
2179 trypos = &linecomment_pos;
d0241e74bfdb patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents: 28773
diff changeset
2180 trypos->lnum = curwin->w_cursor.lnum - 1;
26516
9596c652420b patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents: 26187
diff changeset
2181 }
9596c652420b patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents: 26187
diff changeset
2182 }
9596c652420b patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents: 26187
diff changeset
2183 if (trypos != NULL)
9596c652420b patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents: 26187
diff changeset
2184 {
9596c652420b patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents: 26187
diff changeset
2185 // find how indented the line beginning the comment is
9596c652420b patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents: 26187
diff changeset
2186 getvcol(curwin, trypos, &col, NULL, NULL);
9596c652420b patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents: 26187
diff changeset
2187 amount = col;
9596c652420b patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents: 26187
diff changeset
2188 goto theend;
9596c652420b patch 8.2.3787: no proper formatting of a C line comment after a statement
Bram Moolenaar <Bram@vim.org>
parents: 26187
diff changeset
2189 }
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2190 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2191
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2192 // If we're inside a comment and not looking at the start of the
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2193 // comment, try using the 'comments' option.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2194 if (!cin_iscomment(theline) && comment_pos != NULL) // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2195 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2196 int lead_start_len = 2;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2197 int lead_middle_len = 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2198 char_u lead_start[COM_MAX_LEN]; // start-comment string
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2199 char_u lead_middle[COM_MAX_LEN]; // middle-comment string
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2200 char_u lead_end[COM_MAX_LEN]; // end-comment string
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2201 char_u *p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2202 int start_align = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2203 int start_off = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2204 int done = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2205
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2206 // find how indented the line beginning the comment is
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2207 getvcol(curwin, comment_pos, &col, NULL, NULL);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2208 amount = col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2209 *lead_start = NUL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2210 *lead_middle = NUL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2211
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2212 p = curbuf->b_p_com;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2213 while (*p != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2214 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2215 int align = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2216 int off = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2217 int what = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2218
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2219 while (*p != NUL && *p != ':')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2220 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2221 if (*p == COM_START || *p == COM_END || *p == COM_MIDDLE)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2222 what = *p++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2223 else if (*p == COM_LEFT || *p == COM_RIGHT)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2224 align = *p++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2225 else if (VIM_ISDIGIT(*p) || *p == '-')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2226 off = getdigits(&p);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2227 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2228 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2229 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2230
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2231 if (*p == ':')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2232 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2233 (void)copy_option_part(&p, lead_end, COM_MAX_LEN, ",");
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2234 if (what == COM_START)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2235 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2236 STRCPY(lead_start, lead_end);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2237 lead_start_len = (int)STRLEN(lead_start);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2238 start_off = off;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2239 start_align = align;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2240 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2241 else if (what == COM_MIDDLE)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2242 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2243 STRCPY(lead_middle, lead_end);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2244 lead_middle_len = (int)STRLEN(lead_middle);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2245 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2246 else if (what == COM_END)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2247 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2248 // If our line starts with the middle comment string, line it
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2249 // up with the comment opener per the 'comments' option.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2250 if (STRNCMP(theline, lead_middle, lead_middle_len) == 0
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2251 && STRNCMP(theline, lead_end, STRLEN(lead_end)) != 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2252 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2253 done = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2254 if (curwin->w_cursor.lnum > 1)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2255 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2256 // If the start comment string matches in the previous
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2257 // line, use the indent of that line plus offset. If
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2258 // the middle comment string matches in the previous
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2259 // line, use the indent of that line. XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2260 look = skipwhite(ml_get(curwin->w_cursor.lnum - 1));
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2261 if (STRNCMP(look, lead_start, lead_start_len) == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2262 amount = get_indent_lnum(curwin->w_cursor.lnum - 1);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2263 else if (STRNCMP(look, lead_middle,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2264 lead_middle_len) == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2265 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2266 amount = get_indent_lnum(curwin->w_cursor.lnum - 1);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2267 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2268 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2269 // If the start comment string doesn't match with the
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2270 // start of the comment, skip this entry. XXX
29507
d3058719eff5 patch 9.0.0095: conditions are always true
Bram Moolenaar <Bram@vim.org>
parents: 29340
diff changeset
2271 else if (STRNCMP(ml_get(comment_pos->lnum)
d3058719eff5 patch 9.0.0095: conditions are always true
Bram Moolenaar <Bram@vim.org>
parents: 29340
diff changeset
2272 + comment_pos->col,
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2273 lead_start, lead_start_len) != 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2274 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2275 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2276 if (start_off != 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2277 amount += start_off;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2278 else if (start_align == COM_RIGHT)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2279 amount += vim_strsize(lead_start)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2280 - vim_strsize(lead_middle);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2281 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2282 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2283
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2284 // If our line starts with the end comment string, line it up
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2285 // with the middle comment
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2286 if (STRNCMP(theline, lead_middle, lead_middle_len) != 0
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2287 && STRNCMP(theline, lead_end, STRLEN(lead_end)) == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2288 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2289 amount = get_indent_lnum(curwin->w_cursor.lnum - 1);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2290 // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2291 if (off != 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2292 amount += off;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2293 else if (align == COM_RIGHT)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2294 amount += vim_strsize(lead_start)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2295 - vim_strsize(lead_middle);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2296 done = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2297 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2298 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2299 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2300 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2301
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2302 // If our line starts with an asterisk, line up with the
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2303 // asterisk in the comment opener; otherwise, line up
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2304 // with the first character of the comment text.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2305 if (done)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2306 ;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2307 else if (theline[0] == '*')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2308 amount += 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2309 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2310 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2311 // If we are more than one line away from the comment opener, take
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2312 // the indent of the previous non-empty line. If 'cino' has "CO"
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2313 // and we are just below the comment opener and there are any
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2314 // white characters after it line up with the text after it;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2315 // otherwise, add the amount specified by "c" in 'cino'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2316 amount = -1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2317 for (lnum = cur_curpos.lnum - 1; lnum > comment_pos->lnum; --lnum)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2318 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2319 if (linewhite(lnum)) // skip blank lines
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2320 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2321 amount = get_indent_lnum(lnum); // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2322 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2323 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2324 if (amount == -1) // use the comment opener
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2325 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2326 if (!curbuf->b_ind_in_comment2)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2327 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2328 start = ml_get(comment_pos->lnum);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2329 look = start + comment_pos->col + 2; // skip / and *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2330 if (*look != NUL) // if something after it
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2331 comment_pos->col = (colnr_T)(skipwhite(look) - start);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2332 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2333 getvcol(curwin, comment_pos, &col, NULL, NULL);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2334 amount = col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2335 if (curbuf->b_ind_in_comment2 || *look == NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2336 amount += curbuf->b_ind_in_comment;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2337 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2338 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2339 goto theend;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2340 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2341
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2342 // Are we looking at a ']' that has a match?
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2343 if (*skipwhite(theline) == ']'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2344 && (trypos = find_match_char('[', curbuf->b_ind_maxparen)) != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2345 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2346 // align with the line containing the '['.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2347 amount = get_indent_lnum(trypos->lnum);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2348 goto theend;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2349 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2350
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2351 // Are we inside parentheses or braces? XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2352 if (((trypos = find_match_paren(curbuf->b_ind_maxparen)) != NULL
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2353 && curbuf->b_ind_java == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2354 || (tryposBrace = find_start_brace()) != NULL
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2355 || trypos != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2356 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2357 if (trypos != NULL && tryposBrace != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2358 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2359 // Both an unmatched '(' and '{' is found. Use the one which is
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2360 // closer to the current cursor position, set the other to NULL.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2361 if (trypos->lnum != tryposBrace->lnum
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2362 ? trypos->lnum < tryposBrace->lnum
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2363 : trypos->col < tryposBrace->col)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2364 trypos = NULL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2365 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2366 tryposBrace = NULL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2367 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2368
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2369 if (trypos != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2370 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2371 // If the matching paren is more than one line away, use the indent of
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2372 // a previous non-empty line that matches the same paren.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2373 if (theline[0] == ')' && curbuf->b_ind_paren_prev)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2374 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2375 // Line up with the start of the matching paren line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2376 amount = get_indent_lnum(curwin->w_cursor.lnum - 1); // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2377 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2378 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2379 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2380 amount = -1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2381 our_paren_pos = *trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2382 for (lnum = cur_curpos.lnum - 1; lnum > our_paren_pos.lnum; --lnum)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2383 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2384 l = skipwhite(ml_get(lnum));
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2385 if (cin_nocode(l)) // skip comment lines
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2386 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2387 if (cin_ispreproc_cont(&l, &lnum, &amount))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2388 continue; // ignore #define, #if, etc.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2389 curwin->w_cursor.lnum = lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2390
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2391 // Skip a comment or raw string. XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2392 if ((trypos = ind_find_start_CORS(NULL)) != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2393 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2394 lnum = trypos->lnum + 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2395 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2396 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2397
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2398 // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2399 if ((trypos = find_match_paren(
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2400 corr_ind_maxparen(&cur_curpos))) != NULL
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2401 && trypos->lnum == our_paren_pos.lnum
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2402 && trypos->col == our_paren_pos.col)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2403 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2404 amount = get_indent_lnum(lnum); // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2405
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2406 if (theline[0] == ')')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2407 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2408 if (our_paren_pos.lnum != lnum
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2409 && cur_amount > amount)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2410 cur_amount = amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2411 amount = -1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2412 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2413 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2414 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2415 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2416 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2417
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2418 // Line up with line where the matching paren is. XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2419 // If the line starts with a '(' or the indent for unclosed
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2420 // parentheses is zero, line up with the unclosed parentheses.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2421 if (amount == -1)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2422 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2423 int ignore_paren_col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2424 int is_if_for_while = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2425
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2426 if (curbuf->b_ind_if_for_while)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2427 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2428 // Look for the outermost opening parenthesis on this line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2429 // and check whether it belongs to an "if", "for" or "while".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2430
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2431 pos_T cursor_save = curwin->w_cursor;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2432 pos_T outermost;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2433 char_u *line;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2434
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2435 trypos = &our_paren_pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2436 do {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2437 outermost = *trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2438 curwin->w_cursor.lnum = outermost.lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2439 curwin->w_cursor.col = outermost.col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2440
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2441 trypos = find_match_paren(curbuf->b_ind_maxparen);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2442 } while (trypos && trypos->lnum == outermost.lnum);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2443
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2444 curwin->w_cursor = cursor_save;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2445
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2446 line = ml_get(outermost.lnum);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2447
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2448 is_if_for_while =
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2449 cin_is_if_for_while_before_offset(line, &outermost.col);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2450 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2451
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2452 amount = skip_label(our_paren_pos.lnum, &look);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2453 look = skipwhite(look);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2454 if (*look == '(')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2455 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2456 linenr_T save_lnum = curwin->w_cursor.lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2457 char_u *line;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2458 int look_col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2459
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2460 // Ignore a '(' in front of the line that has a match before
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2461 // our matching '('.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2462 curwin->w_cursor.lnum = our_paren_pos.lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2463 line = ml_get_curline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2464 look_col = (int)(look - line);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2465 curwin->w_cursor.col = look_col + 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2466 if ((trypos = findmatchlimit(NULL, ')', 0,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2467 curbuf->b_ind_maxparen))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2468 != NULL
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2469 && trypos->lnum == our_paren_pos.lnum
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2470 && trypos->col < our_paren_pos.col)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2471 ignore_paren_col = trypos->col + 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2472
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2473 curwin->w_cursor.lnum = save_lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2474 look = ml_get(our_paren_pos.lnum) + look_col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2475 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2476 if (theline[0] == ')' || (curbuf->b_ind_unclosed == 0
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2477 && is_if_for_while == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2478 || (!curbuf->b_ind_unclosed_noignore && *look == '('
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2479 && ignore_paren_col == 0))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2480 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2481 // If we're looking at a close paren, line up right there;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2482 // otherwise, line up with the next (non-white) character.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2483 // When b_ind_unclosed_wrapped is set and the matching paren is
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2484 // the last nonwhite character of the line, use either the
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2485 // indent of the current line or the indentation of the next
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2486 // outer paren and add b_ind_unclosed_wrapped (for very long
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2487 // lines).
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2488 if (theline[0] != ')')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2489 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2490 cur_amount = MAXCOL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2491 l = ml_get(our_paren_pos.lnum);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2492 if (curbuf->b_ind_unclosed_wrapped
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2493 && cin_ends_in(l, (char_u *)"(", NULL))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2494 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2495 // look for opening unmatched paren, indent one level
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2496 // for each additional level
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2497 n = 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2498 for (col = 0; col < our_paren_pos.col; ++col)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2499 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2500 switch (l[col])
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2501 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2502 case '(':
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2503 case '{': ++n;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2504 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2505
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2506 case ')':
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2507 case '}': if (n > 1)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2508 --n;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2509 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2510 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2511 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2512
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2513 our_paren_pos.col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2514 amount += n * curbuf->b_ind_unclosed_wrapped;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2515 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2516 else if (curbuf->b_ind_unclosed_whiteok)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2517 our_paren_pos.col++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2518 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2519 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2520 col = our_paren_pos.col + 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2521 while (VIM_ISWHITE(l[col]))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2522 col++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2523 if (l[col] != NUL) // In case of trailing space
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2524 our_paren_pos.col = col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2525 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2526 our_paren_pos.col++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2527 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2528 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2529
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2530 // Find how indented the paren is, or the character after it
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2531 // if we did the above "if".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2532 if (our_paren_pos.col > 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2533 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2534 getvcol(curwin, &our_paren_pos, &col, NULL, NULL);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2535 if (cur_amount > (int)col)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2536 cur_amount = col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2537 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2538 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2539
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2540 if (theline[0] == ')' && curbuf->b_ind_matching_paren)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2541 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2542 // Line up with the start of the matching paren line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2543 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2544 else if ((curbuf->b_ind_unclosed == 0 && is_if_for_while == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2545 || (!curbuf->b_ind_unclosed_noignore
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2546 && *look == '(' && ignore_paren_col == 0))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2547 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2548 if (cur_amount != MAXCOL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2549 amount = cur_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2550 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2551 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2552 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2553 // Add b_ind_unclosed2 for each '(' before our matching one,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2554 // but ignore (void) before the line (ignore_paren_col).
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2555 col = our_paren_pos.col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2556 while ((int)our_paren_pos.col > ignore_paren_col)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2557 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2558 --our_paren_pos.col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2559 switch (*ml_get_pos(&our_paren_pos))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2560 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2561 case '(': amount += curbuf->b_ind_unclosed2;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2562 col = our_paren_pos.col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2563 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2564 case ')': amount -= curbuf->b_ind_unclosed2;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2565 col = MAXCOL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2566 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2567 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2568 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2569
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2570 // Use b_ind_unclosed once, when the first '(' is not inside
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2571 // braces
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2572 if (col == MAXCOL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2573 amount += curbuf->b_ind_unclosed;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2574 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2575 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2576 curwin->w_cursor.lnum = our_paren_pos.lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2577 curwin->w_cursor.col = col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2578 if (find_match_paren_after_brace(curbuf->b_ind_maxparen)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2579 != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2580 amount += curbuf->b_ind_unclosed2;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2581 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2582 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2583 if (is_if_for_while)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2584 amount += curbuf->b_ind_if_for_while;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2585 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2586 amount += curbuf->b_ind_unclosed;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2587 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2588 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2589 // For a line starting with ')' use the minimum of the two
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2590 // positions, to avoid giving it more indent than the previous
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2591 // lines:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2592 // func_long_name( if (x
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2593 // arg && yy
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2594 // ) ^ not here ) ^ not here
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2595 if (cur_amount < amount)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2596 amount = cur_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2597 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2598 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2599
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2600 // add extra indent for a comment
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2601 if (cin_iscomment(theline))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2602 amount += curbuf->b_ind_comment;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2603 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2604 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2605 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2606 // We are inside braces, there is a { before this line at the position
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2607 // stored in tryposBrace.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2608 // Make a copy of tryposBrace, it may point to pos_copy inside
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2609 // find_start_brace(), which may be changed somewhere.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2610 tryposCopy = *tryposBrace;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2611 tryposBrace = &tryposCopy;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2612 trypos = tryposBrace;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2613 ourscope = trypos->lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2614 start = ml_get(ourscope);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2615
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2616 // Now figure out how indented the line is in general.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2617 // If the brace was at the start of the line, we use that;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2618 // otherwise, check out the indentation of the line as
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2619 // a whole and then add the "imaginary indent" to that.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2620 look = skipwhite(start);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2621 if (*look == '{')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2622 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2623 getvcol(curwin, trypos, &col, NULL, NULL);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2624 amount = col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2625 if (*start == '{')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2626 start_brace = BRACE_IN_COL0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2627 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2628 start_brace = BRACE_AT_START;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2629 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2630 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2631 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2632 // That opening brace might have been on a continuation
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2633 // line. if so, find the start of the line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2634 curwin->w_cursor.lnum = ourscope;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2635
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2636 // Position the cursor over the rightmost paren, so that
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2637 // matching it will take us back to the start of the line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2638 lnum = ourscope;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2639 if (find_last_paren(start, '(', ')')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2640 && (trypos = find_match_paren(curbuf->b_ind_maxparen))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2641 != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2642 lnum = trypos->lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2643
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2644 // It could have been something like
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2645 // case 1: if (asdf &&
31804
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents: 31667
diff changeset
2646 // condition) {
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2647 // }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2648 if ((curbuf->b_ind_js || curbuf->b_ind_keep_case_label)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2649 && cin_iscase(skipwhite(ml_get_curline()), FALSE))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2650 amount = get_indent();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2651 else if (curbuf->b_ind_js)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2652 amount = get_indent_lnum(lnum);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2653 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2654 amount = skip_label(lnum, &l);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2655
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2656 start_brace = BRACE_AT_END;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2657 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2658
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2659 // For Javascript check if the line starts with "key:".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2660 if (curbuf->b_ind_js)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2661 js_cur_has_key = cin_has_js_key(theline);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2662
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2663 // If we're looking at a closing brace, that's where
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2664 // we want to be. otherwise, add the amount of room
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2665 // that an indent is supposed to be.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2666 if (theline[0] == '}')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2667 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2668 // they may want closing braces to line up with something
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2669 // other than the open brace. indulge them, if so.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2670 amount += curbuf->b_ind_close_extra;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2671 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2672 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2673 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2674 // If we're looking at an "else", try to find an "if"
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2675 // to match it with.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2676 // If we're looking at a "while", try to find a "do"
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2677 // to match it with.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2678 lookfor = LOOKFOR_INITIAL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2679 if (cin_iselse(theline))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2680 lookfor = LOOKFOR_IF;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2681 else if (cin_iswhileofdo(theline, cur_curpos.lnum)) // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2682 lookfor = LOOKFOR_DO;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2683 if (lookfor != LOOKFOR_INITIAL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2684 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2685 curwin->w_cursor.lnum = cur_curpos.lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2686 if (find_match(lookfor, ourscope) == OK)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2687 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2688 amount = get_indent(); // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2689 goto theend;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2690 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2691 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2692
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2693 // We get here if we are not on an "while-of-do" or "else" (or
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2694 // failed to find a matching "if").
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2695 // Search backwards for something to line up with.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2696 // First set amount for when we don't find anything.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2697
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2698 // if the '{' is _really_ at the left margin, use the imaginary
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2699 // location of a left-margin brace. Otherwise, correct the
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2700 // location for b_ind_open_extra.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2701
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2702 if (start_brace == BRACE_IN_COL0) // '{' is in column 0
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2703 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2704 amount = curbuf->b_ind_open_left_imag;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2705 lookfor_cpp_namespace = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2706 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2707 else if (start_brace == BRACE_AT_START &&
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2708 lookfor_cpp_namespace) // '{' is at start
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2709 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2710
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2711 lookfor_cpp_namespace = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2712 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2713 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2714 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2715 if (start_brace == BRACE_AT_END) // '{' is at end of line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2716 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2717 amount += curbuf->b_ind_open_imag;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2718
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2719 l = skipwhite(ml_get_curline());
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2720 if (cin_is_cpp_namespace(l))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2721 amount += curbuf->b_ind_cpp_namespace;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2722 else if (cin_is_cpp_extern_c(l))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2723 amount += curbuf->b_ind_cpp_extern_c;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2724 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2725 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2726 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2727 // Compensate for adding b_ind_open_extra later.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2728 amount -= curbuf->b_ind_open_extra;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2729 if (amount < 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2730 amount = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2731 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2732 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2733
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2734 lookfor_break = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2735
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2736 if (cin_iscase(theline, FALSE)) // it's a switch() label
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2737 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2738 lookfor = LOOKFOR_CASE; // find a previous switch() label
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2739 amount += curbuf->b_ind_case;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2740 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2741 else if (cin_isscopedecl(theline)) // private:, ...
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2742 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2743 lookfor = LOOKFOR_SCOPEDECL; // class decl is this block
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2744 amount += curbuf->b_ind_scopedecl;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2745 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2746 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2747 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2748 if (curbuf->b_ind_case_break && cin_isbreak(theline))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2749 // break; ...
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2750 lookfor_break = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2751
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2752 lookfor = LOOKFOR_INITIAL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2753 // b_ind_level from start of block
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2754 amount += curbuf->b_ind_level;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2755 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2756 scope_amount = amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2757 whilelevel = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2758
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2759 // Search backwards. If we find something we recognize, line up
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2760 // with that.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2761 //
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2762 // If we're looking at an open brace, indent
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2763 // the usual amount relative to the conditional
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2764 // that opens the block.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2765 curwin->w_cursor = cur_curpos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2766 for (;;)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2767 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2768 curwin->w_cursor.lnum--;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2769 curwin->w_cursor.col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2770
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2771 // If we went all the way back to the start of our scope, line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2772 // up with it.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2773 if (curwin->w_cursor.lnum <= ourscope)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2774 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2775 // We reached end of scope:
18498
9e6d5a4abb1c patch 8.1.2243: typos in comments
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
2776 // If looking for an enum or structure initialization
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2777 // go further back:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2778 // If it is an initializer (enum xxx or xxx =), then
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2779 // don't add ind_continuation, otherwise it is a variable
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2780 // declaration:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2781 // int x,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2782 // here; <-- add ind_continuation
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2783 if (lookfor == LOOKFOR_ENUM_OR_INIT)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2784 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2785 if (curwin->w_cursor.lnum == 0
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2786 || curwin->w_cursor.lnum
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2787 < ourscope - curbuf->b_ind_maxparen)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2788 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2789 // nothing found (abuse curbuf->b_ind_maxparen as
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2790 // limit) assume terminated line (i.e. a variable
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2791 // initialization)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2792 if (cont_amount > 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2793 amount = cont_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2794 else if (!curbuf->b_ind_js)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2795 amount += ind_continuation;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2796 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2797 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2798
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2799 // If we're in a comment or raw string now, skip to
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2800 // the start of it.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2801 trypos = ind_find_start_CORS(NULL);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2802 if (trypos != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2803 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2804 curwin->w_cursor.lnum = trypos->lnum + 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2805 curwin->w_cursor.col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2806 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2807 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2808
29340
fba9e366ced4 patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents: 28942
diff changeset
2809 l = ml_get_curline();
fba9e366ced4 patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents: 28942
diff changeset
2810
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2811 // Skip preprocessor directives and blank lines.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2812 if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2813 &amount))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2814 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2815
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2816 if (cin_nocode(l))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2817 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2818
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2819 terminated = cin_isterminated(l, FALSE, TRUE);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2820
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2821 // If we are at top level and the line looks like a
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2822 // function declaration, we are done
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2823 // (it's a variable declaration).
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2824 if (start_brace != BRACE_IN_COL0
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2825 || !cin_isfuncdecl(&l, curwin->w_cursor.lnum, 0))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2826 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2827 // if the line is terminated with another ','
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2828 // it is a continued variable initialization.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2829 // don't add extra indent.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2830 // TODO: does not work, if a function
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2831 // declaration is split over multiple lines:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2832 // cin_isfuncdecl returns FALSE then.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2833 if (terminated == ',')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2834 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2835
18498
9e6d5a4abb1c patch 8.1.2243: typos in comments
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
2836 // if it is an enum declaration or an assignment,
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2837 // we are done.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2838 if (terminated != ';' && cin_isinit())
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2839 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2840
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2841 // nothing useful found
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2842 if (terminated == 0 || terminated == '{')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2843 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2844 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2845
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2846 if (terminated != ';')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2847 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2848 // Skip parens and braces. Position the cursor
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2849 // over the rightmost paren, so that matching it
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2850 // will take us back to the start of the line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2851 // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2852 trypos = NULL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2853 if (find_last_paren(l, '(', ')'))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2854 trypos = find_match_paren(
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2855 curbuf->b_ind_maxparen);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2856
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2857 if (trypos == NULL && find_last_paren(l, '{', '}'))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2858 trypos = find_start_brace();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2859
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2860 if (trypos != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2861 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2862 curwin->w_cursor.lnum = trypos->lnum + 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2863 curwin->w_cursor.col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2864 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2865 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2866 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2867
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2868 // it's a variable declaration, add indentation
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2869 // like in
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2870 // int a,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2871 // b;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2872 if (cont_amount > 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2873 amount = cont_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2874 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2875 amount += ind_continuation;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2876 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2877 else if (lookfor == LOOKFOR_UNTERM)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2878 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2879 if (cont_amount > 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2880 amount = cont_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2881 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2882 amount += ind_continuation;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2883 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2884 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2885 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2886 if (lookfor != LOOKFOR_TERM
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2887 && lookfor != LOOKFOR_CPP_BASECLASS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2888 && lookfor != LOOKFOR_COMMA)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2889 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2890 amount = scope_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2891 if (theline[0] == '{')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2892 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2893 amount += curbuf->b_ind_open_extra;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2894 added_to_amount = curbuf->b_ind_open_extra;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2895 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2896 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2897
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2898 if (lookfor_cpp_namespace)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2899 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2900 // Looking for C++ namespace, need to look further
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2901 // back.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2902 if (curwin->w_cursor.lnum == ourscope)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2903 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2904
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2905 if (curwin->w_cursor.lnum == 0
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2906 || curwin->w_cursor.lnum
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2907 < ourscope - FIND_NAMESPACE_LIM)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2908 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2909
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2910 // If we're in a comment or raw string now, skip
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2911 // to the start of it.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2912 trypos = ind_find_start_CORS(NULL);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2913 if (trypos != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2914 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2915 curwin->w_cursor.lnum = trypos->lnum + 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2916 curwin->w_cursor.col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2917 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2918 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2919
29340
fba9e366ced4 patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents: 28942
diff changeset
2920 l = ml_get_curline();
fba9e366ced4 patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents: 28942
diff changeset
2921
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2922 // Skip preprocessor directives and blank lines.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2923 if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2924 &amount))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2925 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2926
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2927 // Finally the actual check for "namespace".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2928 if (cin_is_cpp_namespace(l))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2929 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2930 amount += curbuf->b_ind_cpp_namespace
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2931 - added_to_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2932 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2933 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2934 else if (cin_is_cpp_extern_c(l))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2935 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2936 amount += curbuf->b_ind_cpp_extern_c
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2937 - added_to_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2938 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2939 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2940
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2941 if (cin_nocode(l))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2942 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2943 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2944 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2945 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2946 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2947
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2948 // If we're in a comment or raw string now, skip to the start
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2949 // of it. XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2950 if ((trypos = ind_find_start_CORS(&raw_string_start)) != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2951 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2952 curwin->w_cursor.lnum = trypos->lnum + 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2953 curwin->w_cursor.col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2954 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2955 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2956
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2957 l = ml_get_curline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2958
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2959 // If this is a switch() label, may line up relative to that.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2960 // If this is a C++ scope declaration, do the same.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2961 iscase = cin_iscase(l, FALSE);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2962 if (iscase || cin_isscopedecl(l))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2963 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2964 // we are only looking for cpp base class
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2965 // declaration/initialization any longer
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2966 if (lookfor == LOOKFOR_CPP_BASECLASS)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2967 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2968
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2969 // When looking for a "do" we are not interested in
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2970 // labels.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2971 if (whilelevel > 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2972 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2973
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2974 // case xx:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2975 // c = 99 + <- this indent plus continuation
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2976 //-> here;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2977 if (lookfor == LOOKFOR_UNTERM
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2978 || lookfor == LOOKFOR_ENUM_OR_INIT)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2979 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2980 if (cont_amount > 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2981 amount = cont_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2982 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2983 amount += ind_continuation;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2984 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2985 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2986
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2987 // case xx: <- line up with this case
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2988 // x = 333;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2989 // case yy:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2990 if ( (iscase && lookfor == LOOKFOR_CASE)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2991 || (iscase && lookfor_break)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2992 || (!iscase && lookfor == LOOKFOR_SCOPEDECL))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2993 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2994 // Check that this case label is not for another
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2995 // switch() XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2996 if ((trypos = find_start_brace()) == NULL
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2997 || trypos->lnum == ourscope)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2998 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2999 amount = get_indent(); // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3000 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3001 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3002 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3003 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3004
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3005 n = get_indent_nolabel(curwin->w_cursor.lnum); // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3006
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3007 // case xx: if (cond) <- line up with this if
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3008 // y = y + 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3009 // -> s = 99;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3010 //
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3011 // case xx:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3012 // if (cond) <- line up with this line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3013 // y = y + 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3014 // -> s = 99;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3015 if (lookfor == LOOKFOR_TERM)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3016 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3017 if (n)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3018 amount = n;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3019
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3020 if (!lookfor_break)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3021 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3022 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3023
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3024 // case xx: x = x + 1; <- line up with this x
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3025 // -> y = y + 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3026 //
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3027 // case xx: if (cond) <- line up with this if
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3028 // -> y = y + 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3029 if (n)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3030 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3031 amount = n;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3032 l = after_label(ml_get_curline());
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3033 if (l != NULL && cin_is_cinword(l))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3034 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3035 if (theline[0] == '{')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3036 amount += curbuf->b_ind_open_extra;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3037 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3038 amount += curbuf->b_ind_level
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3039 + curbuf->b_ind_no_brace;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3040 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3041 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3042 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3043
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3044 // Try to get the indent of a statement before the switch
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3045 // label. If nothing is found, line up relative to the
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3046 // switch label.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3047 // break; <- may line up with this line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3048 // case xx:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3049 // -> y = 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3050 scope_amount = get_indent() + (iscase // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3051 ? curbuf->b_ind_case_code
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3052 : curbuf->b_ind_scopedecl_code);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3053 lookfor = curbuf->b_ind_case_break
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3054 ? LOOKFOR_NOBREAK : LOOKFOR_ANY;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3055 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3056 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3057
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3058 // Looking for a switch() label or C++ scope declaration,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3059 // ignore other lines, skip {}-blocks.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3060 if (lookfor == LOOKFOR_CASE || lookfor == LOOKFOR_SCOPEDECL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3061 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3062 if (find_last_paren(l, '{', '}')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3063 && (trypos = find_start_brace()) != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3064 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3065 curwin->w_cursor.lnum = trypos->lnum + 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3066 curwin->w_cursor.col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3067 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3068 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3069 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3070
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3071 // Ignore jump labels with nothing after them.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3072 if (!curbuf->b_ind_js && cin_islabel())
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3073 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3074 l = after_label(ml_get_curline());
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3075 if (l == NULL || cin_nocode(l))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3076 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3077 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3078
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3079 // Ignore #defines, #if, etc.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3080 // Ignore comment and empty lines.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3081 // (need to get the line again, cin_islabel() may have
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3082 // unlocked it)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3083 l = ml_get_curline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3084 if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum, &amount)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3085 || cin_nocode(l))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3086 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3087
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3088 // Are we at the start of a cpp base class declaration or
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3089 // constructor initialization? XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3090 n = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3091 if (lookfor != LOOKFOR_TERM && curbuf->b_ind_cpp_baseclass > 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3092 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3093 n = cin_is_cpp_baseclass(&cache_cpp_baseclass);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3094 l = ml_get_curline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3095 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3096 if (n)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3097 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3098 if (lookfor == LOOKFOR_UNTERM)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3099 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3100 if (cont_amount > 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3101 amount = cont_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3102 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3103 amount += ind_continuation;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3104 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3105 else if (theline[0] == '{')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3106 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3107 // Need to find start of the declaration.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3108 lookfor = LOOKFOR_UNTERM;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3109 ind_continuation = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3110 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3111 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3112 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3113 // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3114 amount = get_baseclass_amount(
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3115 cache_cpp_baseclass.lpos.col);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3116 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3117 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3118 else if (lookfor == LOOKFOR_CPP_BASECLASS)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3119 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3120 // only look, whether there is a cpp base class
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3121 // declaration or initialization before the opening brace.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3122 if (cin_isterminated(l, TRUE, FALSE))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3123 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3124 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3125 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3126 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3127
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3128 // What happens next depends on the line being terminated.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3129 // If terminated with a ',' only consider it terminating if
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3130 // there is another unterminated statement behind, eg:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3131 // 123,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3132 // sizeof
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3133 // here
18498
9e6d5a4abb1c patch 8.1.2243: typos in comments
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
3134 // Otherwise check whether it is an enumeration or structure
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3135 // initialisation (not indented) or a variable declaration
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3136 // (indented).
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3137 terminated = cin_isterminated(l, FALSE, TRUE);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3138
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3139 if (js_cur_has_key)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3140 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3141 js_cur_has_key = 0; // only check the first line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3142 if (curbuf->b_ind_js && terminated == ',')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3143 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3144 // For Javascript we might be inside an object:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3145 // key: something, <- align with this
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3146 // key: something
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3147 // or:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3148 // key: something + <- align with this
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3149 // something,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3150 // key: something
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3151 lookfor = LOOKFOR_JS_KEY;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3152 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3153 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3154 if (lookfor == LOOKFOR_JS_KEY && cin_has_js_key(l))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3155 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3156 amount = get_indent();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3157 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3158 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3159 if (lookfor == LOOKFOR_COMMA)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3160 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3161 if (tryposBrace != NULL && tryposBrace->lnum
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3162 >= curwin->w_cursor.lnum)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3163 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3164 if (terminated == ',')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3165 // line below current line is the one that starts a
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3166 // (possibly broken) line ending in a comma.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3167 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3168 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3169 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3170 amount = get_indent();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3171 if (curwin->w_cursor.lnum - 1 == ourscope)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3172 // line above is start of the scope, thus current
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3173 // line is the one that stars a (possibly broken)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3174 // line ending in a comma.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3175 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3176 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3177 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3178
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3179 if (terminated == 0 || (lookfor != LOOKFOR_UNTERM
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3180 && terminated == ','))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3181 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3182 if (lookfor != LOOKFOR_ENUM_OR_INIT &&
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3183 (*skipwhite(l) == '[' || l[STRLEN(l) - 1] == '['))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3184 amount += ind_continuation;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3185 // if we're in the middle of a paren thing,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3186 // go back to the line that starts it so
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3187 // we can get the right prevailing indent
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3188 // if ( foo &&
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3189 // bar )
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3190
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3191 // Position the cursor over the rightmost paren, so that
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3192 // matching it will take us back to the start of the line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3193 // Ignore a match before the start of the block.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3194 (void)find_last_paren(l, '(', ')');
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3195 trypos = find_match_paren(corr_ind_maxparen(&cur_curpos));
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3196 if (trypos != NULL && (trypos->lnum < tryposBrace->lnum
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3197 || (trypos->lnum == tryposBrace->lnum
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3198 && trypos->col < tryposBrace->col)))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3199 trypos = NULL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3200
29340
fba9e366ced4 patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents: 28942
diff changeset
3201 l = ml_get_curline();
fba9e366ced4 patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents: 28942
diff changeset
3202
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3203 // If we are looking for ',', we also look for matching
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3204 // braces.
29340
fba9e366ced4 patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents: 28942
diff changeset
3205 if (trypos == NULL && terminated == ',')
fba9e366ced4 patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents: 28942
diff changeset
3206 {
fba9e366ced4 patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents: 28942
diff changeset
3207 if (find_last_paren(l, '{', '}'))
fba9e366ced4 patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents: 28942
diff changeset
3208 trypos = find_start_brace();
fba9e366ced4 patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents: 28942
diff changeset
3209 l = ml_get_curline();
fba9e366ced4 patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents: 28942
diff changeset
3210 }
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3211
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3212 if (trypos != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3213 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3214 // Check if we are on a case label now. This is
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3215 // handled above.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3216 // case xx: if ( asdf &&
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3217 // asdf)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3218 curwin->w_cursor = *trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3219 l = ml_get_curline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3220 if (cin_iscase(l, FALSE) || cin_isscopedecl(l))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3221 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3222 ++curwin->w_cursor.lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3223 curwin->w_cursor.col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3224 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3225 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3226 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3227
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3228 // Skip over continuation lines to find the one to get the
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3229 // indent from
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3230 // char *usethis = "bla{backslash}
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3231 // bla",
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3232 // here;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3233 if (terminated == ',')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3234 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3235 while (curwin->w_cursor.lnum > 1)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3236 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3237 l = ml_get(curwin->w_cursor.lnum - 1);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3238 if (*l == NUL || l[STRLEN(l) - 1] != '\\')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3239 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3240 --curwin->w_cursor.lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3241 curwin->w_cursor.col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3242 }
29340
fba9e366ced4 patch 9.0.0013: reproducing memory access errors can be difficult
Bram Moolenaar <Bram@vim.org>
parents: 28942
diff changeset
3243 l = ml_get_curline();
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3244 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3245
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3246 // Get indent and pointer to text for current line,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3247 // ignoring any jump label. XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3248 if (curbuf->b_ind_js)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3249 cur_amount = get_indent();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3250 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3251 cur_amount = skip_label(curwin->w_cursor.lnum, &l);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3252 // If this is just above the line we are indenting, and it
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3253 // starts with a '{', line it up with this line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3254 // while (not)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3255 // -> {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3256 // }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3257 if (terminated != ',' && lookfor != LOOKFOR_TERM
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3258 && theline[0] == '{')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3259 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3260 amount = cur_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3261 // Only add b_ind_open_extra when the current line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3262 // doesn't start with a '{', which must have a match
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3263 // in the same line (scope is the same). Probably:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3264 // { 1, 2 },
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3265 // -> { 3, 4 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3266 if (*skipwhite(l) != '{')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3267 amount += curbuf->b_ind_open_extra;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3268
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3269 if (curbuf->b_ind_cpp_baseclass && !curbuf->b_ind_js)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3270 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3271 // have to look back, whether it is a cpp base
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3272 // class declaration or initialization
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3273 lookfor = LOOKFOR_CPP_BASECLASS;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3274 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3275 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3276 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3277 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3278
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3279 // Check if we are after an "if", "while", etc.
31804
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents: 31667
diff changeset
3280 // Also allow "} else".
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3281 if (cin_is_cinword(l) || cin_iselse(skipwhite(l)))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3282 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3283 // Found an unterminated line after an if (), line up
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3284 // with the last one.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3285 // if (cond)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3286 // 100 +
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3287 // -> here;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3288 if (lookfor == LOOKFOR_UNTERM
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3289 || lookfor == LOOKFOR_ENUM_OR_INIT)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3290 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3291 if (cont_amount > 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3292 amount = cont_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3293 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3294 amount += ind_continuation;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3295 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3296 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3297
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3298 // If this is just above the line we are indenting, we
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3299 // are finished.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3300 // while (not)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3301 // -> here;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3302 // Otherwise this indent can be used when the line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3303 // before this is terminated.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3304 // yyy;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3305 // if (stat)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3306 // while (not)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3307 // xxx;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3308 // -> here;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3309 amount = cur_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3310 if (theline[0] == '{')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3311 amount += curbuf->b_ind_open_extra;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3312 if (lookfor != LOOKFOR_TERM)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3313 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3314 amount += curbuf->b_ind_level
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3315 + curbuf->b_ind_no_brace;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3316 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3317 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3318
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3319 // Special trick: when expecting the while () after a
32395
2ed95122d59c patch 9.0.1529: code style test doesn't check for space after "if"
Bram Moolenaar <Bram@vim.org>
parents: 32190
diff changeset
3320 // do, line up with the while ()
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3321 // do
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3322 // x = 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3323 // -> here
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3324 l = skipwhite(ml_get_curline());
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3325 if (cin_isdo(l))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3326 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3327 if (whilelevel == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3328 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3329 --whilelevel;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3330 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3331
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3332 // When searching for a terminated line, don't use the
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3333 // one between the "if" and the matching "else".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3334 // Need to use the scope of this "else". XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3335 // If whilelevel != 0 continue looking for a "do {".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3336 if (cin_iselse(l) && whilelevel == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3337 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3338 // If we're looking at "} else", let's make sure we
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3339 // find the opening brace of the enclosing scope,
31804
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents: 31667
diff changeset
3340 // not the one from "if (condition) {".
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3341 if (*l == '}')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3342 curwin->w_cursor.col =
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3343 (colnr_T)(l - ml_get_curline()) + 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3344
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3345 if ((trypos = find_start_brace()) == NULL
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3346 || find_match(LOOKFOR_IF, trypos->lnum)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3347 == FAIL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3348 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3349 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3350 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3351
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3352 // If we're below an unterminated line that is not an
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3353 // "if" or something, we may line up with this line or
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3354 // add something for a continuation line, depending on
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3355 // the line before this one.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3356 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3357 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3358 // Found two unterminated lines on a row, line up with
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3359 // the last one.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3360 // c = 99 +
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3361 // 100 +
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3362 // -> here;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3363 if (lookfor == LOOKFOR_UNTERM)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3364 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3365 // When line ends in a comma add extra indent
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3366 if (terminated == ',')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3367 amount += ind_continuation;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3368 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3369 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3370
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3371 if (lookfor == LOOKFOR_ENUM_OR_INIT)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3372 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3373 // Found two lines ending in ',', lineup with the
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3374 // lowest one, but check for cpp base class
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3375 // declaration/initialization, if it is an
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3376 // opening brace or we are looking just for
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3377 // enumerations/initializations.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3378 if (terminated == ',')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3379 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3380 if (curbuf->b_ind_cpp_baseclass == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3381 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3382
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3383 lookfor = LOOKFOR_CPP_BASECLASS;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3384 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3385 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3386
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3387 // Ignore unterminated lines in between, but
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3388 // reduce indent.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3389 if (amount > cur_amount)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3390 amount = cur_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3391 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3392 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3393 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3394 // Found first unterminated line on a row, may
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3395 // line up with this line, remember its indent
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3396 // 100 +
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3397 // -> here;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3398 l = ml_get_curline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3399 amount = cur_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3400
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3401 n = (int)STRLEN(l);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3402 if (terminated == ',' && (*skipwhite(l) == ']'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3403 || (n >=2 && l[n - 2] == ']')))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3404 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3405
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3406 // If previous line ends in ',', check whether we
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3407 // are in an initialization or enum
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3408 // struct xxx =
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3409 // {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3410 // sizeof a,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3411 // 124 };
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3412 // or a normal possible continuation line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3413 // but only, of no other statement has been found
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3414 // yet.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3415 if (lookfor == LOOKFOR_INITIAL && terminated == ',')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3416 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3417 if (curbuf->b_ind_js)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3418 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3419 // Search for a line ending in a comma
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3420 // and line up with the line below it
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3421 // (could be the current line).
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3422 // some = [
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3423 // 1, <- line up here
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3424 // 2,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3425 // some = [
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3426 // 3 + <- line up here
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3427 // 4 *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3428 // 5,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3429 // 6,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3430 if (cin_iscomment(skipwhite(l)))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3431 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3432 lookfor = LOOKFOR_COMMA;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3433 trypos = find_match_char('[',
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3434 curbuf->b_ind_maxparen);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3435 if (trypos != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3436 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3437 if (trypos->lnum
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3438 == curwin->w_cursor.lnum - 1)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3439 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3440 // Current line is first inside
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3441 // [], line up with it.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3442 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3443 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3444 ourscope = trypos->lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3445 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3446 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3447 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3448 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3449 lookfor = LOOKFOR_ENUM_OR_INIT;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3450 cont_amount = cin_first_id_amount();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3451 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3452 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3453 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3454 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3455 if (lookfor == LOOKFOR_INITIAL
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3456 && *l != NUL
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3457 && l[STRLEN(l) - 1] == '\\')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3458 // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3459 cont_amount = cin_get_equal_amount(
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3460 curwin->w_cursor.lnum);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3461 if (lookfor != LOOKFOR_TERM
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3462 && lookfor != LOOKFOR_JS_KEY
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3463 && lookfor != LOOKFOR_COMMA
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3464 && raw_string_start != curwin->w_cursor.lnum)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3465 lookfor = LOOKFOR_UNTERM;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3466 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3467 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3468 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3469 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3470
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3471 // Check if we are after a while (cond);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3472 // If so: Ignore until the matching "do".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3473 else if (cin_iswhileofdo_end(terminated)) // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3474 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3475 // Found an unterminated line after a while ();, line up
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3476 // with the last one.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3477 // while (cond);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3478 // 100 + <- line up with this one
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3479 // -> here;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3480 if (lookfor == LOOKFOR_UNTERM
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3481 || lookfor == LOOKFOR_ENUM_OR_INIT)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3482 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3483 if (cont_amount > 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3484 amount = cont_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3485 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3486 amount += ind_continuation;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3487 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3488 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3489
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3490 if (whilelevel == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3491 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3492 lookfor = LOOKFOR_TERM;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3493 amount = get_indent(); // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3494 if (theline[0] == '{')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3495 amount += curbuf->b_ind_open_extra;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3496 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3497 ++whilelevel;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3498 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3499
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3500 // We are after a "normal" statement.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3501 // If we had another statement we can stop now and use the
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3502 // indent of that other statement.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3503 // Otherwise the indent of the current statement may be used,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3504 // search backwards for the next "normal" statement.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3505 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3506 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3507 // Skip single break line, if before a switch label. It
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3508 // may be lined up with the case label.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3509 if (lookfor == LOOKFOR_NOBREAK
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3510 && cin_isbreak(skipwhite(ml_get_curline())))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3511 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3512 lookfor = LOOKFOR_ANY;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3513 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3514 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3515
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3516 // Handle "do {" line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3517 if (whilelevel > 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3518 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3519 l = cin_skipcomment(ml_get_curline());
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3520 if (cin_isdo(l))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3521 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3522 amount = get_indent(); // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3523 --whilelevel;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3524 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3525 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3526 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3527
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3528 // Found a terminated line above an unterminated line. Add
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3529 // the amount for a continuation line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3530 // x = 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3531 // y = foo +
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3532 // -> here;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3533 // or
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3534 // int x = 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3535 // int foo,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3536 // -> here;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3537 if (lookfor == LOOKFOR_UNTERM
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3538 || lookfor == LOOKFOR_ENUM_OR_INIT)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3539 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3540 if (cont_amount > 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3541 amount = cont_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3542 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3543 amount += ind_continuation;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3544 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3545 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3546
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3547 // Found a terminated line above a terminated line or "if"
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3548 // etc. line. Use the amount of the line below us.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3549 // x = 1; x = 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3550 // if (asdf) y = 2;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3551 // while (asdf) ->here;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3552 // here;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3553 // ->foo;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3554 if (lookfor == LOOKFOR_TERM)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3555 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3556 if (!lookfor_break && whilelevel == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3557 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3558 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3559
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3560 // First line above the one we're indenting is terminated.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3561 // To know what needs to be done look further backward for
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3562 // a terminated line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3563 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3564 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3565 // position the cursor over the rightmost paren, so
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3566 // that matching it will take us back to the start of
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3567 // the line. Helps for:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3568 // func(asdr,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3569 // asdfasdf);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3570 // here;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3571 term_again:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3572 l = ml_get_curline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3573 if (find_last_paren(l, '(', ')')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3574 && (trypos = find_match_paren(
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3575 curbuf->b_ind_maxparen)) != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3576 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3577 // Check if we are on a case label now. This is
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3578 // handled above.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3579 // case xx: if ( asdf &&
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3580 // asdf)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3581 curwin->w_cursor = *trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3582 l = ml_get_curline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3583 if (cin_iscase(l, FALSE) || cin_isscopedecl(l))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3584 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3585 ++curwin->w_cursor.lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3586 curwin->w_cursor.col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3587 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3588 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3589 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3590
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3591 // When aligning with the case statement, don't align
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3592 // with a statement after it.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3593 // case 1: { <-- don't use this { position
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3594 // stat;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3595 // }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3596 // case 2:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3597 // stat;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3598 // }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3599 iscase = (curbuf->b_ind_keep_case_label
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3600 && cin_iscase(l, FALSE));
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3601
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3602 // Get indent and pointer to text for current line,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3603 // ignoring any jump label.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3604 amount = skip_label(curwin->w_cursor.lnum, &l);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3605
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3606 if (theline[0] == '{')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3607 amount += curbuf->b_ind_open_extra;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3608 // See remark above: "Only add b_ind_open_extra.."
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3609 l = skipwhite(l);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3610 if (*l == '{')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3611 amount -= curbuf->b_ind_open_extra;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3612 lookfor = iscase ? LOOKFOR_ANY : LOOKFOR_TERM;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3613
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3614 // When a terminated line starts with "else" skip to
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3615 // the matching "if":
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3616 // else 3;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3617 // indent this;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3618 // Need to use the scope of this "else". XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3619 // If whilelevel != 0 continue looking for a "do {".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3620 if (lookfor == LOOKFOR_TERM
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3621 && *l != '}'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3622 && cin_iselse(l)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3623 && whilelevel == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3624 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3625 if ((trypos = find_start_brace()) == NULL
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3626 || find_match(LOOKFOR_IF, trypos->lnum)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3627 == FAIL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3628 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3629 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3630 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3631
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3632 // If we're at the end of a block, skip to the start of
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3633 // that block.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3634 l = ml_get_curline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3635 if (find_last_paren(l, '{', '}') // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3636 && (trypos = find_start_brace()) != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3637 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3638 curwin->w_cursor = *trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3639 // if not "else {" check for terminated again
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3640 // but skip block for "} else {"
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3641 l = cin_skipcomment(ml_get_curline());
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3642 if (*l == '}' || !cin_iselse(l))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3643 goto term_again;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3644 ++curwin->w_cursor.lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3645 curwin->w_cursor.col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3646 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3647 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3648 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3649 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3650 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3651 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3652
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3653 // add extra indent for a comment
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3654 if (cin_iscomment(theline))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3655 amount += curbuf->b_ind_comment;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3656
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3657 // subtract extra left-shift for jump labels
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3658 if (curbuf->b_ind_jump_label > 0 && original_line_islabel)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3659 amount -= curbuf->b_ind_jump_label;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3660
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3661 goto theend;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3662 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3663
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3664 // ok -- we're not inside any sort of structure at all!
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3665 //
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3666 // This means we're at the top level, and everything should
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3667 // basically just match where the previous line is, except
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3668 // for the lines immediately following a function declaration,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3669 // which are K&R-style parameters and need to be indented.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3670 //
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3671 // if our line starts with an open brace, forget about any
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3672 // prevailing indent and make sure it looks like the start
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3673 // of a function
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3674
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3675 if (theline[0] == '{')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3676 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3677 amount = curbuf->b_ind_first_open;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3678 goto theend;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3679 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3680
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3681 // If the NEXT line is a function declaration, the current
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3682 // line needs to be indented as a function type spec.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3683 // Don't do this if the current line looks like a comment or if the
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3684 // current line is terminated, ie. ends in ';', or if the current line
31804
50555279168b patch 9.0.1234: the code style has to be checked manually
Bram Moolenaar <Bram@vim.org>
parents: 31667
diff changeset
3685 // contains { or }: "void f(condition) {\n if (1)"
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3686 if (cur_curpos.lnum < curbuf->b_ml.ml_line_count
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3687 && !cin_nocode(theline)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3688 && vim_strchr(theline, '{') == NULL
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3689 && vim_strchr(theline, '}') == NULL
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3690 && !cin_ends_in(theline, (char_u *)":", NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3691 && !cin_ends_in(theline, (char_u *)",", NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3692 && cin_isfuncdecl(NULL, cur_curpos.lnum + 1,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3693 cur_curpos.lnum + 1)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3694 && !cin_isterminated(theline, FALSE, TRUE))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3695 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3696 amount = curbuf->b_ind_func_type;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3697 goto theend;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3698 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3699
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3700 // search backwards until we find something we recognize
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3701 amount = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3702 curwin->w_cursor = cur_curpos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3703 while (curwin->w_cursor.lnum > 1)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3704 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3705 curwin->w_cursor.lnum--;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3706 curwin->w_cursor.col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3707
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3708 l = ml_get_curline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3709
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3710 // If we're in a comment or raw string now, skip to the start
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3711 // of it. XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3712 if ((trypos = ind_find_start_CORS(NULL)) != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3713 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3714 curwin->w_cursor.lnum = trypos->lnum + 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3715 curwin->w_cursor.col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3716 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3717 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3718
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3719 // Are we at the start of a cpp base class declaration or
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3720 // constructor initialization? XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3721 n = FALSE;
29507
d3058719eff5 patch 9.0.0095: conditions are always true
Bram Moolenaar <Bram@vim.org>
parents: 29340
diff changeset
3722 if (curbuf->b_ind_cpp_baseclass != 0)
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3723 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3724 n = cin_is_cpp_baseclass(&cache_cpp_baseclass);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3725 l = ml_get_curline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3726 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3727 if (n)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3728 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3729 // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3730 amount = get_baseclass_amount(cache_cpp_baseclass.lpos.col);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3731 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3732 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3733
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3734 // Skip preprocessor directives and blank lines.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3735 if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum, &amount))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3736 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3737
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3738 if (cin_nocode(l))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3739 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3740
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3741 // If the previous line ends in ',', use one level of
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3742 // indentation:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3743 // int foo,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3744 // bar;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3745 // do this before checking for '}' in case of eg.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3746 // enum foobar
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3747 // {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3748 // ...
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3749 // } foo,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3750 // bar;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3751 n = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3752 if (cin_ends_in(l, (char_u *)",", NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3753 || (*l != NUL && (n = l[STRLEN(l) - 1]) == '\\'))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3754 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3755 // take us back to opening paren
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3756 if (find_last_paren(l, '(', ')')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3757 && (trypos = find_match_paren(
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3758 curbuf->b_ind_maxparen)) != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3759 curwin->w_cursor = *trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3760
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3761 // For a line ending in ',' that is a continuation line go
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3762 // back to the first line with a backslash:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3763 // char *foo = "bla{backslash}
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3764 // bla",
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3765 // here;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3766 while (n == 0 && curwin->w_cursor.lnum > 1)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3767 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3768 l = ml_get(curwin->w_cursor.lnum - 1);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3769 if (*l == NUL || l[STRLEN(l) - 1] != '\\')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3770 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3771 --curwin->w_cursor.lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3772 curwin->w_cursor.col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3773 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3774
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3775 amount = get_indent(); // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3776
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3777 if (amount == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3778 amount = cin_first_id_amount();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3779 if (amount == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3780 amount = ind_continuation;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3781 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3782 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3783
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3784 // If the line looks like a function declaration, and we're
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3785 // not in a comment, put it the left margin.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3786 if (cin_isfuncdecl(NULL, cur_curpos.lnum, 0)) // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3787 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3788 l = ml_get_curline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3789
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3790 // Finding the closing '}' of a previous function. Put
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3791 // current line at the left margin. For when 'cino' has "fs".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3792 if (*skipwhite(l) == '}')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3793 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3794
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3795 // (matching {)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3796 // If the previous line ends on '};' (maybe followed by
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3797 // comments) align at column 0. For example:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3798 // char *string_array[] = { "foo",
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3799 // / * x * / "b};ar" }; / * foobar * /
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3800 if (cin_ends_in(l, (char_u *)"};", NULL))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3801 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3802
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3803 // If the previous line ends on '[' we are probably in an
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3804 // array constant:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3805 // something = [
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3806 // 234, <- extra indent
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3807 if (cin_ends_in(l, (char_u *)"[", NULL))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3808 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3809 amount = get_indent() + ind_continuation;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3810 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3811 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3812
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3813 // Find a line only has a semicolon that belongs to a previous
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3814 // line ending in '}', e.g. before an #endif. Don't increase
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3815 // indent then.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3816 if (*(look = skipwhite(l)) == ';' && cin_nocode(look + 1))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3817 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3818 pos_T curpos_save = curwin->w_cursor;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3819
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3820 while (curwin->w_cursor.lnum > 1)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3821 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3822 look = ml_get(--curwin->w_cursor.lnum);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3823 if (!(cin_nocode(look) || cin_ispreproc_cont(
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3824 &look, &curwin->w_cursor.lnum, &amount)))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3825 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3826 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3827 if (curwin->w_cursor.lnum > 0
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3828 && cin_ends_in(look, (char_u *)"}", NULL))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3829 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3830
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3831 curwin->w_cursor = curpos_save;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3832 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3833
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3834 // If the PREVIOUS line is a function declaration, the current
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3835 // line (and the ones that follow) needs to be indented as
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3836 // parameters.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3837 if (cin_isfuncdecl(&l, curwin->w_cursor.lnum, 0))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3838 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3839 amount = curbuf->b_ind_param;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3840 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3841 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3842
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3843 // If the previous line ends in ';' and the line before the
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3844 // previous line ends in ',' or '\', ident to column zero:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3845 // int foo,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3846 // bar;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3847 // indent_to_0 here;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3848 if (cin_ends_in(l, (char_u *)";", NULL))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3849 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3850 l = ml_get(curwin->w_cursor.lnum - 1);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3851 if (cin_ends_in(l, (char_u *)",", NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3852 || (*l != NUL && l[STRLEN(l) - 1] == '\\'))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3853 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3854 l = ml_get_curline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3855 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3856
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3857 // Doesn't look like anything interesting -- so just
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3858 // use the indent of this line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3859 //
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3860 // Position the cursor over the rightmost paren, so that
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3861 // matching it will take us back to the start of the line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3862 find_last_paren(l, '(', ')');
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3863
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3864 if ((trypos = find_match_paren(curbuf->b_ind_maxparen)) != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3865 curwin->w_cursor = *trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3866 amount = get_indent(); // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3867 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3868 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3869
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3870 // add extra indent for a comment
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3871 if (cin_iscomment(theline))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3872 amount += curbuf->b_ind_comment;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3873
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3874 // add extra indent if the previous line ended in a backslash:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3875 // "asdfasdf{backslash}
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3876 // here";
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3877 // char *foo = "asdf{backslash}
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3878 // here";
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3879 if (cur_curpos.lnum > 1)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3880 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3881 l = ml_get(cur_curpos.lnum - 1);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3882 if (*l != NUL && l[STRLEN(l) - 1] == '\\')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3883 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3884 cur_amount = cin_get_equal_amount(cur_curpos.lnum - 1);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3885 if (cur_amount > 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3886 amount = cur_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3887 else if (cur_amount == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3888 amount += ind_continuation;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3889 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3890 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3891
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3892 theend:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3893 if (amount < 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3894 amount = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3895
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3896 laterend:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3897 // put the cursor back where it belongs
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3898 curwin->w_cursor = cur_curpos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3899
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3900 vim_free(linecopy);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3901
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3902 return amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3903 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3904
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3905 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3906 * return TRUE if 'cinkeys' contains the key "keytyped",
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3907 * when == '*': Only if key is preceded with '*' (indent before insert)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3908 * when == '!': Only if key is preceded with '!' (don't insert)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3909 * when == ' ': Only if key is not preceded with '*'(indent afterwards)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3910 *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3911 * "keytyped" can have a few special values:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3912 * KEY_OPEN_FORW
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3913 * KEY_OPEN_BACK
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3914 * KEY_COMPLETE just finished completion.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3915 *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3916 * If line_is_empty is TRUE accept keys with '0' before them.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3917 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3918 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3919 in_cinkeys(
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3920 int keytyped,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3921 int when,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3922 int line_is_empty)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3923 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3924 char_u *look;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3925 int try_match;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3926 int try_match_word;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3927 char_u *p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3928 char_u *line;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3929 int icase;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3930 int i;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3931
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3932 if (keytyped == NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3933 // Can happen with CTRL-Y and CTRL-E on a short line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3934 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3935
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3936 #ifdef FEAT_EVAL
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3937 if (*curbuf->b_p_inde != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3938 look = curbuf->b_p_indk; // 'indentexpr' set: use 'indentkeys'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3939 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3940 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3941 look = curbuf->b_p_cink; // 'indentexpr' empty: use 'cinkeys'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3942 while (*look)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3943 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3944 // Find out if we want to try a match with this key, depending on
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3945 // 'when' and a '*' or '!' before the key.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3946 switch (when)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3947 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3948 case '*': try_match = (*look == '*'); break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3949 case '!': try_match = (*look == '!'); break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3950 default: try_match = (*look != '*'); break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3951 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3952 if (*look == '*' || *look == '!')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3953 ++look;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3954
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3955 // If there is a '0', only accept a match if the line is empty.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3956 // But may still match when typing last char of a word.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3957 if (*look == '0')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3958 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3959 try_match_word = try_match;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3960 if (!line_is_empty)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3961 try_match = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3962 ++look;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3963 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3964 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3965 try_match_word = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3966
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3967 // does it look like a control character?
27490
fb4c30606b4a patch 8.2.4273: the EBCDIC support is outdated
Bram Moolenaar <Bram@vim.org>
parents: 26819
diff changeset
3968 if (*look == '^' && look[1] >= '?' && look[1] <= '_')
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3969 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3970 if (try_match && keytyped == Ctrl_chr(look[1]))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3971 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3972 look += 2;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3973 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3974 // 'o' means "o" command, open forward.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3975 // 'O' means "O" command, open backward.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3976 else if (*look == 'o')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3977 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3978 if (try_match && keytyped == KEY_OPEN_FORW)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3979 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3980 ++look;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3981 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3982 else if (*look == 'O')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3983 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3984 if (try_match && keytyped == KEY_OPEN_BACK)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3985 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3986 ++look;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3987 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3988
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3989 // 'e' means to check for "else" at start of line and just before the
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3990 // cursor.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3991 else if (*look == 'e')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3992 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3993 if (try_match && keytyped == 'e' && curwin->w_cursor.col >= 4)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3994 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3995 p = ml_get_curline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3996 if (skipwhite(p) == p + curwin->w_cursor.col - 4 &&
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3997 STRNCMP(p + curwin->w_cursor.col - 4, "else", 4) == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3998 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3999 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4000 ++look;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4001 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4002
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4003 // ':' only causes an indent if it is at the end of a label or case
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4004 // statement, or when it was before typing the ':' (to fix
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4005 // class::method for C++).
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4006 else if (*look == ':')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4007 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4008 if (try_match && keytyped == ':')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4009 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4010 p = ml_get_curline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4011 if (cin_iscase(p, FALSE) || cin_isscopedecl(p) || cin_islabel())
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4012 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4013 // Need to get the line again after cin_islabel().
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4014 p = ml_get_curline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4015 if (curwin->w_cursor.col > 2
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4016 && p[curwin->w_cursor.col - 1] == ':'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4017 && p[curwin->w_cursor.col - 2] == ':')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4018 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4019 p[curwin->w_cursor.col - 1] = ' ';
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4020 i = (cin_iscase(p, FALSE) || cin_isscopedecl(p)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4021 || cin_islabel());
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4022 p = ml_get_curline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4023 p[curwin->w_cursor.col - 1] = ':';
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4024 if (i)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4025 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4026 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4027 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4028 ++look;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4029 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4030
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4031
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4032 // Is it a key in <>, maybe?
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4033 else if (*look == '<')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4034 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4035 if (try_match)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4036 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4037 // make up some named keys <o>, <O>, <e>, <0>, <>>, <<>, <*>,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4038 // <:> and <!> so that people can re-indent on o, O, e, 0, <,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4039 // >, *, : and ! keys if they really really want to.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4040 if (vim_strchr((char_u *)"<>!*oOe0:", look[1]) != NULL
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4041 && keytyped == look[1])
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4042 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4043
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4044 if (keytyped == get_special_key_code(look + 1))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4045 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4046 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4047 while (*look && *look != '>')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4048 look++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4049 while (*look == '>')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4050 look++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4051 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4052
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4053 // Is it a word: "=word"?
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4054 else if (*look == '=' && look[1] != ',' && look[1] != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4055 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4056 ++look;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4057 if (*look == '~')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4058 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4059 icase = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4060 ++look;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4061 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4062 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4063 icase = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4064 p = vim_strchr(look, ',');
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4065 if (p == NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4066 p = look + STRLEN(look);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4067 if ((try_match || try_match_word)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4068 && curwin->w_cursor.col >= (colnr_T)(p - look))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4069 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4070 int match = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4071
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4072 if (keytyped == KEY_COMPLETE)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4073 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4074 char_u *s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4075
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4076 // Just completed a word, check if it starts with "look".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4077 // search back for the start of a word.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4078 line = ml_get_curline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4079 if (has_mbyte)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4080 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4081 char_u *n;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4082
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4083 for (s = line + curwin->w_cursor.col; s > line; s = n)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4084 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4085 n = mb_prevptr(line, s);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4086 if (!vim_iswordp(n))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4087 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4088 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4089 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4090 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4091 for (s = line + curwin->w_cursor.col; s > line; --s)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4092 if (!vim_iswordc(s[-1]))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4093 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4094 if (s + (p - look) <= line + curwin->w_cursor.col
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4095 && (icase
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4096 ? MB_STRNICMP(s, look, p - look)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4097 : STRNCMP(s, look, p - look)) == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4098 match = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4099 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4100 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4101 // TODO: multi-byte
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4102 if (keytyped == (int)p[-1] || (icase && keytyped < 256
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4103 && TOLOWER_LOC(keytyped) == TOLOWER_LOC((int)p[-1])))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4104 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4105 line = ml_get_cursor();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4106 if ((curwin->w_cursor.col == (colnr_T)(p - look)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4107 || !vim_iswordc(line[-(p - look) - 1]))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4108 && (icase
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4109 ? MB_STRNICMP(line - (p - look), look, p - look)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4110 : STRNCMP(line - (p - look), look, p - look))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4111 == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4112 match = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4113 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4114 if (match && try_match_word && !try_match)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4115 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4116 // "0=word": Check if there are only blanks before the
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4117 // word.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4118 if (getwhitecols_curline() !=
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4119 (int)(curwin->w_cursor.col - (p - look)))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4120 match = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4121 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4122 if (match)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4123 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4124 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4125 look = p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4126 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4127
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4128 // ok, it's a boring generic character.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4129 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4130 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4131 if (try_match && *look == keytyped)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4132 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4133 if (*look != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4134 ++look;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4135 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4136
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4137 // Skip over ", ".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4138 look = skip_to_option_part(look);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4139 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4140 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4141 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4142
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4143 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4144 * Do C or expression indenting on the current line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4145 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4146 void
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4147 do_c_expr_indent(void)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4148 {
31091
551ce1a137da patch 9.0.0880: preprocessor indenting is off
Bram Moolenaar <Bram@vim.org>
parents: 29507
diff changeset
4149 #ifdef FEAT_EVAL
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4150 if (*curbuf->b_p_inde != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4151 fixthisline(get_expr_indent);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4152 else
31091
551ce1a137da patch 9.0.0880: preprocessor indenting is off
Bram Moolenaar <Bram@vim.org>
parents: 29507
diff changeset
4153 #endif
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4154 fixthisline(get_c_indent);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4155 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4156
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4157 #if defined(FEAT_EVAL) || defined(PROTO)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4158 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4159 * "cindent(lnum)" function
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4160 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4161 void
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4162 f_cindent(typval_T *argvars UNUSED, typval_T *rettv)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4163 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4164 pos_T pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4165 linenr_T lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4166
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
4167 if (in_vim9script() && check_for_lnum_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
4168 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
4169
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4170 pos = curwin->w_cursor;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4171 lnum = tv_get_lnum(argvars);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4172 if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4173 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4174 curwin->w_cursor.lnum = lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4175 rettv->vval.v_number = get_c_indent();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4176 curwin->w_cursor = pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4177 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4178 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4179 rettv->vval.v_number = -1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4180 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4181 #endif