annotate src/indent.c @ 25248:cf0774d010b7 v8.2.3160

patch 8.2.3160: 'breakindent' does not work well for bulleted lists Commit: https://github.com/vim/vim/commit/4a0b85ad0193ac162e2d8458e4b1c5ad2e2b0193 Author: Christian Brabandt <cb@256bit.org> Date: Wed Jul 14 20:00:27 2021 +0200 patch 8.2.3160: 'breakindent' does not work well for bulleted lists Problem: 'breakindent' does not work well for bulleted and numbered lists. Solution: Add the "list" entry to 'breakindentopt'. (Christian Brabandt, closes #8564, closes #1661)
author Bram Moolenaar <Bram@vim.org>
date Wed, 14 Jul 2021 20:15:04 +0200
parents 8f2262c72178
children b3d7becabe99
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.
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
21 */
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
22 int
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
23 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
24 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
25 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
26 int t;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
27 char_u *cp;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
28
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
29 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
30 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
31 *array = NULL;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
32 return TRUE;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
33 }
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 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
36 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
37 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
38 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
39 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
40
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
41 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
42 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
43 if (cp != end)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
44 emsg(_(e_positive));
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
45 else
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
46 emsg(_(e_invarg));
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
47 return FALSE;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
48 }
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 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
52 continue;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
53 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
54 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
55 ++valcount;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
56 continue;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
57 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
58 emsg(_(e_invarg));
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
59 return FALSE;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
60 }
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 *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
63 if (*array == NULL)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
64 return FALSE;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
65 (*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
66
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
67 t = 1;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
68 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
69 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
70 (*array)[t++] = atoi((char *)cp);
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
71 while (*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
72 ++cp;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
73 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
74 ++cp;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
75 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
76
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
77 return TRUE;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
78 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
79
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
80 /*
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
81 * 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
82 * 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
83 * 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
84 */
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
85 int
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
86 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
87 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
88 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
89 int tabcount;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
90 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
91 int t;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
92 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
93
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
94 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
95 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
96
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
97 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
98
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
99 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
100 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
101 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
102 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
103 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
104 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
105 break;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
106 }
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 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
109 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
110
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
111 return padding;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
112 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
113
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 * 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
116 */
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
117 int
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
118 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
119 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
120 int tabcount;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
121 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
122 int t;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
123 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
124
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
125 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
126 return ts;
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 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
129 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
130 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
131 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
132 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
133 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
134 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
135 break;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
136 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
137 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
138 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
139 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
140
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
141 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
142 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
143
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 * 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
146 */
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
147 colnr_T
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
148 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
149 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
150 int tabcount;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
151 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
152 int t;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
153 int excess;
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 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
156 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
157
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
158 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
159 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
160 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
161 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
162 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
163 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
164 }
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 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
167 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
168 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
169
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
170 /*
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
171 * 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
172 * to another.
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
173 */
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
174 void
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
175 tabstop_fromto(
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
176 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
177 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
178 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
179 int *vts,
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
180 int *ntabs,
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
181 int *nspcs)
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
182 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
183 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
184 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
185 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
186 int tabcount;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
187 int t;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
188 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
189
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
190 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
191 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
192 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
193 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
194
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
195 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
196 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
197 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
198 spaces -= initspc;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
199 tabs++;
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 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
202 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
203
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
204 *ntabs = tabs;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
205 *nspcs = spaces;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
206 return;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
207 }
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 // 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
210 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
211 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
212 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
213 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
214 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
215 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
216 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
217 break;
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 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
221 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
222
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
223 // 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
224 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
225 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
226 *ntabs = 0;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
227 *nspcs = spaces;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
228 return;
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 *ntabs = 1;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
232 spaces -= padding;
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 // 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
235 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
236 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
237 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
238 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
239 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
240 *nspcs = spaces;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
241 return;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
242 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
243 ++*ntabs;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
244 spaces -= padding;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
245 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
246
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
247 *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
248 *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
249 }
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 /*
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
252 * 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
253 */
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
254 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
255 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
256 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
257 int t;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
258
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
259 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
260 return FALSE;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
261 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
262 return TRUE;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
263 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
264 return FALSE;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
265
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
266 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
267 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
268 return FALSE;
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 return TRUE;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
271 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
272
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
273 # 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
274 /*
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
275 * 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
276 */
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
277 int *
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
278 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
279 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
280 int *newts;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
281 int t;
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 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
284 return NULL;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
285 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
286 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
287 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
288 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
289 return newts;
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
290 }
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
291 # endif
17940
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
292
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 * 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
295 */
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
296 int
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
297 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
298 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
299 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
300 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
301
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
302 /*
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
303 * 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
304 */
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
305 int
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
306 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
307 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
308 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
309 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
310
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
311 #endif
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 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
315 * '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
316 */
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
317 long
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
318 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
319 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
320 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
321 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
322
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 * 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
325 */
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
326 static long
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
327 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
328 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
329 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
330 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
331
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
332 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
333 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
334 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
335 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
336 }
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
337
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
338 /*
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
339 * 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
340 */
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
341 long
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
342 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
343 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
344 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
345
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
346 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
347 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
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 /*
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
351 * 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
352 */
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
353 long
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
354 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
355 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
356 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
357 #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
358 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
359 #else
17940
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
360 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
361 #endif
17940
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
362 }
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 /*
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
365 * 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
366 * '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
367 */
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
368 long
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
369 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
370 {
079e10a49ea1 patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
371 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
372 }
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
373
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
374 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
375 * 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
376 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
377 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
378 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
379 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
380 #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
381 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
382 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
383 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
384 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
385 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
386 }
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 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
389 * 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
390 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
391 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
392 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
393 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
394 #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
395 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
396 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
397 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
398 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
399 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
400 }
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 #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
403 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
404 * 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
405 * "buf".
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
406 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
407 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
408 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
409 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
410 # 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
411 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
412 (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
413 # else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
414 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
415 # endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
416 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
417 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
418
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
419 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
420 * 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
421 * '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
422 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
423 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
424 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
425 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
426 int ts,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
427 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
428 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
429 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
430
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
431 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
432 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
433 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
434 {
23952
44be09b25619 patch 8.2.2518: 'listchars' should be window-local
Bram Moolenaar <Bram@vim.org>
parents: 23833
diff changeset
435 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
436 // 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
437 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
438 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
439 // 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
440 // 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
441 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
442 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
443 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
444 ++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
445 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
446 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
447 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
448 return count;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
449 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
450
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
451 #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
452 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
453 * 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
454 * variable tabstops.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
455 * 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
456 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
457 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
458 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
459 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
460 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
461
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
462 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
463 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
464 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
465 {
23952
44be09b25619 patch 8.2.2518: 'listchars' should be window-local
Bram Moolenaar <Bram@vim.org>
parents: 23833
diff changeset
466 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
467 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
468 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
469 // 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
470 // 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
471 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
472 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
473 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
474 ++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
475 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
476 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
477 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
478 return count;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
479 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
480 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
481
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
482 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
483 * 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
484 * 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
485 * 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
486 * "flags":
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
487 * 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
488 * 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
489 * 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
490 * 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
491 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
492 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
493 set_indent(
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
494 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
495 int flags)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
496 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
497 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
498 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
499 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
500 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
501 int todo;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
502 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
503 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
504 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
505 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
506 #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
507 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
508 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
509 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
510 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
511 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
512 // '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
513
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
514 // 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
515 // 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
516 todo = size;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
517 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
518 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
519
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
520 // 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
521 // 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
522
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
523 // 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
524 // '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
525 // 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
526 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
527 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
528 // 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
529 // 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
530 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
531 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
532 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
533
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
534 // 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
535 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
536 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
537 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
538 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
539 #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
540 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
541 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
542 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
543 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
544 - (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
545 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
546 // 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
547 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
548 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
549 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
550 ++ind_len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
551 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
552 }
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 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
555 --todo;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
556 ++ind_len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
557 ++ind_done;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
558 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
559 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
560 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
561
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
562 #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
563 // 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
564 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
565 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
566 // 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
567 // 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
568 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
569 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
570
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
571 // 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
572 #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
573 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
574 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
575 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
576 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
577 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
578 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
579 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
580 doit = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
581 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
582 ++ind_len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
583 // 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
584 #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
585 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
586 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
587 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
588 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
589
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
590 // 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
591 #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
592 for (;;)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
593 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
594 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
595 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
596 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
597 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
598 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
599 doit = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
600 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
601 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
602 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
603 ++ind_len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
604 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
605 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
606 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
607 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
608 {
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 -= (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
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_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
616 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
617 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
618 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
619 // 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
620 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
621 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
622 if (*p != ' ')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
623 doit = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
624 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
625 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
626 --todo;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
627 ++ind_len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
628 // ++ind_done;
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
631 // 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
632 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
633 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
634
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
635 // 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
636 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
637 p = oldline;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
638 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
639 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
640 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
641
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
642 // 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
643 // 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
644 // 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
645 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
646 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
647 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
648 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
649 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
650 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
651 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
652 // 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
653 // 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
654 p = oldline;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
655 s = newline;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
656 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
657 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
658 *s++ = *p++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
659 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
660 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
661
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
662 // 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
663 // than old)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
664 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
665 ++p;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
666
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
667 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
668 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
669 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
670 todo = size;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
671 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
672 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
673 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
674 s = newline;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
675 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
676
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
677 // 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
678 // 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
679 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
680 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
681 // 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
682 // 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
683 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
684 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
685 p = oldline;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
686 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
687
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
688 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
689 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
690 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
691 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
692 #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
693 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
694 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
695 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
696 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
697 - (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
698 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
699 // 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
700 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
701 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
702 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
703 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
704 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
705 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
706 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
707 --todo;
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;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
709 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
710 *s++ = *p++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
711 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
712
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
713 // 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
714 #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
715 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
716 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
717 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
718 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
719 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
720 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
721 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
722 *s++ = TAB;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
723 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
724 #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
725 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
726 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
727 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
728
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
729 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
730 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
731
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
732 #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
733 for (;;)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
734 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
735 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
736 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
737 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
738 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
739 *s++ = TAB;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
740 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
741 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
742 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
743 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
744 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
745 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
746 *s++ = TAB;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
747 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
748 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
749 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
750 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
751 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
752 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
753 *s++ = ' ';
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
754 --todo;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
755 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
756 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
757
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
758 // 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
759 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
760 {
21070
87e85a13e9cf patch 8.2.1086: possibly using freed memory when text properties used
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
761 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
762 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
763
87e85a13e9cf patch 8.2.1086: possibly using freed memory when text properties used
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
764 // 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
765 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
766 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
767 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
768
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
769 // 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
770 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
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 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
773 // 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
774 // 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
775 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
776 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
777 // 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
778 // 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
779 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
780 }
18763
49b78d6465e5 patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents: 18679
diff changeset
781 #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
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 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
784
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
785 // 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
786 // 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
787 // 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
788 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
789 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
790 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
791 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
792 retval = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
793 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
794 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
795 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
796
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
797 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
798 return retval;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
799 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
800
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 * 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
803 * 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
804 * 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
805 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
806 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
807 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
808 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
809 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
810 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
811
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
812 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
813 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
814
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
815 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
816 return -1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
817 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
818
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
819 // In format_lines() (i.e. not insert mode), fo+=q is needed too...
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
820 if ((State & INSERT) || has_format_option(FO_Q_COMS))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
821 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
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.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
824 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
825 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
826 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
827
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
828 // 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
829 // 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
830 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
831 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
832 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
833 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
834 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
835 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
836 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
837 }
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 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
840 return -1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
841 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
842 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
843 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
844
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
845 #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
846 /*
18679
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
847 * 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
848 * initialized.
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
849 */
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
850 int
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
851 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
852 {
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
853 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
854 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
855 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
856 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
857 int bri_list = 0;
18679
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
858
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
859 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
860 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
861 {
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
862 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
863 && ((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
864 {
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
865 p += 6;
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
866 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
867 }
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
868 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
869 {
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
870 p += 4;
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
871 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
872 }
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
873 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
874 {
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
875 p += 3;
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
876 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
877 }
25248
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
878 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
879 {
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
880 p += 5;
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
881 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
882 }
18679
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
883 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
884 return FAIL;
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
885 if (*p == ',')
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
886 ++p;
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
887 }
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
888
19503
a4be2f9cfb01 patch 8.2.0309: window-local values have confusing name
Bram Moolenaar <Bram@vim.org>
parents: 18933
diff changeset
889 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
890 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
891 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
892 wp->w_briopt_list = bri_list;
18679
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
893
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
894 return OK;
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
895 }
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
896
fd95d4dbeb37 patch 8.1.2331: the option.c file is still very big
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
897 /*
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
898 * 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
899 * 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
900 * 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
901 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
902 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
903 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
904 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
905 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
906 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
907 static int prev_indent = 0; // cached indent value
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
908 static long prev_ts = 0L; // cached tabstop value
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
909 static char_u *prev_line = NULL; // cached pointer to line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
910 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
911 # 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
912 static int *prev_vts = NULL; // cached vartabs values
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
913 # endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
914 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
915 // 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
916 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
917 - ((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
918 && (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
919 ? 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
920
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
921 // used cached indent, unless pointer or 'tabstop' changed
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
922 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
923 || 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
924 # 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
925 || 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
926 # endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
927 )
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
928 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
929 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
930 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
931 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
932 # 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
933 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
934 prev_indent = get_indent_str_vtab(line,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
935 (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
936 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
937 # else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
938 prev_indent = get_indent_str(line,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
939 (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
940 # endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
941 }
19503
a4be2f9cfb01 patch 8.2.0309: window-local values have confusing name
Bram Moolenaar <Bram@vim.org>
parents: 18933
diff changeset
942 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
943
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
944 // indent minus the length of the showbreak string
19503
a4be2f9cfb01 patch 8.2.0309: window-local values have confusing name
Bram Moolenaar <Bram@vim.org>
parents: 18933
diff changeset
945 if (wp->w_briopt_sbr)
18578
e9e60e0088b5 patch 8.1.2283: missed on use of p_sbr
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
946 bri -= vim_strsize(get_showbreak_value(wp));
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
947
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
948 // 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
949 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
950
25248
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
951 // add additional indent for numbered lists
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
952 if (wp->w_briopt_list > 0)
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
953 {
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
954 regmatch_T regmatch;
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
955
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
956 regmatch.regprog = vim_regcomp(curbuf->b_p_flp,
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
957 RE_MAGIC + RE_STRING + RE_AUTO + RE_STRICT);
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
958 if (regmatch.regprog != NULL)
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
959 {
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
960 if (vim_regexec(&regmatch, line, 0))
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
961 bri += wp->w_briopt_list;
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
962 vim_regfree(regmatch.regprog);
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
963 }
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
964 }
cf0774d010b7 patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
965
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
966 // 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
967 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
968 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
969
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
970 // 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
971 // 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
972 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
973 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
974 ? 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
975
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
976 return bri;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
977 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
978 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
979
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
980 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
981 * 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
982 * 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
983 * 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
984 * the line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
985 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
986 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
987 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
988 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
989 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
990 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
991
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
992 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
993 ++ptr;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
994 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
995 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
996 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
997 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
998 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
999
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1000 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) || defined(PROTO)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1001 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1002 * 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
1003 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1004 void
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1005 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
1006 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1007 long i;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1008 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
1009 int amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1010 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
1011 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
1012 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
1013
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1014 // 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
1015 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
1016 {
25064
8f2262c72178 patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 23952
diff changeset
1017 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
1018 return;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1019 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1020
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1021 for (i = oap->line_count; --i >= 0 && !got_int; )
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1022 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1023 // it's a slow thing to do, so give feedback so there's no worry that
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1024 // the computer's just hung.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1025
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1026 if (i > 1
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1027 && (i % 50 == 0 || i == oap->line_count - 1)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1028 && 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
1029 smsg(_("%ld lines to indent... "), i);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1030
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1031 // Be vi-compatible: For lisp indenting the first line is not
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1032 // indented, unless there is only one line.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1033 # ifdef FEAT_LISP
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1034 if (i != oap->line_count - 1 || oap->line_count == 1
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1035 || how != 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
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 l = skipwhite(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
1039 if (*l == NUL) // empty or blank line
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1040 amount = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1041 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1042 amount = how(); // get the indent for this 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 if (amount >= 0 && set_indent(amount, SIN_UNDO))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1045 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1046 // did change the indent, call changed_lines() later
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1047 if (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
1048 first_changed = 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
1049 last_changed = 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
1050 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1051 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1052 ++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
1053 curwin->w_cursor.col = 0; // make sure it's valid
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1054 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1055
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1056 // 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
1057 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
1058 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
1059
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1060 // 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
1061 // 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
1062 // 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
1063 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
1064 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
1065 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
1066 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
1067 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
1068 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
1069
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1070 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
1071 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1072 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
1073 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
1074 "%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
1075 }
22699
e82579016863 patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents: 21070
diff changeset
1076 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
1077 {
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18578
diff changeset
1078 // set '[ and '] marks
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18578
diff changeset
1079 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
1080 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
1081 }
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1082 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1083 #endif // defined(FEAT_LISP) || defined(FEAT_CINDENT)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1084
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1085 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) || defined(PROTO)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1086 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1087 * 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
1088 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1089 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1090 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
1091 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1092 return
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1093 # ifdef FEAT_SMARTINDENT
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1094 # ifdef FEAT_CINDENT
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1095 (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
1096 # else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1097 curbuf->b_p_si
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1098 # endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1099 # endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1100 # ifdef FEAT_CINDENT
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1101 (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
1102 && 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
1103 # endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1104 ;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1105 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1106 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1107
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1108 #ifdef FEAT_SMARTINDENT
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1109 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1110 * 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
1111 * 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
1112 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1113 void
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1114 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
1115 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1116 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
1117 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
1118 int i;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1119 int temp;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1120
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1121 // do some very smart indenting when entering '{' or '}'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1122 if (((did_si || can_si_back) && c == '{') || (can_si && c == '}'))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1123 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1124 // 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
1125 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
1126 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1127 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
1128 // 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
1129 // 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
1130 // 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
1131 // 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
1132 // lines -- webb
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1133 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
1134 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
1135 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
1136 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
1137 ;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1138 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
1139 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
1140 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
1141 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
1142 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
1143 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
1144 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
1145 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
1146 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1147 (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
1148 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1149 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
1150 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1151 // 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
1152 // 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
1153 temp = TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1154 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
1155 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1156 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
1157 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
1158 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
1159 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1160 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
1161
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1162 // 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
1163 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
1164 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1165 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1166 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
1167 temp = FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1168 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
1169 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1170 if (temp)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1171 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
1172 }
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1175 // set indent of '#' always to 0
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1176 if (curwin->w_cursor.col > 0 && can_si && c == '#')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1177 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1178 // 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
1179 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
1180 (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
1181 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1182
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1183 // 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
1184 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
1185 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
1186 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1187 #endif
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 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1190 * 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
1191 * 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
1192 * 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
1193 * 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
1194 * 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
1195 * 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
1196 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1197 void
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1198 change_indent(
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1199 int type,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1200 int amount,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1201 int round,
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1202 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
1203 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
1204 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1205 int vcol;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1206 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
1207 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
1208 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
1209 int i;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1210 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
1211 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
1212 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
1213 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
1214 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
1215 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
1216
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1217 // VREPLACE mode needs to know what the line was like before changing
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1218 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
1219 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1220 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
1221 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
1222 }
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 // 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
1225 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
1226 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
1227 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
1228 vcol = vc;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1229
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1230 // 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
1231 // 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
1232 // 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
1233 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
1234
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1235 // 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
1236 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
1237 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
1238 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
1239
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1240 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
1241
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1242 // 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
1243 // 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
1244 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
1245 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
1246
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1247 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
1248 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
1249
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1250 // 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
1251 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
1252 (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
1253 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1254 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1255 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
1256
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1257 // 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
1258 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
1259 State = INSERT;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1260 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
1261 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
1262 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1263 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
1264
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1265 // 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
1266 // 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
1267 // 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
1268 // 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
1269 // 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
1270 // 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
1271 // 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
1272 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
1273 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1274 // 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
1275 // 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
1276 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
1277 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
1278 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
1279 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1280 else if (!(State & INSERT))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1281 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
1282 else
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 // 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
1285 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
1286 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
1287
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1288 // 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
1289 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
1290 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
1291 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
1292 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
1293 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1294 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
1295 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
1296 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
1297 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1298 ++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
1299 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
1300 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1301 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
1302
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1303 // 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
1304 // 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
1305 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
1306 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1307 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
1308 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
1309 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
1310 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
1311 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1312 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
1313 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
1314 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
1315 ptr[i] = ' ';
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1316 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
1317 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
1318 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1319 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1320
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1321 // 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
1322 // 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
1323 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
1324 }
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 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
1327
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1328 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
1329 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
1330 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1331 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
1332 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
1333 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
1334
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1335 // May have to adjust the start of the insert.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1336 if (State & INSERT)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1337 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1338 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
1339 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1340 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
1341 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
1342 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1343 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
1344 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1345 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
1346 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
1347 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1348 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
1349 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1350
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1351 // For REPLACE mode, may have to fix the replace stack, 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
1352 // If the number of characters before the cursor decreased, need to pop a
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1353 // few characters 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
1354 // 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
1355 // 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
1356 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
1357 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1358 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
1359 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1360 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
1361 --start_col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1362 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1363 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
1364 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1365 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
1366 if (replaced)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1367 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1368 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
1369 replaced = NUL;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1370 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1371 ++start_col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1372 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1373 }
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 // For VREPLACE mode, we also have to fix the replace stack. In this case
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1376 // it is always possible because we backspace over the whole line and then
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1377 // put it back again the way we wanted it.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1378 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
1379 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1380 // 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
1381 // 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
1382 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
1383 return;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1384
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1385 // 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
1386 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
1387 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
1388 return;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1389
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1390 // 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
1391 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
1392
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1393 // 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
1394 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
1395 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
1396
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1397 // 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
1398 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
1399
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1400 // 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
1401 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
1402
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1403 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
1404 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1405 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1406
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 * 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
1409 * 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
1410 * 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
1411 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1412 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1413 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
1414 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1415 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
1416 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
1417 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
1418 int todo;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1419 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
1420 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
1421 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
1422 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
1423 int round;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1424 #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
1425 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
1426 #endif
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 // 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
1429 // 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
1430 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
1431 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1432 todo = size;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1433 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
1434 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
1435 #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
1436 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
1437 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1438 s = src;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1439
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1440 // 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
1441 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
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 (*s == TAB)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1444 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1445 #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
1446 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
1447 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
1448 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1449 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
1450 - (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
1451 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1452 // 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
1453 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
1454 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1455 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
1456 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
1457 #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
1458 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
1459 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1460 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1461 else
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 --todo;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1464 ++ind_done;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1465 #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
1466 ++ind_col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1467 #endif
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 ++ind_len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1470 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
1471 *p++ = *s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1472 ++s;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1473 }
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 // 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
1476 #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
1477 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
1478 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
1479 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1480 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
1481 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1482 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
1483 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1484 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
1485 ++ind_len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1486 #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
1487 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
1488 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1489 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
1490 *p++ = TAB;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1491 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1492
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1493 // 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
1494 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
1495 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1496 #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
1497 for (;;)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1498 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1499 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
1500 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
1501 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
1502 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1503 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
1504 ++ind_len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1505 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
1506 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
1507 *p++ = TAB;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1508 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1509 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1510 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
1511 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1512 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
1513 ++ind_len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1514 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
1515 *p++ = TAB;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1516 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1517 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1518 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1519
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1520 // 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
1521 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
1522 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1523 --todo;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1524 ++ind_len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1525 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
1526 *p++ = ' ';
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1527 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1528
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1529 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
1530 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1531 // 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
1532 // 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
1533 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
1534 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
1535 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
1536 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1537 p = line;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1538 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1539 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1540
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1541 // 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
1542 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
1543
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1544 // 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
1545 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
1546
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1547 // 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
1548 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
1549 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1550 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1551
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1552 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1553 * ":retab".
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 void
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1556 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
1557 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1558 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
1559 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
1560 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
1561 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
1562 long len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1563 long col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1564 long vcol;
18933
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1565 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
1566 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
1567 long old_len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1568 char_u *ptr;
18933
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1569 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
1570 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
1571 #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
1572 int *new_vts_array = NULL;
18933
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1573 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
1574 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1575 int temp;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1576 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
1577 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1578 int save_list;
18933
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1579 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
1580 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
1581
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1582 save_list = curwin->w_p_list;
18933
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1583 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
1584
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1585 #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
1586 new_ts_str = eap->arg;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1587 if (!tabstop_set(eap->arg, &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
1588 return;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1589 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
1590 ++(eap->arg);
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 // 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
1593 // 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
1594 // is null.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1595 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
1596 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1597 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
1598 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
1599 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1600 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1601 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
1602 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1603 new_ts = getdigits(&(eap->arg));
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1604 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
1605 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1606 emsg(_(e_positive));
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1607 return;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1608 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1609 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
1610 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
1611 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1612 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
1613 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1614 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
1615 col = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1616 vcol = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1617 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
1618 for (;;)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1619 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1620 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
1621 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1622 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
1623 {
18933
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1624 // 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
1625 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
1626 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
1627 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1628 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
1629 num_spaces++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1630 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1631 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
1632 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1633 else
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 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
1636 {
18933
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1637 // 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
1638
18933
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1639 // 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
1640 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
1641 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
1642 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
1643 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1644 #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
1645 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
1646
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1647 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
1648 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
1649 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
1650 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
1651 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1652 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
1653 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
1654 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1655 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
1656 num_tabs++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1657 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1658 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
1659 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
1660 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1661 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1662 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
1663 (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
1664 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1665 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
1666 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1667 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
1668 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
1669 (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
1670 {
18933
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1671 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
1672 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1673 }
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
18933
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1676 // 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
1677 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
1678 old_len = (long)STRLEN(ptr);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1679 new_line = alloc(old_len - col + start_col + len + 1);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1680 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
1681 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1682 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
1683 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
1684 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
1685 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
1686 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
1687 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
1688 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
1689 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
1690 // "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
1691 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
1692 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
1693 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
1694 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
1695 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
1696 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
1697 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1698 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1699 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
1700 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
1701 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1702 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
1703 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1704 vcol += chartabsize(ptr + 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
1705 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
1706 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
1707 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1708 ++col;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1709 }
18933
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1710 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
1711 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1712 line_breakcheck();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1713 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1714 if (got_int)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1715 emsg(_(e_interr));
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 #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
1718 // 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
1719 // 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
1720 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
1721 && 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
1722 && 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
1723 ; // 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
1724 else 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
1725 && 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
1726 ; // 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
1727 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1728 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
1729 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1730 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
1731 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
1732 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1733 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
1734 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
1735
18933
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1736 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
1737
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1738 #ifdef FEAT_VARTABS
18933
82c732e8d23d patch 8.2.0027: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1739 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
1740 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1741 // 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
1742 // 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
1743 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
1744
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1745 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
1746 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1747 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
1748 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
1749 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
1750 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
1751 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1752 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1753 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1754 // '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
1755 // 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
1756 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
1757 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
1758 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1759 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
1760 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1761 #else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1762 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
1763 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1764 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
1765
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1766 u_clearline();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1767 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1768
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1769 #if (defined(FEAT_CINDENT) && 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
1770 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1771 * 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
1772 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1773 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1774 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
1775 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1776 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
1777 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
1778 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
1779 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
1780 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
1781 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
1782 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
1783 OPT_LOCAL);
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1784
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1785 // 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
1786 // 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
1787 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
1788 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
1789 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
1790 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
1791 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
1792 ++sandbox;
20229
06a1dd50463e patch 8.2.0670: cannot change window when evaluating 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents: 19503
diff changeset
1793 ++textwinlock;
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1794
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1795 // 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
1796 // evaluating it.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1797 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
1798 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
1799 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1800 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
1801 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
1802 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1803
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1804 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
1805 --sandbox;
20229
06a1dd50463e patch 8.2.0670: cannot change window when evaluating 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents: 19503
diff changeset
1806 --textwinlock;
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1807
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1808 // 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
1809 // 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
1810 // command.
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1811 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
1812 State = INSERT;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1813 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
1814 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
1815 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
1816 check_cursor();
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1817 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
1818
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1819 // 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
1820 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
1821 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
1822
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1823 return indent;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1824 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1825 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1826
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1827 #if defined(FEAT_LISP) || defined(PROTO)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1828
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1829 static int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1830 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
1831 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1832 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
1833 int len;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1834 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
1835
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1836 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
1837 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1838 (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
1839 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
1840 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
1841 return TRUE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1842 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1843 return FALSE;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1844 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1845
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 * 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
1848 * 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
1849 * 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
1850 * 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
1851 *
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1852 * TODO:
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1853 * 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
1854 * 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
1855 * - 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
1856 * - 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
1857 * - 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
1858 * 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
1859 * 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
1860 * 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
1861 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1862 int
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1863 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
1864 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1865 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
1866 int amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1867 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
1868 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
1869 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
1870 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
1871 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
1872
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1873 // 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
1874 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
1875
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1876 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
1877 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
1878
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1879 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
1880 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
1881 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1882 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1883 paren = *pos;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1884 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
1885 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
1886 pos = &paren;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1887 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1888 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
1889 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1890 // 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
1891 // 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
1892 amount = -1;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1893 parencount = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1894
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1895 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
1896 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1897 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
1898 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1899 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
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 (*that == ';')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1902 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1903 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
1904 ++that;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1905 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1906 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1907 if (*that == '\\')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1908 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1909 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
1910 ++that;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1911 continue;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1912 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1913 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
1914 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1915 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
1916 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1917 // 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
1918 if (*that == '\\')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1919 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1920 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
1921 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1922 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
1923 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1924 ++that;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1925 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1926 }
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 }
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 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
1931 ++parencount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1932 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
1933 --parencount;
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 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
1936 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1937 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
1938 break;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1939 }
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
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1942 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
1943 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1944 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
1945 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
1946 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
1947
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1948 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
1949
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1950 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
1951 amount = 2;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1952 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1953 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1954 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
1955
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1956 amount = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1957 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
1958 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1959 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
1960 col--;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1961 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1962
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1963 // 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
1964 // 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
1965 //
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1966 // (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
1967 // (...)) of (...))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1968
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1969 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
1970 && 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
1971 amount += 2;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1972 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1973 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1974 that++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1975 amount++;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1976 firsttry = amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1977
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1978 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
1979 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1980 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
1981 ++that;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1982 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1983
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1984 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
1985 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1986 // 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
1987 // 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
1988 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
1989 firsttry++;
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 parencount = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1992 quotecount = 0;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1993
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1994 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
1995 || (*that != '"'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1996 && *that != '\''
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1997 && *that != '#'
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
1998 && (*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
1999 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2000 while (*that
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2001 && (!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
2002 || quotecount
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2003 || parencount)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2004 && (!((*that == '(' || *that == '[')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2005 && !quotecount
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2006 && !parencount
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2007 && vi_lisp)))
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2008 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2009 if (*that == '"')
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2010 quotecount = !quotecount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2011 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
2012 && !quotecount)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2013 ++parencount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2014 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
2015 && !quotecount)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2016 --parencount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2017 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
2018 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
2019 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
2020 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
2021 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
2022 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2023 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2024 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
2025 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2026 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
2027 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
2028 that++;
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 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
2031 amount = firsttry;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2032 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2033 }
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 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2036 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2037 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2038 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
2039
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2040 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
2041
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2042 return amount;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2043 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2044 #endif // FEAT_LISP
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 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) || defined(PROTO)
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2047 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2048 * 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
2049 * 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
2050 * 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
2051 * "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
2052 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2053
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2054 void
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2055 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
2056 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2057 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
2058
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2059 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
2060 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2061 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
2062 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
2063 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
2064 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2065 }
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 void
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2068 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
2069 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2070 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
2071 return;
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2072 # ifdef FEAT_LISP
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2073 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
2074 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
2075 # endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2076 # if defined(FEAT_LISP) && defined(FEAT_CINDENT)
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 # endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2079 # ifdef FEAT_CINDENT
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2080 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
2081 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
2082 # endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2083 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2084 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2085
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2086 #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
2087 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2088 * "indent()" function
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2089 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2090 void
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2091 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
2092 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2093 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
2094
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2095 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
2096 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
2097 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
2098 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2099 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
2100 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2101
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2102 /*
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2103 * "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
2104 */
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2105 void
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2106 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
2107 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2108 #ifdef FEAT_LISP
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2109 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
2110 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
2111
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2112 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
2113 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
2114 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
2115 {
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2116 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
2117 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
2118 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
2119 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2120 else
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2121 #endif
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2122 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
2123 }
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 17940
diff changeset
2124 #endif