annotate src/cindent.c @ 20433:5950284a517f v8.2.0771

patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code Commit: https://github.com/vim/vim/commit/6f5b6dfb16228c0ce1e4379b7bafed02eaddbab2 Author: Bram Moolenaar <Bram@vim.org> Date: Sat May 16 21:20:12 2020 +0200 patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code Problem: Vim9: cannot call a compiled closure from not compiled code. Solution: Pass funcexe to call_user_func().
author Bram Moolenaar <Bram@vim.org>
date Sat, 16 May 2020 21:30:10 +0200
parents 9f4648953f1a
children d30b16692ce0
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 #if defined(FEAT_CINDENT) || defined(FEAT_SMARTINDENT)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 * 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
38 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 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
41 {
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;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 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
44 int cinw_len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 int retval = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 int len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 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
49 cinw_buf = alloc(cinw_len);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 if (cinw_buf != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 line = skipwhite(line);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 for (cinw = curbuf->b_p_cinw; *cinw; )
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 len = copy_option_part(&cinw, cinw_buf, cinw_len, ",");
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 if (STRNCMP(line, cinw_buf, len) == 0
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 && (!vim_iswordc(line[len]) || !vim_iswordc(line[len - 1])))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 retval = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 break;
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 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 vim_free(cinw_buf);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 return retval;
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 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 #if defined(FEAT_CINDENT) || defined(FEAT_SYN_HL)
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 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 * 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
73 * 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
74 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 static char_u *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 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
77 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 int i;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 // 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
81 for ( ; ; ++p)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 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
84 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 if (!p[1]) // ' 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
86 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 i = 2;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 if (p[1] == '\\') // '\n' or '\000'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 ++i;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 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
92 ++i;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 if (p[i] == '\'') // check for trailing '
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 p += i;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 }
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 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
101 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 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
103 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 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
105 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 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
107 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 if (p[0] == '"')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 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
111 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 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
113 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 // 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
115 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
116 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
117
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 if (paren != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 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
121
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 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
123 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
124 && 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
125 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 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
127 break;
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 if (p[0] == '"')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 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
131 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 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
134 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 if (!*p)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 --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
137 return p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 * 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
142 * 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
143 * 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
144 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 static pos_T *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 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
147 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 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
149 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 pos_T *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 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
153 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 pos_T *pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 char_u *line;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 char_u *p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 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
158
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 for (;;)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 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
162 if (pos == NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 // 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
166 // If it is then restrict the search to below this line and try again.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 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
168 for (p = line; *p && (colnr_T)(p - line) < pos->col; ++p)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 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
170 if ((colnr_T)(p - line) <= pos->col)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 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
173 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
174 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 pos = NULL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 }
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 return pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 }
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 * 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
184 * 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
185 * 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
186 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 static pos_T *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 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
189 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 pos_T *pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 char_u *line;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 char_u *p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 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
194
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 for (;;)
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 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
198 if (pos == NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 // 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
202 // If it is then restrict the search to below this line and try again.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 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
204 for (p = line; *p && (colnr_T)(p - line) < pos->col; ++p)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 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
206 if ((colnr_T)(p - line) <= pos->col)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 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
209 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
210 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 pos = NULL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 break;
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 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 return pos;
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 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 * 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
220 * 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
221 * 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
222 * 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
223 * 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
224 * "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
225 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 static pos_T *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 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
228 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 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
230 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
231 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
232
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 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
234 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
235 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 // 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
237 // 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
238 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
239 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
240 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 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
242
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 // 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
244 // 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
245 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
246 && 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
247 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 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
249 *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
250 return rs_pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 return comment_pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 #endif // FEAT_CINDENT || FEAT_SYN_HL
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 #if defined(FEAT_CINDENT) || defined(PROTO)
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 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 * 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
260 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 cindent_on(void)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 return (!p_paste && (curbuf->b_p_cin
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 # ifdef FEAT_EVAL
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 || *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
267 # endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268 ));
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 // 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
272 typedef struct {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 int found;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 lpos_T lpos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 } 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
276
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 * 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
279 * 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
280 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 static char_u *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 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
283 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 while (*s)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 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
287
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 s = skipwhite(s);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 // 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
291 // 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
292 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
293 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 s += STRLEN(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 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 if (*s != '/')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 ++s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 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
301 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302 s += STRLEN(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 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 if (*s != '*')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 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
308 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
309 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 s += 2;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 break;
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 return s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316
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 * 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
319 * not considered code.
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 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 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
323 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 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
325 }
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 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 * 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
329 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 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
332 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 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
334 }
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 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 * 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
338 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340 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
341 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 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
343 }
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 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 * 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
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 *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349 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
350 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 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
352 char_u *line;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 char_u *p;
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 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
356 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
357 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 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
359 p = skipwhite(line);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 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
361 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362 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
363 return &pos;
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 if (*p != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 break;
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 return NULL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 }
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 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 * 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
373 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 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
376 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 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
378 int quote = -1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 if (*s == '\'' || *s == '"')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 // 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
383 quote = *s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 ++s;
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 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
387 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 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
390 ++s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 if (*s == quote)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 ++s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 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
395
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 // "::" 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
397 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
398 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399
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 * 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
402 * "*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
403 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 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
406 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 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
408 return FALSE;
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 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
411 (*s)++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 *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
414
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 // "::" 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
416 return (**s == ':' && *++*s != ':');
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 }
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 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 * Recognize a "public/private/protected" scope declaration label.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 cin_isscopedecl(char_u *s)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 int i;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 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
428 if (STRNCMP(s, "public", 6) == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 i = 6;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 else if (STRNCMP(s, "protected", 9) == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 i = 9;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 else if (STRNCMP(s, "private", 7) == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 i = 7;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 return (*(s = cin_skipcomment(s + i)) == ':' && s[1] != ':');
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 * 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
441 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443 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
444 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 if (*skipwhite(s) == '#')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 * 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
452 * 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
453 * 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
454 * 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
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_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
458 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 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
460 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
461 int retval = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 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
463
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 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
465 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
466
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 for (;;)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 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
470 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 retval = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 *lnump = lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 if (lnum == 1)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 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
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 break;
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 if (lnum != *lnump)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 *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
484 if (retval)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 *amount = candidate_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486 return retval;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 }
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 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 cin_iselse(
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 char_u *p)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 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
494 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
495 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
496 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 * 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
500 * '}'.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
501 * 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
502 * 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
503 * 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
504 * 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
505 * 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
506 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 cin_isterminated(
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 char_u *s,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 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
511 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
512 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 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
514 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
515 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
516
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 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
518
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 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
520 found_start = *s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 if (!found_start)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 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
524
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 while (*s)
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 // 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
528 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
529 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
530 --n_open;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 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
532 && (*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
533 && 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
534 return *s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 else if (*s == '{')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 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
538 return *s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 ++n_open;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543 if (*s)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 s++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 return found_start;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 * 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
551 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 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
554 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 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
556
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 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
558 }
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 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 * 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
562 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 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
565 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 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
567 && *(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
568 && s[1] != ':');
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 }
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 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 * 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
573 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 cin_iscase(
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 char_u *s,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 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
578 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 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
580 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
581 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 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
583 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 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
585 if (*s == NUL)
9f4648953f1a patch 8.2.0112: illegal memory access when using 'cindent'
Bram Moolenaar <Bram@vim.org>
parents: 18757
diff changeset
586 break;
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 if (*s == ':')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 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
590 ++s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 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
595 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
596 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
597 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
598 else if (*s == '"')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 // JS etc.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601 if (strict)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 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
603 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 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
611 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 return FALSE;
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 * 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
617 * 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
618 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 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
621 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 char_u *s;
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 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
625
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 // 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
627 // 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
628 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
629 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 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
631 return FALSE;
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 if (cin_islabel_skip(&s))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 // Only accept a label if the previous line is terminated or is a case
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 // label.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 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
638 pos_T *trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 char_u *line;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 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
642 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
643 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 --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
645
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 // If we're in a comment or raw string now, 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
647 // it.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 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
649 if ((trypos = 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
650 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
651
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 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
653 if (cin_ispreproc(line)) // 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
654 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 if (*(line = cin_skipcomment(line)) == NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 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
659 if (cin_isterminated(line, TRUE, FALSE)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 || cin_isscopedecl(line)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 || cin_iscase(line, TRUE)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 || (cin_islabel_skip(&line) && cin_nocode(line)))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 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
667 return TRUE; // label at start of file???
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 * 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
674 * 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
675 * 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
676 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 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
679 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 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
681 char_u *r;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 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
683
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 while (*p != NUL)
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 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
687 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
688 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 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
690 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
691 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
692 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
693 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 if (*p != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700
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 * 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
703 * "[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
704 * "[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
705 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 cin_isinit(void)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 char_u *s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 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
711
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 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
713
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 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
715 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
716
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 for (;;)
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 int i, l;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 for (i = 0; i < (int)(sizeof(skip) / sizeof(char *)); ++i)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 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
724 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
725 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 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
727 l = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 break;
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 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 if (l != 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 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
736 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 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
739 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 return FALSE;
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 // 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
745 #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
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 * 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
749 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 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
752 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 char_u *p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 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
755 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
756
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 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
758 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
759 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 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
761 while (*p != NUL)
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 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
764 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 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
766 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
767 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 else if (*p == '{')
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 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 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
773 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 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
775 if (has_name)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 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
777 ++p;
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 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
780 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 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
782 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 // 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
784 p += 3;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 }
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 return TRUE;
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 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 * 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
798 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 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
801 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 char_u *p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803 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
804
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
805 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
806 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
807 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808 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
809 while (*p != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
811 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
812 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 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
814 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815 else if (*p == '{')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
819 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
820 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821 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
822 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 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
824 p += 3;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 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
827 && p[4] == '"')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 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
830 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831 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
832 p += 5;
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
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 return FALSE;
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 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 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
840 }
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 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843
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 * 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
846 * 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
847 * 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
848 * ^
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850 static char_u *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851 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
852 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853 for ( ; *l; ++l)
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 if (*l == ':')
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 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
858 ++l;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859 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
860 break;
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 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
863 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
864 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 if (*l == NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866 return NULL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 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
868 if (*l == NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 return NULL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 return 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
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 * 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
875 * 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
876 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878 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
879 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880 char_u *l;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 pos_T fp;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 colnr_T col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 char_u *p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 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
886 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
887 if (p == NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 return 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 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
891 fp.lnum = lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892 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
893 return (int)col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 }
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 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897 * 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
898 * 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
899 * 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
900 * ^
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903 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
904 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905 char_u *l;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906 int amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 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
908
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
909 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
910 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
911 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
912 // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913 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
914 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 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
916 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
917 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
918 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
919 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
921 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922 amount = get_indent();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 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
924 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925 *pp = l;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 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
928 return amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 * 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
933 * 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
934 * 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
935 * 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
936 * 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
937 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939 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
940 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 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
942 int len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 pos_T fp;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 colnr_T col;
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 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
947 p = skipwhite(line);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 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
949 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
950 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
951 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
952 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
953 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954 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
955 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
956 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
957 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
958 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
959 || (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
960 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
961 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
962 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
963 || (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
964 || (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
965 || (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
966 p = s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968 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
969 ;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 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
971 return 0;
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 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
974 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
975 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
976 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
977 return (int)col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 }
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 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 * 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
982 * char *foo = "here";
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 * 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
984 * 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
985 * foo = "asdf\
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 * asdf\
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 * here";
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 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
990 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
991 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 char_u *line;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 char_u *s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 colnr_T col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995 pos_T fp;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 if (lnum > 1)
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 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
1000 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
1001 return -1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004 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
1005 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
1006 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007 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
1008 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
1009 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 ++s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1012 if (*s != '=')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013 return 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015 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
1016 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
1017 return 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 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
1020 ++s;
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 fp.lnum = lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023 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
1024 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
1025 return (int)col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1028 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029 * 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
1030 * 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
1031 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1032 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033 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
1034 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 char_u *line;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036 char_u *p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 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
1038
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 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
1040 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
1041 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1042 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
1043 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
1044 else
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 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
1047 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
1048 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 p = new_p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 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
1054 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056 static pos_T *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 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
1058 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 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
1060 pos_T *trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061 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
1062 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
1063
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1064 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
1065 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
1066 retry:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 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
1068 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069 // 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
1070 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
1071 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1072 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
1073 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
1074 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075 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
1076 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
1077 goto retry;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 trypos = NULL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 else
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 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
1084
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1085 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
1086 trypos = &pos_copy;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1087 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
1088 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
1089 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090 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
1091 - trypos_wk->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_wk;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1095 goto retry;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1096 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1097 trypos = NULL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 }
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 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101 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
1102 return trypos;
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106 * 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
1107 * 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
1108 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1109 static pos_T *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 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
1111 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112 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
1113 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114
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 * 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
1117 * 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
1118 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 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
1121 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 int i;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123 int retval = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 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
1125
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1126 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
1127
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 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
1129 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130 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
1131 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
1132 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
1133 ++open_count;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1134 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
1135 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1136 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
1137 --open_count;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140 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
1141 retval = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1143 }
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 return retval;
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
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 * 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
1150 * 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
1151 * no semicolons anywhere.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1152 * 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
1153 * "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
1154 * 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
1155 * "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
1156 * "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
1157 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1158 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159 cin_isfuncdecl(
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1160 char_u **sp,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1161 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
1162 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
1163 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164 char_u *s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165 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
1166 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
1167 int retval = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1168 pos_T *trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169 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
1170
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1171 if (sp == NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1172 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
1173 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174 s = *sp;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176 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
1177 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
1178 && (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
1179 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1180 lnum = trypos->lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1181 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
1182 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183 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
1184 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1186
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187 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
1188 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1189 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
1190
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1191 // 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
1192 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
1193 return FALSE;
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 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
1196 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1197 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
1198 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
1199 else if (*s == ':')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1200 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1201 if (*(s + 1) == ':')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1202 s += 2;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1203 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1204 // 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
1205 // 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
1206 // : 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
1207 // , b(0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1208 // {...
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1209 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1210 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1211 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1212 ++s;
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 if (*s != '(')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1215 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
1216
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1217 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
1218 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1219 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
1220 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1221 // ')' at the end: may have found a match
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1222 // Check for he previous line not to end in a backslash:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1223 // #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
1224 // defined(y)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1225 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
1226 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
1227 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
1228 retval = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1229 goto done;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1230 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1231 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
1232 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1233 int comma = (*s == ',');
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1234
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1235 // ',' 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
1236 // 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
1237 // func(arg1
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1238 // , arg2)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1239 for (;;)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1240 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1241 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
1242 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1243 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
1244 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
1245 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1246 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1247 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
1248 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1249 // 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
1250 // 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
1251 s = skipwhite(s);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1252 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
1253 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1254 just_started = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1255 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1256 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
1257 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
1258 else
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 ++s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1261 just_started = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1262 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1263 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1264
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1265 done:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1266 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
1267 *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
1268
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1269 return retval;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1270 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1271
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1272 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1273 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
1274 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1275 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
1276 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1277
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1278 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1279 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
1280 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1281 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
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 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1285 * 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
1286 * 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
1287 * ')' 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
1288 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1289 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1290 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
1291 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1292 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
1293 pos_T *trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1294 int retval = FALSE;
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 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
1297 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
1298 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
1299 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
1300 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1301 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
1302 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
1303 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
1304 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
1305 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
1306 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1307 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1308 ++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
1309 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1310 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
1311 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
1312 && *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
1313 retval = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1314 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
1315 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1316 return retval;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1317 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1318
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 * 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
1321 * 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
1322 * 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
1323 * string was found.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1324 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1325 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1326 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
1327 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1328 int offset = *poffset;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1329
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1330 if (offset-- < 2)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1331 return 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1332 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
1333 --offset;
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 offset -= 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1336 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
1337 goto probablyFound;
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 if (offset >= 1)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1340 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1341 offset -= 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1342 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
1343 goto probablyFound;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1344
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1345 if (offset >= 2)
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 offset -= 2;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1348 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
1349 goto probablyFound;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1350 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1351 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1352 return 0;
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 probablyFound:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1355 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
1356 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1357 *poffset = offset;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1358 return 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 return 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1361 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1362
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 * 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
1365 * do
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1366 * nothing;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1367 * while (foo
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1368 * && bar); <-- here
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1369 * 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
1370 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1371 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1372 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
1373 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1374 char_u *line;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1375 char_u *p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1376 char_u *s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1377 pos_T *trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1378 int i;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1379
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1380 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
1381 return FALSE;
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 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
1384 while (*p != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1385 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1386 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
1387 if (*p == ')')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1388 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1389 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
1390 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
1391 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1392 // 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
1393 // 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
1394 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
1395 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
1396 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
1397 if (trypos != NULL)
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 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
1400 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
1401 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
1402 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
1403 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1404 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
1405 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1406 }
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1409 // 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
1410 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
1411 p = line + i;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1412 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1413 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1414 if (*p != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1415 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1416 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1417 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1418 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1419
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1420 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1421 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
1422 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1423 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
1424 }
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 * 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
1428 * constructor-initialization. eg:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1429 *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1430 * class MyClass :
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1431 * baseClass <-- here
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1432 * 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
1433 * 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
1434 * MyClass::MyClass(...) :
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1435 * 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
1436 *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1437 * 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
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_is_cpp_baseclass(
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1441 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
1442 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1443 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
1444 char_u *s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1445 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
1446 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
1447 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
1448
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1449 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
1450 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
1451
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1452 pos->col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1453
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1454 s = skipwhite(line);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1455 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
1456 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1457 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
1458 if (*s == NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1459 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1460
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1461 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
1462
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1463 // 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
1464 // '{' 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
1465 // a = cond ?
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1466 // func() :
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1467 // asdf;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1468 // func::foo()
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1469 // : something
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 // 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
1472 // : something(4),
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1473 // somethingelse(3)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1474 // {}
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1475 while (lnum > 1)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1476 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1477 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
1478 s = skipwhite(line);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1479 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
1480 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1481 while (*s != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1482 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1483 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
1484 if (*s == '{' || *s == '}'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1485 || (*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
1486 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1487 if (*s != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1488 ++s;
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 if (*s != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1491 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1492 --lnum;
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1495 pos->lnum = lnum;
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);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1497 s = line;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1498 for (;;)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1499 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1500 if (*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 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
1503 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1504 // 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
1505 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
1506 s = line;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1507 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1508 if (s == line)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1509 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1510 // 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
1511 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
1512 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1513 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
1514 if (*s == NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1515 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1516 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1517
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1518 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
1519 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
1520 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
1521 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1522 if (s[1] == ':')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1523 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1524 // 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
1525 // initialization any more
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1526 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
1527 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
1528 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1529 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
1530 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1531 // 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
1532 // 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
1533 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
1534 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
1535 pos->col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1536 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
1537 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1538 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1539 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
1540 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1541 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
1542 || (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
1543 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1544 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
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1547 if (*s == 'c')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1548 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
1549 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1550 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
1551 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1552 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1553 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1554 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
1555 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1556 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
1557 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1558 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
1559 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1560 // 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
1561 // something like "):"
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1562 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
1563 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
1564 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1565 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
1566 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1567 // 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
1568 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1569 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1570 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
1571 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1572 // 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
1573 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
1574 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
1575 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1576 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
1577 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1578 // 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
1579 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
1580
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1581 // 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
1582 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
1583 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
1584 }
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 // 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
1587 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
1588 pos->col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1589
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1590 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
1591 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1592 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1593
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1594 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
1595 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
1596 pos->lnum = lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1597 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
1598 }
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 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1601 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
1602 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1603 int amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1604 colnr_T vcol;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1605 pos_T *trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1606
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1607 if (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 amount = get_indent();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1610 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
1611 && (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
1612 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
1613 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
1614 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
1615 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1616 else
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 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
1619 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
1620 amount = (int)vcol;
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 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
1623 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
1624 return amount;
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
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 * 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
1629 * 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
1630 * 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
1631 * work.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1632 */
18757
c469e1930456 patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18498
diff changeset
1633 // foo()
c469e1930456 patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18498
diff changeset
1634 // {
c469e1930456 patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18498
diff changeset
1635 // }
18265
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 static pos_T *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1638 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
1639 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1640 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
1641 pos_T *trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1642 pos_T *pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1643 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
1644
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1645 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
1646 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
1647 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1648 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
1649 trypos = &pos_copy;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1650 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
1651 pos = NULL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1652 // 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
1653 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
1654 && (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
1655 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1656 if (pos != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1657 curwin->w_cursor.lnum = pos->lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1658 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1659 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
1660 return trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1661 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1662
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 * 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
1665 * unmatched {.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1666 * 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
1667 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1668 static pos_T *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1669 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
1670 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1671 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
1672
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1673 if (trypos != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1674 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1675 pos_T *tryposBrace = find_start_brace();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1676
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1677 // If both an unmatched '(' and '{' is found. Ignore the '('
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1678 // position if the '{' is further down.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1679 if (tryposBrace != NULL
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1680 && (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
1681 ? 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
1682 : 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
1683 trypos = NULL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1684 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1685 return trypos;
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1688 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1689 * 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
1690 * 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
1691 * 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
1692 * 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
1693 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1694 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1695 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
1696 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1697 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
1698
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1699 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
1700 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
1701 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
1702 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1703
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1704 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1705 * 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
1706 * 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
1707 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1708 void
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1709 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
1710 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1711 char_u *p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1712 char_u *l;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1713 char_u *digits;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1714 int n;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1715 int divider;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1716 int fraction = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1717 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
1718
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1719 // 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
1720
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1721 // 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
1722 // block should be.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1723 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
1724
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1725 // 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
1726 // 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
1727 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
1728
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1729 // 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
1730 // an opening brace.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1731 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
1732
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1733 // 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
1734 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
1735
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1736 // 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
1737 // located.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1738 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
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 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
1741 // 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
1742 // 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
1743 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
1744
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1745 // 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
1746 // 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
1747 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
1748
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1749 // 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
1750 // 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
1751 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
1752
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1753 // 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
1754 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
1755
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1756 // 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
1757 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
1758
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1759 // 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
1760 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
1761
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1762 // 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
1763 // should be located.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1764 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
1765
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1766 // 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
1767 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
1768
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1769 // 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
1770 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
1771
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1772 // 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
1773 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
1774
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1775 // 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
1776 // should be indented.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1777 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
1778
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1779 // 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
1780 // should be located.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1781 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
1782
18498
9e6d5a4abb1c patch 8.1.2243: typos in comments
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
1783 // 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
1784 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
1785
18498
9e6d5a4abb1c patch 8.1.2243: typos in comments
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
1786 // 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
1787 // 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
1788 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
1789
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1790 // Suppress ignoring spaces from the indent of a line starting with an
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1791 // unclosed parentheses.
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_unclosed_noignore = 0;
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 // 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
1795 // 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
1796 // 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
1797 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
1798
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1799 // 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
1800 // 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
1801 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
1802
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1803 // Indent a closing parentheses under the line start of the matching
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1804 // opening parentheses.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1805 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
1806
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1807 // Indent a closing parentheses under the previous line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1808 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
1809
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1810 // 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
1811 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
1812
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1813 // 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
1814 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
1815
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1816 // 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
1817 // 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
1818 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
1819
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1820 // 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
1821 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
1822
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1823 // 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
1824 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
1825
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1826 // 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
1827 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
1828
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1829 // 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
1830 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
1831
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1832 // 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
1833 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
1834
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1835 // Handle C++ namespace.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1836 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
1837
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1838 // Handle continuation lines containing conditions of if(), for() and
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1839 // while().
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_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
1841
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1842 // indentation for # comments
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_hash_comment = 0;
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 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
1846 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
1847
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1848 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
1849 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1850 l = p++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1851 if (*p == '-')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1852 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1853 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
1854 n = getdigits(&p);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1855 divider = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1856 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
1857 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1858 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
1859 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
1860 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1861 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1862 if (divider)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1863 divider *= 10;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1864 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1865 divider = 10;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1866 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1867 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1868 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
1869 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1870 if (p == digits)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1871 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
1872 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1873 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1874 n *= sw;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1875 if (divider)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1876 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
1877 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1878 ++p;
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 if (l[1] == '-')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1881 n = -n;
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 // 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
1884 // 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
1885 switch (*l)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1886 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1887 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
1888 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
1889 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
1890 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
1891 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
1892 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
1893 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
1894 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
1895 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
1896 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
1897 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
1898 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
1899 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
1900 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
1901 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
1902 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
1903 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
1904 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
1905 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
1906 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
1907 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
1908 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
1909 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
1910 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
1911 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
1912 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
1913 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
1914 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
1915 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
1916 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
1917 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
1918 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
1919 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
1920 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
1921 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
1922 case 'E': buf->b_ind_cpp_extern_c = n; break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1923 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1924 if (*p == ',')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1925 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1926 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1927 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1928
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1929 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1930 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
1931 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1932 char_u *look;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1933 pos_T *theirscope;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1934 char_u *mightbeif;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1935 int elselevel;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1936 int whilelevel;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1937
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1938 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
1939 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1940 elselevel = 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1941 whilelevel = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1942 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1943 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1944 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1945 elselevel = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1946 whilelevel = 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1947 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1948
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1949 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
1950
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1951 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
1952 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1953 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
1954 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
1955
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1956 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
1957 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
1958 || cin_isif(look)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1959 || 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
1960 || 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
1961 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1962 // 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
1963 // 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
1964 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
1965 if (theirscope == NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1966 break;
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 // 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
1969 // 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
1970 // 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
1971 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
1972 break;
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 // 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
1975 // 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
1976 // different scope...
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1977 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
1978 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1979
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1980 // 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
1981 // 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
1982 // increment elselevel
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1983 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
1984 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
1985 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1986 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
1987 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
1988 ++elselevel;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1989 continue;
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1992 // 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
1993 // 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
1994 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
1995 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1996 ++whilelevel;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1997 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1998 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1999
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2000 // 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
2001 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
2002 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
2003 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2004 elselevel--;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2005 // 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
2006 // 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
2007 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
2008 whilelevel = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2009 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2010
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2011 // 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
2012 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
2013 whilelevel--;
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 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
2016 // 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
2017 // 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
2018 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
2019 return OK;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2020 }
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 return FAIL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2023 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2024
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2025 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2026 * 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
2027 * 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
2028 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2029 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2030 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
2031 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2032 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
2033 int amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2034 int scope_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2035 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
2036 colnr_T col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2037 char_u *theline;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2038 char_u *linecopy;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2039 pos_T *trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2040 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
2041 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
2042 pos_T tryposCopy;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2043 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
2044 char_u *start;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2045 int start_brace;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2046 #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
2047 #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
2048 #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
2049 linenr_T ourscope;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2050 char_u *l;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2051 char_u *look;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2052 char_u terminated;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2053 int lookfor;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2054 int whilelevel;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2055 linenr_T lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2056 int n;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2057 int iscase;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2058 int lookfor_break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2059 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
2060 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
2061 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
2062 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
2063 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
2064 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
2065 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
2066
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2067 // 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
2068 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
2069
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2070 // 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
2071 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
2072
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2073 // 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
2074 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
2075 return 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2076
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2077 // 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
2078 // 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
2079 // 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
2080 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
2081 if (linecopy == NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2082 return 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2083
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2084 // 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
2085 // 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
2086 // inserting new stuff.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2087 // 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
2088 // check for that.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2089 if ((State & INSERT)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2090 && 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
2091 && 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
2092 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
2093
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2094 theline = skipwhite(linecopy);
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 // 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
2097
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2098 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
2099
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2100 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
2101
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2102 // 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
2103 // 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
2104 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
2105 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
2106 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2107 // 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
2108 tryposCopy = *comment_pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2109 comment_pos = &tryposCopy;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2110 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2111 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
2112 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
2113 || 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
2114 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2115 amount = -1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2116 goto laterend;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2117 }
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 // #defines and so on always go at the left when included in 'cinkeys'.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2120 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
2121 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2122 amount = curbuf->b_ind_hash_comment;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2123 goto theend;
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2126 // 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
2127 // - 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
2128 // - '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
2129 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
2130 && 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
2131 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2132 amount = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2133 goto theend;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2134 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2135
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2136 // 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
2137 // previous line, lineup with that one.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2138 if (cin_islinecomment(theline)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2139 && (trypos = find_line_comment()) != NULL) // XXX
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 // 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
2142 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
2143 amount = col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2144 goto theend;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2145 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2146
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2147 // 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
2148 // 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
2149 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
2150 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2151 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
2152 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
2153 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
2154 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
2155 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
2156 char_u *p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2157 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
2158 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
2159 int done = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2160
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2161 // 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
2162 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
2163 amount = col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2164 *lead_start = NUL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2165 *lead_middle = NUL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2166
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2167 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
2168 while (*p != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2169 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2170 int align = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2171 int off = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2172 int what = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2173
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2174 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
2175 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2176 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
2177 what = *p++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2178 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
2179 align = *p++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2180 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
2181 off = getdigits(&p);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2182 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2183 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2184 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2185
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2186 if (*p == ':')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2187 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2188 (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
2189 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
2190 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2191 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
2192 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
2193 start_off = off;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2194 start_align = align;
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 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
2197 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2198 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
2199 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
2200 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2201 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
2202 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2203 // 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
2204 // 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
2205 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
2206 && 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
2207 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2208 done = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2209 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
2210 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2211 // 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
2212 // 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
2213 // 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
2214 // 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
2215 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
2216 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
2217 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
2218 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
2219 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
2220 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2221 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
2222 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2223 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2224 // 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
2225 // start of the comment, skip this entry. XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2226 else if (STRNCMP(ml_get(comment_pos->lnum) + comment_pos->col,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2227 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
2228 continue;
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 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
2231 amount += start_off;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2232 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
2233 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
2234 - 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
2235 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2236 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2237
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2238 // 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
2239 // 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
2240 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
2241 && 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
2242 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2243 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
2244 // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2245 if (off != 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2246 amount += off;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2247 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
2248 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
2249 - 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
2250 done = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2251 break;
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 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2254 }
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 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
2257 // 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
2258 // 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
2259 if (done)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2260 ;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2261 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
2262 amount += 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2263 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2264 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2265 // 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
2266 // 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
2267 // 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
2268 // 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
2269 // 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
2270 amount = -1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2271 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
2272 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2273 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
2274 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2275 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
2276 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2277 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2278 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
2279 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2280 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
2281 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2282 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
2283 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
2284 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
2285 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
2286 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2287 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
2288 amount = col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2289 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
2290 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
2291 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2292 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2293 goto theend;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2294 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2295
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2296 // 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
2297 if (*skipwhite(theline) == ']'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2298 && (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
2299 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2300 // 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
2301 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
2302 goto theend;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2303 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2304
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2305 // 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
2306 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
2307 && 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
2308 || (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
2309 || trypos != NULL)
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 (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
2312 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2313 // 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
2314 // 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
2315 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
2316 ? 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
2317 : 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
2318 trypos = NULL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2319 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2320 tryposBrace = NULL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2321 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2322
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2323 if (trypos != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2324 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2325 // 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
2326 // 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
2327 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
2328 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2329 // 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
2330 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
2331 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2332 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2333 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2334 amount = -1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2335 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
2336 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
2337 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2338 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
2339 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
2340 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2341 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
2342 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
2343 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
2344
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2345 // 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
2346 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
2347 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2348 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
2349 continue;
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2352 // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2353 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
2354 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
2355 && 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
2356 && 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
2357 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2358 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
2359
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2360 if (theline[0] == ')')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2361 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2362 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
2363 && cur_amount > amount)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2364 cur_amount = amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2365 amount = -1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2366 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2367 break;
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 }
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2372 // 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
2373 // 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
2374 // 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
2375 if (amount == -1)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2376 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2377 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
2378 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
2379
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2380 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
2381 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2382 // 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
2383 // 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
2384
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2385 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
2386 pos_T outermost;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2387 char_u *line;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2388
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2389 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
2390 do {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2391 outermost = *trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2392 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
2393 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
2394
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2395 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
2396 } 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
2397
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2398 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
2399
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2400 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
2401
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2402 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
2403 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
2404 }
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 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
2407 look = skipwhite(look);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2408 if (*look == '(')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2409 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2410 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
2411 char_u *line;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2412 int look_col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2413
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2414 // 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
2415 // our matching '('.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2416 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
2417 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
2418 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
2419 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
2420 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
2421 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
2422 != NULL
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2423 && 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
2424 && 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
2425 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
2426
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2427 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
2428 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
2429 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2430 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
2431 && 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
2432 || (!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
2433 && 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
2434 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2435 // 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
2436 // 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
2437 // 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
2438 // 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
2439 // 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
2440 // 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
2441 // lines).
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2442 if (theline[0] != ')')
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 cur_amount = MAXCOL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2445 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
2446 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
2447 && 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
2448 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2449 // 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
2450 // 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
2451 n = 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2452 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
2453 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2454 switch (l[col])
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 case '(':
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2457 case '{': ++n;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2458 break;
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 case ')':
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2461 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
2462 --n;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2463 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2464 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2465 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2466
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2467 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
2468 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
2469 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2470 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
2471 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
2472 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2473 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2474 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
2475 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
2476 col++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2477 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
2478 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
2479 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2480 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
2481 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2482 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2483
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2484 // 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
2485 // 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
2486 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
2487 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2488 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
2489 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
2490 cur_amount = col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2491 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2492 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2493
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2494 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
2495 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2496 // 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
2497 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2498 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
2499 || (!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
2500 && *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
2501 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2502 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
2503 amount = cur_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2504 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2505 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2506 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2507 // 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
2508 // 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
2509 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
2510 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
2511 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2512 --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
2513 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
2514 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2515 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
2516 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
2517 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2518 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
2519 col = MAXCOL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2520 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2521 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2522 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2523
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2524 // 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
2525 // braces
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2526 if (col == MAXCOL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2527 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
2528 else
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 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
2531 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
2532 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
2533 != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2534 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
2535 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2536 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2537 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
2538 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
2539 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2540 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
2541 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2542 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2543 // 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
2544 // 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
2545 // lines:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2546 // 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
2547 // arg && yy
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2548 // ) ^ 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
2549 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
2550 amount = cur_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2551 }
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2554 // 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
2555 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
2556 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
2557 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2558 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2559 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2560 // 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
2561 // stored in tryposBrace.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2562 // 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
2563 // 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
2564 tryposCopy = *tryposBrace;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2565 tryposBrace = &tryposCopy;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2566 trypos = tryposBrace;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2567 ourscope = trypos->lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2568 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
2569
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2570 // 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
2571 // 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
2572 // 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
2573 // 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
2574 look = skipwhite(start);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2575 if (*look == '{')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2576 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2577 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
2578 amount = col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2579 if (*start == '{')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2580 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
2581 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2582 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
2583 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2584 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2585 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2586 // 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
2587 // 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
2588 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
2589
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2590 // 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
2591 // 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
2592 lnum = ourscope;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2593 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
2594 && (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
2595 != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2596 lnum = trypos->lnum;
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 // 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
2599 // case 1: if (asdf &&
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2600 // ldfd) {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2601 // }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2602 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
2603 && 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
2604 amount = get_indent();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2605 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
2606 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
2607 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2608 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
2609
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2610 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
2611 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2612
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2613 // 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
2614 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
2615 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
2616
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2617 // 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
2618 // 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
2619 // 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
2620 if (theline[0] == '}')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2621 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2622 // 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
2623 // 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
2624 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
2625 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2626 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2627 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2628 // 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
2629 // 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
2630 // 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
2631 // 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
2632 lookfor = LOOKFOR_INITIAL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2633 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
2634 lookfor = LOOKFOR_IF;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2635 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
2636 lookfor = LOOKFOR_DO;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2637 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
2638 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2639 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
2640 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
2641 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2642 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
2643 goto theend;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2644 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2645 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2646
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2647 // 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
2648 // 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
2649 // 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
2650 // 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
2651
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2652 // 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
2653 // 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
2654 // 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
2655
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2656 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
2657 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2658 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
2659 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
2660 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2661 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
2662 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
2663 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2664
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2665 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
2666 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2667 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2668 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2669 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
2670 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2671 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
2672
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2673 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
2674 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
2675 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
2676 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
2677 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
2678 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2679 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2680 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2681 // 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
2682 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
2683 if (amount < 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2684 amount = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2685 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2686 }
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 lookfor_break = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2689
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2690 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
2691 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2692 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
2693 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
2694 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2695 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
2696 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2697 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
2698 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
2699 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2700 else
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 (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
2703 // break; ...
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2704 lookfor_break = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2705
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2706 lookfor = LOOKFOR_INITIAL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2707 // 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
2708 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
2709 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2710 scope_amount = amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2711 whilelevel = 0;
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 // 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
2714 // with that.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2715 //
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2716 // 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
2717 // 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
2718 // 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
2719 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
2720 for (;;)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2721 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2722 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
2723 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
2724
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2725 // 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
2726 // up with it.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2727 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
2728 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2729 // We reached end of scope:
18498
9e6d5a4abb1c patch 8.1.2243: typos in comments
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
2730 // 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
2731 // go further back:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2732 // 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
2733 // 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
2734 // declaration:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2735 // int x,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2736 // 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
2737 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
2738 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2739 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
2740 || 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
2741 < 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
2742 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2743 // 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
2744 // 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
2745 // initialization)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2746 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
2747 amount = cont_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2748 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
2749 amount += ind_continuation;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2750 break;
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2753 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
2754
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2755 // 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
2756 // 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
2757 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
2758 if (trypos != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2759 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2760 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
2761 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
2762 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2763 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2764
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2765 // 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
2766 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
2767 &amount))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2768 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2769
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2770 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
2771 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2772
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2773 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
2774
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2775 // 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
2776 // 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
2777 // (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
2778 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
2779 || !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
2780 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2781 // 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
2782 // 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
2783 // 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
2784 // 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
2785 // 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
2786 // 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
2787 if (terminated == ',')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2788 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2789
18498
9e6d5a4abb1c patch 8.1.2243: typos in comments
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
2790 // 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
2791 // we are done.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2792 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
2793 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2794
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2795 // nothing useful found
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2796 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
2797 continue;
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2800 if (terminated != ';')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2801 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2802 // 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
2803 // 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
2804 // 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
2805 // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2806 trypos = NULL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2807 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
2808 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
2809 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
2810
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2811 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
2812 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
2813
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2814 if (trypos != NULL)
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 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
2817 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
2818 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2819 }
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2822 // 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
2823 // like in
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2824 // int a,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2825 // b;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2826 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
2827 amount = cont_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2828 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2829 amount += ind_continuation;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2830 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2831 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
2832 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2833 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
2834 amount = cont_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2835 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2836 amount += ind_continuation;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2837 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2838 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2839 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2840 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
2841 && 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
2842 && lookfor != LOOKFOR_COMMA)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2843 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2844 amount = scope_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2845 if (theline[0] == '{')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2846 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2847 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
2848 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
2849 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2850 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2851
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2852 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
2853 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2854 // 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
2855 // back.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2856 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
2857 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2858
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2859 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
2860 || 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
2861 < 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
2862 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2863
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2864 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
2865
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2866 // 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
2867 // 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
2868 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
2869 if (trypos != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2870 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2871 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
2872 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
2873 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2874 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2875
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2876 // 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
2877 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
2878 &amount))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2879 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2880
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2881 // 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
2882 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
2883 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2884 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
2885 - added_to_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2886 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2887 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2888 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
2889 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2890 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
2891 - added_to_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2892 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2893 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2894
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2895 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
2896 continue;
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 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2899 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2900 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2901
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2902 // 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
2903 // of it. XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2904 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
2905 {
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 = trypos->lnum + 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2907 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
2908 continue;
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2911 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
2912
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2913 // 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
2914 // 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
2915 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
2916 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
2917 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2918 // 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
2919 // 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
2920 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
2921 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2922
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2923 // 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
2924 // labels.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2925 if (whilelevel > 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2926 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2927
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2928 // case xx:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2929 // 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
2930 //-> here;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2931 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
2932 || 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
2933 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2934 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
2935 amount = cont_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2936 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2937 amount += ind_continuation;
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 // 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
2942 // x = 333;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2943 // case yy:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2944 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
2945 || (iscase && lookfor_break)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2946 || (!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
2947 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2948 // 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
2949 // switch() 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 = 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
2951 || trypos->lnum == ourscope)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2952 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2953 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
2954 break;
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 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2957 }
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 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
2960
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2961 // 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
2962 // y = y + 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2963 // -> s = 99;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2964 //
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2965 // case xx:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2966 // 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
2967 // y = y + 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2968 // -> s = 99;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2969 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
2970 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2971 if (n)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2972 amount = n;
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 if (!lookfor_break)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2975 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2976 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2977
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2978 // 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
2979 // -> y = y + 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2980 //
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2981 // 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
2982 // -> y = y + 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2983 if (n)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2984 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2985 amount = n;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2986 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
2987 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
2988 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2989 if (theline[0] == '{')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2990 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
2991 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2992 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
2993 + 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
2994 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2995 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2996 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2997
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2998 // 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
2999 // 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
3000 // switch label.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3001 // 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
3002 // case xx:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3003 // -> y = 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3004 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
3005 ? 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
3006 : 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
3007 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
3008 ? 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
3009 continue;
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3012 // 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
3013 // 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
3014 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
3015 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3016 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
3017 && (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
3018 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3019 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
3020 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
3021 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3022 continue;
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3025 // 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
3026 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
3027 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3028 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
3029 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
3030 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3031 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3032
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3033 // 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
3034 // 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
3035 // (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
3036 // unlocked it)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3037 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
3038 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
3039 || cin_nocode(l))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3040 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3041
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3042 // 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
3043 // constructor initialization? XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3044 n = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3045 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
3046 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3047 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
3048 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
3049 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3050 if (n)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3051 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3052 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
3053 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3054 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
3055 amount = cont_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3056 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3057 amount += ind_continuation;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3058 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3059 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
3060 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3061 // 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
3062 lookfor = LOOKFOR_UNTERM;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3063 ind_continuation = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3064 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3065 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3066 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3067 // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3068 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
3069 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
3070 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3071 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3072 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
3073 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3074 // 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
3075 // 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
3076 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
3077 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3078 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3079 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3080 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3081
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3082 // 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
3083 // 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
3084 // 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
3085 // 123,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3086 // sizeof
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3087 // here
18498
9e6d5a4abb1c patch 8.1.2243: typos in comments
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
3088 // 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
3089 // 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
3090 // (indented).
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3091 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
3092
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3093 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
3094 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3095 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
3096 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
3097 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3098 // 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
3099 // 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
3100 // key: something
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3101 // or:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3102 // 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
3103 // something,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3104 // key: something
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3105 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
3106 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3107 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3108 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
3109 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3110 amount = get_indent();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3111 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3112 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3113 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
3114 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3115 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
3116 >= 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
3117 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3118 if (terminated == ',')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3119 // 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
3120 // (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
3121 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3122 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3123 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3124 amount = get_indent();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3125 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
3126 // 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
3127 // 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
3128 // 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
3129 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3130 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3131 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3132
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3133 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
3134 && terminated == ','))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3135 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3136 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
3137 (*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
3138 amount += ind_continuation;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3139 // 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
3140 // 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
3141 // 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
3142 // if ( foo &&
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3143 // bar )
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3144
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3145 // 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
3146 // 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
3147 // 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
3148 (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
3149 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
3150 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
3151 || (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
3152 && 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
3153 trypos = NULL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3154
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3155 // 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
3156 // braces.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3157 if (trypos == NULL && terminated == ','
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3158 && 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
3159 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
3160
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3161 if (trypos != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3162 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3163 // 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
3164 // handled above.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3165 // 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
3166 // asdf)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3167 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
3168 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
3169 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
3170 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3171 ++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
3172 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
3173 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3174 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3175 }
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 // 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
3178 // indent from
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3179 // 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
3180 // bla",
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3181 // here;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3182 if (terminated == ',')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3183 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3184 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
3185 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3186 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
3187 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
3188 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3189 --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
3190 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
3191 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3192 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3193
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3194 // 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
3195 // 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
3196 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
3197 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
3198 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3199 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
3200 // 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
3201 // 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
3202 // while (not)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3203 // -> {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3204 // }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3205 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
3206 && theline[0] == '{')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3207 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3208 amount = cur_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3209 // 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
3210 // 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
3211 // 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
3212 // { 1, 2 },
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3213 // -> { 3, 4 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3214 if (*skipwhite(l) != '{')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3215 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
3216
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3217 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
3218 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3219 // 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
3220 // 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
3221 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
3222 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3223 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3224 break;
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 // Check if we are after an "if", "while", etc.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3228 // Also allow " } else".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3229 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
3230 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3231 // 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
3232 // 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
3233 // if (cond)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3234 // 100 +
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3235 // -> here;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3236 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
3237 || 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
3238 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3239 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
3240 amount = cont_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3241 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3242 amount += ind_continuation;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3243 break;
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 // 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
3247 // are finished.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3248 // while (not)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3249 // -> here;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3250 // 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
3251 // 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
3252 // yyy;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3253 // if (stat)
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 // xxx;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3256 // -> here;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3257 amount = cur_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3258 if (theline[0] == '{')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3259 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
3260 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
3261 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3262 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
3263 + 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
3264 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3265 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3266
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3267 // Special trick: when expecting the while () after a
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3268 // do, line up with the while()
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3269 // do
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3270 // x = 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3271 // -> here
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3272 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
3273 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
3274 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3275 if (whilelevel == 0)
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 --whilelevel;
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3280 // 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
3281 // 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
3282 // 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
3283 // 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
3284 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
3285 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3286 // 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
3287 // find the opening brace of the enclosing scope,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3288 // not the one from "if () {".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3289 if (*l == '}')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3290 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
3291 (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
3292
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3293 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
3294 || 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
3295 == FAIL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3296 break;
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 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3299
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3300 // 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
3301 // "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
3302 // 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
3303 // 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
3304 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3305 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3306 // 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
3307 // the last one.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3308 // c = 99 +
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3309 // 100 +
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3310 // -> here;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3311 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
3312 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3313 // 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
3314 if (terminated == ',')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3315 amount += ind_continuation;
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 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
3320 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3321 // 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
3322 // 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
3323 // 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
3324 // 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
3325 // enumerations/initializations.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3326 if (terminated == ',')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3327 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3328 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
3329 break;
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 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
3332 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3333 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3334
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3335 // 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
3336 // reduce indent.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3337 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
3338 amount = cur_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3339 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3340 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3341 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3342 // 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
3343 // 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
3344 // 100 +
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3345 // -> here;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3346 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
3347 amount = cur_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3348
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3349 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
3350 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
3351 || (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
3352 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3353
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3354 // 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
3355 // 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
3356 // struct xxx =
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 // sizeof a,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3359 // 124 };
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3360 // 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
3361 // 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
3362 // yet.
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_INITIAL && terminated == ',')
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 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
3366 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3367 // 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
3368 // 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
3369 // (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
3370 // some = [
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3371 // 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
3372 // 2,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3373 // some = [
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3374 // 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
3375 // 4 *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3376 // 5,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3377 // 6,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3378 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
3379 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3380 lookfor = LOOKFOR_COMMA;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3381 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
3382 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
3383 if (trypos != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3384 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3385 if (trypos->lnum
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3386 == 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
3387 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3388 // 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
3389 // [], 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
3390 break;
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 ourscope = trypos->lnum;
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 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3395 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3396 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3397 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
3398 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
3399 }
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 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3402 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3403 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
3404 && *l != NUL
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3405 && 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
3406 // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3407 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
3408 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
3409 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
3410 && 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
3411 && lookfor != LOOKFOR_COMMA
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3412 && 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
3413 lookfor = LOOKFOR_UNTERM;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3414 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3415 }
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 }
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 // 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
3420 // 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
3421 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
3422 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3423 // 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
3424 // 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
3425 // while (cond);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3426 // 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
3427 // -> here;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3428 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
3429 || 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
3430 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3431 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
3432 amount = cont_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3433 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3434 amount += ind_continuation;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3435 break;
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3438 if (whilelevel == 0)
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 lookfor = LOOKFOR_TERM;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3441 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
3442 if (theline[0] == '{')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3443 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
3444 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3445 ++whilelevel;
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3448 // 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
3449 // 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
3450 // 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
3451 // 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
3452 // 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
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 // 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
3456 // 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
3457 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
3458 && 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
3459 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3460 lookfor = LOOKFOR_ANY;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3461 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3462 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3463
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3464 // Handle "do {" line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3465 if (whilelevel > 0)
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 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
3468 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
3469 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3470 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
3471 --whilelevel;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3472 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3473 }
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3476 // 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
3477 // 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
3478 // x = 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3479 // y = foo +
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3480 // -> here;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3481 // or
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3482 // int x = 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3483 // int foo,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3484 // -> here;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3485 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
3486 || 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
3487 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3488 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
3489 amount = cont_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3490 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3491 amount += ind_continuation;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3492 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3493 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3494
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3495 // 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
3496 // 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
3497 // 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
3498 // 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
3499 // while (asdf) ->here;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3500 // here;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3501 // ->foo;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3502 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
3503 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3504 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
3505 break;
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3508 // 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
3509 // 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
3510 // a terminated line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3511 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3512 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3513 // 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
3514 // 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
3515 // 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
3516 // func(asdr,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3517 // asdfasdf);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3518 // here;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3519 term_again:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3520 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
3521 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
3522 && (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
3523 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
3524 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3525 // 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
3526 // handled above.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3527 // 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
3528 // asdf)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3529 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
3530 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
3531 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
3532 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3533 ++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
3534 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
3535 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3536 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3537 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3538
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3539 // 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
3540 // 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
3541 // 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
3542 // stat;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3543 // }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3544 // case 2:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3545 // stat;
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 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
3548 && 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
3549
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3550 // 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
3551 // 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
3552 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
3553
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3554 if (theline[0] == '{')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3555 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
3556 // 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
3557 l = skipwhite(l);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3558 if (*l == '{')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3559 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
3560 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
3561
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3562 // 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
3563 // the matching "if":
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3564 // else 3;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3565 // indent this;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3566 // 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
3567 // 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
3568 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
3569 && *l != '}'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3570 && cin_iselse(l)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3571 && whilelevel == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3572 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3573 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
3574 || 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
3575 == FAIL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3576 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3577 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3578 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3579
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3580 // 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
3581 // that block.
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 (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
3584 && (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
3585 {
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 = *trypos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3587 // 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
3588 // 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
3589 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
3590 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
3591 goto term_again;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3592 ++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
3593 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
3594 }
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 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3597 }
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 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3600
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3601 // 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
3602 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
3603 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
3604
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3605 // 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
3606 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
3607 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
3608
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3609 goto theend;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3610 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3611
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3612 // 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
3613 //
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3614 // 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
3615 // 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
3616 // 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
3617 // 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
3618 //
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3619 // 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
3620 // 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
3621 // of a function
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3622
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3623 if (theline[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 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
3626 goto theend;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3627 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3628
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3629 // 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
3630 // 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
3631 // 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
3632 // current line is terminated, ie. ends in ';', or if the current line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3633 // contains { or }: "void f() {\n if (1)"
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3634 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
3635 && !cin_nocode(theline)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3636 && 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
3637 && 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
3638 && !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
3639 && !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
3640 && 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
3641 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
3642 && !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
3643 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3644 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
3645 goto theend;
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 // 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
3649 amount = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3650 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
3651 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
3652 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3653 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
3654 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
3655
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3656 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
3657
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3658 // 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
3659 // of it. XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3660 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
3661 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3662 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
3663 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
3664 continue;
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3667 // 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
3668 // constructor initialization? XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3669 n = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3670 if (curbuf->b_ind_cpp_baseclass != 0 && theline[0] != '{')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3671 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3672 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
3673 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
3674 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3675 if (n)
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 // XXX
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3678 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
3679 break;
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3682 // 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
3683 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
3684 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3685
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3686 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
3687 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3688
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3689 // 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
3690 // indentation:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3691 // int foo,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3692 // bar;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3693 // 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
3694 // enum foobar
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 // ...
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3697 // } foo,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3698 // bar;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3699 n = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3700 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
3701 || (*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
3702 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3703 // 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
3704 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
3705 && (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
3706 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
3707 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
3708
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3709 // 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
3710 // 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
3711 // 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
3712 // bla",
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3713 // here;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3714 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
3715 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3716 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
3717 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
3718 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3719 --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
3720 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
3721 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3722
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3723 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
3724
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3725 if (amount == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3726 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
3727 if (amount == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3728 amount = ind_continuation;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3729 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3730 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3731
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3732 // 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
3733 // 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
3734 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
3735 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3736 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
3737
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3738 // 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
3739 // 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
3740 if (*skipwhite(l) == '}')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3741 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3742
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3743 // (matching {)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3744 // 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
3745 // 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
3746 // 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
3747 // / * 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
3748 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
3749 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3750
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3751 // 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
3752 // array constant:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3753 // something = [
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3754 // 234, <- extra indent
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3755 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
3756 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3757 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
3758 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3759 }
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 // 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
3762 // 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
3763 // indent then.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3764 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
3765 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3766 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
3767
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3768 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
3769 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3770 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
3771 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
3772 &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
3773 break;
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 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
3776 && 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
3777 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3778
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3779 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
3780 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3781
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3782 // 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
3783 // 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
3784 // parameters.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3785 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
3786 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3787 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
3788 break;
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3791 // 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
3792 // 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
3793 // int foo,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3794 // bar;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3795 // 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
3796 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
3797 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3798 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
3799 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
3800 || (*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
3801 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3802 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
3803 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3804
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3805 // 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
3806 // 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
3807 //
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3808 // 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
3809 // 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
3810 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
3811
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3812 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
3813 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
3814 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
3815 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3816 }
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 // 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
3819 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
3820 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
3821
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3822 // 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
3823 // "asdfasdf{backslash}
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3824 // here";
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3825 // 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
3826 // here";
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3827 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
3828 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3829 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
3830 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
3831 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3832 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
3833 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
3834 amount = cur_amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3835 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
3836 amount += ind_continuation;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3837 }
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3840 theend:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3841 if (amount < 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3842 amount = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3843
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3844 laterend:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3845 // 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
3846 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
3847
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3848 vim_free(linecopy);
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 return amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3851 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3852
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3853 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3854 * 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
3855 * 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
3856 * 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
3857 * 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
3858 *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3859 * "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
3860 * KEY_OPEN_FORW
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3861 * KEY_OPEN_BACK
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3862 * 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
3863 *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3864 * 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
3865 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3866 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3867 in_cinkeys(
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3868 int keytyped,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3869 int when,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3870 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
3871 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3872 char_u *look;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3873 int try_match;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3874 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
3875 char_u *p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3876 char_u *line;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3877 int icase;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3878 int i;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3879
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3880 if (keytyped == NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3881 // 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
3882 return FALSE;
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 #ifdef FEAT_EVAL
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3885 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
3886 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
3887 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3888 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3889 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
3890 while (*look)
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 // 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
3893 // '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
3894 switch (when)
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 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
3897 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
3898 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
3899 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3900 if (*look == '*' || *look == '!')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3901 ++look;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3902
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3903 // 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
3904 // 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
3905 if (*look == '0')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3906 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3907 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
3908 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
3909 try_match = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3910 ++look;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3911 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3912 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3913 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
3914
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3915 // does it look like a control character?
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3916 if (*look == '^'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3917 #ifdef EBCDIC
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3918 && (Ctrl_chr(look[1]) != 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3919 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3920 && look[1] >= '?' && look[1] <= '_'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3921 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3922 )
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 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
3925 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3926 look += 2;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3927 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3928 // '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
3929 // '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
3930 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
3931 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3932 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
3933 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3934 ++look;
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 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
3937 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3938 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
3939 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3940 ++look;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3941 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3942
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3943 // '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
3944 // cursor.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3945 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
3946 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3947 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
3948 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3949 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
3950 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
3951 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
3952 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3953 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3954 ++look;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3955 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3956
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3957 // ':' 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
3958 // 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
3959 // 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
3960 else if (*look == ':')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3961 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3962 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
3963 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3964 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
3965 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
3966 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3967 // 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
3968 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
3969 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
3970 && 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
3971 && 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
3972 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3973 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
3974 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
3975 || cin_islabel());
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3976 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
3977 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
3978 if (i)
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 }
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 ++look;
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3985
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3986 // 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
3987 else if (*look == '<')
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 if (try_match)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3990 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3991 // 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
3992 // <:> 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
3993 // >, *, : 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
3994 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
3995 && keytyped == look[1])
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3996 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3997
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3998 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
3999 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4000 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4001 while (*look && *look != '>')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4002 look++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4003 while (*look == '>')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4004 look++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4005 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4006
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4007 // 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
4008 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
4009 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4010 ++look;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4011 if (*look == '~')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4012 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4013 icase = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4014 ++look;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4015 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4016 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4017 icase = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4018 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
4019 if (p == NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4020 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
4021 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
4022 && 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
4023 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4024 int match = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4025
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4026 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
4027 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4028 char_u *s;
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 // 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
4031 // 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
4032 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
4033 if (has_mbyte)
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 char_u *n;
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 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
4038 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4039 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
4040 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
4041 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4042 }
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 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4045 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
4046 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
4047 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4048 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
4049 && (icase
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4050 ? 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
4051 : 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
4052 match = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4053 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4054 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4055 // TODO: multi-byte
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4056 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
4057 && 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
4058 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4059 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
4060 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
4061 || !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
4062 && (icase
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4063 ? 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
4064 : 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
4065 == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4066 match = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4067 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4068 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
4069 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4070 // "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
4071 // word.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4072 if (getwhitecols_curline() !=
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4073 (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
4074 match = FALSE;
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 if (match)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4077 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4078 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4079 look = p;
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4082 // 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
4083 else
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 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
4086 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4087 if (*look != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4088 ++look;
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4091 // Skip over ", ".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4092 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
4093 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4094 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4095 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4096
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4097 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4098 * 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
4099 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4100 void
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4101 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
4102 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4103 # ifdef FEAT_EVAL
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4104 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
4105 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
4106 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4107 # endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4108 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
4109 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4110 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4111
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4112 #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
4113 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4114 * "cindent(lnum)" function
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 void
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4117 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
4118 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4119 # ifdef FEAT_CINDENT
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4120 pos_T pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4121 linenr_T lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4122
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4123 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
4124 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
4125 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
4126 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4127 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
4128 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
4129 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
4130 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4131 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4132 # endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4133 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
4134 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4135 #endif