annotate src/indent.c @ 29234:96ff6c230a66 v8.2.5136

patch 8.2.5136: debugger test fails when run with valgrind Commit: https://github.com/vim/vim/commit/e366ed4f2c6fa8cb663f1b9599b39d57ddbd8a2a Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jun 19 20:13:56 2022 +0100 patch 8.2.5136: debugger test fails when run with valgrind Problem: Debugger test fails when run with valgrind. Solution: Wait longer when using valgrind.
author Bram Moolenaar <Bram@vim.org>
date Sun, 19 Jun 2022 21:15:03 +0200
parents a2c89e5446b7
children 9bc63b4f9c33
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15699
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * indent.c: Indentation related functions
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 */
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 #include "vim.h"
2d941023bd2f patch 8.1.0857: indent functionality is not separated
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15
17940
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
16 #if defined(FEAT_VARTABS) || defined(PROTO)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
17
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
18 /*
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
19 * Set the integer values corresponding to the string setting of 'vartabstop'.
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
20 * "array" will be set, caller must free it if needed.
25733
4b2616ffe32b patch 8.2.3402: invalid memory access when using :retab with large value
Bram Moolenaar <Bram@vim.org>
parents: 25701
diff changeset
21 * Return FAIL for an error.
17940
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
22 */
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
23 int
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
24 tabstop_set(char_u *var, int **array)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
25 {
25733
4b2616ffe32b patch 8.2.3402: invalid memory access when using :retab with large value
Bram Moolenaar <Bram@vim.org>
parents: 25701
diff changeset
26 int valcount = 1;
4b2616ffe32b patch 8.2.3402: invalid memory access when using :retab with large value
Bram Moolenaar <Bram@vim.org>
parents: 25701
diff changeset
27 int t;
4b2616ffe32b patch 8.2.3402: invalid memory access when using :retab with large value
Bram Moolenaar <Bram@vim.org>
parents: 25701
diff changeset
28 char_u *cp;
17940
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
29
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
30 if (var[0] == NUL || (var[0] == '0' && var[1] == NUL))
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
31 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
32 *array = NULL;
25733
4b2616ffe32b patch 8.2.3402: invalid memory access when using :retab with large value
Bram Moolenaar <Bram@vim.org>
parents: 25701
diff changeset
33 return OK;
17940
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
34 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
35
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
36 for (cp = var; *cp != NUL; ++cp)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
37 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
38 if (cp == var || cp[-1] == ',')
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
39 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
40 char_u *end;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
41
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
42 if (strtol((char *)cp, (char **)&end, 10) <= 0)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
43 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
44 if (cp != end)
26877
06a137af96f8 patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
45 emsg(_(e_argument_must_be_positive));
17940
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
46 else
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26775
diff changeset
47 semsg(_(e_invalid_argument_str), cp);
25733
4b2616ffe32b patch 8.2.3402: invalid memory access when using :retab with large value
Bram Moolenaar <Bram@vim.org>
parents: 25701
diff changeset
48 return FAIL;
17940
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
49 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
50 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
51
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
52 if (VIM_ISDIGIT(*cp))
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
53 continue;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
54 if (cp[0] == ',' && cp > var && cp[-1] != ',' && cp[1] != NUL)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
55 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
56 ++valcount;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
57 continue;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
58 }
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26775
diff changeset
59 semsg(_(e_invalid_argument_str), var);
25733
4b2616ffe32b patch 8.2.3402: invalid memory access when using :retab with large value
Bram Moolenaar <Bram@vim.org>
parents: 25701
diff changeset
60 return FAIL;
17940
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
61 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
62
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
63 *array = ALLOC_MULT(int, valcount + 1);
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
64 if (*array == NULL)
25733
4b2616ffe32b patch 8.2.3402: invalid memory access when using :retab with large value
Bram Moolenaar <Bram@vim.org>
parents: 25701
diff changeset
65 return FAIL;
17940
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
66 (*array)[0] = valcount;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
67
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
68 t = 1;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
69 for (cp = var; *cp != NUL;)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
70 {
25733
4b2616ffe32b patch 8.2.3402: invalid memory access when using :retab with large value
Bram Moolenaar <Bram@vim.org>
parents: 25701
diff changeset
71 int n = atoi((char *)cp);
4b2616ffe32b patch 8.2.3402: invalid memory access when using :retab with large value
Bram Moolenaar <Bram@vim.org>
parents: 25701
diff changeset
72
25735
07e23f808680 patch 8.2.3403: memory leak for :retab with invalid argument
Bram Moolenaar <Bram@vim.org>
parents: 25733
diff changeset
73 // Catch negative values, overflow and ridiculous big values.
27543
8e8fb566dfa5 patch 8.2.4298: divide by zero with huge tabstop value
Bram Moolenaar <Bram@vim.org>
parents: 27521
diff changeset
74 if (n <= 0 || n > TABSTOP_MAX)
25733
4b2616ffe32b patch 8.2.3402: invalid memory access when using :retab with large value
Bram Moolenaar <Bram@vim.org>
parents: 25701
diff changeset
75 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26775
diff changeset
76 semsg(_(e_invalid_argument_str), cp);
25735
07e23f808680 patch 8.2.3403: memory leak for :retab with invalid argument
Bram Moolenaar <Bram@vim.org>
parents: 25733
diff changeset
77 vim_free(*array);
07e23f808680 patch 8.2.3403: memory leak for :retab with invalid argument
Bram Moolenaar <Bram@vim.org>
parents: 25733
diff changeset
78 *array = NULL;
25733
4b2616ffe32b patch 8.2.3402: invalid memory access when using :retab with large value
Bram Moolenaar <Bram@vim.org>
parents: 25701
diff changeset
79 return FAIL;
4b2616ffe32b patch 8.2.3402: invalid memory access when using :retab with large value
Bram Moolenaar <Bram@vim.org>
parents: 25701
diff changeset
80 }
4b2616ffe32b patch 8.2.3402: invalid memory access when using :retab with large value
Bram Moolenaar <Bram@vim.org>
parents: 25701
diff changeset
81 (*array)[t++] = n;
4b2616ffe32b patch 8.2.3402: invalid memory access when using :retab with large value
Bram Moolenaar <Bram@vim.org>
parents: 25701
diff changeset
82 while (*cp != NUL && *cp != ',')
17940
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
83 ++cp;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
84 if (*cp != NUL)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
85 ++cp;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
86 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
87
25733
4b2616ffe32b patch 8.2.3402: invalid memory access when using :retab with large value
Bram Moolenaar <Bram@vim.org>
parents: 25701
diff changeset
88 return OK;
17940
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
89 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
90
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
91 /*
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
92 * Calculate the number of screen spaces a tab will occupy.
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
93 * If "vts" is set then the tab widths are taken from that array,
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
94 * otherwise the value of ts is used.
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
95 */
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
96 int
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
97 tabstop_padding(colnr_T col, int ts_arg, int *vts)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
98 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
99 int ts = ts_arg == 0 ? 8 : ts_arg;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
100 int tabcount;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
101 colnr_T tabcol = 0;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
102 int t;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
103 int padding = 0;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
104
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
105 if (vts == NULL || vts[0] == 0)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
106 return ts - (col % ts);
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
107
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
108 tabcount = vts[0];
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
109
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
110 for (t = 1; t <= tabcount; ++t)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
111 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
112 tabcol += vts[t];
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
113 if (tabcol > col)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
114 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
115 padding = (int)(tabcol - col);
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
116 break;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
117 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
118 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
119 if (t > tabcount)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
120 padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]);
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
121
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
122 return padding;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
123 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
124
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
125 /*
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
126 * Find the size of the tab that covers a particular column.
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
127 */
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
128 int
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
129 tabstop_at(colnr_T col, int ts, int *vts)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
130 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
131 int tabcount;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
132 colnr_T tabcol = 0;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
133 int t;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
134 int tab_size = 0;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
135
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
136 if (vts == 0 || vts[0] == 0)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
137 return ts;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
138
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
139 tabcount = vts[0];
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
140 for (t = 1; t <= tabcount; ++t)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
141 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
142 tabcol += vts[t];
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
143 if (tabcol > col)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
144 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
145 tab_size = vts[t];
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
146 break;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
147 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
148 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
149 if (t > tabcount)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
150 tab_size = vts[tabcount];
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
151
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
152 return tab_size;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
153 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
154
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
155 /*
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
156 * Find the column on which a tab starts.
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
157 */
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
158 colnr_T
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
159 tabstop_start(colnr_T col, int ts, int *vts)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
160 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
161 int tabcount;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
162 colnr_T tabcol = 0;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
163 int t;
28809
d0241e74bfdb patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents: 28773
diff changeset
164 int excess;
17940
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
165
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
166 if (vts == NULL || vts[0] == 0)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
167 return (col / ts) * ts;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
168
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
169 tabcount = vts[0];
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
170 for (t = 1; t <= tabcount; ++t)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
171 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
172 tabcol += vts[t];
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
173 if (tabcol > col)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
174 return tabcol - vts[t];
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
175 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
176
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
177 excess = tabcol % vts[tabcount];
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
178 return excess + ((col - excess) / vts[tabcount]) * vts[tabcount];
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
179 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
180
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
181 /*
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
182 * Find the number of tabs and spaces necessary to get from one column
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
183 * to another.
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
184 */
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
185 void
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
186 tabstop_fromto(
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
187 colnr_T start_col,
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
188 colnr_T end_col,
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
189 int ts_arg,
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
190 int *vts,
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
191 int *ntabs,
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
192 int *nspcs)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
193 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
194 int spaces = end_col - start_col;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
195 colnr_T tabcol = 0;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
196 int padding = 0;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
197 int tabcount;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
198 int t;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
199 int ts = ts_arg == 0 ? curbuf->b_p_ts : ts_arg;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
200
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
201 if (vts == NULL || vts[0] == 0)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
202 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
203 int tabs = 0;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
204 int initspc = 0;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
205
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
206 initspc = ts - (start_col % ts);
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
207 if (spaces >= initspc)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
208 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
209 spaces -= initspc;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
210 tabs++;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
211 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
212 tabs += spaces / ts;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
213 spaces -= (spaces / ts) * ts;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
214
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
215 *ntabs = tabs;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
216 *nspcs = spaces;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
217 return;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
218 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
219
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
220 // Find the padding needed to reach the next tabstop.
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
221 tabcount = vts[0];
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
222 for (t = 1; t <= tabcount; ++t)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
223 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
224 tabcol += vts[t];
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
225 if (tabcol > start_col)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
226 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
227 padding = (int)(tabcol - start_col);
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
228 break;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
229 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
230 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
231 if (t > tabcount)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
232 padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]);
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
233
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
234 // If the space needed is less than the padding no tabs can be used.
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
235 if (spaces < padding)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
236 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
237 *ntabs = 0;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
238 *nspcs = spaces;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
239 return;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
240 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
241
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
242 *ntabs = 1;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
243 spaces -= padding;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
244
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
245 // At least one tab has been used. See if any more will fit.
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
246 while (spaces != 0 && ++t <= tabcount)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
247 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
248 padding = vts[t];
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
249 if (spaces < padding)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
250 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
251 *nspcs = spaces;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
252 return;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
253 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
254 ++*ntabs;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
255 spaces -= padding;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
256 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
257
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
258 *ntabs += spaces / vts[tabcount];
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
259 *nspcs = spaces % vts[tabcount];
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
260 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
261
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
262 /*
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
263 * See if two tabstop arrays contain the same values.
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
264 */
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
265 static int
17940
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
266 tabstop_eq(int *ts1, int *ts2)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
267 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
268 int t;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
269
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
270 if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0))
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
271 return FALSE;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
272 if (ts1 == ts2)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
273 return TRUE;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
274 if (ts1[0] != ts2[0])
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
275 return FALSE;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
276
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
277 for (t = 1; t <= ts1[0]; ++t)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
278 if (ts1[t] != ts2[t])
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
279 return FALSE;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
280
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
281 return TRUE;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
282 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
283
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
284 # if defined(FEAT_BEVAL) || defined(PROTO)
17940
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
285 /*
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
286 * Copy a tabstop array, allocating space for the new array.
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
287 */
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
288 int *
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
289 tabstop_copy(int *oldts)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
290 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
291 int *newts;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
292 int t;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
293
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
294 if (oldts == NULL)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
295 return NULL;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
296 newts = ALLOC_MULT(int, oldts[0] + 1);
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
297 if (newts != NULL)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
298 for (t = 0; t <= oldts[0]; ++t)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
299 newts[t] = oldts[t];
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
300 return newts;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
301 }
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
302 # endif
17940
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
303
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
304 /*
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
305 * Return a count of the number of tabstops.
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
306 */
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
307 int
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
308 tabstop_count(int *ts)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
309 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
310 return ts != NULL ? ts[0] : 0;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
311 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
312
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
313 /*
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
314 * Return the first tabstop, or 8 if there are no tabstops defined.
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
315 */
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
316 int
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
317 tabstop_first(int *ts)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
318 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
319 return ts != NULL ? ts[1] : 8;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
320 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
321
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
322 #endif
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
323
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
324 /*
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
325 * Return the effective shiftwidth value for current buffer, using the
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
326 * 'tabstop' value when 'shiftwidth' is zero.
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
327 */
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
328 long
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
329 get_sw_value(buf_T *buf)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
330 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
331 return get_sw_value_col(buf, 0);
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
332 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
333
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
334 /*
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
335 * Idem, using "pos".
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
336 */
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
337 static long
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
338 get_sw_value_pos(buf_T *buf, pos_T *pos)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
339 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
340 pos_T save_cursor = curwin->w_cursor;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
341 long sw_value;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
342
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
343 curwin->w_cursor = *pos;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
344 sw_value = get_sw_value_col(buf, get_nolist_virtcol());
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
345 curwin->w_cursor = save_cursor;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
346 return sw_value;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
347 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
348
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
349 /*
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
350 * Idem, using the first non-black in the current line.
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
351 */
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
352 long
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
353 get_sw_value_indent(buf_T *buf)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
354 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
355 pos_T pos = curwin->w_cursor;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
356
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
357 pos.col = getwhitecols_curline();
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
358 return get_sw_value_pos(buf, &pos);
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
359 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
360
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
361 /*
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
362 * Idem, using virtual column "col".
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
363 */
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
364 long
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
365 get_sw_value_col(buf_T *buf, colnr_T col UNUSED)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
366 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
367 return buf->b_p_sw ? buf->b_p_sw :
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
368 #ifdef FEAT_VARTABS
17940
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
369 tabstop_at(col, buf->b_p_ts, buf->b_p_vts_array);
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
370 #else
17940
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
371 buf->b_p_ts;
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
372 #endif
17940
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
373 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
374
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
375 /*
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
376 * Return the effective softtabstop value for the current buffer, using the
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
377 * 'shiftwidth' value when 'softtabstop' is negative.
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
378 */
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
379 long
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
380 get_sts_value(void)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
381 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
382 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
383 }
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
384
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
385 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
386 * Count the size (in window cells) of the indent in the current line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
387 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
388 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
389 get_indent(void)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
390 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
391 #ifdef FEAT_VARTABS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
392 return get_indent_str_vtab(ml_get_curline(), (int)curbuf->b_p_ts,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
393 curbuf->b_p_vts_array, FALSE);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
394 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
395 return get_indent_str(ml_get_curline(), (int)curbuf->b_p_ts, FALSE);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
396 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
397 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
398
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
399 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
400 * Count the size (in window cells) of the indent in line "lnum".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
401 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
402 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
403 get_indent_lnum(linenr_T lnum)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
404 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
405 #ifdef FEAT_VARTABS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
406 return get_indent_str_vtab(ml_get(lnum), (int)curbuf->b_p_ts,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
407 curbuf->b_p_vts_array, FALSE);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
408 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
409 return get_indent_str(ml_get(lnum), (int)curbuf->b_p_ts, FALSE);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
410 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
411 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
412
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
413 #if defined(FEAT_FOLDING) || defined(PROTO)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
414 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
415 * Count the size (in window cells) of the indent in line "lnum" of buffer
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
416 * "buf".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
417 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
418 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
419 get_indent_buf(buf_T *buf, linenr_T lnum)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
420 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
421 # ifdef FEAT_VARTABS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
422 return get_indent_str_vtab(ml_get_buf(buf, lnum, FALSE),
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
423 (int)curbuf->b_p_ts, buf->b_p_vts_array, FALSE);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
424 # else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
425 return get_indent_str(ml_get_buf(buf, lnum, FALSE), (int)buf->b_p_ts, FALSE);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
426 # endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
427 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
428 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
429
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
430 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
431 * count the size (in window cells) of the indent in line "ptr", with
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
432 * 'tabstop' at "ts"
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
433 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
434 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
435 get_indent_str(
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
436 char_u *ptr,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
437 int ts,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
438 int list) // if TRUE, count only screen size for tabs
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
439 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
440 int count = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
441
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
442 for ( ; *ptr; ++ptr)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
443 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
444 if (*ptr == TAB)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
445 {
23952
44be09b25619 patch 8.2.2518: 'listchars' should be window-local
Bram Moolenaar <Bram@vim.org>
parents: 23833
diff changeset
446 if (!list || curwin->w_lcs_chars.tab1)
44be09b25619 patch 8.2.2518: 'listchars' should be window-local
Bram Moolenaar <Bram@vim.org>
parents: 23833
diff changeset
447 // count a tab for what it is worth
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
448 count += ts - (count % ts);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
449 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
450 // In list mode, when tab is not set, count screen char width
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
451 // for Tab, displays: ^I
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
452 count += ptr2cells(ptr);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
453 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
454 else if (*ptr == ' ')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
455 ++count; // count a space for one
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
456 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
457 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
458 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
459 return count;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
460 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
461
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
462 #ifdef FEAT_VARTABS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
463 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
464 * Count the size (in window cells) of the indent in line "ptr", using
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
465 * variable tabstops.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
466 * if "list" is TRUE, count only screen size for tabs.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
467 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
468 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
469 get_indent_str_vtab(char_u *ptr, int ts, int *vts, int list)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
470 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
471 int count = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
472
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
473 for ( ; *ptr; ++ptr)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
474 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
475 if (*ptr == TAB) // count a tab for what it is worth
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
476 {
23952
44be09b25619 patch 8.2.2518: 'listchars' should be window-local
Bram Moolenaar <Bram@vim.org>
parents: 23833
diff changeset
477 if (!list || curwin->w_lcs_chars.tab1)
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
478 count += tabstop_padding(count, ts, vts);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
479 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
480 // In list mode, when tab is not set, count screen char width
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
481 // for Tab, displays: ^I
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
482 count += ptr2cells(ptr);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
483 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
484 else if (*ptr == ' ')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
485 ++count; // count a space for one
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
486 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
487 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
488 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
489 return count;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
490 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
491 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
492
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
493 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
494 * Set the indent of the current line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
495 * Leaves the cursor on the first non-blank in the line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
496 * Caller must take care of undo.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
497 * "flags":
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
498 * SIN_CHANGED: call changed_bytes() if the line was changed.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
499 * SIN_INSERT: insert the indent in front of the line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
500 * SIN_UNDO: save line for undo before changing it.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
501 * Returns TRUE if the line was changed.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
502 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
503 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
504 set_indent(
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
505 int size, // measured in spaces
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
506 int flags)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
507 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
508 char_u *p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
509 char_u *newline;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
510 char_u *oldline;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
511 char_u *s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
512 int todo;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
513 int ind_len; // measured in characters
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
514 int line_len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
515 int doit = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
516 int ind_done = 0; // measured in spaces
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
517 #ifdef FEAT_VARTABS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
518 int ind_col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
519 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
520 int tab_pad;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
521 int retval = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
522 int orig_char_len = -1; // number of initial whitespace chars when
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
523 // 'et' and 'pi' are both set
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
524
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
525 // First check if there is anything to do and compute the number of
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
526 // characters needed for the indent.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
527 todo = size;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
528 ind_len = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
529 p = oldline = ml_get_curline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
530
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
531 // Calculate the buffer size for the new indent, and check to see if it
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
532 // isn't already set
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
533
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
534 // if 'expandtab' isn't set: use TABs; if both 'expandtab' and
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
535 // 'preserveindent' are set count the number of characters at the
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
536 // beginning of the line to be copied
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
537 if (!curbuf->b_p_et || (!(flags & SIN_INSERT) && curbuf->b_p_pi))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
538 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
539 // If 'preserveindent' is set then reuse as much as possible of
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
540 // the existing indent structure for the new indent
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
541 if (!(flags & SIN_INSERT) && curbuf->b_p_pi)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
542 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
543 ind_done = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
544
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
545 // count as many characters as we can use
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
546 while (todo > 0 && VIM_ISWHITE(*p))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
547 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
548 if (*p == TAB)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
549 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
550 #ifdef FEAT_VARTABS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
551 tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
552 curbuf->b_p_vts_array);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
553 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
554 tab_pad = (int)curbuf->b_p_ts
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
555 - (ind_done % (int)curbuf->b_p_ts);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
556 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
557 // stop if this tab will overshoot the target
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
558 if (todo < tab_pad)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
559 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
560 todo -= tab_pad;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
561 ++ind_len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
562 ind_done += tab_pad;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
563 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
564 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
565 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
566 --todo;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
567 ++ind_len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
568 ++ind_done;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
569 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
570 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
571 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
572
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
573 #ifdef FEAT_VARTABS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
574 // These diverge from this point.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
575 ind_col = ind_done;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
576 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
577 // Set initial number of whitespace chars to copy if we are
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
578 // preserving indent but expandtab is set
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
579 if (curbuf->b_p_et)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
580 orig_char_len = ind_len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
581
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
582 // Fill to next tabstop with a tab, if possible
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
583 #ifdef FEAT_VARTABS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
584 tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
585 curbuf->b_p_vts_array);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
586 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
587 tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
588 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
589 if (todo >= tab_pad && orig_char_len == -1)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
590 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
591 doit = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
592 todo -= tab_pad;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
593 ++ind_len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
594 // ind_done += tab_pad;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
595 #ifdef FEAT_VARTABS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
596 ind_col += tab_pad;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
597 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
598 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
599 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
600
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
601 // count tabs required for indent
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
602 #ifdef FEAT_VARTABS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
603 for (;;)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
604 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
605 tab_pad = tabstop_padding(ind_col, curbuf->b_p_ts,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
606 curbuf->b_p_vts_array);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
607 if (todo < tab_pad)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
608 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
609 if (*p != TAB)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
610 doit = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
611 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
612 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
613 todo -= tab_pad;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
614 ++ind_len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
615 ind_col += tab_pad;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
616 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
617 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
618 while (todo >= (int)curbuf->b_p_ts)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
619 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
620 if (*p != TAB)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
621 doit = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
622 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
623 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
624 todo -= (int)curbuf->b_p_ts;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
625 ++ind_len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
626 // ind_done += (int)curbuf->b_p_ts;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
627 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
628 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
629 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
630 // count spaces required for indent
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
631 while (todo > 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
632 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
633 if (*p != ' ')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
634 doit = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
635 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
636 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
637 --todo;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
638 ++ind_len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
639 // ++ind_done;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
640 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
641
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
642 // Return if the indent is OK already.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
643 if (!doit && !VIM_ISWHITE(*p) && !(flags & SIN_INSERT))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
644 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
645
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
646 // Allocate memory for the new line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
647 if (flags & SIN_INSERT)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
648 p = oldline;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
649 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
650 p = skipwhite(p);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
651 line_len = (int)STRLEN(p) + 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
652
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
653 // If 'preserveindent' and 'expandtab' are both set keep the original
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
654 // characters and allocate accordingly. We will fill the rest with spaces
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
655 // after the if (!curbuf->b_p_et) below.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
656 if (orig_char_len != -1)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
657 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
658 newline = alloc(orig_char_len + size - ind_done + line_len);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
659 if (newline == NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
660 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
661 todo = size - ind_done;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
662 ind_len = orig_char_len + todo; // Set total length of indent in
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
663 // characters, which may have been
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
664 // undercounted until now
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
665 p = oldline;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
666 s = newline;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
667 while (orig_char_len > 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
668 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
669 *s++ = *p++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
670 orig_char_len--;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
671 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
672
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
673 // Skip over any additional white space (useful when newindent is less
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
674 // than old)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
675 while (VIM_ISWHITE(*p))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
676 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
677
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
678 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
679 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
680 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
681 todo = size;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
682 newline = alloc(ind_len + line_len);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
683 if (newline == NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
684 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
685 s = newline;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
686 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
687
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
688 // Put the characters in the new line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
689 // if 'expandtab' isn't set: use TABs
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
690 if (!curbuf->b_p_et)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
691 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
692 // If 'preserveindent' is set then reuse as much as possible of
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
693 // the existing indent structure for the new indent
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
694 if (!(flags & SIN_INSERT) && curbuf->b_p_pi)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
695 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
696 p = oldline;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
697 ind_done = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
698
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
699 while (todo > 0 && VIM_ISWHITE(*p))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
700 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
701 if (*p == TAB)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
702 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
703 #ifdef FEAT_VARTABS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
704 tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
705 curbuf->b_p_vts_array);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
706 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
707 tab_pad = (int)curbuf->b_p_ts
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
708 - (ind_done % (int)curbuf->b_p_ts);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
709 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
710 // stop if this tab will overshoot the target
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
711 if (todo < tab_pad)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
712 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
713 todo -= tab_pad;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
714 ind_done += tab_pad;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
715 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
716 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
717 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
718 --todo;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
719 ++ind_done;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
720 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
721 *s++ = *p++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
722 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
723
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
724 // Fill to next tabstop with a tab, if possible
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
725 #ifdef FEAT_VARTABS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
726 tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
727 curbuf->b_p_vts_array);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
728 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
729 tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
730 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
731 if (todo >= tab_pad)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
732 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
733 *s++ = TAB;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
734 todo -= tab_pad;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
735 #ifdef FEAT_VARTABS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
736 ind_done += tab_pad;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
737 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
738 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
739
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
740 p = skipwhite(p);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
741 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
742
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
743 #ifdef FEAT_VARTABS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
744 for (;;)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
745 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
746 tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
747 curbuf->b_p_vts_array);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
748 if (todo < tab_pad)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
749 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
750 *s++ = TAB;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
751 todo -= tab_pad;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
752 ind_done += tab_pad;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
753 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
754 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
755 while (todo >= (int)curbuf->b_p_ts)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
756 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
757 *s++ = TAB;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
758 todo -= (int)curbuf->b_p_ts;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
759 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
760 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
761 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
762 while (todo > 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
763 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
764 *s++ = ' ';
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
765 --todo;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
766 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
767 mch_memmove(s, p, (size_t)line_len);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
768
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
769 // Replace the line (unless undo fails).
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
770 if (!(flags & SIN_UNDO) || u_savesub(curwin->w_cursor.lnum) == OK)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
771 {
21070
87e85a13e9cf patch 8.2.1086: possibly using freed memory when text properties used
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
772 colnr_T old_offset = (colnr_T)(p - oldline);
87e85a13e9cf patch 8.2.1086: possibly using freed memory when text properties used
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
773 colnr_T new_offset = (colnr_T)(s - newline);
87e85a13e9cf patch 8.2.1086: possibly using freed memory when text properties used
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
774
87e85a13e9cf patch 8.2.1086: possibly using freed memory when text properties used
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
775 // this may free "newline"
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
776 ml_replace(curwin->w_cursor.lnum, newline, FALSE);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
777 if (flags & SIN_CHANGED)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
778 changed_bytes(curwin->w_cursor.lnum, 0);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
779
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
780 // Correct saved cursor position if it is in this line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
781 if (saved_cursor.lnum == curwin->w_cursor.lnum)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
782 {
21070
87e85a13e9cf patch 8.2.1086: possibly using freed memory when text properties used
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
783 if (saved_cursor.col >= old_offset)
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
784 // cursor was after the indent, adjust for the number of
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
785 // bytes added/removed
21070
87e85a13e9cf patch 8.2.1086: possibly using freed memory when text properties used
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
786 saved_cursor.col += ind_len - old_offset;
87e85a13e9cf patch 8.2.1086: possibly using freed memory when text properties used
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
787 else if (saved_cursor.col >= new_offset)
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
788 // cursor was in the indent, and is now after it, put it back
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
789 // at the start of the indent (replacing spaces with TAB)
21070
87e85a13e9cf patch 8.2.1086: possibly using freed memory when text properties used
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
790 saved_cursor.col = new_offset;
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
791 }
18763
49b78d6465e5 patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents: 18679
diff changeset
792 #ifdef FEAT_PROP_POPUP
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
793 {
21070
87e85a13e9cf patch 8.2.1086: possibly using freed memory when text properties used
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
794 int added = ind_len - old_offset;
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
795
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
796 // When increasing indent this behaves like spaces were inserted at
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
797 // the old indent, when decreasing indent it behaves like spaces
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
798 // were deleted at the new indent.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
799 adjust_prop_columns(curwin->w_cursor.lnum,
21070
87e85a13e9cf patch 8.2.1086: possibly using freed memory when text properties used
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
800 added > 0 ? old_offset : (colnr_T)ind_len, added, 0);
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
801 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
802 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
803 retval = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
804 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
805 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
806 vim_free(newline);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
807
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
808 curwin->w_cursor.col = ind_len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
809 return retval;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
810 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
811
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
812 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
813 * Return the indent of the current line after a number. Return -1 if no
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
814 * number was found. Used for 'n' in 'formatoptions': numbered list.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
815 * Since a pattern is used it can actually handle more than numbers.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
816 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
817 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
818 get_number_indent(linenr_T lnum)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
819 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
820 colnr_T col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
821 pos_T pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
822
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
823 regmatch_T regmatch;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
824 int lead_len = 0; // length of comment leader
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
825
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
826 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: 17940
diff changeset
827 return -1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
828 pos.lnum = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
829
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
830 // In format_lines() (i.e. not insert mode), fo+=q is needed too...
28773
d770568e6c98 patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents: 28716
diff changeset
831 if ((State & MODE_INSERT) || has_format_option(FO_Q_COMS))
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
832 lead_len = get_leader_len(ml_get(lnum), NULL, FALSE, TRUE);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
833
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
834 regmatch.regprog = vim_regcomp(curbuf->b_p_flp, RE_MAGIC);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
835 if (regmatch.regprog != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
836 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
837 regmatch.rm_ic = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
838
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
839 // vim_regexec() expects a pointer to a line. This lets us
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
840 // start matching for the flp beyond any comment leader...
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
841 if (vim_regexec(&regmatch, ml_get(lnum) + lead_len, (colnr_T)0))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
842 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
843 pos.lnum = lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
844 pos.col = (colnr_T)(*regmatch.endp - ml_get(lnum));
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
845 pos.coladd = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
846 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
847 vim_regfree(regmatch.regprog);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
848 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
849
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
850 if (pos.lnum == 0 || *ml_get_pos(&pos) == NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
851 return -1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
852 getvcol(curwin, &pos, &col, NULL, NULL);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
853 return (int)col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
854 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
855
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
856 #if defined(FEAT_LINEBREAK) || defined(PROTO)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
857 /*
18679
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
858 * This is called when 'breakindentopt' is changed and when a window is
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
859 * initialized.
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
860 */
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
861 int
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
862 briopt_check(win_T *wp)
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
863 {
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
864 char_u *p;
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
865 int bri_shift = 0;
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
866 long bri_min = 20;
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
867 int bri_sbr = FALSE;
25248
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
868 int bri_list = 0;
28716
2bd5cb054180 patch 8.2.4882: cannot make 'breakindent' use a specific column
Bram Moolenaar <Bram@vim.org>
parents: 28540
diff changeset
869 int bri_vcol = 0;
18679
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
870
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
871 p = wp->w_p_briopt;
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
872 while (*p != NUL)
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
873 {
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
874 if (STRNCMP(p, "shift:", 6) == 0
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
875 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
876 {
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
877 p += 6;
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
878 bri_shift = getdigits(&p);
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
879 }
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
880 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
881 {
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
882 p += 4;
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
883 bri_min = getdigits(&p);
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
884 }
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
885 else if (STRNCMP(p, "sbr", 3) == 0)
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
886 {
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
887 p += 3;
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
888 bri_sbr = TRUE;
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
889 }
25248
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
890 else if (STRNCMP(p, "list:", 5) == 0)
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
891 {
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
892 p += 5;
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
893 bri_list = getdigits(&p);
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
894 }
28716
2bd5cb054180 patch 8.2.4882: cannot make 'breakindent' use a specific column
Bram Moolenaar <Bram@vim.org>
parents: 28540
diff changeset
895 else if (STRNCMP(p, "column:", 7) == 0)
2bd5cb054180 patch 8.2.4882: cannot make 'breakindent' use a specific column
Bram Moolenaar <Bram@vim.org>
parents: 28540
diff changeset
896 {
2bd5cb054180 patch 8.2.4882: cannot make 'breakindent' use a specific column
Bram Moolenaar <Bram@vim.org>
parents: 28540
diff changeset
897 p += 7;
2bd5cb054180 patch 8.2.4882: cannot make 'breakindent' use a specific column
Bram Moolenaar <Bram@vim.org>
parents: 28540
diff changeset
898 bri_vcol = getdigits(&p);
2bd5cb054180 patch 8.2.4882: cannot make 'breakindent' use a specific column
Bram Moolenaar <Bram@vim.org>
parents: 28540
diff changeset
899 }
18679
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
900 if (*p != ',' && *p != NUL)
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
901 return FAIL;
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
902 if (*p == ',')
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
903 ++p;
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
904 }
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
905
19503
a4be2f9cfb01 patch 8.2.0309: window-local values have confusing name
Bram Moolenaar <Bram@vim.org>
parents: 18933
diff changeset
906 wp->w_briopt_shift = bri_shift;
a4be2f9cfb01 patch 8.2.0309: window-local values have confusing name
Bram Moolenaar <Bram@vim.org>
parents: 18933
diff changeset
907 wp->w_briopt_min = bri_min;
a4be2f9cfb01 patch 8.2.0309: window-local values have confusing name
Bram Moolenaar <Bram@vim.org>
parents: 18933
diff changeset
908 wp->w_briopt_sbr = bri_sbr;
25248
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
909 wp->w_briopt_list = bri_list;
28716
2bd5cb054180 patch 8.2.4882: cannot make 'breakindent' use a specific column
Bram Moolenaar <Bram@vim.org>
parents: 28540
diff changeset
910 wp->w_briopt_vcol = bri_vcol;
18679
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
911
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
912 return OK;
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
913 }
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
914
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
915 /*
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
916 * Return appropriate space number for breakindent, taking influencing
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
917 * parameters into account. Window must be specified, since it is not
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
918 * necessarily always the current one.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
919 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
920 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
921 get_breakindent_win(
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
922 win_T *wp,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
923 char_u *line) // start of the line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
924 {
27000
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
925 static int prev_indent = 0; // cached indent value
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
926 static long prev_ts = 0L; // cached tabstop value
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
927 static char_u *prev_line = NULL; // cached pointer to line
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
928 static varnumber_T prev_tick = 0; // changedtick of cached value
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
929 # ifdef FEAT_VARTABS
27000
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
930 static int *prev_vts = NULL; // cached vartabs values
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
931 # endif
27000
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
932 static int prev_list = 0; // cached list value
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
933 static int prev_listopt = 0; // cached w_p_briopt_list value
27128
164d59ddd48a patch 8.2.4093: cached breakindent values not initialized properly
Bram Moolenaar <Bram@vim.org>
parents: 27000
diff changeset
934 // cached formatlistpat value
164d59ddd48a patch 8.2.4093: cached breakindent values not initialized properly
Bram Moolenaar <Bram@vim.org>
parents: 27000
diff changeset
935 static char_u *prev_flp = NULL;
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
936 int bri = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
937 // window width minus window margin space, i.e. what rests for text
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
938 const int eff_wwidth = wp->w_width
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
939 - ((wp->w_p_nu || wp->w_p_rnu)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
940 && (vim_strchr(p_cpo, CPO_NUMCOL) == NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
941 ? number_width(wp) + 1 : 0);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
942
27128
164d59ddd48a patch 8.2.4093: cached breakindent values not initialized properly
Bram Moolenaar <Bram@vim.org>
parents: 27000
diff changeset
943 // used cached indent, unless
164d59ddd48a patch 8.2.4093: cached breakindent values not initialized properly
Bram Moolenaar <Bram@vim.org>
parents: 27000
diff changeset
944 // - line pointer changed
164d59ddd48a patch 8.2.4093: cached breakindent values not initialized properly
Bram Moolenaar <Bram@vim.org>
parents: 27000
diff changeset
945 // - 'tabstop' changed
164d59ddd48a patch 8.2.4093: cached breakindent values not initialized properly
Bram Moolenaar <Bram@vim.org>
parents: 27000
diff changeset
946 // - 'briopt_list changed' changed or
164d59ddd48a patch 8.2.4093: cached breakindent values not initialized properly
Bram Moolenaar <Bram@vim.org>
parents: 27000
diff changeset
947 // - 'formatlistpattern' changed
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
948 if (prev_line != line || prev_ts != wp->w_buffer->b_p_ts
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
949 || prev_tick != CHANGEDTICK(wp->w_buffer)
27000
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
950 || prev_listopt != wp->w_briopt_list
27128
164d59ddd48a patch 8.2.4093: cached breakindent values not initialized properly
Bram Moolenaar <Bram@vim.org>
parents: 27000
diff changeset
951 || (prev_flp == NULL
164d59ddd48a patch 8.2.4093: cached breakindent values not initialized properly
Bram Moolenaar <Bram@vim.org>
parents: 27000
diff changeset
952 || (STRCMP(prev_flp, get_flp_value(wp->w_buffer)) != 0))
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
953 # ifdef FEAT_VARTABS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
954 || prev_vts != wp->w_buffer->b_p_vts_array
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
955 # endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
956 )
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
957 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
958 prev_line = line;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
959 prev_ts = wp->w_buffer->b_p_ts;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
960 prev_tick = CHANGEDTICK(wp->w_buffer);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
961 # ifdef FEAT_VARTABS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
962 prev_vts = wp->w_buffer->b_p_vts_array;
28716
2bd5cb054180 patch 8.2.4882: cannot make 'breakindent' use a specific column
Bram Moolenaar <Bram@vim.org>
parents: 28540
diff changeset
963 if (wp->w_briopt_vcol == 0)
2bd5cb054180 patch 8.2.4882: cannot make 'breakindent' use a specific column
Bram Moolenaar <Bram@vim.org>
parents: 28540
diff changeset
964 prev_indent = get_indent_str_vtab(line,
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
965 (int)wp->w_buffer->b_p_ts,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
966 wp->w_buffer->b_p_vts_array, wp->w_p_list);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
967 # else
28716
2bd5cb054180 patch 8.2.4882: cannot make 'breakindent' use a specific column
Bram Moolenaar <Bram@vim.org>
parents: 28540
diff changeset
968 if (wp->w_briopt_vcol == 0)
2bd5cb054180 patch 8.2.4882: cannot make 'breakindent' use a specific column
Bram Moolenaar <Bram@vim.org>
parents: 28540
diff changeset
969 prev_indent = get_indent_str(line,
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
970 (int)wp->w_buffer->b_p_ts, wp->w_p_list);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
971 # endif
27000
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
972 prev_listopt = wp->w_briopt_list;
27128
164d59ddd48a patch 8.2.4093: cached breakindent values not initialized properly
Bram Moolenaar <Bram@vim.org>
parents: 27000
diff changeset
973 prev_list = 0;
164d59ddd48a patch 8.2.4093: cached breakindent values not initialized properly
Bram Moolenaar <Bram@vim.org>
parents: 27000
diff changeset
974 vim_free(prev_flp);
164d59ddd48a patch 8.2.4093: cached breakindent values not initialized properly
Bram Moolenaar <Bram@vim.org>
parents: 27000
diff changeset
975 prev_flp = vim_strsave(get_flp_value(wp->w_buffer));
27000
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
976 // add additional indent for numbered lists
28716
2bd5cb054180 patch 8.2.4882: cannot make 'breakindent' use a specific column
Bram Moolenaar <Bram@vim.org>
parents: 28540
diff changeset
977 if (wp->w_briopt_list != 0 && wp->w_briopt_vcol == 0)
27000
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
978 {
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
979 regmatch_T regmatch;
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
980
27128
164d59ddd48a patch 8.2.4093: cached breakindent values not initialized properly
Bram Moolenaar <Bram@vim.org>
parents: 27000
diff changeset
981 regmatch.regprog = vim_regcomp(prev_flp,
164d59ddd48a patch 8.2.4093: cached breakindent values not initialized properly
Bram Moolenaar <Bram@vim.org>
parents: 27000
diff changeset
982 RE_MAGIC + RE_STRING + RE_AUTO + RE_STRICT);
27000
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
983
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
984 if (regmatch.regprog != NULL)
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
985 {
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
986 regmatch.rm_ic = FALSE;
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
987 if (vim_regexec(&regmatch, line, 0))
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
988 {
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
989 if (wp->w_briopt_list > 0)
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
990 prev_list = wp->w_briopt_list;
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
991 else
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
992 prev_list = (*regmatch.endp - *regmatch.startp);
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
993 }
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
994 vim_regfree(regmatch.regprog);
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
995 }
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
996 }
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
997 }
28716
2bd5cb054180 patch 8.2.4882: cannot make 'breakindent' use a specific column
Bram Moolenaar <Bram@vim.org>
parents: 28540
diff changeset
998 if (wp->w_briopt_vcol != 0)
2bd5cb054180 patch 8.2.4882: cannot make 'breakindent' use a specific column
Bram Moolenaar <Bram@vim.org>
parents: 28540
diff changeset
999 {
2bd5cb054180 patch 8.2.4882: cannot make 'breakindent' use a specific column
Bram Moolenaar <Bram@vim.org>
parents: 28540
diff changeset
1000 // column value has priority
2bd5cb054180 patch 8.2.4882: cannot make 'breakindent' use a specific column
Bram Moolenaar <Bram@vim.org>
parents: 28540
diff changeset
1001 bri = wp->w_briopt_vcol;
2bd5cb054180 patch 8.2.4882: cannot make 'breakindent' use a specific column
Bram Moolenaar <Bram@vim.org>
parents: 28540
diff changeset
1002 prev_list = 0;
2bd5cb054180 patch 8.2.4882: cannot make 'breakindent' use a specific column
Bram Moolenaar <Bram@vim.org>
parents: 28540
diff changeset
1003 }
2bd5cb054180 patch 8.2.4882: cannot make 'breakindent' use a specific column
Bram Moolenaar <Bram@vim.org>
parents: 28540
diff changeset
1004 else
2bd5cb054180 patch 8.2.4882: cannot make 'breakindent' use a specific column
Bram Moolenaar <Bram@vim.org>
parents: 28540
diff changeset
1005 bri = prev_indent + wp->w_briopt_shift;
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1006
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1007 // Add offset for number column, if 'n' is in 'cpoptions'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1008 bri += win_col_off2(wp);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1009
25248
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1010 // add additional indent for numbered lists
25322
b3d7becabe99 patch 8.2.3198: cannot use 'formatlistpat' for breakindent
Bram Moolenaar <Bram@vim.org>
parents: 25248
diff changeset
1011 if (wp->w_briopt_list != 0)
25248
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1012 {
27000
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
1013 if (wp->w_briopt_list > 0)
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
1014 bri += prev_list;
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
1015 else
8c0730eca2ce patch 8.2.4029: debugging NFA regexp my crash, cached indent may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 26877
diff changeset
1016 bri = prev_list;
25248
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1017 }
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1018
25322
b3d7becabe99 patch 8.2.3198: cannot use 'formatlistpat' for breakindent
Bram Moolenaar <Bram@vim.org>
parents: 25248
diff changeset
1019 // indent minus the length of the showbreak string
b3d7becabe99 patch 8.2.3198: cannot use 'formatlistpat' for breakindent
Bram Moolenaar <Bram@vim.org>
parents: 25248
diff changeset
1020 if (wp->w_briopt_sbr)
b3d7becabe99 patch 8.2.3198: cannot use 'formatlistpat' for breakindent
Bram Moolenaar <Bram@vim.org>
parents: 25248
diff changeset
1021 bri -= vim_strsize(get_showbreak_value(wp));
b3d7becabe99 patch 8.2.3198: cannot use 'formatlistpat' for breakindent
Bram Moolenaar <Bram@vim.org>
parents: 25248
diff changeset
1022
b3d7becabe99 patch 8.2.3198: cannot use 'formatlistpat' for breakindent
Bram Moolenaar <Bram@vim.org>
parents: 25248
diff changeset
1023
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1024 // never indent past left window margin
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1025 if (bri < 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1026 bri = 0;
25248
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1027
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1028 // always leave at least bri_min characters on the left,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1029 // if text width is sufficient
19503
a4be2f9cfb01 patch 8.2.0309: window-local values have confusing name
Bram Moolenaar <Bram@vim.org>
parents: 18933
diff changeset
1030 else if (bri > eff_wwidth - wp->w_briopt_min)
a4be2f9cfb01 patch 8.2.0309: window-local values have confusing name
Bram Moolenaar <Bram@vim.org>
parents: 18933
diff changeset
1031 bri = (eff_wwidth - wp->w_briopt_min < 0)
a4be2f9cfb01 patch 8.2.0309: window-local values have confusing name
Bram Moolenaar <Bram@vim.org>
parents: 18933
diff changeset
1032 ? 0 : eff_wwidth - wp->w_briopt_min;
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1033
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1034 return bri;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1035 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1036 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1037
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1038 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1039 * When extra == 0: Return TRUE if the cursor is before or on the first
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1040 * non-blank in the line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1041 * When extra == 1: Return TRUE if the cursor is before the first non-blank in
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1042 * the line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1043 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1044 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1045 inindent(int extra)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1046 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1047 char_u *ptr;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1048 colnr_T col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1049
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1050 for (col = 0, ptr = ml_get_curline(); VIM_ISWHITE(*ptr); ++col)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1051 ++ptr;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1052 if (col >= curwin->w_cursor.col + extra)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1053 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1054 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1055 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1056 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1057
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1058 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1059 * op_reindent - handle reindenting a block of lines.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1060 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1061 void
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1062 op_reindent(oparg_T *oap, int (*how)(void))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1063 {
28540
63e9b0016a6c patch 8.2.4794: compiler warning for not initialized variable
Bram Moolenaar <Bram@vim.org>
parents: 28536
diff changeset
1064 long i = 0;
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1065 char_u *l;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1066 int amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1067 linenr_T first_changed = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1068 linenr_T last_changed = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1069 linenr_T start_lnum = curwin->w_cursor.lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1070
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1071 // Don't even try when 'modifiable' is off.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1072 if (!curbuf->b_p_ma)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1073 {
25064
8f2262c72178 patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 23952
diff changeset
1074 emsg(_(e_cannot_make_changes_modifiable_is_off));
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1075 return;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1076 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1077
28536
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1078 // Save for undo. Do this once for all lines, much faster than doing this
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1079 // for each line separately, especially when undoing.
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1080 if (u_savecommon(start_lnum - 1, start_lnum + oap->line_count,
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1081 start_lnum + oap->line_count, FALSE) == OK)
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1082 for (i = oap->line_count; --i >= 0 && !got_int; )
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1083 {
28536
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1084 // it's a slow thing to do, so give feedback so there's no worry
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1085 // that the computer's just hung.
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1086
28536
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1087 if (i > 1
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1088 && (i % 50 == 0 || i == oap->line_count - 1)
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1089 && oap->line_count > p_report)
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1090 smsg(_("%ld lines to indent... "), i);
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1091
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1092 // Be vi-compatible: For lisp indenting the first line is not
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1093 // indented, unless there is only one line.
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1094 if (i != oap->line_count - 1 || oap->line_count == 1
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1095 || how != get_lisp_indent)
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1096 {
28536
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1097 l = skipwhite(ml_get_curline());
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1098 if (*l == NUL) // empty or blank line
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1099 amount = 0;
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1100 else
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1101 amount = how(); // get the indent for this line
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1102
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1103 if (amount >= 0 && set_indent(amount, 0))
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1104 {
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1105 // did change the indent, call changed_lines() later
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1106 if (first_changed == 0)
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1107 first_changed = curwin->w_cursor.lnum;
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1108 last_changed = curwin->w_cursor.lnum;
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1109 }
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1110 }
28536
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1111 ++curwin->w_cursor.lnum;
b6f2f545f8cc patch 8.2.4792: indent operator creates an undo entry for every line
Bram Moolenaar <Bram@vim.org>
parents: 27821
diff changeset
1112 curwin->w_cursor.col = 0; // make sure it's valid
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1113 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1114
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1115 // put cursor on first non-blank of indented line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1116 curwin->w_cursor.lnum = start_lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1117 beginline(BL_SOL | BL_FIX);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1118
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1119 // Mark changed lines so that they will be redrawn. When Visual
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1120 // highlighting was present, need to continue until the last line. When
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1121 // there is no change still need to remove the Visual highlighting.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1122 if (last_changed != 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1123 changed_lines(first_changed, 0,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1124 oap->is_VIsual ? start_lnum + oap->line_count :
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1125 last_changed + 1, 0L);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1126 else if (oap->is_VIsual)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1127 redraw_curbuf_later(INVERTED);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1128
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1129 if (oap->line_count > p_report)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1130 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1131 i = oap->line_count - (i + 1);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1132 smsg(NGETTEXT("%ld line indented ",
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1133 "%ld lines indented ", i), i);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1134 }
22699
e82579016863 patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents: 21070
diff changeset
1135 if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0)
18619
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18578
diff changeset
1136 {
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18578
diff changeset
1137 // set '[ and '] marks
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18578
diff changeset
1138 curbuf->b_op_start = oap->start;
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18578
diff changeset
1139 curbuf->b_op_end = oap->end;
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18578
diff changeset
1140 }
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1141 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1142
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1143 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1144 * Return TRUE if lines starting with '#' should be left aligned.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1145 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1146 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1147 preprocs_left(void)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1148 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1149 return
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1150 (curbuf->b_p_si && !curbuf->b_p_cin) ||
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1151 (curbuf->b_p_cin && in_cinkeys('#', ' ', TRUE)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1152 && curbuf->b_ind_hash_comment == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1153 ;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1154 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1155
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1156 /*
28856
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
1157 * Return TRUE if the conditions are OK for smart indenting.
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
1158 */
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
1159 int
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
1160 may_do_si()
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
1161 {
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
1162 return curbuf->b_p_si
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
1163 && !curbuf->b_p_cin
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
1164 # ifdef FEAT_EVAL
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
1165 && *curbuf->b_p_inde == NUL
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
1166 # endif
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
1167 && !p_paste;
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
1168 }
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
1169
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
1170 /*
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1171 * Try to do some very smart auto-indenting.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1172 * Used when inserting a "normal" character.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1173 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1174 void
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1175 ins_try_si(int c)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1176 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1177 pos_T *pos, old_pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1178 char_u *ptr;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1179 int i;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1180 int temp;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1181
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1182 // do some very smart indenting when entering '{' or '}'
28860
3942ea75b4c0 patch 8.2.4953: with 'si' inserting '}' after completion goes wrong
Bram Moolenaar <Bram@vim.org>
parents: 28856
diff changeset
1183 if (((did_si || can_si_back) && c == '{')
3942ea75b4c0 patch 8.2.4953: with 'si' inserting '}' after completion goes wrong
Bram Moolenaar <Bram@vim.org>
parents: 28856
diff changeset
1184 || (can_si && c == '}' && inindent(0)))
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1185 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1186 // for '}' set indent equal to indent of line containing matching '{'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1187 if (c == '}' && (pos = findmatch(NULL, '{')) != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1188 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1189 old_pos = curwin->w_cursor;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1190 // If the matching '{' has a ')' immediately before it (ignoring
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1191 // white-space), then line up with the start of the line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1192 // containing the matching '(' if there is one. This handles the
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1193 // case where an "if (..\n..) {" statement continues over multiple
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1194 // lines -- webb
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1195 ptr = ml_get(pos->lnum);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1196 i = pos->col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1197 if (i > 0) // skip blanks before '{'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1198 while (--i > 0 && VIM_ISWHITE(ptr[i]))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1199 ;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1200 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: 17940
diff changeset
1201 curwin->w_cursor.col = i;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1202 if (ptr[i] == ')' && (pos = findmatch(NULL, '(')) != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1203 curwin->w_cursor = *pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1204 i = get_indent();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1205 curwin->w_cursor = old_pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1206 if (State & VREPLACE_FLAG)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1207 change_indent(INDENT_SET, i, FALSE, NUL, TRUE);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1208 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1209 (void)set_indent(i, SIN_CHANGED);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1210 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1211 else if (curwin->w_cursor.col > 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1212 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1213 // when inserting '{' after "O" reduce indent, but not
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1214 // more than indent of previous line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1215 temp = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1216 if (c == '{' && can_si_back && curwin->w_cursor.lnum > 1)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1217 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1218 old_pos = curwin->w_cursor;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1219 i = get_indent();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1220 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: 17940
diff changeset
1221 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1222 ptr = skipwhite(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: 17940
diff changeset
1223
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1224 // ignore empty lines and lines starting with '#'.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1225 if (*ptr != '#' && *ptr != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1226 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1227 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1228 if (get_indent() >= i)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1229 temp = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1230 curwin->w_cursor = old_pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1231 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1232 if (temp)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1233 shift_line(TRUE, FALSE, 1, TRUE);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1234 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1235 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1236
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1237 // set indent of '#' always to 0
28856
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
1238 if (curwin->w_cursor.col > 0 && can_si && c == '#' && inindent(0))
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1239 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1240 // remember current indent for next line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1241 old_indent = get_indent();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1242 (void)set_indent(0, SIN_CHANGED);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1243 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1244
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1245 // Adjust ai_col, the char at this position can be deleted.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1246 if (ai_col > curwin->w_cursor.col)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1247 ai_col = curwin->w_cursor.col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1248 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1249
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1250 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1251 * Insert an indent (for <Tab> or CTRL-T) or delete an indent (for CTRL-D).
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1252 * Keep the cursor on the same character.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1253 * type == INDENT_INC increase indent (for CTRL-T or <Tab>)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1254 * type == INDENT_DEC decrease indent (for CTRL-D)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1255 * type == INDENT_SET set indent to "amount"
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1256 * if round is TRUE, round the indent to 'shiftwidth' (only with _INC and _Dec).
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1257 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1258 void
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1259 change_indent(
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1260 int type,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1261 int amount,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1262 int round,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1263 int replaced, // replaced character, put on replace stack
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1264 int call_changed_bytes) // call changed_bytes()
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1265 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1266 int vcol;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1267 int last_vcol;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1268 int insstart_less; // reduction for Insstart.col
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1269 int new_cursor_col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1270 int i;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1271 char_u *ptr;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1272 int save_p_list;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1273 int start_col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1274 colnr_T vc;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1275 colnr_T orig_col = 0; // init for GCC
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1276 char_u *new_line, *orig_line = NULL; // init for GCC
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1277
28773
d770568e6c98 patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents: 28716
diff changeset
1278 // MODE_VREPLACE state needs to know what the line was like before changing
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1279 if (State & VREPLACE_FLAG)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1280 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1281 orig_line = vim_strsave(ml_get_curline()); // Deal with NULL below
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1282 orig_col = curwin->w_cursor.col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1283 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1284
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1285 // for the following tricks we don't want list mode
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1286 save_p_list = curwin->w_p_list;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1287 curwin->w_p_list = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1288 vc = getvcol_nolist(&curwin->w_cursor);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1289 vcol = vc;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1290
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1291 // For Replace mode we need to fix the replace stack later, which is only
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1292 // possible when the cursor is in the indent. Remember the number of
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1293 // characters before the cursor if it's possible.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1294 start_col = curwin->w_cursor.col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1295
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1296 // determine offset from first non-blank
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1297 new_cursor_col = curwin->w_cursor.col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1298 beginline(BL_WHITE);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1299 new_cursor_col -= curwin->w_cursor.col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1300
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1301 insstart_less = curwin->w_cursor.col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1302
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1303 // If the cursor is in the indent, compute how many screen columns the
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1304 // cursor is to the left of the first non-blank.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1305 if (new_cursor_col < 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1306 vcol = get_indent() - vcol;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1307
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1308 if (new_cursor_col > 0) // can't fix replace stack
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1309 start_col = -1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1310
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1311 // Set the new indent. The cursor will be put on the first non-blank.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1312 if (type == INDENT_SET)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1313 (void)set_indent(amount, call_changed_bytes ? SIN_CHANGED : 0);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1314 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1315 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1316 int save_State = State;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1317
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1318 // Avoid being called recursively.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1319 if (State & VREPLACE_FLAG)
28773
d770568e6c98 patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents: 28716
diff changeset
1320 State = MODE_INSERT;
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1321 shift_line(type == INDENT_DEC, round, 1, call_changed_bytes);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1322 State = save_State;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1323 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1324 insstart_less -= curwin->w_cursor.col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1325
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1326 // Try to put cursor on same character.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1327 // If the cursor is at or after the first non-blank in the line,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1328 // compute the cursor column relative to the column of the first
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1329 // non-blank character.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1330 // If we are not in insert mode, leave the cursor on the first non-blank.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1331 // If the cursor is before the first non-blank, position it relative
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1332 // to the first non-blank, counted in screen columns.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1333 if (new_cursor_col >= 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1334 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1335 // When changing the indent while the cursor is touching it, reset
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1336 // Insstart_col to 0.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1337 if (new_cursor_col == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1338 insstart_less = MAXCOL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1339 new_cursor_col += curwin->w_cursor.col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1340 }
28773
d770568e6c98 patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents: 28716
diff changeset
1341 else if (!(State & MODE_INSERT))
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1342 new_cursor_col = curwin->w_cursor.col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1343 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1344 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1345 // Compute the screen column where the cursor should be.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1346 vcol = get_indent() - vcol;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1347 curwin->w_virtcol = (colnr_T)((vcol < 0) ? 0 : vcol);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1348
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1349 // Advance the cursor until we reach the right screen column.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1350 vcol = last_vcol = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1351 new_cursor_col = -1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1352 ptr = ml_get_curline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1353 while (vcol <= (int)curwin->w_virtcol)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1354 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1355 last_vcol = vcol;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1356 if (has_mbyte && new_cursor_col >= 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1357 new_cursor_col += (*mb_ptr2len)(ptr + new_cursor_col);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1358 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1359 ++new_cursor_col;
27821
c3b34e4bbe34 patch 8.2.4436: crash with weird 'vartabstop' value
Bram Moolenaar <Bram@vim.org>
parents: 27677
diff changeset
1360 if (ptr[new_cursor_col] == NUL)
c3b34e4bbe34 patch 8.2.4436: crash with weird 'vartabstop' value
Bram Moolenaar <Bram@vim.org>
parents: 27677
diff changeset
1361 break;
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1362 vcol += lbr_chartabsize(ptr, ptr + new_cursor_col, (colnr_T)vcol);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1363 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1364 vcol = last_vcol;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1365
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1366 // May need to insert spaces to be able to position the cursor on
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1367 // the right screen column.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1368 if (vcol != (int)curwin->w_virtcol)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1369 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1370 curwin->w_cursor.col = (colnr_T)new_cursor_col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1371 i = (int)curwin->w_virtcol - vcol;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1372 ptr = alloc(i + 1);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1373 if (ptr != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1374 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1375 new_cursor_col += i;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1376 ptr[i] = NUL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1377 while (--i >= 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1378 ptr[i] = ' ';
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1379 ins_str(ptr);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1380 vim_free(ptr);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1381 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1382 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1383
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1384 // When changing the indent while the cursor is in it, reset
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1385 // Insstart_col to 0.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1386 insstart_less = MAXCOL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1387 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1388
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1389 curwin->w_p_list = save_p_list;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1390
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1391 if (new_cursor_col <= 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1392 curwin->w_cursor.col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1393 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1394 curwin->w_cursor.col = (colnr_T)new_cursor_col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1395 curwin->w_set_curswant = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1396 changed_cline_bef_curs();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1397
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1398 // May have to adjust the start of the insert.
28773
d770568e6c98 patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents: 28716
diff changeset
1399 if (State & MODE_INSERT)
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1400 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1401 if (curwin->w_cursor.lnum == Insstart.lnum && Insstart.col != 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1402 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1403 if ((int)Insstart.col <= insstart_less)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1404 Insstart.col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1405 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1406 Insstart.col -= insstart_less;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1407 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1408 if ((int)ai_col <= insstart_less)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1409 ai_col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1410 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1411 ai_col -= insstart_less;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1412 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1413
28773
d770568e6c98 patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents: 28716
diff changeset
1414 // For MODE_REPLACE state, may have to fix the replace stack, if it's
d770568e6c98 patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents: 28716
diff changeset
1415 // possible. If the number of characters before the cursor decreased, need
d770568e6c98 patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents: 28716
diff changeset
1416 // to pop a few characters from the replace stack.
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1417 // If the number of characters before the cursor increased, need to push a
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1418 // few NULs onto the replace stack.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1419 if (REPLACE_NORMAL(State) && start_col >= 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1420 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1421 while (start_col > (int)curwin->w_cursor.col)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1422 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1423 replace_join(0); // remove a NUL from the replace stack
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1424 --start_col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1425 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1426 while (start_col < (int)curwin->w_cursor.col || replaced)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1427 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1428 replace_push(NUL);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1429 if (replaced)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1430 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1431 replace_push(replaced);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1432 replaced = NUL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1433 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1434 ++start_col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1435 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1436 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1437
28773
d770568e6c98 patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents: 28716
diff changeset
1438 // For MODE_VREPLACE state, we also have to fix the replace stack. In this
d770568e6c98 patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents: 28716
diff changeset
1439 // case it is always possible because we backspace over the whole line and
d770568e6c98 patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents: 28716
diff changeset
1440 // then put it back again the way we wanted it.
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1441 if (State & VREPLACE_FLAG)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1442 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1443 // If orig_line didn't allocate, just return. At least we did the job,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1444 // even if you can't backspace.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1445 if (orig_line == NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1446 return;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1447
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1448 // Save new line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1449 new_line = vim_strsave(ml_get_curline());
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1450 if (new_line == NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1451 return;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1452
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1453 // We only put back the new line up to the cursor
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1454 new_line[curwin->w_cursor.col] = NUL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1455
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1456 // Put back original line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1457 ml_replace(curwin->w_cursor.lnum, orig_line, FALSE);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1458 curwin->w_cursor.col = orig_col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1459
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1460 // Backspace from cursor to start of line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1461 backspace_until_column(0);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1462
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1463 // Insert new stuff into line again
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1464 ins_bytes(new_line);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1465
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1466 vim_free(new_line);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1467 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1468 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1469
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1470 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1471 * Copy the indent from ptr to the current line (and fill to size)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1472 * Leaves the cursor on the first non-blank in the line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1473 * Returns TRUE if the line was changed.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1474 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1475 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1476 copy_indent(int size, char_u *src)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1477 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1478 char_u *p = NULL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1479 char_u *line = NULL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1480 char_u *s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1481 int todo;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1482 int ind_len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1483 int line_len = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1484 int tab_pad;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1485 int ind_done;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1486 int round;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1487 #ifdef FEAT_VARTABS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1488 int ind_col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1489 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1490
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1491 // Round 1: compute the number of characters needed for the indent
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1492 // Round 2: copy the characters.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1493 for (round = 1; round <= 2; ++round)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1494 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1495 todo = size;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1496 ind_len = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1497 ind_done = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1498 #ifdef FEAT_VARTABS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1499 ind_col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1500 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1501 s = src;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1502
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1503 // Count/copy the usable portion of the source line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1504 while (todo > 0 && VIM_ISWHITE(*s))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1505 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1506 if (*s == TAB)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1507 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1508 #ifdef FEAT_VARTABS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1509 tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1510 curbuf->b_p_vts_array);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1511 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1512 tab_pad = (int)curbuf->b_p_ts
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1513 - (ind_done % (int)curbuf->b_p_ts);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1514 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1515 // Stop if this tab will overshoot the target
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1516 if (todo < tab_pad)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1517 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1518 todo -= tab_pad;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1519 ind_done += tab_pad;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1520 #ifdef FEAT_VARTABS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1521 ind_col += tab_pad;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1522 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1523 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1524 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1525 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1526 --todo;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1527 ++ind_done;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1528 #ifdef FEAT_VARTABS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1529 ++ind_col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1530 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1531 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1532 ++ind_len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1533 if (p != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1534 *p++ = *s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1535 ++s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1536 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1537
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1538 // Fill to next tabstop with a tab, if possible
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1539 #ifdef FEAT_VARTABS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1540 tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1541 curbuf->b_p_vts_array);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1542 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1543 tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1544 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1545 if (todo >= tab_pad && !curbuf->b_p_et)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1546 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1547 todo -= tab_pad;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1548 ++ind_len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1549 #ifdef FEAT_VARTABS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1550 ind_col += tab_pad;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1551 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1552 if (p != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1553 *p++ = TAB;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1554 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1555
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1556 // Add tabs required for indent
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1557 if (!curbuf->b_p_et)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1558 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1559 #ifdef FEAT_VARTABS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1560 for (;;)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1561 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1562 tab_pad = tabstop_padding(ind_col, curbuf->b_p_ts,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1563 curbuf->b_p_vts_array);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1564 if (todo < tab_pad)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1565 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1566 todo -= tab_pad;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1567 ++ind_len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1568 ind_col += tab_pad;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1569 if (p != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1570 *p++ = TAB;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1571 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1572 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1573 while (todo >= (int)curbuf->b_p_ts)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1574 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1575 todo -= (int)curbuf->b_p_ts;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1576 ++ind_len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1577 if (p != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1578 *p++ = TAB;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1579 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1580 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1581 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1582
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1583 // Count/add spaces required for indent
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1584 while (todo > 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1585 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1586 --todo;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1587 ++ind_len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1588 if (p != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1589 *p++ = ' ';
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1590 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1591
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1592 if (p == NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1593 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1594 // Allocate memory for the result: the copied indent, new indent
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1595 // and the rest of the line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1596 line_len = (int)STRLEN(ml_get_curline()) + 1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1597 line = alloc(ind_len + line_len);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1598 if (line == NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1599 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1600 p = line;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1601 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1602 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1603
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1604 // Append the original line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1605 mch_memmove(p, ml_get_curline(), (size_t)line_len);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1606
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1607 // Replace the line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1608 ml_replace(curwin->w_cursor.lnum, line, FALSE);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1609
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1610 // Put the cursor after the indent.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1611 curwin->w_cursor.col = ind_len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1612 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1613 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1614
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1615 /*
29177
6a6c56354cfc patch 8.2.5108: retab test disabled because it hangs on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 29167
diff changeset
1616 * Give a "resulting text too long" error and maybe set got_int.
6a6c56354cfc patch 8.2.5108: retab test disabled because it hangs on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 29167
diff changeset
1617 */
6a6c56354cfc patch 8.2.5108: retab test disabled because it hangs on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 29167
diff changeset
1618 static void
6a6c56354cfc patch 8.2.5108: retab test disabled because it hangs on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 29167
diff changeset
1619 emsg_text_too_long(void)
6a6c56354cfc patch 8.2.5108: retab test disabled because it hangs on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 29167
diff changeset
1620 {
6a6c56354cfc patch 8.2.5108: retab test disabled because it hangs on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 29167
diff changeset
1621 emsg(_(e_resulting_text_too_long));
6a6c56354cfc patch 8.2.5108: retab test disabled because it hangs on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 29167
diff changeset
1622 #ifdef FEAT_EVAL
6a6c56354cfc patch 8.2.5108: retab test disabled because it hangs on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 29167
diff changeset
1623 // when not inside a try/catch set got_int to break out of any loop
6a6c56354cfc patch 8.2.5108: retab test disabled because it hangs on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 29167
diff changeset
1624 if (trylevel == 0)
6a6c56354cfc patch 8.2.5108: retab test disabled because it hangs on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 29167
diff changeset
1625 #endif
6a6c56354cfc patch 8.2.5108: retab test disabled because it hangs on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 29167
diff changeset
1626 got_int = TRUE;
6a6c56354cfc patch 8.2.5108: retab test disabled because it hangs on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 29167
diff changeset
1627 }
6a6c56354cfc patch 8.2.5108: retab test disabled because it hangs on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 29167
diff changeset
1628
6a6c56354cfc patch 8.2.5108: retab test disabled because it hangs on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 29167
diff changeset
1629 /*
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1630 * ":retab".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1631 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1632 void
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1633 ex_retab(exarg_T *eap)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1634 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1635 linenr_T lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1636 int got_tab = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1637 long num_spaces = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1638 long num_tabs;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1639 long len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1640 long col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1641 long vcol;
18933
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1642 long start_col = 0; // For start of white-space string
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1643 long start_vcol = 0; // For start of white-space string
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1644 long old_len;
27673
ba7dcf54d309 patch 8.2.4362: :retab may allocate too much memory
Bram Moolenaar <Bram@vim.org>
parents: 27667
diff changeset
1645 long new_len;
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1646 char_u *ptr;
18933
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1647 char_u *new_line = (char_u *)1; // init to non-NULL
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1648 int did_undo; // called u_save for current line
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1649 #ifdef FEAT_VARTABS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1650 int *new_vts_array = NULL;
18933
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1651 char_u *new_ts_str; // string value of tab argument
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1652 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1653 int temp;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1654 int new_ts;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1655 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1656 int save_list;
18933
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1657 linenr_T first_line = 0; // first changed line
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1658 linenr_T last_line = 0; // last changed line
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1659
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1660 save_list = curwin->w_p_list;
18933
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1661 curwin->w_p_list = 0; // don't want list mode here
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1662
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1663 #ifdef FEAT_VARTABS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1664 new_ts_str = eap->arg;
25733
4b2616ffe32b patch 8.2.3402: invalid memory access when using :retab with large value
Bram Moolenaar <Bram@vim.org>
parents: 25701
diff changeset
1665 if (tabstop_set(eap->arg, &new_vts_array) == FAIL)
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1666 return;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1667 while (vim_isdigit(*(eap->arg)) || *(eap->arg) == ',')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1668 ++(eap->arg);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1669
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1670 // This ensures that either new_vts_array and new_ts_str are freshly
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1671 // allocated, or new_vts_array points to an existing array and new_ts_str
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1672 // is null.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1673 if (new_vts_array == NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1674 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1675 new_vts_array = curbuf->b_p_vts_array;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1676 new_ts_str = NULL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1677 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1678 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1679 new_ts_str = vim_strnsave(new_ts_str, eap->arg - new_ts_str);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1680 #else
25735
07e23f808680 patch 8.2.3403: memory leak for :retab with invalid argument
Bram Moolenaar <Bram@vim.org>
parents: 25733
diff changeset
1681 ptr = eap->arg;
07e23f808680 patch 8.2.3403: memory leak for :retab with invalid argument
Bram Moolenaar <Bram@vim.org>
parents: 25733
diff changeset
1682 new_ts = getdigits(&ptr);
07e23f808680 patch 8.2.3403: memory leak for :retab with invalid argument
Bram Moolenaar <Bram@vim.org>
parents: 25733
diff changeset
1683 if (new_ts < 0 && *eap->arg == '-')
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1684 {
26877
06a137af96f8 patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
1685 emsg(_(e_argument_must_be_positive));
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1686 return;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1687 }
27434
c1702fd7e716 patch 8.2.4245: ":retab 0" may cause illegal memory access
Bram Moolenaar <Bram@vim.org>
parents: 27313
diff changeset
1688 if (new_ts < 0 || new_ts > TABSTOP_MAX)
25735
07e23f808680 patch 8.2.3403: memory leak for :retab with invalid argument
Bram Moolenaar <Bram@vim.org>
parents: 25733
diff changeset
1689 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26775
diff changeset
1690 semsg(_(e_invalid_argument_str), eap->arg);
25735
07e23f808680 patch 8.2.3403: memory leak for :retab with invalid argument
Bram Moolenaar <Bram@vim.org>
parents: 25733
diff changeset
1691 return;
07e23f808680 patch 8.2.3403: memory leak for :retab with invalid argument
Bram Moolenaar <Bram@vim.org>
parents: 25733
diff changeset
1692 }
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1693 if (new_ts == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1694 new_ts = curbuf->b_p_ts;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1695 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1696 for (lnum = eap->line1; !got_int && lnum <= eap->line2; ++lnum)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1697 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1698 ptr = ml_get(lnum);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1699 col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1700 vcol = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1701 did_undo = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1702 for (;;)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1703 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1704 if (VIM_ISWHITE(ptr[col]))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1705 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1706 if (!got_tab && num_spaces == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1707 {
18933
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1708 // First consecutive white-space
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1709 start_vcol = vcol;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1710 start_col = col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1711 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1712 if (ptr[col] == ' ')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1713 num_spaces++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1714 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1715 got_tab = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1716 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1717 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1718 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1719 if (got_tab || (eap->forceit && num_spaces > 1))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1720 {
18933
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1721 // Retabulate this string of white-space
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1722
18933
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1723 // len is virtual length of white string
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1724 len = num_spaces = vcol - start_vcol;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1725 num_tabs = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1726 if (!curbuf->b_p_et)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1727 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1728 #ifdef FEAT_VARTABS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1729 int t, s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1730
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1731 tabstop_fromto(start_vcol, vcol,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1732 curbuf->b_p_ts, new_vts_array, &t, &s);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1733 num_tabs = t;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1734 num_spaces = s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1735 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1736 temp = new_ts - (start_vcol % new_ts);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1737 if (num_spaces >= temp)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1738 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1739 num_spaces -= temp;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1740 num_tabs++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1741 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1742 num_tabs += num_spaces / new_ts;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1743 num_spaces -= (num_spaces / new_ts) * new_ts;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1744 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1745 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1746 if (curbuf->b_p_et || got_tab ||
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1747 (num_spaces + num_tabs < len))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1748 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1749 if (did_undo == FALSE)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1750 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1751 did_undo = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1752 if (u_save((linenr_T)(lnum - 1),
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1753 (linenr_T)(lnum + 1)) == FAIL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1754 {
18933
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1755 new_line = NULL; // flag out-of-memory
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1756 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1757 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1758 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1759
18933
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1760 // len is actual number of white characters used
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1761 len = num_spaces + num_tabs;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1762 old_len = (long)STRLEN(ptr);
27673
ba7dcf54d309 patch 8.2.4362: :retab may allocate too much memory
Bram Moolenaar <Bram@vim.org>
parents: 27667
diff changeset
1763 new_len = old_len - col + start_col + len + 1;
27677
567f4f964ccc patch 8.2.4364: MS-Windows: still running out of memory for a very long line
Bram Moolenaar <Bram@vim.org>
parents: 27673
diff changeset
1764 if (new_len <= 0 || new_len >= MAXCOL)
27673
ba7dcf54d309 patch 8.2.4362: :retab may allocate too much memory
Bram Moolenaar <Bram@vim.org>
parents: 27667
diff changeset
1765 {
29177
6a6c56354cfc patch 8.2.5108: retab test disabled because it hangs on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 29167
diff changeset
1766 emsg_text_too_long();
27673
ba7dcf54d309 patch 8.2.4362: :retab may allocate too much memory
Bram Moolenaar <Bram@vim.org>
parents: 27667
diff changeset
1767 break;
ba7dcf54d309 patch 8.2.4362: :retab may allocate too much memory
Bram Moolenaar <Bram@vim.org>
parents: 27667
diff changeset
1768 }
ba7dcf54d309 patch 8.2.4362: :retab may allocate too much memory
Bram Moolenaar <Bram@vim.org>
parents: 27667
diff changeset
1769 new_line = alloc(new_len);
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1770 if (new_line == NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1771 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1772 if (start_col > 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1773 mch_memmove(new_line, ptr, (size_t)start_col);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1774 mch_memmove(new_line + start_col + len,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1775 ptr + col, (size_t)(old_len - col + 1));
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1776 ptr = new_line + start_col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1777 for (col = 0; col < len; col++)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1778 ptr[col] = (col < num_tabs) ? '\t' : ' ';
23833
dd8f2c6b6396 patch 8.2.2458: Coverity warns for :retab using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
1779 if (ml_replace(lnum, new_line, FALSE) == OK)
dd8f2c6b6396 patch 8.2.2458: Coverity warns for :retab using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
1780 // "new_line" may have been copied
dd8f2c6b6396 patch 8.2.2458: Coverity warns for :retab using freed memory
Bram Moolenaar <Bram@vim.org>
parents: 22699
diff changeset
1781 new_line = curbuf->b_ml.ml_line_ptr;
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1782 if (first_line == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1783 first_line = lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1784 last_line = lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1785 ptr = new_line;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1786 col = start_col + len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1787 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1788 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1789 got_tab = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1790 num_spaces = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1791 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1792 if (ptr[col] == NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1793 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1794 vcol += chartabsize(ptr + col, (colnr_T)vcol);
27667
289e87a78307 patch 8.2.4359: crash when repeatedly using :retab
Bram Moolenaar <Bram@vim.org>
parents: 27543
diff changeset
1795 if (vcol >= MAXCOL)
289e87a78307 patch 8.2.4359: crash when repeatedly using :retab
Bram Moolenaar <Bram@vim.org>
parents: 27543
diff changeset
1796 {
29177
6a6c56354cfc patch 8.2.5108: retab test disabled because it hangs on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 29167
diff changeset
1797 emsg_text_too_long();
27667
289e87a78307 patch 8.2.4359: crash when repeatedly using :retab
Bram Moolenaar <Bram@vim.org>
parents: 27543
diff changeset
1798 break;
289e87a78307 patch 8.2.4359: crash when repeatedly using :retab
Bram Moolenaar <Bram@vim.org>
parents: 27543
diff changeset
1799 }
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1800 if (has_mbyte)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1801 col += (*mb_ptr2len)(ptr + col);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1802 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1803 ++col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1804 }
18933
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1805 if (new_line == NULL) // out of memory
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1806 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1807 line_breakcheck();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1808 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1809 if (got_int)
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26775
diff changeset
1810 emsg(_(e_interrupted));
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1811
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1812 #ifdef FEAT_VARTABS
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1813 // If a single value was given then it can be considered equal to
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1814 // either the value of 'tabstop' or the value of 'vartabstop'.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1815 if (tabstop_count(curbuf->b_p_vts_array) == 0
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1816 && tabstop_count(new_vts_array) == 1
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1817 && curbuf->b_p_ts == tabstop_first(new_vts_array))
18933
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1818 ; // not changed
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1819 else if (tabstop_count(curbuf->b_p_vts_array) > 0
28809
d0241e74bfdb patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents: 28773
diff changeset
1820 && tabstop_eq(curbuf->b_p_vts_array, new_vts_array))
18933
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1821 ; // not changed
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1822 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1823 redraw_curbuf_later(NOT_VALID);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1824 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1825 if (curbuf->b_p_ts != new_ts)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1826 redraw_curbuf_later(NOT_VALID);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1827 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1828 if (first_line != 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1829 changed_lines(first_line, 0, last_line + 1, 0L);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1830
18933
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1831 curwin->w_p_list = save_list; // restore 'list'
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1832
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1833 #ifdef FEAT_VARTABS
18933
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1834 if (new_ts_str != NULL) // set the new tabstop
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1835 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1836 // If 'vartabstop' is in use or if the value given to retab has more
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1837 // than one tabstop then update 'vartabstop'.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1838 int *old_vts_ary = curbuf->b_p_vts_array;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1839
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1840 if (tabstop_count(old_vts_ary) > 0 || tabstop_count(new_vts_array) > 1)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1841 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1842 set_string_option_direct((char_u *)"vts", -1, new_ts_str,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1843 OPT_FREE|OPT_LOCAL, 0);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1844 curbuf->b_p_vts_array = new_vts_array;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1845 vim_free(old_vts_ary);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1846 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1847 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1848 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1849 // 'vartabstop' wasn't in use and a single value was given to
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1850 // retab then update 'tabstop'.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1851 curbuf->b_p_ts = tabstop_first(new_vts_array);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1852 vim_free(new_vts_array);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1853 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1854 vim_free(new_ts_str);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1855 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1856 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1857 curbuf->b_p_ts = new_ts;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1858 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1859 coladvance(curwin->w_curswant);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1860
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1861 u_clearline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1862 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1863
28942
6cdf55afaae9 patch 8.2.4993: smart/C/lisp indenting is optional
Bram Moolenaar <Bram@vim.org>
parents: 28860
diff changeset
1864 #if defined(FEAT_EVAL) || defined(PROTO)
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1865 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1866 * Get indent level from 'indentexpr'.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1867 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1868 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1869 get_expr_indent(void)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1870 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1871 int indent = -1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1872 char_u *inde_copy;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1873 pos_T save_pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1874 colnr_T save_curswant;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1875 int save_set_curswant;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1876 int save_State;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1877 int use_sandbox = was_set_insecurely((char_u *)"indentexpr",
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1878 OPT_LOCAL);
27313
748ab01dbdc5 patch 8.2.4185: cannot use an import in 'indentexpr'
Bram Moolenaar <Bram@vim.org>
parents: 27128
diff changeset
1879 sctx_T save_sctx = current_sctx;
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1880
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1881 // Save and restore cursor position and curswant, in case it was changed
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1882 // via :normal commands
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1883 save_pos = curwin->w_cursor;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1884 save_curswant = curwin->w_curswant;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1885 save_set_curswant = curwin->w_set_curswant;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1886 set_vim_var_nr(VV_LNUM, curwin->w_cursor.lnum);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1887 if (use_sandbox)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1888 ++sandbox;
29014
45c182c4f7e9 patch 8.2.5029: "textlock" is always zero
Bram Moolenaar <Bram@vim.org>
parents: 28942
diff changeset
1889 ++textlock;
27313
748ab01dbdc5 patch 8.2.4185: cannot use an import in 'indentexpr'
Bram Moolenaar <Bram@vim.org>
parents: 27128
diff changeset
1890 current_sctx = curbuf->b_p_script_ctx[BV_INDE];
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1891
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1892 // Need to make a copy, the 'indentexpr' option could be changed while
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1893 // evaluating it.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1894 inde_copy = vim_strsave(curbuf->b_p_inde);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1895 if (inde_copy != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1896 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1897 indent = (int)eval_to_number(inde_copy);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1898 vim_free(inde_copy);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1899 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1900
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1901 if (use_sandbox)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1902 --sandbox;
29014
45c182c4f7e9 patch 8.2.5029: "textlock" is always zero
Bram Moolenaar <Bram@vim.org>
parents: 28942
diff changeset
1903 --textlock;
27313
748ab01dbdc5 patch 8.2.4185: cannot use an import in 'indentexpr'
Bram Moolenaar <Bram@vim.org>
parents: 27128
diff changeset
1904 current_sctx = save_sctx;
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1905
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1906 // Restore the cursor position so that 'indentexpr' doesn't need to.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1907 // Pretend to be in Insert mode, allow cursor past end of line for "o"
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1908 // command.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1909 save_State = State;
28773
d770568e6c98 patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents: 28716
diff changeset
1910 State = MODE_INSERT;
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1911 curwin->w_cursor = save_pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1912 curwin->w_curswant = save_curswant;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1913 curwin->w_set_curswant = save_set_curswant;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1914 check_cursor();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1915 State = save_State;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1916
25445
65f04b6effd5 patch 8.2.3259: when 'indentexpr' causes an error did_throw may hang
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
1917 // Reset did_throw, unless 'debug' has "throw" and inside a try/catch.
65f04b6effd5 patch 8.2.3259: when 'indentexpr' causes an error did_throw may hang
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
1918 if (did_throw && (vim_strchr(p_debug, 't') == NULL || trylevel == 0))
65f04b6effd5 patch 8.2.3259: when 'indentexpr' causes an error did_throw may hang
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
1919 {
65f04b6effd5 patch 8.2.3259: when 'indentexpr' causes an error did_throw may hang
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
1920 handle_did_throw();
65f04b6effd5 patch 8.2.3259: when 'indentexpr' causes an error did_throw may hang
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
1921 did_throw = FALSE;
65f04b6effd5 patch 8.2.3259: when 'indentexpr' causes an error did_throw may hang
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
1922 }
65f04b6effd5 patch 8.2.3259: when 'indentexpr' causes an error did_throw may hang
Bram Moolenaar <Bram@vim.org>
parents: 25384
diff changeset
1923
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1924 // If there is an error, just keep the current indent.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1925 if (indent < 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1926 indent = get_indent();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1927
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1928 return indent;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1929 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1930 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1931
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1932 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1933 lisp_match(char_u *p)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1934 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1935 char_u buf[LSIZE];
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1936 int len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1937 char_u *word = *curbuf->b_p_lw != NUL ? curbuf->b_p_lw : p_lispwords;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1938
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1939 while (*word != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1940 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1941 (void)copy_option_part(&word, buf, LSIZE, ",");
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1942 len = (int)STRLEN(buf);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1943 if (STRNCMP(buf, p, len) == 0 && p[len] == ' ')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1944 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1945 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1946 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1947 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1948
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1949 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1950 * When 'p' is present in 'cpoptions, a Vi compatible method is used.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1951 * The incompatible newer method is quite a bit better at indenting
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1952 * code in lisp-like languages than the traditional one; it's still
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1953 * mostly heuristics however -- Dirk van Deun, dirk@rave.org
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1954 *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1955 * TODO:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1956 * Findmatch() should be adapted for lisp, also to make showmatch
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1957 * work correctly: now (v5.3) it seems all C/C++ oriented:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1958 * - it does not recognize the #\( and #\) notations as character literals
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1959 * - it doesn't know about comments starting with a semicolon
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1960 * - it incorrectly interprets '(' as a character literal
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1961 * All this messes up get_lisp_indent in some rare cases.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1962 * Update from Sergey Khorev:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1963 * I tried to fix the first two issues.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1964 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1965 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1966 get_lisp_indent(void)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1967 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1968 pos_T *pos, realpos, paren;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1969 int amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1970 char_u *that;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1971 colnr_T col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1972 colnr_T firsttry;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1973 int parencount, quotecount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1974 int vi_lisp;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1975
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1976 // Set vi_lisp to use the vi-compatible method
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1977 vi_lisp = (vim_strchr(p_cpo, CPO_LISP) != NULL);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1978
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1979 realpos = curwin->w_cursor;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1980 curwin->w_cursor.col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1981
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1982 if ((pos = findmatch(NULL, '(')) == NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1983 pos = findmatch(NULL, '[');
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1984 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1985 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1986 paren = *pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1987 pos = findmatch(NULL, '[');
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1988 if (pos == NULL || LT_POSP(pos, &paren))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1989 pos = &paren;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1990 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1991 if (pos != NULL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1992 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1993 // Extra trick: Take the indent of the first previous non-white
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1994 // line that is at the same () level.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1995 amount = -1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1996 parencount = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1997
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1998 while (--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: 17940
diff changeset
1999 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2000 if (linewhite(curwin->w_cursor.lnum))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2001 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2002 for (that = ml_get_curline(); *that != NUL; ++that)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2003 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2004 if (*that == ';')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2005 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2006 while (*(that + 1) != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2007 ++that;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2008 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2009 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2010 if (*that == '\\')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2011 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2012 if (*(that + 1) != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2013 ++that;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2014 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2015 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2016 if (*that == '"' && *(that + 1) != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2017 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2018 while (*++that && *that != '"')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2019 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2020 // skipping escaped characters in the string
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2021 if (*that == '\\')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2022 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2023 if (*++that == NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2024 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2025 if (that[1] == NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2026 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2027 ++that;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2028 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2029 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2030 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2031 }
29206
a2c89e5446b7 patch 8.2.5122: lisp indenting my run over the end of the line
Bram Moolenaar <Bram@vim.org>
parents: 29177
diff changeset
2032 if (*that == NUL)
a2c89e5446b7 patch 8.2.5122: lisp indenting my run over the end of the line
Bram Moolenaar <Bram@vim.org>
parents: 29177
diff changeset
2033 break;
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2034 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2035 if (*that == '(' || *that == '[')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2036 ++parencount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2037 else if (*that == ')' || *that == ']')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2038 --parencount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2039 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2040 if (parencount == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2041 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2042 amount = get_indent();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2043 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2044 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2045 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2046
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2047 if (amount == -1)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2048 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2049 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: 17940
diff changeset
2050 curwin->w_cursor.col = pos->col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2051 col = pos->col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2052
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2053 that = ml_get_curline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2054
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2055 if (vi_lisp && get_indent() == 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2056 amount = 2;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2057 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2058 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2059 char_u *line = that;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2060
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2061 amount = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2062 while (*that && col)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2063 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2064 amount += lbr_chartabsize_adv(line, &that, (colnr_T)amount);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2065 col--;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2066 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2067
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2068 // Some keywords require "body" indenting rules (the
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2069 // non-standard-lisp ones are Scheme special forms):
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2070 //
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2071 // (let ((a 1)) instead (let ((a 1))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2072 // (...)) of (...))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2073
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2074 if (!vi_lisp && (*that == '(' || *that == '[')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2075 && lisp_match(that + 1))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2076 amount += 2;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2077 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2078 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2079 that++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2080 amount++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2081 firsttry = amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2082
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2083 while (VIM_ISWHITE(*that))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2084 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2085 amount += lbr_chartabsize(line, that, (colnr_T)amount);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2086 ++that;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2087 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2088
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2089 if (*that && *that != ';') // not a comment line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2090 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2091 // test *that != '(' to accommodate first let/do
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2092 // argument if it is more than one line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2093 if (!vi_lisp && *that != '(' && *that != '[')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2094 firsttry++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2095
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2096 parencount = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2097 quotecount = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2098
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2099 if (vi_lisp
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2100 || (*that != '"'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2101 && *that != '\''
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2102 && *that != '#'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2103 && (*that < '0' || *that > '9')))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2104 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2105 while (*that
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2106 && (!VIM_ISWHITE(*that)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2107 || quotecount
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2108 || parencount)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2109 && (!((*that == '(' || *that == '[')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2110 && !quotecount
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2111 && !parencount
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2112 && vi_lisp)))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2113 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2114 if (*that == '"')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2115 quotecount = !quotecount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2116 if ((*that == '(' || *that == '[')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2117 && !quotecount)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2118 ++parencount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2119 if ((*that == ')' || *that == ']')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2120 && !quotecount)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2121 --parencount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2122 if (*that == '\\' && *(that+1) != NUL)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2123 amount += lbr_chartabsize_adv(
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2124 line, &that, (colnr_T)amount);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2125 amount += lbr_chartabsize_adv(
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2126 line, &that, (colnr_T)amount);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2127 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2128 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2129 while (VIM_ISWHITE(*that))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2130 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2131 amount += lbr_chartabsize(
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2132 line, that, (colnr_T)amount);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2133 that++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2134 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2135 if (!*that || *that == ';')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2136 amount = firsttry;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2137 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2138 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2139 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2140 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2141 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2142 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2143 amount = 0; // no matching '(' or '[' found, use zero indent
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2144
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2145 curwin->w_cursor = realpos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2146
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2147 return amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2148 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2149
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2150 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2151 * Re-indent the current line, based on the current contents of it and the
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2152 * surrounding lines. Fixing the cursor position seems really easy -- I'm very
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2153 * confused what all the part that handles Control-T is doing that I'm not.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2154 * "get_the_indent" should be get_c_indent, get_expr_indent or get_lisp_indent.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2155 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2156
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2157 void
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2158 fixthisline(int (*get_the_indent)(void))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2159 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2160 int amount = get_the_indent();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2161
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2162 if (amount >= 0)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2163 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2164 change_indent(INDENT_SET, amount, FALSE, 0, TRUE);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2165 if (linewhite(curwin->w_cursor.lnum))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2166 did_ai = TRUE; // delete the indent if the line stays empty
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2167 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2168 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2169
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26775
diff changeset
2170 /*
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26775
diff changeset
2171 * Fix indent for 'lisp' and 'cindent'.
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26775
diff changeset
2172 */
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2173 void
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2174 fix_indent(void)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2175 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2176 if (p_paste)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2177 return;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2178 if (curbuf->b_p_lisp && curbuf->b_p_ai)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2179 fixthisline(get_lisp_indent);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2180 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2181 if (cindent_on())
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2182 do_c_expr_indent();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2183 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2184
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2185 #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: 17940
diff changeset
2186 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2187 * "indent()" function
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2188 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2189 void
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2190 f_indent(typval_T *argvars, typval_T *rettv)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2191 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2192 linenr_T lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2193
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25322
diff changeset
2194 if (in_vim9script() && check_for_lnum_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25322
diff changeset
2195 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25322
diff changeset
2196
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2197 lnum = tv_get_lnum(argvars);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2198 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: 17940
diff changeset
2199 rettv->vval.v_number = get_indent_lnum(lnum);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2200 else
26775
2df40c348c70 patch 8.2.3916: no error for passing an invalid line number to append()
Bram Moolenaar <Bram@vim.org>
parents: 25735
diff changeset
2201 {
2df40c348c70 patch 8.2.3916: no error for passing an invalid line number to append()
Bram Moolenaar <Bram@vim.org>
parents: 25735
diff changeset
2202 if (in_vim9script())
2df40c348c70 patch 8.2.3916: no error for passing an invalid line number to append()
Bram Moolenaar <Bram@vim.org>
parents: 25735
diff changeset
2203 semsg(_(e_invalid_line_number_nr), lnum);
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2204 rettv->vval.v_number = -1;
26775
2df40c348c70 patch 8.2.3916: no error for passing an invalid line number to append()
Bram Moolenaar <Bram@vim.org>
parents: 25735
diff changeset
2205 }
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2206 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2207
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2208 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2209 * "lispindent(lnum)" function
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2210 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2211 void
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2212 f_lispindent(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: 17940
diff changeset
2213 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2214 pos_T pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2215 linenr_T lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2216
25384
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25322
diff changeset
2217 if (in_vim9script() && check_for_lnum_arg(argvars, 0) == FAIL)
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25322
diff changeset
2218 return;
e8e2c4d33b9b patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents: 25322
diff changeset
2219
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2220 pos = curwin->w_cursor;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2221 lnum = tv_get_lnum(argvars);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2222 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: 17940
diff changeset
2223 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2224 curwin->w_cursor.lnum = lnum;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2225 rettv->vval.v_number = get_lisp_indent();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2226 curwin->w_cursor = pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2227 }
26775
2df40c348c70 patch 8.2.3916: no error for passing an invalid line number to append()
Bram Moolenaar <Bram@vim.org>
parents: 25735
diff changeset
2228 else if (in_vim9script())
2df40c348c70 patch 8.2.3916: no error for passing an invalid line number to append()
Bram Moolenaar <Bram@vim.org>
parents: 25735
diff changeset
2229 semsg(_(e_invalid_line_number_nr), lnum);
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2230 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2231 rettv->vval.v_number = -1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2232 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2233 #endif