annotate src/misc1.c @ 2361:e12685c50982 vim73

Fix some duplicates in ":find" completion. (Nazri Ramliy)
author Bram Moolenaar <bram@vim.org>
date Tue, 20 Jul 2010 18:10:15 +0200
parents f4440cdd59ae
children 797f7b467b03
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 * misc1.c: functions that didn't seem to fit elsewhere
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 #include "vim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 #include "version.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 static char_u *vim_version_dir __ARGS((char_u *vimdir));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 static char_u *remove_tail __ARGS((char_u *p, char_u *pend, char_u *name));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 static int copy_indent __ARGS((int size, char_u *src));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 * Count the size (in window cells) of the indent in the current line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 get_indent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 return get_indent_str(ml_get_curline(), (int)curbuf->b_p_ts);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 * Count the size (in window cells) of the indent in line "lnum".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 get_indent_lnum(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 return get_indent_str(ml_get(lnum), (int)curbuf->b_p_ts);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 #if defined(FEAT_FOLDING) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 * Count the size (in window cells) of the indent in line "lnum" of buffer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 * "buf".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 get_indent_buf(buf, lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 return get_indent_str(ml_get_buf(buf, lnum, FALSE), (int)buf->b_p_ts);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 * count the size (in window cells) of the indent in line "ptr", with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 * 'tabstop' at "ts"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 */
164
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 135
diff changeset
58 int
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 get_indent_str(ptr, ts)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 int ts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 int count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 for ( ; *ptr; ++ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 if (*ptr == TAB) /* count a tab for what it is worth */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 count += ts - (count % ts);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 else if (*ptr == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 ++count; /* count a space for one */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 }
164
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 135
diff changeset
74 return count;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 * Set the indent of the current line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 * Leaves the cursor on the first non-blank in the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 * Caller must take care of undo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 * "flags":
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 * SIN_CHANGED: call changed_bytes() if the line was changed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 * SIN_INSERT: insert the indent in front of the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 * SIN_UNDO: save line for undo before changing it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 * Returns TRUE if the line was changed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 set_indent(size, flags)
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
89 int size; /* measured in spaces */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 int flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 char_u *newline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 char_u *oldline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 int todo;
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
97 int ind_len; /* measured in characters */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 int line_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 int doit = FALSE;
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
100 int ind_done = 0; /* measured in spaces */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 int tab_pad;
217
89114a6baf3c updated for version 7.0061
vimboss
parents: 196
diff changeset
102 int retval = FALSE;
1359
a66a49322b6b updated for version 7.1-073
vimboss
parents: 1348
diff changeset
103 int orig_char_len = -1; /* number of initial whitespace chars when
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
104 'et' and 'pi' are both set */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 * First check if there is anything to do and compute the number of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 * characters needed for the indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 todo = size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 ind_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 p = oldline = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 /* Calculate the buffer size for the new indent, and check to see if it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 * isn't already set */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
117 /* if 'expandtab' isn't set: use TABs; if both 'expandtab' and
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
118 * 'preserveindent' are set count the number of characters at the
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
119 * beginning of the line to be copied */
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
120 if (!curbuf->b_p_et || (!(flags & SIN_INSERT) && curbuf->b_p_pi))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 /* If 'preserveindent' is set then reuse as much as possible of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 * the existing indent structure for the new indent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 if (!(flags & SIN_INSERT) && curbuf->b_p_pi)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 ind_done = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 /* count as many characters as we can use */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 while (todo > 0 && vim_iswhite(*p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 if (*p == TAB)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 tab_pad = (int)curbuf->b_p_ts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 - (ind_done % (int)curbuf->b_p_ts);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 /* stop if this tab will overshoot the target */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 if (todo < tab_pad)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 todo -= tab_pad;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 ++ind_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 ind_done += tab_pad;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 --todo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 ++ind_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 ++ind_done;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
151 /* Set initial number of whitespace chars to copy if we are
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
152 * preserving indent but expandtab is set */
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
153 if (curbuf->b_p_et)
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
154 orig_char_len = ind_len;
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
155
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 /* Fill to next tabstop with a tab, if possible */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts);
1359
a66a49322b6b updated for version 7.1-073
vimboss
parents: 1348
diff changeset
158 if (todo >= tab_pad && orig_char_len == -1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 doit = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 todo -= tab_pad;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 ++ind_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 /* ind_done += tab_pad; */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 /* count tabs required for indent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 while (todo >= (int)curbuf->b_p_ts)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 if (*p != TAB)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 doit = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 todo -= (int)curbuf->b_p_ts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 ++ind_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 /* ind_done += (int)curbuf->b_p_ts; */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 /* count spaces required for indent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 while (todo > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 if (*p != ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 doit = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 --todo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 ++ind_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 /* ++ind_done; */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 /* Return if the indent is OK already. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 if (!doit && !vim_iswhite(*p) && !(flags & SIN_INSERT))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 /* Allocate memory for the new line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 if (flags & SIN_INSERT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 p = oldline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 p = skipwhite(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 line_len = (int)STRLEN(p) + 1;
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
201
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
202 /* If 'preserveindent' and 'expandtab' are both set keep the original
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
203 * characters and allocate accordingly. We will fill the rest with spaces
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
204 * after the if (!curbuf->b_p_et) below. */
1359
a66a49322b6b updated for version 7.1-073
vimboss
parents: 1348
diff changeset
205 if (orig_char_len != -1)
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
206 {
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
207 newline = alloc(orig_char_len + size - ind_done + line_len);
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
208 if (newline == NULL)
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
209 return FALSE;
1359
a66a49322b6b updated for version 7.1-073
vimboss
parents: 1348
diff changeset
210 todo = size - ind_done;
a66a49322b6b updated for version 7.1-073
vimboss
parents: 1348
diff changeset
211 ind_len = orig_char_len + todo; /* Set total length of indent in
a66a49322b6b updated for version 7.1-073
vimboss
parents: 1348
diff changeset
212 * characters, which may have been
a66a49322b6b updated for version 7.1-073
vimboss
parents: 1348
diff changeset
213 * undercounted until now */
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
214 p = oldline;
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
215 s = newline;
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
216 while (orig_char_len > 0)
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
217 {
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
218 *s++ = *p++;
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
219 orig_char_len--;
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
220 }
1474
276244befa5b updated for version 7.1-189
vimboss
parents: 1470
diff changeset
221
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
222 /* Skip over any additional white space (useful when newindent is less
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
223 * than old) */
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
224 while (vim_iswhite(*p))
1474
276244befa5b updated for version 7.1-189
vimboss
parents: 1470
diff changeset
225 ++p;
1348
17a83c0532e8 updated for version 7.1-062
vimboss
parents: 1341
diff changeset
226
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
227 }
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
228 else
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
229 {
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
230 todo = size;
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
231 newline = alloc(ind_len + line_len);
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
232 if (newline == NULL)
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
233 return FALSE;
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
234 s = newline;
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
235 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 /* Put the characters in the new line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238 /* if 'expandtab' isn't set: use TABs */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 if (!curbuf->b_p_et)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 /* If 'preserveindent' is set then reuse as much as possible of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 * the existing indent structure for the new indent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 if (!(flags & SIN_INSERT) && curbuf->b_p_pi)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 p = oldline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 ind_done = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 while (todo > 0 && vim_iswhite(*p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 if (*p == TAB)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 tab_pad = (int)curbuf->b_p_ts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 - (ind_done % (int)curbuf->b_p_ts);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254 /* stop if this tab will overshoot the target */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 if (todo < tab_pad)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 todo -= tab_pad;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 ind_done += tab_pad;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 --todo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 ++ind_done;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 *s++ = *p++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 /* Fill to next tabstop with a tab, if possible */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 if (todo >= tab_pad)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 *s++ = TAB;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 todo -= tab_pad;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 p = skipwhite(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 while (todo >= (int)curbuf->b_p_ts)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 *s++ = TAB;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 todo -= (int)curbuf->b_p_ts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 while (todo > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287 *s++ = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 --todo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 mch_memmove(s, p, (size_t)line_len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292 /* Replace the line (unless undo fails). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 if (!(flags & SIN_UNDO) || u_savesub(curwin->w_cursor.lnum) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 ml_replace(curwin->w_cursor.lnum, newline, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296 if (flags & SIN_CHANGED)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 changed_bytes(curwin->w_cursor.lnum, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 /* Correct saved cursor position if it's after the indent. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299 if (saved_cursor.lnum == curwin->w_cursor.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300 && saved_cursor.col >= (colnr_T)(p - oldline))
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 834
diff changeset
301 saved_cursor.col += ind_len - (colnr_T)(p - oldline);
217
89114a6baf3c updated for version 7.0061
vimboss
parents: 196
diff changeset
302 retval = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 vim_free(newline);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307 curwin->w_cursor.col = ind_len;
217
89114a6baf3c updated for version 7.0061
vimboss
parents: 196
diff changeset
308 return retval;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 * Copy the indent from ptr to the current line (and fill to size)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313 * Leaves the cursor on the first non-blank in the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314 * Returns TRUE if the line was changed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 copy_indent(size, src)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 int size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319 char_u *src;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 char_u *p = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322 char_u *line = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 int todo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325 int ind_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326 int line_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 int tab_pad;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 int ind_done;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 int round;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 /* Round 1: compute the number of characters needed for the indent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332 * Round 2: copy the characters. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 for (round = 1; round <= 2; ++round)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335 todo = size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 ind_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 ind_done = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338 s = src;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 /* Count/copy the usable portion of the source line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 while (todo > 0 && vim_iswhite(*s))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 if (*s == TAB)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345 tab_pad = (int)curbuf->b_p_ts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346 - (ind_done % (int)curbuf->b_p_ts);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347 /* Stop if this tab will overshoot the target */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 if (todo < tab_pad)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350 todo -= tab_pad;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351 ind_done += tab_pad;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 --todo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 ++ind_done;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 ++ind_len;
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 838
diff changeset
359 if (p != NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360 *p++ = *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361 ++s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 /* Fill to next tabstop with a tab, if possible */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366 if (todo >= tab_pad)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
367 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368 todo -= tab_pad;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369 ++ind_len;
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 838
diff changeset
370 if (p != NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371 *p++ = TAB;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374 /* Add tabs required for indent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375 while (todo >= (int)curbuf->b_p_ts)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 todo -= (int)curbuf->b_p_ts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 ++ind_len;
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 838
diff changeset
379 if (p != NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 *p++ = TAB;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383 /* Count/add spaces required for indent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384 while (todo > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386 --todo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 ++ind_len;
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 838
diff changeset
388 if (p != NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389 *p++ = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 838
diff changeset
392 if (p == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394 /* Allocate memory for the result: the copied indent, new indent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395 * and the rest of the line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 line_len = (int)STRLEN(ml_get_curline()) + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 line = alloc(ind_len + line_len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398 if (line == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400 p = line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404 /* Append the original line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 mch_memmove(p, ml_get_curline(), (size_t)line_len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407 /* Replace the line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408 ml_replace(curwin->w_cursor.lnum, line, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410 /* Put the cursor after the indent. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411 curwin->w_cursor.col = ind_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 * Return the indent of the current line after a number. Return -1 if no
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417 * number was found. Used for 'n' in 'formatoptions': numbered list.
41
f529edb9bab3 updated for version 7.0025
vimboss
parents: 39
diff changeset
418 * Since a pattern is used it can actually handle more than numbers.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 get_number_indent(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
424 colnr_T col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425 pos_T pos;
41
f529edb9bab3 updated for version 7.0025
vimboss
parents: 39
diff changeset
426 regmmatch_T regmatch;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428 if (lnum > curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429 return -1;
41
f529edb9bab3 updated for version 7.0025
vimboss
parents: 39
diff changeset
430 pos.lnum = 0;
f529edb9bab3 updated for version 7.0025
vimboss
parents: 39
diff changeset
431 regmatch.regprog = vim_regcomp(curbuf->b_p_flp, RE_MAGIC);
f529edb9bab3 updated for version 7.0025
vimboss
parents: 39
diff changeset
432 if (regmatch.regprog != NULL)
f529edb9bab3 updated for version 7.0025
vimboss
parents: 39
diff changeset
433 {
f529edb9bab3 updated for version 7.0025
vimboss
parents: 39
diff changeset
434 regmatch.rmm_ic = FALSE;
410
c60ba877860b updated for version 7.0107
vimboss
parents: 408
diff changeset
435 regmatch.rmm_maxcol = 0;
1521
cc4fe241baa3 updated for version 7.1-236
vimboss
parents: 1474
diff changeset
436 if (vim_regexec_multi(&regmatch, curwin, curbuf, lnum,
cc4fe241baa3 updated for version 7.1-236
vimboss
parents: 1474
diff changeset
437 (colnr_T)0, NULL))
41
f529edb9bab3 updated for version 7.0025
vimboss
parents: 39
diff changeset
438 {
f529edb9bab3 updated for version 7.0025
vimboss
parents: 39
diff changeset
439 pos.lnum = regmatch.endpos[0].lnum + lnum;
f529edb9bab3 updated for version 7.0025
vimboss
parents: 39
diff changeset
440 pos.col = regmatch.endpos[0].col;
f529edb9bab3 updated for version 7.0025
vimboss
parents: 39
diff changeset
441 #ifdef FEAT_VIRTUALEDIT
f529edb9bab3 updated for version 7.0025
vimboss
parents: 39
diff changeset
442 pos.coladd = 0;
f529edb9bab3 updated for version 7.0025
vimboss
parents: 39
diff changeset
443 #endif
f529edb9bab3 updated for version 7.0025
vimboss
parents: 39
diff changeset
444 }
f529edb9bab3 updated for version 7.0025
vimboss
parents: 39
diff changeset
445 vim_free(regmatch.regprog);
f529edb9bab3 updated for version 7.0025
vimboss
parents: 39
diff changeset
446 }
f529edb9bab3 updated for version 7.0025
vimboss
parents: 39
diff changeset
447
f529edb9bab3 updated for version 7.0025
vimboss
parents: 39
diff changeset
448 if (pos.lnum == 0 || *ml_get_pos(&pos) == NUL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
450 getvcol(curwin, &pos, &col, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
451 return (int)col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 #if defined(FEAT_CINDENT) || defined(FEAT_SMARTINDENT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456 static int cin_is_cinword __ARGS((char_u *line));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 * Return TRUE if the string "line" starts with a word from 'cinwords'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462 cin_is_cinword(line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 char_u *line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465 char_u *cinw;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466 char_u *cinw_buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467 int cinw_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
468 int retval = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471 cinw_len = (int)STRLEN(curbuf->b_p_cinw) + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472 cinw_buf = alloc((unsigned)cinw_len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473 if (cinw_buf != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475 line = skipwhite(line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476 for (cinw = curbuf->b_p_cinw; *cinw; )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
477 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
478 len = copy_option_part(&cinw, cinw_buf, cinw_len, ",");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479 if (STRNCMP(line, cinw_buf, len) == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 && (!vim_iswordc(line[len]) || !vim_iswordc(line[len - 1])))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482 retval = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
483 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
485 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486 vim_free(cinw_buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
488 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
493 * open_line: Add a new line below or above the current line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495 * For VREPLACE mode, we only add a new line when we get to the end of the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496 * file, otherwise we just start replacing the next line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498 * Caller must take care of undo. Since VREPLACE may affect any number of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499 * lines however, it may call u_save_cursor() again when starting to change a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500 * new line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501 * "flags": OPENLINE_DELSPACES delete spaces after cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502 * OPENLINE_DO_COM format comments
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
503 * OPENLINE_KEEPTRAIL keep trailing spaces
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
504 * OPENLINE_MARKFIX adjust mark positions after the line break
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
506 * Return TRUE for success, FALSE for failure
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
507 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
508 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
509 open_line(dir, flags, old_indent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510 int dir; /* FORWARD or BACKWARD */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511 int flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
512 int old_indent; /* indent for after ^^D in Insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
513 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
514 char_u *saved_line; /* copy of the original line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
515 char_u *next_line = NULL; /* copy of the next line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
516 char_u *p_extra = NULL; /* what goes to next line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
517 int less_cols = 0; /* less columns for mark in new line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
518 int less_cols_off = 0; /* columns to skip for mark adjust */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
519 pos_T old_cursor; /* old cursor position */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
520 int newcol = 0; /* new cursor column */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
521 int newindent = 0; /* auto-indent of the new line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522 int n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
523 int trunc_line = FALSE; /* truncate current line afterwards */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
524 int retval = FALSE; /* return value, default is FAIL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
525 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
526 int extra_len = 0; /* length of p_extra string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
527 int lead_len; /* length of comment leader */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
528 char_u *lead_flags; /* position in 'comments' for comment leader */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
529 char_u *leader = NULL; /* copy of comment leader */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
530 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
531 char_u *allocated = NULL; /* allocated memory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532 #if defined(FEAT_SMARTINDENT) || defined(FEAT_VREPLACE) || defined(FEAT_LISP) \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533 || defined(FEAT_CINDENT) || defined(FEAT_COMMENTS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
534 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
535 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
536 int saved_char = NUL; /* init for GCC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
537 #if defined(FEAT_SMARTINDENT) || defined(FEAT_COMMENTS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
538 pos_T *pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
539 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
540 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
541 int do_si = (!p_paste && curbuf->b_p_si
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
542 # ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
543 && !curbuf->b_p_cin
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
544 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
545 );
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
546 int no_si = FALSE; /* reset did_si afterwards */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
547 int first_char = NUL; /* init for GCC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
548 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
549 #if defined(FEAT_VREPLACE) && (defined(FEAT_LISP) || defined(FEAT_CINDENT))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
550 int vreplace_mode;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
551 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
552 int did_append; /* appended a new line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
553 int saved_pi = curbuf->b_p_pi; /* copy of preserveindent setting */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
554
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
555 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
556 * make a copy of the current line so we can mess with it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
557 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
558 saved_line = vim_strsave(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
559 if (saved_line == NULL) /* out of memory! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
560 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
561
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
562 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
563 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
564 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
565 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
566 * With VREPLACE we make a copy of the next line, which we will be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
567 * starting to replace. First make the new line empty and let vim play
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
568 * with the indenting and comment leader to its heart's content. Then
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
569 * we grab what it ended up putting on the new line, put back the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
570 * original line, and call ins_char() to put each new character onto
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
571 * the line, replacing what was there before and pushing the right
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
572 * stuff onto the replace stack. -- webb.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574 if (curwin->w_cursor.lnum < orig_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575 next_line = vim_strsave(ml_get(curwin->w_cursor.lnum + 1));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577 next_line = vim_strsave((char_u *)"");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578 if (next_line == NULL) /* out of memory! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
579 goto theend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582 * In VREPLACE mode, a NL replaces the rest of the line, and starts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
583 * replacing the next line, so push all of the characters left on the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
584 * line onto the replace stack. We'll push any other characters that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
585 * might be replaced at the start of the next line (due to autoindent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
586 * etc) a bit later.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
587 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588 replace_push(NUL); /* Call twice because BS over NL expects it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589 replace_push(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590 p = saved_line + curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
591 while (*p != NUL)
1470
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1408
diff changeset
592 {
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1408
diff changeset
593 #ifdef FEAT_MBYTE
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1408
diff changeset
594 if (has_mbyte)
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1408
diff changeset
595 p += replace_push_mb(p);
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1408
diff changeset
596 else
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1408
diff changeset
597 #endif
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1408
diff changeset
598 replace_push(*p++);
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1408
diff changeset
599 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600 saved_line[curwin->w_cursor.col] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
601 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
604 if ((State & INSERT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
605 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
606 && !(State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
607 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
608 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
610 p_extra = saved_line + curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
611 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
612 if (do_si) /* need first char after new line break */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
613 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
614 p = skipwhite(p_extra);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
615 first_char = *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
616 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
617 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
618 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
619 extra_len = (int)STRLEN(p_extra);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
620 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
621 saved_char = *p_extra;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
622 *p_extra = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
623 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
624
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
625 u_clearline(); /* cannot do "U" command when adding lines */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
626 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
627 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
628 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
629 ai_col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
630
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
631 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
632 * If we just did an auto-indent, then we didn't type anything on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
633 * the prior line, and it should be truncated. Do this even if 'ai' is not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
634 * set because automatically inserting a comment leader also sets did_ai.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
635 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
636 if (dir == FORWARD && did_ai)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
637 trunc_line = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
638
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
639 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
640 * If 'autoindent' and/or 'smartindent' is set, try to figure out what
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
641 * indent to use for the new line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
642 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
643 if (curbuf->b_p_ai
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
644 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
645 || do_si
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
646 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
647 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
648 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
649 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
650 * count white space on current line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
651 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
652 newindent = get_indent_str(saved_line, (int)curbuf->b_p_ts);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
653 if (newindent == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
654 newindent = old_indent; /* for ^^D command in insert mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
655
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
656 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
657 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
658 * Do smart indenting.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
659 * In insert/replace mode (only when dir == FORWARD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
660 * we may move some text to the next line. If it starts with '{'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
661 * don't add an indent. Fixes inserting a NL before '{' in line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
662 * "if (condition) {"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
663 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
664 if (!trunc_line && do_si && *saved_line != NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
665 && (p_extra == NULL || first_char != '{'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
666 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
667 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
668 char_u last_char;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
669
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
670 old_cursor = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
671 ptr = saved_line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
672 # ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
673 if (flags & OPENLINE_DO_COM)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
674 lead_len = get_leader_len(ptr, NULL, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
675 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
676 lead_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
677 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
678 if (dir == FORWARD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
679 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
680 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
681 * Skip preprocessor directives, unless they are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
682 * recognised as comments.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
683 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
684 if (
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
685 # ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
686 lead_len == 0 &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
687 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
688 ptr[0] == '#')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
689 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
690 while (ptr[0] == '#' && curwin->w_cursor.lnum > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
691 ptr = ml_get(--curwin->w_cursor.lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
692 newindent = get_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
693 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
694 # ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
695 if (flags & OPENLINE_DO_COM)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
696 lead_len = get_leader_len(ptr, NULL, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
697 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
698 lead_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
699 if (lead_len > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
700 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
701 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
702 * This case gets the following right:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
703 * \*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
704 * * A comment (read '\' as '/').
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
705 * *\
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
706 * #define IN_THE_WAY
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
707 * This should line up here;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
708 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
709 p = skipwhite(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
710 if (p[0] == '/' && p[1] == '*')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
711 p++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
712 if (p[0] == '*')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
713 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
714 for (p++; *p; p++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
715 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
716 if (p[0] == '/' && p[-1] == '*')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
717 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
718 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
719 * End of C comment, indent should line up
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
720 * with the line containing the start of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
721 * the comment
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
722 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
723 curwin->w_cursor.col = (colnr_T)(p - ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
724 if ((pos = findmatch(NULL, NUL)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
725 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
726 curwin->w_cursor.lnum = pos->lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
727 newindent = get_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
728 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
729 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
730 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
731 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
732 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
733 else /* Not a comment line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
734 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
735 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
736 /* Find last non-blank in line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
737 p = ptr + STRLEN(ptr) - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
738 while (p > ptr && vim_iswhite(*p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
739 --p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
740 last_char = *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
741
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
742 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
743 * find the character just before the '{' or ';'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
744 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
745 if (last_char == '{' || last_char == ';')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
746 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
747 if (p > ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
748 --p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
749 while (p > ptr && vim_iswhite(*p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
750 --p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
751 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
752 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
753 * Try to catch lines that are split over multiple
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
754 * lines. eg:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
755 * if (condition &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
756 * condition) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
757 * Should line up here!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
758 * }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
759 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
760 if (*p == ')')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
761 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
762 curwin->w_cursor.col = (colnr_T)(p - ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
763 if ((pos = findmatch(NULL, '(')) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
764 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
765 curwin->w_cursor.lnum = pos->lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
766 newindent = get_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
767 ptr = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
768 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
769 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
770 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
771 * If last character is '{' do indent, without
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
772 * checking for "if" and the like.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
773 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
774 if (last_char == '{')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
775 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
776 did_si = TRUE; /* do indent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
777 no_si = TRUE; /* don't delete it when '{' typed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
778 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
779 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
780 * Look for "if" and the like, use 'cinwords'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
781 * Don't do this if the previous line ended in ';' or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
782 * '}'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
783 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
784 else if (last_char != ';' && last_char != '}'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
785 && cin_is_cinword(ptr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
786 did_si = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
787 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
788 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
789 else /* dir == BACKWARD */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
790 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
791 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
792 * Skip preprocessor directives, unless they are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
793 * recognised as comments.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
794 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
795 if (
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
796 # ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
797 lead_len == 0 &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
798 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
799 ptr[0] == '#')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
800 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
801 int was_backslashed = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
802
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
803 while ((ptr[0] == '#' || was_backslashed) &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
804 curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
805 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
806 if (*ptr && ptr[STRLEN(ptr) - 1] == '\\')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
807 was_backslashed = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
808 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
809 was_backslashed = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
810 ptr = ml_get(++curwin->w_cursor.lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
811 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
812 if (was_backslashed)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
813 newindent = 0; /* Got to end of file */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
814 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
815 newindent = get_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
816 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
817 p = skipwhite(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
818 if (*p == '}') /* if line starts with '}': do indent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
819 did_si = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
820 else /* can delete indent when '{' typed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
821 can_si_back = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
822 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
823 curwin->w_cursor = old_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
824 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
825 if (do_si)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
826 can_si = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
827 #endif /* FEAT_SMARTINDENT */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
828
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
829 did_ai = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
830 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
831
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
832 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
833 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
834 * Find out if the current line starts with a comment leader.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
835 * This may then be inserted in front of the new line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
836 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
837 end_comment_pending = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
838 if (flags & OPENLINE_DO_COM)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
839 lead_len = get_leader_len(saved_line, &lead_flags, dir == BACKWARD);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
840 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
841 lead_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
842 if (lead_len > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
843 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
844 char_u *lead_repl = NULL; /* replaces comment leader */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
845 int lead_repl_len = 0; /* length of *lead_repl */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
846 char_u lead_middle[COM_MAX_LEN]; /* middle-comment string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
847 char_u lead_end[COM_MAX_LEN]; /* end-comment string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
848 char_u *comment_end = NULL; /* where lead_end has been found */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
849 int extra_space = FALSE; /* append extra space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
850 int current_flag;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
851 int require_blank = FALSE; /* requires blank after middle */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
852 char_u *p2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
853
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
854 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
855 * If the comment leader has the start, middle or end flag, it may not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
856 * be used or may be replaced with the middle leader.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
857 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
858 for (p = lead_flags; *p && *p != ':'; ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
859 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
860 if (*p == COM_BLANK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
861 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
862 require_blank = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
863 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
864 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
865 if (*p == COM_START || *p == COM_MIDDLE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
866 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
867 current_flag = *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
868 if (*p == COM_START)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
869 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
870 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
871 * Doing "O" on a start of comment does not insert leader.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
872 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
873 if (dir == BACKWARD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
874 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
875 lead_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
876 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
877 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
878
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
879 /* find start of middle part */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
880 (void)copy_option_part(&p, lead_middle, COM_MAX_LEN, ",");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
881 require_blank = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
882 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
883
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
884 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
885 * Isolate the strings of the middle and end leader.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
886 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
887 while (*p && p[-1] != ':') /* find end of middle flags */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
888 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
889 if (*p == COM_BLANK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
890 require_blank = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
891 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
892 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
893 (void)copy_option_part(&p, lead_middle, COM_MAX_LEN, ",");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
894
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
895 while (*p && p[-1] != ':') /* find end of end flags */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
896 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
897 /* Check whether we allow automatic ending of comments */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
898 if (*p == COM_AUTO_END)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
899 end_comment_pending = -1; /* means we want to set it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
900 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
901 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
902 n = copy_option_part(&p, lead_end, COM_MAX_LEN, ",");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
903
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
904 if (end_comment_pending == -1) /* we can set it now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
905 end_comment_pending = lead_end[n - 1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
906
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
907 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
908 * If the end of the comment is in the same line, don't use
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
909 * the comment leader.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
910 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
911 if (dir == FORWARD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
912 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
913 for (p = saved_line + lead_len; *p; ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
914 if (STRNCMP(p, lead_end, n) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
915 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
916 comment_end = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
917 lead_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
918 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
919 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
920 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
921
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
922 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
923 * Doing "o" on a start of comment inserts the middle leader.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
924 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
925 if (lead_len > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
926 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
927 if (current_flag == COM_START)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
928 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
929 lead_repl = lead_middle;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
930 lead_repl_len = (int)STRLEN(lead_middle);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
931 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
932
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
933 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
934 * If we have hit RETURN immediately after the start
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
935 * comment leader, then put a space after the middle
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
936 * comment leader on the next line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
937 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
938 if (!vim_iswhite(saved_line[lead_len - 1])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
939 && ((p_extra != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
940 && (int)curwin->w_cursor.col == lead_len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
941 || (p_extra == NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
942 && saved_line[lead_len] == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
943 || require_blank))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
944 extra_space = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
945 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
946 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
947 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
948 if (*p == COM_END)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
949 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
950 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
951 * Doing "o" on the end of a comment does not insert leader.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
952 * Remember where the end is, might want to use it to find the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
953 * start (for C-comments).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
954 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
955 if (dir == FORWARD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
956 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
957 comment_end = skipwhite(saved_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
958 lead_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
959 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
960 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
961
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
962 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
963 * Doing "O" on the end of a comment inserts the middle leader.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
964 * Find the string for the middle leader, searching backwards.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
965 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
966 while (p > curbuf->b_p_com && *p != ',')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
967 --p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
968 for (lead_repl = p; lead_repl > curbuf->b_p_com
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
969 && lead_repl[-1] != ':'; --lead_repl)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
970 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
971 lead_repl_len = (int)(p - lead_repl);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
972
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
973 /* We can probably always add an extra space when doing "O" on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
974 * the comment-end */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
975 extra_space = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
976
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
977 /* Check whether we allow automatic ending of comments */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
978 for (p2 = p; *p2 && *p2 != ':'; p2++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
979 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
980 if (*p2 == COM_AUTO_END)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
981 end_comment_pending = -1; /* means we want to set it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
982 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
983 if (end_comment_pending == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
984 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
985 /* Find last character in end-comment string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
986 while (*p2 && *p2 != ',')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
987 p2++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
988 end_comment_pending = p2[-1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
989 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
990 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
991 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
992 if (*p == COM_FIRST)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
993 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
994 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
995 * Comment leader for first line only: Don't repeat leader
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
996 * when using "O", blank out leader when using "o".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
997 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
998 if (dir == BACKWARD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
999 lead_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1000 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1001 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1002 lead_repl = (char_u *)"";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1003 lead_repl_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1004 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1005 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1006 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1007 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1008 if (lead_len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1009 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1010 /* allocate buffer (may concatenate p_exta later) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1011 leader = alloc(lead_len + lead_repl_len + extra_space +
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1012 extra_len + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1013 allocated = leader; /* remember to free it later */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1014
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1015 if (leader == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1016 lead_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1017 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1018 {
419
f713fc55bf7b updated for version 7.0109
vimboss
parents: 410
diff changeset
1019 vim_strncpy(leader, saved_line, lead_len);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1020
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1021 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1022 * Replace leader with lead_repl, right or left adjusted
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1023 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1024 if (lead_repl != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1025 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1026 int c = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1027 int off = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1028
1996
077c15286de8 updated for version 7.2-293
vimboss
parents: 1987
diff changeset
1029 for (p = lead_flags; *p != NUL && *p != ':'; )
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1030 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1031 if (*p == COM_RIGHT || *p == COM_LEFT)
1996
077c15286de8 updated for version 7.2-293
vimboss
parents: 1987
diff changeset
1032 c = *p++;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1033 else if (VIM_ISDIGIT(*p) || *p == '-')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1034 off = getdigits(&p);
1996
077c15286de8 updated for version 7.2-293
vimboss
parents: 1987
diff changeset
1035 else
077c15286de8 updated for version 7.2-293
vimboss
parents: 1987
diff changeset
1036 ++p;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1037 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1038 if (c == COM_RIGHT) /* right adjusted leader */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1039 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1040 /* find last non-white in the leader to line up with */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1041 for (p = leader + lead_len - 1; p > leader
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1042 && vim_iswhite(*p); --p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1043 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1044 ++p;
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1045
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1046 #ifdef FEAT_MBYTE
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1047 /* Compute the length of the replaced characters in
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1048 * screen characters, not bytes. */
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1049 {
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1050 int repl_size = vim_strnsize(lead_repl,
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1051 lead_repl_len);
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1052 int old_size = 0;
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1053 char_u *endp = p;
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1054 int l;
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1055
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1056 while (old_size < repl_size && p > leader)
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1057 {
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
1058 mb_ptr_back(leader, p);
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1059 old_size += ptr2cells(p);
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1060 }
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 834
diff changeset
1061 l = lead_repl_len - (int)(endp - p);
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1062 if (l != 0)
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1063 mch_memmove(endp + l, endp,
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1064 (size_t)((leader + lead_len) - endp));
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1065 lead_len += l;
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1066 }
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1067 #else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1068 if (p < leader + lead_repl_len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1069 p = leader;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1070 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1071 p -= lead_repl_len;
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1072 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1073 mch_memmove(p, lead_repl, (size_t)lead_repl_len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1074 if (p + lead_repl_len > leader + lead_len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1075 p[lead_repl_len] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1076
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1077 /* blank-out any other chars from the old leader. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1078 while (--p >= leader)
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1079 {
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1080 #ifdef FEAT_MBYTE
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1081 int l = mb_head_off(leader, p);
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1082
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1083 if (l > 1)
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1084 {
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1085 p -= l;
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1086 if (ptr2cells(p) > 1)
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1087 {
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1088 p[1] = ' ';
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1089 --l;
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1090 }
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1091 mch_memmove(p + 1, p + l + 1,
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1092 (size_t)((leader + lead_len) - (p + l + 1)));
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1093 lead_len -= l;
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1094 *p = ' ';
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1095 }
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1096 else
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1097 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1098 if (!vim_iswhite(*p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1099 *p = ' ';
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1100 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1101 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1102 else /* left adjusted leader */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1103 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1104 p = skipwhite(leader);
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1105 #ifdef FEAT_MBYTE
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1106 /* Compute the length of the replaced characters in
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1107 * screen characters, not bytes. Move the part that is
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1108 * not to be overwritten. */
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1109 {
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1110 int repl_size = vim_strnsize(lead_repl,
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1111 lead_repl_len);
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1112 int i;
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1113 int l;
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1114
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1115 for (i = 0; p[i] != NUL && i < lead_len; i += l)
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1116 {
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 445
diff changeset
1117 l = (*mb_ptr2len)(p + i);
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1118 if (vim_strnsize(p, i + l) > repl_size)
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1119 break;
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1120 }
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1121 if (i != lead_repl_len)
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1122 {
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1123 mch_memmove(p + lead_repl_len, p + i,
2002
071166147fc5 updated for version 7.2-299
vimboss
parents: 1996
diff changeset
1124 (size_t)(lead_len - i - (p - leader)));
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1125 lead_len += lead_repl_len - i;
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1126 }
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1127 }
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1128 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1129 mch_memmove(p, lead_repl, (size_t)lead_repl_len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1130
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1131 /* Replace any remaining non-white chars in the old
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1132 * leader by spaces. Keep Tabs, the indent must
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1133 * remain the same. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1134 for (p += lead_repl_len; p < leader + lead_len; ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1135 if (!vim_iswhite(*p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1136 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1137 /* Don't put a space before a TAB. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1138 if (p + 1 < leader + lead_len && p[1] == TAB)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1139 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1140 --lead_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1141 mch_memmove(p, p + 1,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1142 (leader + lead_len) - p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1143 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1144 else
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1145 {
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1146 #ifdef FEAT_MBYTE
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 445
diff changeset
1147 int l = (*mb_ptr2len)(p);
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1148
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1149 if (l > 1)
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1150 {
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1151 if (ptr2cells(p) > 1)
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1152 {
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1153 /* Replace a double-wide char with
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1154 * two spaces */
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1155 --l;
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1156 *p++ = ' ';
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1157 }
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1158 mch_memmove(p + 1, p + l,
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1159 (leader + lead_len) - p);
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1160 lead_len -= l - 1;
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1161 }
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1162 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1163 *p = ' ';
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1164 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1165 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1166 *p = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1167 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1168
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1169 /* Recompute the indent, it may have changed. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1170 if (curbuf->b_p_ai
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1171 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1172 || do_si
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1173 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1174 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1175 newindent = get_indent_str(leader, (int)curbuf->b_p_ts);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1176
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1177 /* Add the indent offset */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1178 if (newindent + off < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1179 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1180 off = -newindent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1181 newindent = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1182 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1183 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1184 newindent += off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1185
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1186 /* Correct trailing spaces for the shift, so that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1187 * alignment remains equal. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1188 while (off > 0 && lead_len > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1189 && leader[lead_len - 1] == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1190 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1191 /* Don't do it when there is a tab before the space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1192 if (vim_strchr(skipwhite(leader), '\t') != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1193 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1194 --lead_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1195 --off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1196 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1197
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1198 /* If the leader ends in white space, don't add an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1199 * extra space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1200 if (lead_len > 0 && vim_iswhite(leader[lead_len - 1]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1201 extra_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1202 leader[lead_len] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1203 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1204
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1205 if (extra_space)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1206 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1207 leader[lead_len++] = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1208 leader[lead_len] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1209 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1210
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1211 newcol = lead_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1212
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1213 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1214 * if a new indent will be set below, remove the indent that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1215 * is in the comment leader
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1216 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1217 if (newindent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1218 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1219 || did_si
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1220 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1221 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1222 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1223 while (lead_len && vim_iswhite(*leader))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1224 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1225 --lead_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1226 --newcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1227 ++leader;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1228 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1229 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1230
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1231 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1232 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1233 did_si = can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1234 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1235 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1236 else if (comment_end != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1237 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1238 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1239 * We have finished a comment, so we don't use the leader.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1240 * If this was a C-comment and 'ai' or 'si' is set do a normal
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1241 * indent to align with the line containing the start of the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1242 * comment.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1243 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1244 if (comment_end[0] == '*' && comment_end[1] == '/' &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1245 (curbuf->b_p_ai
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1246 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1247 || do_si
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1248 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1249 ))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1250 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1251 old_cursor = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1252 curwin->w_cursor.col = (colnr_T)(comment_end - saved_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1253 if ((pos = findmatch(NULL, NUL)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1254 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1255 curwin->w_cursor.lnum = pos->lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1256 newindent = get_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1257 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1258 curwin->w_cursor = old_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1259 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1260 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1261 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1262 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1263
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1264 /* (State == INSERT || State == REPLACE), only when dir == FORWARD */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1265 if (p_extra != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1266 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1267 *p_extra = saved_char; /* restore char that NUL replaced */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1268
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1269 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1270 * When 'ai' set or "flags" has OPENLINE_DELSPACES, skip to the first
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1271 * non-blank.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1272 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1273 * When in REPLACE mode, put the deleted blanks on the replace stack,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1274 * preceded by a NUL, so they can be put back when a BS is entered.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1275 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1276 if (REPLACE_NORMAL(State))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1277 replace_push(NUL); /* end of extra blanks */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1278 if (curbuf->b_p_ai || (flags & OPENLINE_DELSPACES))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1279 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1280 while ((*p_extra == ' ' || *p_extra == '\t')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1281 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1282 && (!enc_utf8
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1283 || !utf_iscomposing(utf_ptr2char(p_extra + 1)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1284 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1285 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1286 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1287 if (REPLACE_NORMAL(State))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1288 replace_push(*p_extra);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1289 ++p_extra;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1290 ++less_cols_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1291 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1292 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1293 if (*p_extra != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1294 did_ai = FALSE; /* append some text, don't truncate now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1295
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1296 /* columns for marks adjusted for removed columns */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1297 less_cols = (int)(p_extra - saved_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1298 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1299
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1300 if (p_extra == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1301 p_extra = (char_u *)""; /* append empty line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1302
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1303 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1304 /* concatenate leader and p_extra, if there is a leader */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1305 if (lead_len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1306 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1307 STRCAT(leader, p_extra);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1308 p_extra = leader;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1309 did_ai = TRUE; /* So truncating blanks works with comments */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1310 less_cols -= lead_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1311 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1312 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1313 end_comment_pending = NUL; /* turns out there was no leader */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1314 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1315
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1316 old_cursor = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1317 if (dir == BACKWARD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1318 --curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1319 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1320 if (!(State & VREPLACE_FLAG) || old_cursor.lnum >= orig_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1321 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1322 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1323 if (ml_append(curwin->w_cursor.lnum, p_extra, (colnr_T)0, FALSE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1324 == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1325 goto theend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1326 /* Postpone calling changed_lines(), because it would mess up folding
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1327 * with markers. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1328 mark_adjust(curwin->w_cursor.lnum + 1, (linenr_T)MAXLNUM, 1L, 0L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1329 did_append = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1330 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1331 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1332 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1333 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1334 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1335 * In VREPLACE mode we are starting to replace the next line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1336 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1337 curwin->w_cursor.lnum++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1338 if (curwin->w_cursor.lnum >= Insstart.lnum + vr_lines_changed)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1339 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1340 /* In case we NL to a new line, BS to the previous one, and NL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1341 * again, we don't want to save the new line for undo twice.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1342 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1343 (void)u_save_cursor(); /* errors are ignored! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1344 vr_lines_changed++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1345 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1346 ml_replace(curwin->w_cursor.lnum, p_extra, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1347 changed_bytes(curwin->w_cursor.lnum, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1348 curwin->w_cursor.lnum--;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1349 did_append = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1350 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1351 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1352
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1353 if (newindent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1354 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1355 || did_si
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1356 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1357 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1358 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1359 ++curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1360 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1361 if (did_si)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1362 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1363 if (p_sr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1364 newindent -= newindent % (int)curbuf->b_p_sw;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1365 newindent += (int)curbuf->b_p_sw;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1366 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1367 #endif
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
1368 /* Copy the indent */
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
1369 if (curbuf->b_p_ci)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1370 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1371 (void)copy_indent(newindent, saved_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1372
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1373 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1374 * Set the 'preserveindent' option so that any further screwing
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1375 * with the line doesn't entirely destroy our efforts to preserve
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1376 * it. It gets restored at the function end.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1377 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1378 curbuf->b_p_pi = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1379 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1380 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1381 (void)set_indent(newindent, SIN_INSERT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1382 less_cols -= curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1383
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1384 ai_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1385
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1386 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1387 * In REPLACE mode, for each character in the new indent, there must
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1388 * be a NUL on the replace stack, for when it is deleted with BS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1389 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1390 if (REPLACE_NORMAL(State))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1391 for (n = 0; n < (int)curwin->w_cursor.col; ++n)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1392 replace_push(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1393 newcol += curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1394 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1395 if (no_si)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1396 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1397 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1398 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1399
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1400 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1401 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1402 * In REPLACE mode, for each character in the extra leader, there must be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1403 * a NUL on the replace stack, for when it is deleted with BS.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1404 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1405 if (REPLACE_NORMAL(State))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1406 while (lead_len-- > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1407 replace_push(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1408 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1409
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1410 curwin->w_cursor = old_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1411
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1412 if (dir == FORWARD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1413 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1414 if (trunc_line || (State & INSERT))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1415 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1416 /* truncate current line at cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1417 saved_line[curwin->w_cursor.col] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1418 /* Remove trailing white space, unless OPENLINE_KEEPTRAIL used. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1419 if (trunc_line && !(flags & OPENLINE_KEEPTRAIL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1420 truncate_spaces(saved_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1421 ml_replace(curwin->w_cursor.lnum, saved_line, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1422 saved_line = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1423 if (did_append)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1424 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1425 changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1426 curwin->w_cursor.lnum + 1, 1L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1427 did_append = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1428
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1429 /* Move marks after the line break to the new line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1430 if (flags & OPENLINE_MARKFIX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1431 mark_col_adjust(curwin->w_cursor.lnum,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1432 curwin->w_cursor.col + less_cols_off,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1433 1L, (long)-less_cols);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1434 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1435 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1436 changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1437 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1438
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1439 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1440 * Put the cursor on the new line. Careful: the scrollup() above may
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1441 * have moved w_cursor, we must use old_cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1442 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1443 curwin->w_cursor.lnum = old_cursor.lnum + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1444 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1445 if (did_append)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1446 changed_lines(curwin->w_cursor.lnum, 0, curwin->w_cursor.lnum, 1L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1447
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1448 curwin->w_cursor.col = newcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1449 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1450 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1451 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1452
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1453 #if defined(FEAT_VREPLACE) && (defined(FEAT_LISP) || defined(FEAT_CINDENT))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1454 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1455 * In VREPLACE mode, we are handling the replace stack ourselves, so stop
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1456 * fixthisline() from doing it (via change_indent()) by telling it we're in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1457 * normal INSERT mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1458 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1459 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1460 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1461 vreplace_mode = State; /* So we know to put things right later */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1462 State = INSERT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1463 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1464 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1465 vreplace_mode = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1466 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1467 #ifdef FEAT_LISP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1468 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1469 * May do lisp indenting.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1470 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1471 if (!p_paste
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1472 # ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1473 && leader == NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1474 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1475 && curbuf->b_p_lisp
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1476 && curbuf->b_p_ai)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1477 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1478 fixthisline(get_lisp_indent);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1479 p = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1480 ai_col = (colnr_T)(skipwhite(p) - p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1481 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1482 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1483 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1484 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1485 * May do indenting after opening a new line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1486 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1487 if (!p_paste
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1488 && (curbuf->b_p_cin
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1489 # ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1490 || *curbuf->b_p_inde != NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1491 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1492 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1493 && in_cinkeys(dir == FORWARD
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1494 ? KEY_OPEN_FORW
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1495 : KEY_OPEN_BACK, ' ', linewhite(curwin->w_cursor.lnum)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1496 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1497 do_c_expr_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1498 p = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1499 ai_col = (colnr_T)(skipwhite(p) - p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1500 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1501 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1502 #if defined(FEAT_VREPLACE) && (defined(FEAT_LISP) || defined(FEAT_CINDENT))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1503 if (vreplace_mode != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1504 State = vreplace_mode;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1505 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1506
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1507 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1508 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1509 * Finally, VREPLACE gets the stuff on the new line, then puts back the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1510 * original line, and inserts the new stuff char by char, pushing old stuff
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1511 * onto the replace stack (via ins_char()).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1512 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1513 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1514 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1515 /* Put new line in p_extra */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1516 p_extra = vim_strsave(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1517 if (p_extra == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1518 goto theend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1519
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1520 /* Put back original line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1521 ml_replace(curwin->w_cursor.lnum, next_line, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1522
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1523 /* Insert new stuff into line again */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1524 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1525 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1526 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1527 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1528 ins_bytes(p_extra); /* will call changed_bytes() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1529 vim_free(p_extra);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1530 next_line = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1531 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1532 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1533
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1534 retval = TRUE; /* success! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1535 theend:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1536 curbuf->b_p_pi = saved_pi;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1537 vim_free(saved_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1538 vim_free(next_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1539 vim_free(allocated);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1540 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1541 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1542
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1543 #if defined(FEAT_COMMENTS) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1544 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1545 * get_leader_len() returns the length of the prefix of the given string
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1546 * which introduces a comment. If this string is not a comment then 0 is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1547 * returned.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1548 * When "flags" is not NULL, it is set to point to the flags of the recognized
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1549 * comment leader.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1550 * "backward" must be true for the "O" command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1551 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1552 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1553 get_leader_len(line, flags, backward)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1554 char_u *line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1555 char_u **flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1556 int backward;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1557 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1558 int i, j;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1559 int got_com = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1560 int found_one;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1561 char_u part_buf[COM_MAX_LEN]; /* buffer for one option part */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1562 char_u *string; /* pointer to comment string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1563 char_u *list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1564
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1565 i = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1566 while (vim_iswhite(line[i])) /* leading white space is ignored */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1567 ++i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1568
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1569 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1570 * Repeat to match several nested comment strings.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1571 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1572 while (line[i])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1573 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1574 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1575 * scan through the 'comments' option for a match
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1576 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1577 found_one = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1578 for (list = curbuf->b_p_com; *list; )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1579 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1580 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1581 * Get one option part into part_buf[]. Advance list to next one.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1582 * put string at start of string.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1583 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1584 if (!got_com && flags != NULL) /* remember where flags started */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1585 *flags = list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1586 (void)copy_option_part(&list, part_buf, COM_MAX_LEN, ",");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1587 string = vim_strchr(part_buf, ':');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1588 if (string == NULL) /* missing ':', ignore this part */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1589 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1590 *string++ = NUL; /* isolate flags from string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1591
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1592 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1593 * When already found a nested comment, only accept further
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1594 * nested comments.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1595 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1596 if (got_com && vim_strchr(part_buf, COM_NEST) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1597 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1598
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1599 /* When 'O' flag used don't use for "O" command */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1600 if (backward && vim_strchr(part_buf, COM_NOBACK) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1601 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1602
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1603 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1604 * Line contents and string must match.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1605 * When string starts with white space, must have some white space
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1606 * (but the amount does not need to match, there might be a mix of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1607 * TABs and spaces).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1608 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1609 if (vim_iswhite(string[0]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1610 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1611 if (i == 0 || !vim_iswhite(line[i - 1]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1612 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1613 while (vim_iswhite(string[0]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1614 ++string;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1615 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1616 for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1617 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1618 if (string[j] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1619 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1620
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1621 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1622 * When 'b' flag used, there must be white space or an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1623 * end-of-line after the string in the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1624 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1625 if (vim_strchr(part_buf, COM_BLANK) != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1626 && !vim_iswhite(line[i + j]) && line[i + j] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1627 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1628
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1629 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1630 * We have found a match, stop searching.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1631 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1632 i += j;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1633 got_com = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1634 found_one = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1635 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1636 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1637
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1638 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1639 * No match found, stop scanning.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1640 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1641 if (!found_one)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1642 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1643
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1644 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1645 * Include any trailing white space.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1646 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1647 while (vim_iswhite(line[i]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1648 ++i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1649
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1650 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1651 * If this comment doesn't nest, stop here.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1652 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1653 if (vim_strchr(part_buf, COM_NEST) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1654 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1655 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1656 return (got_com ? i : 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1657 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1658 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1659
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1660 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1661 * Return the number of window lines occupied by buffer line "lnum".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1662 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1663 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1664 plines(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1665 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1666 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1667 return plines_win(curwin, lnum, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1668 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1669
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1670 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1671 plines_win(wp, lnum, winheight)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1672 win_T *wp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1673 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1674 int winheight; /* when TRUE limit to window height */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1675 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1676 #if defined(FEAT_DIFF) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1677 /* Check for filler lines above this buffer line. When folded the result
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1678 * is one line anyway. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1679 return plines_win_nofill(wp, lnum, winheight) + diff_check_fill(wp, lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1680 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1681
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1682 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1683 plines_nofill(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1684 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1685 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1686 return plines_win_nofill(curwin, lnum, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1687 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1688
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1689 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1690 plines_win_nofill(wp, lnum, winheight)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1691 win_T *wp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1692 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1693 int winheight; /* when TRUE limit to window height */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1694 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1695 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1696 int lines;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1697
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1698 if (!wp->w_p_wrap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1699 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1700
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1701 #ifdef FEAT_VERTSPLIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1702 if (wp->w_width == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1703 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1704 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1705
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1706 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1707 /* A folded lines is handled just like an empty line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1708 /* NOTE: Caller must handle lines that are MAYBE folded. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1709 if (lineFolded(wp, lnum) == TRUE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1710 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1711 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1712
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1713 lines = plines_win_nofold(wp, lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1714 if (winheight > 0 && lines > wp->w_height)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1715 return (int)wp->w_height;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1716 return lines;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1717 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1718
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1719 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1720 * Return number of window lines physical line "lnum" will occupy in window
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1721 * "wp". Does not care about folding, 'wrap' or 'diff'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1722 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1723 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1724 plines_win_nofold(wp, lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1725 win_T *wp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1726 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1727 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1728 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1729 long col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1730 int width;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1731
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1732 s = ml_get_buf(wp->w_buffer, lnum, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1733 if (*s == NUL) /* empty line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1734 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1735 col = win_linetabsize(wp, s, (colnr_T)MAXCOL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1736
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1737 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1738 * If list mode is on, then the '$' at the end of the line may take up one
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1739 * extra column.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1740 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1741 if (wp->w_p_list && lcs_eol != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1742 col += 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1743
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1744 /*
2178
c6f1aa1e9f32 Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents: 2162
diff changeset
1745 * Add column offset for 'number', 'relativenumber' and 'foldcolumn'.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1746 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1747 width = W_WIDTH(wp) - win_col_off(wp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1748 if (width <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1749 return 32000;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1750 if (col <= width)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1751 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1752 col -= width;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1753 width += win_col_off2(wp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1754 return (col + (width - 1)) / width + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1755 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1756
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1757 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1758 * Like plines_win(), but only reports the number of physical screen lines
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1759 * used from the start of the line to the given column number.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1760 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1761 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1762 plines_win_col(wp, lnum, column)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1763 win_T *wp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1764 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1765 long column;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1766 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1767 long col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1768 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1769 int lines = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1770 int width;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1771
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1772 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1773 /* Check for filler lines above this buffer line. When folded the result
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1774 * is one line anyway. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1775 lines = diff_check_fill(wp, lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1776 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1777
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1778 if (!wp->w_p_wrap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1779 return lines + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1780
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1781 #ifdef FEAT_VERTSPLIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1782 if (wp->w_width == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1783 return lines + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1784 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1785
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1786 s = ml_get_buf(wp->w_buffer, lnum, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1787
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1788 col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1789 while (*s != NUL && --column >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1790 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1791 col += win_lbr_chartabsize(wp, s, (colnr_T)col, NULL);
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
1792 mb_ptr_adv(s);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1793 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1794
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1795 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1796 * If *s is a TAB, and the TAB is not displayed as ^I, and we're not in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1797 * INSERT mode, then col must be adjusted so that it represents the last
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1798 * screen position of the TAB. This only fixes an error when the TAB wraps
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1799 * from one screen line to the next (when 'columns' is not a multiple of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1800 * 'ts') -- webb.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1801 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1802 if (*s == TAB && (State & NORMAL) && (!wp->w_p_list || lcs_tab1))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1803 col += win_lbr_chartabsize(wp, s, (colnr_T)col, NULL) - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1804
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1805 /*
2178
c6f1aa1e9f32 Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents: 2162
diff changeset
1806 * Add column offset for 'number', 'relativenumber', 'foldcolumn', etc.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1807 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1808 width = W_WIDTH(wp) - win_col_off(wp);
1023
cb7043482eca updated for version 7.0-149
vimboss
parents: 1010
diff changeset
1809 if (width <= 0)
cb7043482eca updated for version 7.0-149
vimboss
parents: 1010
diff changeset
1810 return 9999;
cb7043482eca updated for version 7.0-149
vimboss
parents: 1010
diff changeset
1811
cb7043482eca updated for version 7.0-149
vimboss
parents: 1010
diff changeset
1812 lines += 1;
cb7043482eca updated for version 7.0-149
vimboss
parents: 1010
diff changeset
1813 if (col > width)
cb7043482eca updated for version 7.0-149
vimboss
parents: 1010
diff changeset
1814 lines += (col - width) / (width + win_col_off2(wp)) + 1;
cb7043482eca updated for version 7.0-149
vimboss
parents: 1010
diff changeset
1815 return lines;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1816 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1817
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1818 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1819 plines_m_win(wp, first, last)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1820 win_T *wp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1821 linenr_T first, last;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1822 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1823 int count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1824
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1825 while (first <= last)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1826 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1827 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1828 int x;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1829
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1830 /* Check if there are any really folded lines, but also included lines
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1831 * that are maybe folded. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1832 x = foldedCount(wp, first, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1833 if (x > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1834 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1835 ++count; /* count 1 for "+-- folded" line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1836 first += x;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1837 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1838 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1839 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1840 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1841 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1842 if (first == wp->w_topline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1843 count += plines_win_nofill(wp, first, TRUE) + wp->w_topfill;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1844 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1845 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1846 count += plines_win(wp, first, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1847 ++first;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1848 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1849 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1850 return (count);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1851 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1852
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1853 #if defined(FEAT_VREPLACE) || defined(FEAT_INS_EXPAND) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1854 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1855 * Insert string "p" at the cursor position. Stops at a NUL byte.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1856 * Handles Replace mode and multi-byte characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1857 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1858 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1859 ins_bytes(p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1860 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1861 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1862 ins_bytes_len(p, (int)STRLEN(p));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1863 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1864 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1865
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1866 #if defined(FEAT_VREPLACE) || defined(FEAT_INS_EXPAND) \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1867 || defined(FEAT_COMMENTS) || defined(FEAT_MBYTE) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1868 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1869 * Insert string "p" with length "len" at the cursor position.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1870 * Handles Replace mode and multi-byte characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1871 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1872 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1873 ins_bytes_len(p, len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1874 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1875 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1876 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1877 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1878 # ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1879 int n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1880
1617
5f0c7aae4da2 updated for version 7.1-330
vimboss
parents: 1550
diff changeset
1881 if (has_mbyte)
5f0c7aae4da2 updated for version 7.1-330
vimboss
parents: 1550
diff changeset
1882 for (i = 0; i < len; i += n)
5f0c7aae4da2 updated for version 7.1-330
vimboss
parents: 1550
diff changeset
1883 {
5f0c7aae4da2 updated for version 7.1-330
vimboss
parents: 1550
diff changeset
1884 if (enc_utf8)
5f0c7aae4da2 updated for version 7.1-330
vimboss
parents: 1550
diff changeset
1885 /* avoid reading past p[len] */
5f0c7aae4da2 updated for version 7.1-330
vimboss
parents: 1550
diff changeset
1886 n = utfc_ptr2len_len(p + i, len - i);
5f0c7aae4da2 updated for version 7.1-330
vimboss
parents: 1550
diff changeset
1887 else
5f0c7aae4da2 updated for version 7.1-330
vimboss
parents: 1550
diff changeset
1888 n = (*mb_ptr2len)(p + i);
5f0c7aae4da2 updated for version 7.1-330
vimboss
parents: 1550
diff changeset
1889 ins_char_bytes(p + i, n);
5f0c7aae4da2 updated for version 7.1-330
vimboss
parents: 1550
diff changeset
1890 }
5f0c7aae4da2 updated for version 7.1-330
vimboss
parents: 1550
diff changeset
1891 else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1892 # endif
1617
5f0c7aae4da2 updated for version 7.1-330
vimboss
parents: 1550
diff changeset
1893 for (i = 0; i < len; ++i)
5f0c7aae4da2 updated for version 7.1-330
vimboss
parents: 1550
diff changeset
1894 ins_char(p[i]);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1895 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1896 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1897
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1898 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1899 * Insert or replace a single character at the cursor position.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1900 * When in REPLACE or VREPLACE mode, replace any existing character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1901 * Caller must have prepared for undo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1902 * For multi-byte characters we get the whole character, the caller must
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1903 * convert bytes to a character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1904 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1905 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1906 ins_char(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1907 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1908 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1909 #if defined(FEAT_MBYTE) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1910 char_u buf[MB_MAXBYTES];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1911 int n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1912
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1913 n = (*mb_char2bytes)(c, buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1914
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1915 /* When "c" is 0x100, 0x200, etc. we don't want to insert a NUL byte.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1916 * Happens for CTRL-Vu9900. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1917 if (buf[0] == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1918 buf[0] = '\n';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1919
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1920 ins_char_bytes(buf, n);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1921 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1922
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1923 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1924 ins_char_bytes(buf, charlen)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1925 char_u *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1926 int charlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1927 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1928 int c = buf[0];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1929 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1930 int newlen; /* nr of bytes inserted */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1931 int oldlen; /* nr of bytes deleted (0 when not replacing) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1932 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1933 char_u *newp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1934 char_u *oldp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1935 int linelen; /* length of old line including NUL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1936 colnr_T col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1937 linenr_T lnum = curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1938 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1939
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1940 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1941 /* Break tabs if needed. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1942 if (virtual_active() && curwin->w_cursor.coladd > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1943 coladvance_force(getviscol());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1944 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1945
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1946 col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1947 oldp = ml_get(lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1948 linelen = (int)STRLEN(oldp) + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1949
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1950 /* The lengths default to the values for when not replacing. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1951 oldlen = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1952 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1953 newlen = charlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1954 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1955 newlen = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1956 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1957
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1958 if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1959 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1960 #ifdef FEAT_VREPLACE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1961 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1962 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1963 colnr_T new_vcol = 0; /* init for GCC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1964 colnr_T vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1965 int old_list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1966 #ifndef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1967 char_u buf[2];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1968 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1969
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1970 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1971 * Disable 'list' temporarily, unless 'cpo' contains the 'L' flag.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1972 * Returns the old value of list, so when finished,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1973 * curwin->w_p_list should be set back to this.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1974 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1975 old_list = curwin->w_p_list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1976 if (old_list && vim_strchr(p_cpo, CPO_LISTWM) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1977 curwin->w_p_list = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1978
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1979 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1980 * In virtual replace mode each character may replace one or more
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1981 * characters (zero if it's a TAB). Count the number of bytes to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1982 * be deleted to make room for the new character, counting screen
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1983 * cells. May result in adding spaces to fill a gap.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1984 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1985 getvcol(curwin, &curwin->w_cursor, NULL, &vcol, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1986 #ifndef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1987 buf[0] = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1988 buf[1] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1989 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1990 new_vcol = vcol + chartabsize(buf, vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1991 while (oldp[col + oldlen] != NUL && vcol < new_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1992 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1993 vcol += chartabsize(oldp + col + oldlen, vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1994 /* Don't need to remove a TAB that takes us to the right
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1995 * position. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1996 if (vcol > new_vcol && oldp[col + oldlen] == TAB)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1997 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1998 #ifdef FEAT_MBYTE
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 445
diff changeset
1999 oldlen += (*mb_ptr2len)(oldp + col + oldlen);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2000 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2001 ++oldlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2002 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2003 /* Deleted a bit too much, insert spaces. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2004 if (vcol > new_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2005 newlen += vcol - new_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2006 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2007 curwin->w_p_list = old_list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2008 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2009 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2010 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2011 if (oldp[col] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2012 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2013 /* normal replace */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2014 #ifdef FEAT_MBYTE
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 445
diff changeset
2015 oldlen = (*mb_ptr2len)(oldp + col);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2016 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2017 oldlen = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2018 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2019 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2020
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2021
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2022 /* Push the replaced bytes onto the replace stack, so that they can be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2023 * put back when BS is used. The bytes of a multi-byte character are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2024 * done the other way around, so that the first byte is popped off
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2025 * first (it tells the byte length of the character). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2026 replace_push(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2027 for (i = 0; i < oldlen; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2028 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2029 #ifdef FEAT_MBYTE
1470
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1408
diff changeset
2030 if (has_mbyte)
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1408
diff changeset
2031 i += replace_push_mb(oldp + col + i) - 1;
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1408
diff changeset
2032 else
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1408
diff changeset
2033 #endif
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1408
diff changeset
2034 replace_push(oldp[col + i]);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2035 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2036 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2037
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2038 newp = alloc_check((unsigned)(linelen + newlen - oldlen));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2039 if (newp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2040 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2041
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2042 /* Copy bytes before the cursor. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2043 if (col > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2044 mch_memmove(newp, oldp, (size_t)col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2045
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2046 /* Copy bytes after the changed character(s). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2047 p = newp + col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2048 mch_memmove(p + newlen, oldp + col + oldlen,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2049 (size_t)(linelen - col - oldlen));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2050
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2051 /* Insert or overwrite the new character. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2052 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2053 mch_memmove(p, buf, charlen);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2054 i = charlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2055 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2056 *p = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2057 i = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2058 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2059
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2060 /* Fill with spaces when necessary. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2061 while (i < newlen)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2062 p[i++] = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2063
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2064 /* Replace the line in the buffer. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2065 ml_replace(lnum, newp, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2066
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2067 /* mark the buffer as changed and prepare for displaying */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2068 changed_bytes(lnum, col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2069
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2070 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2071 * If we're in Insert or Replace mode and 'showmatch' is set, then briefly
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2072 * show the match for right parens and braces.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2073 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2074 if (p_sm && (State & INSERT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2075 && msg_silent == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2076 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2077 && charlen == 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2078 #endif
674
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 673
diff changeset
2079 #ifdef FEAT_INS_EXPAND
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 673
diff changeset
2080 && !ins_compl_active()
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 673
diff changeset
2081 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2082 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2083 showmatch(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2084
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2085 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2086 if (!p_ri || (State & REPLACE_FLAG))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2087 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2088 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2089 /* Normal insert: move cursor right */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2090 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2091 curwin->w_cursor.col += charlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2092 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2093 ++curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2094 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2095 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2096 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2097 * TODO: should try to update w_row here, to avoid recomputing it later.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2098 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2099 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2100
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2101 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2102 * Insert a string at the cursor position.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2103 * Note: Does NOT handle Replace mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2104 * Caller must have prepared for undo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2105 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2106 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2107 ins_str(s)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2108 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2109 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2110 char_u *oldp, *newp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2111 int newlen = (int)STRLEN(s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2112 int oldlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2113 colnr_T col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2114 linenr_T lnum = curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2115
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2116 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2117 if (virtual_active() && curwin->w_cursor.coladd > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2118 coladvance_force(getviscol());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2119 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2120
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2121 col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2122 oldp = ml_get(lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2123 oldlen = (int)STRLEN(oldp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2124
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2125 newp = alloc_check((unsigned)(oldlen + newlen + 1));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2126 if (newp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2127 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2128 if (col > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2129 mch_memmove(newp, oldp, (size_t)col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2130 mch_memmove(newp + col, s, (size_t)newlen);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2131 mch_memmove(newp + col + newlen, oldp + col, (size_t)(oldlen - col + 1));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2132 ml_replace(lnum, newp, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2133 changed_bytes(lnum, col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2134 curwin->w_cursor.col += newlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2135 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2136
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2137 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2138 * Delete one character under the cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2139 * If "fixpos" is TRUE, don't leave the cursor on the NUL after the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2140 * Caller must have prepared for undo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2141 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2142 * return FAIL for failure, OK otherwise
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2143 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2144 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2145 del_char(fixpos)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2146 int fixpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2147 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2148 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2149 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2150 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2151 /* Make sure the cursor is at the start of a character. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2152 mb_adjust_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2153 if (*ml_get_cursor() == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2154 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2155 return del_chars(1L, fixpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2156 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2157 #endif
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 594
diff changeset
2158 return del_bytes(1L, fixpos, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2159 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2160
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2161 #if defined(FEAT_MBYTE) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2162 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2163 * Like del_bytes(), but delete characters instead of bytes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2164 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2165 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2166 del_chars(count, fixpos)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2167 long count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2168 int fixpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2169 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2170 long bytes = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2171 long i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2172 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2173 int l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2174
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2175 p = ml_get_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2176 for (i = 0; i < count && *p != NUL; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2177 {
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 445
diff changeset
2178 l = (*mb_ptr2len)(p);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2179 bytes += l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2180 p += l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2181 }
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 594
diff changeset
2182 return del_bytes(bytes, fixpos, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2183 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2184 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2185
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2186 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2187 * Delete "count" bytes under the cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2188 * If "fixpos" is TRUE, don't leave the cursor on the NUL after the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2189 * Caller must have prepared for undo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2190 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2191 * return FAIL for failure, OK otherwise
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2192 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2193 int
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 768
diff changeset
2194 del_bytes(count, fixpos_arg, use_delcombine)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2195 long count;
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 768
diff changeset
2196 int fixpos_arg;
1877
b5c1cb6f8d56 updated for version 7.2-174
vimboss
parents: 1863
diff changeset
2197 int use_delcombine UNUSED; /* 'delcombine' option applies */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2198 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2199 char_u *oldp, *newp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2200 colnr_T oldlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2201 linenr_T lnum = curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2202 colnr_T col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2203 int was_alloced;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2204 long movelen;
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 768
diff changeset
2205 int fixpos = fixpos_arg;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2206
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2207 oldp = ml_get(lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2208 oldlen = (int)STRLEN(oldp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2209
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2210 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2211 * Can't do anything when the cursor is on the NUL after the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2212 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2213 if (col >= oldlen)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2214 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2215
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2216 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2217 /* If 'delcombine' is set and deleting (less than) one character, only
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2218 * delete the last combining character. */
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 594
diff changeset
2219 if (p_deco && use_delcombine && enc_utf8
cd3689efd90a updated for version 7.0173
vimboss
parents: 594
diff changeset
2220 && utfc_ptr2len(oldp + col) >= count)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2221 {
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 694
diff changeset
2222 int cc[MAX_MCO];
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2223 int n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2224
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 694
diff changeset
2225 (void)utfc_ptr2char(oldp + col, cc);
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 694
diff changeset
2226 if (cc[0] != NUL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2227 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2228 /* Find the last composing char, there can be several. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2229 n = col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2230 do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2231 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2232 col = n;
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 445
diff changeset
2233 count = utf_ptr2len(oldp + n);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2234 n += count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2235 } while (UTF_COMPOSINGLIKE(oldp + col, oldp + n));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2236 fixpos = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2237 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2238 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2239 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2240
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2241 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2242 * When count is too big, reduce it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2243 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2244 movelen = (long)oldlen - (long)col - count + 1; /* includes trailing NUL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2245 if (movelen <= 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2246 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2247 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2248 * If we just took off the last character of a non-blank line, and
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 768
diff changeset
2249 * fixpos is TRUE, we don't want to end up positioned at the NUL,
f664cc974a7a updated for version 7.0227
vimboss
parents: 768
diff changeset
2250 * unless "restart_edit" is set or 'virtualedit' contains "onemore".
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2251 */
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 768
diff changeset
2252 if (col > 0 && fixpos && restart_edit == 0
f664cc974a7a updated for version 7.0227
vimboss
parents: 768
diff changeset
2253 #ifdef FEAT_VIRTUALEDIT
f664cc974a7a updated for version 7.0227
vimboss
parents: 768
diff changeset
2254 && (ve_flags & VE_ONEMORE) == 0
f664cc974a7a updated for version 7.0227
vimboss
parents: 768
diff changeset
2255 #endif
f664cc974a7a updated for version 7.0227
vimboss
parents: 768
diff changeset
2256 )
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2257 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2258 --curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2259 #ifdef FEAT_VIRTUALEDIT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2260 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2261 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2262 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2263 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2264 curwin->w_cursor.col -=
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2265 (*mb_head_off)(oldp, oldp + curwin->w_cursor.col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2266 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2267 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2268 count = oldlen - col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2269 movelen = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2270 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2271
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2272 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2273 * If the old line has been allocated the deletion can be done in the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2274 * existing line. Otherwise a new line has to be allocated
1532
87b9f21264a7 updated for version 7.1-247
vimboss
parents: 1521
diff changeset
2275 * Can't do this when using Netbeans, because we would need to invoke
87b9f21264a7 updated for version 7.1-247
vimboss
parents: 1521
diff changeset
2276 * netbeans_removed(), which deallocates the line. Let ml_replace() take
87b9f21264a7 updated for version 7.1-247
vimboss
parents: 1521
diff changeset
2277 * care of notifiying Netbeans.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2278 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2279 #ifdef FEAT_NETBEANS_INTG
2210
8c6a66e2b3cc Add :nbstart and :nbclose.
Bram Moolenaar <bram@vim.org>
parents: 2178
diff changeset
2280 if (netbeans_active())
1532
87b9f21264a7 updated for version 7.1-247
vimboss
parents: 1521
diff changeset
2281 was_alloced = FALSE;
87b9f21264a7 updated for version 7.1-247
vimboss
parents: 1521
diff changeset
2282 else
87b9f21264a7 updated for version 7.1-247
vimboss
parents: 1521
diff changeset
2283 #endif
87b9f21264a7 updated for version 7.1-247
vimboss
parents: 1521
diff changeset
2284 was_alloced = ml_line_alloced(); /* check if oldp was allocated */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2285 if (was_alloced)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2286 newp = oldp; /* use same allocated memory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2287 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2288 { /* need to allocate a new line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2289 newp = alloc((unsigned)(oldlen + 1 - count));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2290 if (newp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2291 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2292 mch_memmove(newp, oldp, (size_t)col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2293 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2294 mch_memmove(newp + col, oldp + col + count, (size_t)movelen);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2295 if (!was_alloced)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2296 ml_replace(lnum, newp, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2297
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2298 /* mark the buffer as changed and prepare for displaying */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2299 changed_bytes(lnum, curwin->w_cursor.col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2300
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2301 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2302 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2303
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2304 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2305 * Delete from cursor to end of line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2306 * Caller must have prepared for undo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2307 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2308 * return FAIL for failure, OK otherwise
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2309 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2310 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2311 truncate_line(fixpos)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2312 int fixpos; /* if TRUE fix the cursor position when done */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2313 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2314 char_u *newp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2315 linenr_T lnum = curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2316 colnr_T col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2317
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2318 if (col == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2319 newp = vim_strsave((char_u *)"");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2320 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2321 newp = vim_strnsave(ml_get(lnum), col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2322
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2323 if (newp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2324 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2325
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2326 ml_replace(lnum, newp, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2327
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2328 /* mark the buffer as changed and prepare for displaying */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2329 changed_bytes(lnum, curwin->w_cursor.col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2330
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2331 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2332 * If "fixpos" is TRUE we don't want to end up positioned at the NUL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2333 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2334 if (fixpos && curwin->w_cursor.col > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2335 --curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2336
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2337 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2338 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2339
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2340 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2341 * Delete "nlines" lines at the cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2342 * Saves the lines for undo first if "undo" is TRUE.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2343 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2344 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2345 del_lines(nlines, undo)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2346 long nlines; /* number of lines to delete */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2347 int undo; /* if TRUE, prepare for undo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2348 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2349 long n;
1929
9230c45fdde6 updated for version 7.2-226
vimboss
parents: 1914
diff changeset
2350 linenr_T first = curwin->w_cursor.lnum;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2351
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2352 if (nlines <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2353 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2354
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2355 /* save the deleted lines for undo */
1929
9230c45fdde6 updated for version 7.2-226
vimboss
parents: 1914
diff changeset
2356 if (undo && u_savedel(first, nlines) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2357 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2358
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2359 for (n = 0; n < nlines; )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2360 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2361 if (curbuf->b_ml.ml_flags & ML_EMPTY) /* nothing to delete */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2362 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2363
1929
9230c45fdde6 updated for version 7.2-226
vimboss
parents: 1914
diff changeset
2364 ml_delete(first, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2365 ++n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2366
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2367 /* If we delete the last line in the file, stop */
1929
9230c45fdde6 updated for version 7.2-226
vimboss
parents: 1914
diff changeset
2368 if (first > curbuf->b_ml.ml_line_count)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2369 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2370 }
1929
9230c45fdde6 updated for version 7.2-226
vimboss
parents: 1914
diff changeset
2371
9230c45fdde6 updated for version 7.2-226
vimboss
parents: 1914
diff changeset
2372 /* Correct the cursor position before calling deleted_lines_mark(), it may
9230c45fdde6 updated for version 7.2-226
vimboss
parents: 1914
diff changeset
2373 * trigger a callback to display the cursor. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2374 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2375 check_cursor_lnum();
1929
9230c45fdde6 updated for version 7.2-226
vimboss
parents: 1914
diff changeset
2376
9230c45fdde6 updated for version 7.2-226
vimboss
parents: 1914
diff changeset
2377 /* adjust marks, mark the buffer as changed and prepare for displaying */
9230c45fdde6 updated for version 7.2-226
vimboss
parents: 1914
diff changeset
2378 deleted_lines_mark(first, n);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2379 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2380
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2381 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2382 gchar_pos(pos)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2383 pos_T *pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2384 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2385 char_u *ptr = ml_get_pos(pos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2386
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2387 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2388 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2389 return (*mb_ptr2char)(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2390 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2391 return (int)*ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2392 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2393
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2394 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2395 gchar_cursor()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2396 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2397 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2398 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2399 return (*mb_ptr2char)(ml_get_cursor());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2400 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2401 return (int)*ml_get_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2402 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2403
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2404 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2405 * Write a character at the current cursor position.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2406 * It is directly written into the block.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2407 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2408 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2409 pchar_cursor(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2410 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2411 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2412 *(ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2413 + curwin->w_cursor.col) = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2414 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2415
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2416 #if 0 /* not used */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2417 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2418 * Put *pos at end of current buffer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2419 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2420 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2421 goto_endofbuf(pos)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2422 pos_T *pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2423 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2424 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2425
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2426 pos->lnum = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2427 pos->col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2428 p = ml_get(pos->lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2429 while (*p++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2430 ++pos->col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2431 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2432 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2433
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2434 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2435 * When extra == 0: Return TRUE if the cursor is before or on the first
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2436 * non-blank in the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2437 * When extra == 1: Return TRUE if the cursor is before the first non-blank in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2438 * the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2439 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2440 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2441 inindent(extra)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2442 int extra;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2443 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2444 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2445 colnr_T col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2446
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2447 for (col = 0, ptr = ml_get_curline(); vim_iswhite(*ptr); ++col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2448 ++ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2449 if (col >= curwin->w_cursor.col + extra)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2450 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2451 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2452 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2453 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2454
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2455 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2456 * Skip to next part of an option argument: Skip space and comma.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2457 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2458 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2459 skip_to_option_part(p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2460 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2461 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2462 if (*p == ',')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2463 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2464 while (*p == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2465 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2466 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2467 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2468
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2469 /*
2288
4dda2bd944e1 Apply patch 7.2.445.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
2470 * Call this function when something in the current buffer is changed.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2471 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2472 * Most often called through changed_bytes() and changed_lines(), which also
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2473 * mark the area of the display to be redrawn.
2288
4dda2bd944e1 Apply patch 7.2.445.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
2474 *
4dda2bd944e1 Apply patch 7.2.445.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
2475 * Careful: may trigger autocommands that reload the buffer.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2476 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2477 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2478 changed()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2479 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2480 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2481 /* The text of the preediting area is inserted, but this doesn't
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2482 * mean a change of the buffer yet. That is delayed until the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2483 * text is committed. (this means preedit becomes empty) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2484 if (im_is_preediting() && !xim_changed_while_preediting)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2485 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2486 xim_changed_while_preediting = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2487 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2488
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2489 if (!curbuf->b_changed)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2490 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2491 int save_msg_scroll = msg_scroll;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2492
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2493 /* Give a warning about changing a read-only file. This may also
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2494 * check-out the file, thus change "curbuf"! */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2495 change_warning(0);
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2496
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2497 /* Create a swap file if that is wanted.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2498 * Don't do this for "nofile" and "nowrite" buffer types. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2499 if (curbuf->b_may_swap
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2500 #ifdef FEAT_QUICKFIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2501 && !bt_dontwrite(curbuf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2502 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2503 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2504 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2505 ml_open_file(curbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2506
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2507 /* The ml_open_file() can cause an ATTENTION message.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2508 * Wait two seconds, to make sure the user reads this unexpected
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2509 * message. Since we could be anywhere, call wait_return() now,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2510 * and don't let the emsg() set msg_scroll. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2511 if (need_wait_return && emsg_silent == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2512 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2513 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2514 ui_delay(2000L, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2515 wait_return(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2516 msg_scroll = save_msg_scroll;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2517 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2518 }
2162
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2519 changed_int();
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2520 }
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2521 ++curbuf->b_changedtick;
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2522 }
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2523
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2524 /*
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2525 * Internal part of changed(), no user interaction.
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2526 */
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2527 void
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2528 changed_int()
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2529 {
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2530 curbuf->b_changed = TRUE;
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2531 ml_setflags(curbuf);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2532 #ifdef FEAT_WINDOWS
2162
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2533 check_status(curbuf);
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2534 redraw_tabline = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2535 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2536 #ifdef FEAT_TITLE
2162
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2537 need_maketitle = TRUE; /* set window title later */
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2538 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2539 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2540
265
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2541 static void changedOneline __ARGS((buf_T *buf, linenr_T lnum));
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2542 static void changed_lines_buf __ARGS((buf_T *buf, linenr_T lnum, linenr_T lnume, long xtra));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2543 static void changed_common __ARGS((linenr_T lnum, colnr_T col, linenr_T lnume, long xtra));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2544
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2545 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2546 * Changed bytes within a single line for the current buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2547 * - marks the windows on this buffer to be redisplayed
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2548 * - marks the buffer changed by calling changed()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2549 * - invalidates cached values
2288
4dda2bd944e1 Apply patch 7.2.445.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
2550 * Careful: may trigger autocommands that reload the buffer.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2551 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2552 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2553 changed_bytes(lnum, col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2554 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2555 colnr_T col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2556 {
265
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2557 changedOneline(curbuf, lnum);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2558 changed_common(lnum, col, lnum + 1, 0L);
265
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2559
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2560 #ifdef FEAT_DIFF
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2561 /* Diff highlighting in other diff windows may need to be updated too. */
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2562 if (curwin->w_p_diff)
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2563 {
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2564 win_T *wp;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2565 linenr_T wlnum;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2566
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2567 for (wp = firstwin; wp != NULL; wp = wp->w_next)
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2568 if (wp->w_p_diff && wp != curwin)
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2569 {
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2570 redraw_win_later(wp, VALID);
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2571 wlnum = diff_lnum_win(lnum, wp);
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2572 if (wlnum > 0)
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2573 changedOneline(wp->w_buffer, wlnum);
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2574 }
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2575 }
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2576 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2577 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2578
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2579 static void
265
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2580 changedOneline(buf, lnum)
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2581 buf_T *buf;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2582 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2583 {
265
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2584 if (buf->b_mod_set)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2585 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2586 /* find the maximum area that must be redisplayed */
265
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2587 if (lnum < buf->b_mod_top)
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2588 buf->b_mod_top = lnum;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2589 else if (lnum >= buf->b_mod_bot)
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2590 buf->b_mod_bot = lnum + 1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2591 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2592 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2593 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2594 /* set the area that must be redisplayed to one line */
265
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2595 buf->b_mod_set = TRUE;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2596 buf->b_mod_top = lnum;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2597 buf->b_mod_bot = lnum + 1;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2598 buf->b_mod_xlines = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2599 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2600 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2601
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2602 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2603 * Appended "count" lines below line "lnum" in the current buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2604 * Must be called AFTER the change and after mark_adjust().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2605 * Takes care of marking the buffer to be redrawn and sets the changed flag.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2606 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2607 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2608 appended_lines(lnum, count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2609 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2610 long count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2611 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2612 changed_lines(lnum + 1, 0, lnum + 1, count);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2613 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2614
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2615 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2616 * Like appended_lines(), but adjust marks first.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2617 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2618 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2619 appended_lines_mark(lnum, count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2620 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2621 long count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2622 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2623 mark_adjust(lnum + 1, (linenr_T)MAXLNUM, count, 0L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2624 changed_lines(lnum + 1, 0, lnum + 1, count);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2625 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2626
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2627 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2628 * Deleted "count" lines at line "lnum" in the current buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2629 * Must be called AFTER the change and after mark_adjust().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2630 * Takes care of marking the buffer to be redrawn and sets the changed flag.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2631 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2632 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2633 deleted_lines(lnum, count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2634 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2635 long count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2636 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2637 changed_lines(lnum, 0, lnum + count, -count);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2638 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2639
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2640 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2641 * Like deleted_lines(), but adjust marks first.
1929
9230c45fdde6 updated for version 7.2-226
vimboss
parents: 1914
diff changeset
2642 * Make sure the cursor is on a valid line before calling, a GUI callback may
9230c45fdde6 updated for version 7.2-226
vimboss
parents: 1914
diff changeset
2643 * be triggered to display the cursor.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2644 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2645 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2646 deleted_lines_mark(lnum, count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2647 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2648 long count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2649 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2650 mark_adjust(lnum, (linenr_T)(lnum + count - 1), (long)MAXLNUM, -count);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2651 changed_lines(lnum, 0, lnum + count, -count);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2652 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2653
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2654 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2655 * Changed lines for the current buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2656 * Must be called AFTER the change and after mark_adjust().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2657 * - mark the buffer changed by calling changed()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2658 * - mark the windows on this buffer to be redisplayed
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2659 * - invalidate cached values
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2660 * "lnum" is the first line that needs displaying, "lnume" the first line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2661 * below the changed lines (BEFORE the change).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2662 * When only inserting lines, "lnum" and "lnume" are equal.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2663 * Takes care of calling changed() and updating b_mod_*.
2288
4dda2bd944e1 Apply patch 7.2.445.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
2664 * Careful: may trigger autocommands that reload the buffer.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2665 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2666 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2667 changed_lines(lnum, col, lnume, xtra)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2668 linenr_T lnum; /* first line with change */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2669 colnr_T col; /* column in first line with change */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2670 linenr_T lnume; /* line below last changed line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2671 long xtra; /* number of extra lines (negative when deleting) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2672 {
265
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2673 changed_lines_buf(curbuf, lnum, lnume, xtra);
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2674
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2675 #ifdef FEAT_DIFF
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2676 if (xtra == 0 && curwin->w_p_diff)
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2677 {
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2678 /* When the number of lines doesn't change then mark_adjust() isn't
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2679 * called and other diff buffers still need to be marked for
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2680 * displaying. */
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2681 win_T *wp;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2682 linenr_T wlnum;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2683
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2684 for (wp = firstwin; wp != NULL; wp = wp->w_next)
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2685 if (wp->w_p_diff && wp != curwin)
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2686 {
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2687 redraw_win_later(wp, VALID);
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2688 wlnum = diff_lnum_win(lnum, wp);
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2689 if (wlnum > 0)
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2690 changed_lines_buf(wp->w_buffer, wlnum,
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2691 lnume - lnum + wlnum, 0L);
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2692 }
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2693 }
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2694 #endif
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2695
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2696 changed_common(lnum, col, lnume, xtra);
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2697 }
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2698
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2699 static void
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2700 changed_lines_buf(buf, lnum, lnume, xtra)
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2701 buf_T *buf;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2702 linenr_T lnum; /* first line with change */
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2703 linenr_T lnume; /* line below last changed line */
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2704 long xtra; /* number of extra lines (negative when deleting) */
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2705 {
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2706 if (buf->b_mod_set)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2707 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2708 /* find the maximum area that must be redisplayed */
265
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2709 if (lnum < buf->b_mod_top)
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2710 buf->b_mod_top = lnum;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2711 if (lnum < buf->b_mod_bot)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2712 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2713 /* adjust old bot position for xtra lines */
265
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2714 buf->b_mod_bot += xtra;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2715 if (buf->b_mod_bot < lnum)
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2716 buf->b_mod_bot = lnum;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2717 }
265
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2718 if (lnume + xtra > buf->b_mod_bot)
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2719 buf->b_mod_bot = lnume + xtra;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2720 buf->b_mod_xlines += xtra;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2721 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2722 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2723 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2724 /* set the area that must be redisplayed */
265
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2725 buf->b_mod_set = TRUE;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2726 buf->b_mod_top = lnum;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2727 buf->b_mod_bot = lnume + xtra;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2728 buf->b_mod_xlines = xtra;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2729 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2730 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2731
2288
4dda2bd944e1 Apply patch 7.2.445.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
2732 /*
4dda2bd944e1 Apply patch 7.2.445.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
2733 * Common code for when a change is was made.
4dda2bd944e1 Apply patch 7.2.445.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
2734 * See changed_lines() for the arguments.
4dda2bd944e1 Apply patch 7.2.445.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
2735 * Careful: may trigger autocommands that reload the buffer.
4dda2bd944e1 Apply patch 7.2.445.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
2736 */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2737 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2738 changed_common(lnum, col, lnume, xtra)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2739 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2740 colnr_T col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2741 linenr_T lnume;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2742 long xtra;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2743 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2744 win_T *wp;
1863
63369d73b551 updated for version 7.2-161
vimboss
parents: 1848
diff changeset
2745 #ifdef FEAT_WINDOWS
63369d73b551 updated for version 7.2-161
vimboss
parents: 1848
diff changeset
2746 tabpage_T *tp;
63369d73b551 updated for version 7.2-161
vimboss
parents: 1848
diff changeset
2747 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2748 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2749 #ifdef FEAT_JUMPLIST
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2750 int cols;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2751 pos_T *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2752 int add;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2753 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2754
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2755 /* mark the buffer as modified */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2756 changed();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2757
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2758 /* set the '. mark */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2759 if (!cmdmod.keepjumps)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2760 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2761 curbuf->b_last_change.lnum = lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2762 curbuf->b_last_change.col = col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2763
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2764 #ifdef FEAT_JUMPLIST
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2765 /* Create a new entry if a new undo-able change was started or we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2766 * don't have an entry yet. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2767 if (curbuf->b_new_change || curbuf->b_changelistlen == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2768 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2769 if (curbuf->b_changelistlen == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2770 add = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2771 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2772 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2773 /* Don't create a new entry when the line number is the same
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2774 * as the last one and the column is not too far away. Avoids
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2775 * creating many entries for typing "xxxxx". */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2776 p = &curbuf->b_changelist[curbuf->b_changelistlen - 1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2777 if (p->lnum != lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2778 add = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2779 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2780 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2781 cols = comp_textwidth(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2782 if (cols == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2783 cols = 79;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2784 add = (p->col + cols < col || col + cols < p->col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2785 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2786 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2787 if (add)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2788 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2789 /* This is the first of a new sequence of undo-able changes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2790 * and it's at some distance of the last change. Use a new
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2791 * position in the changelist. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2792 curbuf->b_new_change = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2793
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2794 if (curbuf->b_changelistlen == JUMPLISTSIZE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2795 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2796 /* changelist is full: remove oldest entry */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2797 curbuf->b_changelistlen = JUMPLISTSIZE - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2798 mch_memmove(curbuf->b_changelist, curbuf->b_changelist + 1,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2799 sizeof(pos_T) * (JUMPLISTSIZE - 1));
1863
63369d73b551 updated for version 7.2-161
vimboss
parents: 1848
diff changeset
2800 FOR_ALL_TAB_WINDOWS(tp, wp)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2801 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2802 /* Correct position in changelist for other windows on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2803 * this buffer. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2804 if (wp->w_buffer == curbuf && wp->w_changelistidx > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2805 --wp->w_changelistidx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2806 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2807 }
1863
63369d73b551 updated for version 7.2-161
vimboss
parents: 1848
diff changeset
2808 FOR_ALL_TAB_WINDOWS(tp, wp)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2809 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2810 /* For other windows, if the position in the changelist is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2811 * at the end it stays at the end. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2812 if (wp->w_buffer == curbuf
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2813 && wp->w_changelistidx == curbuf->b_changelistlen)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2814 ++wp->w_changelistidx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2815 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2816 ++curbuf->b_changelistlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2817 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2818 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2819 curbuf->b_changelist[curbuf->b_changelistlen - 1] =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2820 curbuf->b_last_change;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2821 /* The current window is always after the last change, so that "g,"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2822 * takes you back to it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2823 curwin->w_changelistidx = curbuf->b_changelistlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2824 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2825 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2826
1863
63369d73b551 updated for version 7.2-161
vimboss
parents: 1848
diff changeset
2827 FOR_ALL_TAB_WINDOWS(tp, wp)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2828 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2829 if (wp->w_buffer == curbuf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2830 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2831 /* Mark this window to be redrawn later. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2832 if (wp->w_redr_type < VALID)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2833 wp->w_redr_type = VALID;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2834
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2835 /* Check if a change in the buffer has invalidated the cached
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2836 * values for the cursor. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2837 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2838 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2839 * Update the folds for this window. Can't postpone this, because
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2840 * a following operator might work on the whole fold: ">>dd".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2841 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2842 foldUpdate(wp, lnum, lnume + xtra - 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2843
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2844 /* The change may cause lines above or below the change to become
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2845 * included in a fold. Set lnum/lnume to the first/last line that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2846 * might be displayed differently.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2847 * Set w_cline_folded here as an efficient way to update it when
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2848 * inserting lines just above a closed fold. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2849 i = hasFoldingWin(wp, lnum, &lnum, NULL, FALSE, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2850 if (wp->w_cursor.lnum == lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2851 wp->w_cline_folded = i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2852 i = hasFoldingWin(wp, lnume, NULL, &lnume, FALSE, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2853 if (wp->w_cursor.lnum == lnume)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2854 wp->w_cline_folded = i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2855
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2856 /* If the changed line is in a range of previously folded lines,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2857 * compare with the first line in that range. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2858 if (wp->w_cursor.lnum <= lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2859 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2860 i = find_wl_entry(wp, lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2861 if (i >= 0 && wp->w_cursor.lnum > wp->w_lines[i].wl_lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2862 changed_line_abv_curs_win(wp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2863 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2864 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2865
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2866 if (wp->w_cursor.lnum > lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2867 changed_line_abv_curs_win(wp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2868 else if (wp->w_cursor.lnum == lnum && wp->w_cursor.col >= col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2869 changed_cline_bef_curs_win(wp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2870 if (wp->w_botline >= lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2871 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2872 /* Assume that botline doesn't change (inserted lines make
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2873 * other lines scroll down below botline). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2874 approximate_botline_win(wp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2875 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2876
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2877 /* Check if any w_lines[] entries have become invalid.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2878 * For entries below the change: Correct the lnums for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2879 * inserted/deleted lines. Makes it possible to stop displaying
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2880 * after the change. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2881 for (i = 0; i < wp->w_lines_valid; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2882 if (wp->w_lines[i].wl_valid)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2883 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2884 if (wp->w_lines[i].wl_lnum >= lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2885 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2886 if (wp->w_lines[i].wl_lnum < lnume)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2887 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2888 /* line included in change */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2889 wp->w_lines[i].wl_valid = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2890 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2891 else if (xtra != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2892 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2893 /* line below change */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2894 wp->w_lines[i].wl_lnum += xtra;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2895 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2896 wp->w_lines[i].wl_lastlnum += xtra;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2897 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2898 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2899 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2900 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2901 else if (wp->w_lines[i].wl_lastlnum >= lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2902 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2903 /* change somewhere inside this range of folded lines,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2904 * may need to be redrawn */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2905 wp->w_lines[i].wl_valid = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2906 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2907 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2908 }
1987
613517f0b72a updated for version 7.2-284
vimboss
parents: 1938
diff changeset
2909
613517f0b72a updated for version 7.2-284
vimboss
parents: 1938
diff changeset
2910 #ifdef FEAT_FOLDING
613517f0b72a updated for version 7.2-284
vimboss
parents: 1938
diff changeset
2911 /* Take care of side effects for setting w_topline when folds have
613517f0b72a updated for version 7.2-284
vimboss
parents: 1938
diff changeset
2912 * changed. Esp. when the buffer was changed in another window. */
613517f0b72a updated for version 7.2-284
vimboss
parents: 1938
diff changeset
2913 if (hasAnyFolding(wp))
613517f0b72a updated for version 7.2-284
vimboss
parents: 1938
diff changeset
2914 set_topline(wp, wp->w_topline);
613517f0b72a updated for version 7.2-284
vimboss
parents: 1938
diff changeset
2915 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2916 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2917 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2918
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2919 /* Call update_screen() later, which checks out what needs to be redrawn,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2920 * since it notices b_mod_set and then uses b_mod_*. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2921 if (must_redraw < VALID)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2922 must_redraw = VALID;
694
07d199fe02ed updated for version 7.0209
vimboss
parents: 681
diff changeset
2923
07d199fe02ed updated for version 7.0209
vimboss
parents: 681
diff changeset
2924 #ifdef FEAT_AUTOCMD
07d199fe02ed updated for version 7.0209
vimboss
parents: 681
diff changeset
2925 /* when the cursor line is changed always trigger CursorMoved */
1010
ba32a005373a updated for version 7.0-136
vimboss
parents: 983
diff changeset
2926 if (lnum <= curwin->w_cursor.lnum
ba32a005373a updated for version 7.0-136
vimboss
parents: 983
diff changeset
2927 && lnume + (xtra < 0 ? -xtra : xtra) > curwin->w_cursor.lnum)
694
07d199fe02ed updated for version 7.0209
vimboss
parents: 681
diff changeset
2928 last_cursormoved.lnum = 0;
07d199fe02ed updated for version 7.0209
vimboss
parents: 681
diff changeset
2929 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2930 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2931
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2932 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2933 * unchanged() is called when the changed flag must be reset for buffer 'buf'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2934 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2935 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2936 unchanged(buf, ff)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2937 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2938 int ff; /* also reset 'fileformat' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2939 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2940 if (buf->b_changed || (ff && file_ff_differs(buf)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2941 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2942 buf->b_changed = 0;
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
2943 ml_setflags(buf);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2944 if (ff)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2945 save_file_ff(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2946 #ifdef FEAT_WINDOWS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2947 check_status(buf);
673
513866ffe6af updated for version 7.0200
vimboss
parents: 671
diff changeset
2948 redraw_tabline = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2949 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2950 #ifdef FEAT_TITLE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2951 need_maketitle = TRUE; /* set window title later */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2952 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2953 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2954 ++buf->b_changedtick;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2955 #ifdef FEAT_NETBEANS_INTG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2956 netbeans_unmodified(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2957 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2958 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2959
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2960 #if defined(FEAT_WINDOWS) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2961 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2962 * check_status: called when the status bars for the buffer 'buf'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2963 * need to be updated
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2964 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2965 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2966 check_status(buf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2967 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2968 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2969 win_T *wp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2970
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2971 for (wp = firstwin; wp != NULL; wp = wp->w_next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2972 if (wp->w_buffer == buf && wp->w_status_height)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2973 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2974 wp->w_redr_status = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2975 if (must_redraw < VALID)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2976 must_redraw = VALID;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2977 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2978 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2979 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2980
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2981 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2982 * If the file is readonly, give a warning message with the first change.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2983 * Don't do this for autocommands.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2984 * Don't use emsg(), because it flushes the macro buffer.
548
f43150a669dc updated for version 7.0155
vimboss
parents: 474
diff changeset
2985 * If we have undone all changes b_changed will be FALSE, but "b_did_warn"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2986 * will be TRUE.
2288
4dda2bd944e1 Apply patch 7.2.445.
Bram Moolenaar <bram@vim.org>
parents: 2210
diff changeset
2987 * Careful: may trigger autocommands that reload the buffer.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2988 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2989 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2990 change_warning(col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2991 int col; /* column for message; non-zero when in insert
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2992 mode and 'showmode' is on */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2993 {
1848
cfcc1421f5e4 updated for version 7.2-146
vimboss
parents: 1752
diff changeset
2994 static char *w_readonly = N_("W10: Warning: Changing a readonly file");
cfcc1421f5e4 updated for version 7.2-146
vimboss
parents: 1752
diff changeset
2995
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2996 if (curbuf->b_did_warn == FALSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2997 && curbufIsChanged() == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2998 #ifdef FEAT_AUTOCMD
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2999 && !autocmd_busy
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3000 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3001 && curbuf->b_p_ro)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3002 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3003 #ifdef FEAT_AUTOCMD
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
3004 ++curbuf_lock;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3005 apply_autocmds(EVENT_FILECHANGEDRO, NULL, NULL, FALSE, curbuf);
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
3006 --curbuf_lock;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3007 if (!curbuf->b_p_ro)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3008 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3009 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3010 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3011 * Do what msg() does, but with a column offset if the warning should
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3012 * be after the mode message.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3013 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3014 msg_start();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3015 if (msg_row == Rows - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3016 msg_col = col;
16
3ba373b54370 updated for version 7.0008
vimboss
parents: 14
diff changeset
3017 msg_source(hl_attr(HLF_W));
1848
cfcc1421f5e4 updated for version 7.2-146
vimboss
parents: 1752
diff changeset
3018 MSG_PUTS_ATTR(_(w_readonly), hl_attr(HLF_W) | MSG_HIST);
cfcc1421f5e4 updated for version 7.2-146
vimboss
parents: 1752
diff changeset
3019 #ifdef FEAT_EVAL
cfcc1421f5e4 updated for version 7.2-146
vimboss
parents: 1752
diff changeset
3020 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_readonly), -1);
cfcc1421f5e4 updated for version 7.2-146
vimboss
parents: 1752
diff changeset
3021 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3022 msg_clr_eos();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3023 (void)msg_end();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3024 if (msg_silent == 0 && !silent_mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3025 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3026 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3027 ui_delay(1000L, TRUE); /* give the user time to think about it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3028 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3029 curbuf->b_did_warn = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3030 redraw_cmdline = FALSE; /* don't redraw and erase the message */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3031 if (msg_row < Rows - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3032 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3033 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3034 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3035
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3036 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3037 * Ask for a reply from the user, a 'y' or a 'n'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3038 * No other characters are accepted, the message is repeated until a valid
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3039 * reply is entered or CTRL-C is hit.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3040 * If direct is TRUE, don't use vgetc() but ui_inchar(), don't get characters
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3041 * from any buffers but directly from the user.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3042 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3043 * return the 'y' or 'n'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3044 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3045 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3046 ask_yesno(str, direct)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3047 char_u *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3048 int direct;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3049 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3050 int r = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3051 int save_State = State;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3052
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3053 if (exiting) /* put terminal in raw mode for this question */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3054 settmode(TMODE_RAW);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3055 ++no_wait_return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3056 #ifdef USE_ON_FLY_SCROLL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3057 dont_scroll = TRUE; /* disallow scrolling here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3058 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3059 State = CONFIRM; /* mouse behaves like with :confirm */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3060 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3061 setmouse(); /* disables mouse for xterm */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3062 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3063 ++no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3064 ++allow_keys; /* no mapping here, but recognize keys */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3065
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3066 while (r != 'y' && r != 'n')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3067 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3068 /* same highlighting as for wait_return */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3069 smsg_attr(hl_attr(HLF_R), (char_u *)"%s (y/n)?", str);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3070 if (direct)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3071 r = get_keystroke();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3072 else
1474
276244befa5b updated for version 7.1-189
vimboss
parents: 1470
diff changeset
3073 r = plain_vgetc();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3074 if (r == Ctrl_C || r == ESC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3075 r = 'n';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3076 msg_putchar(r); /* show what you typed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3077 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3078 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3079 --no_wait_return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3080 State = save_State;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3081 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3082 setmouse();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3083 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3084 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3085 --allow_keys;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3086
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3087 return r;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3088 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3089
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3090 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3091 * Get a key stroke directly from the user.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3092 * Ignores mouse clicks and scrollbar events, except a click for the left
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3093 * button (used at the more prompt).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3094 * Doesn't use vgetc(), because it syncs undo and eats mapped characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3095 * Disadvantage: typeahead is ignored.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3096 * Translates the interrupt character for unix to ESC.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3097 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3098 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3099 get_keystroke()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3100 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3101 #define CBUFLEN 151
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3102 char_u buf[CBUFLEN];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3103 int len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3104 int n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3105 int save_mapped_ctrl_c = mapped_ctrl_c;
964
e905716f6a3a updated for version 7.0-090
vimboss
parents: 957
diff changeset
3106 int waited = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3107
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3108 mapped_ctrl_c = FALSE; /* mappings are not used here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3109 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3110 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3111 cursor_on();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3112 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3113
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3114 /* First time: blocking wait. Second time: wait up to 100ms for a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3115 * terminal code to complete. Leave some room for check_termcode() to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3116 * insert a key code into (max 5 chars plus NUL). And
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3117 * fix_input_buffer() can triple the number of bytes. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3118 n = ui_inchar(buf + len, (CBUFLEN - 6 - len) / 3,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3119 len == 0 ? -1L : 100L, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3120 if (n > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3121 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3122 /* Replace zero and CSI by a special key code. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3123 n = fix_input_buffer(buf + len, n, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3124 len += n;
964
e905716f6a3a updated for version 7.0-090
vimboss
parents: 957
diff changeset
3125 waited = 0;
e905716f6a3a updated for version 7.0-090
vimboss
parents: 957
diff changeset
3126 }
e905716f6a3a updated for version 7.0-090
vimboss
parents: 957
diff changeset
3127 else if (len > 0)
e905716f6a3a updated for version 7.0-090
vimboss
parents: 957
diff changeset
3128 ++waited; /* keep track of the waiting time */
e905716f6a3a updated for version 7.0-090
vimboss
parents: 957
diff changeset
3129
e905716f6a3a updated for version 7.0-090
vimboss
parents: 957
diff changeset
3130 /* Incomplete termcode and not timed out yet: get more characters */
e905716f6a3a updated for version 7.0-090
vimboss
parents: 957
diff changeset
3131 if ((n = check_termcode(1, buf, len)) < 0
e905716f6a3a updated for version 7.0-090
vimboss
parents: 957
diff changeset
3132 && (!p_ttimeout || waited * 100L < (p_ttm < 0 ? p_tm : p_ttm)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3133 continue;
964
e905716f6a3a updated for version 7.0-090
vimboss
parents: 957
diff changeset
3134
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3135 /* found a termcode: adjust length */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3136 if (n > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3137 len = n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3138 if (len == 0) /* nothing typed yet */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3139 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3140
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3141 /* Handle modifier and/or special key code. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3142 n = buf[0];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3143 if (n == K_SPECIAL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3144 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3145 n = TO_SPECIAL(buf[1], buf[2]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3146 if (buf[1] == KS_MODIFIER
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3147 || n == K_IGNORE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3148 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3149 || n == K_LEFTMOUSE_NM
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3150 || n == K_LEFTDRAG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3151 || n == K_LEFTRELEASE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3152 || n == K_LEFTRELEASE_NM
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3153 || n == K_MIDDLEMOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3154 || n == K_MIDDLEDRAG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3155 || n == K_MIDDLERELEASE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3156 || n == K_RIGHTMOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3157 || n == K_RIGHTDRAG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3158 || n == K_RIGHTRELEASE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3159 || n == K_MOUSEDOWN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3160 || n == K_MOUSEUP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3161 || n == K_X1MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3162 || n == K_X1DRAG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3163 || n == K_X1RELEASE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3164 || n == K_X2MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3165 || n == K_X2DRAG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3166 || n == K_X2RELEASE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3167 # ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3168 || n == K_VER_SCROLLBAR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3169 || n == K_HOR_SCROLLBAR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3170 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3171 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3172 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3173 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3174 if (buf[1] == KS_MODIFIER)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3175 mod_mask = buf[2];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3176 len -= 3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3177 if (len > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3178 mch_memmove(buf, buf + 3, (size_t)len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3179 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3180 }
828
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
3181 break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3182 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3183 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3184 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3185 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3186 if (MB_BYTE2LEN(n) > len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3187 continue; /* more bytes to get */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3188 buf[len >= CBUFLEN ? CBUFLEN - 1 : len] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3189 n = (*mb_ptr2char)(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3190 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3191 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3192 #ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3193 if (n == intr_char)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3194 n = ESC;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3195 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3196 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3197 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3198
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3199 mapped_ctrl_c = save_mapped_ctrl_c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3200 return n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3201 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3202
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3203 /*
374
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3204 * Get a number from the user.
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3205 * When "mouse_used" is not NULL allow using the mouse.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3206 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3207 int
374
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3208 get_number(colon, mouse_used)
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3209 int colon; /* allow colon to abort */
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3210 int *mouse_used;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3211 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3212 int n = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3213 int c;
810
9f345c48220b updated for version 7.0c
vimboss
parents: 777
diff changeset
3214 int typed = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3215
374
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3216 if (mouse_used != NULL)
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3217 *mouse_used = FALSE;
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3218
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3219 /* When not printing messages, the user won't know what to type, return a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3220 * zero (as if CR was hit). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3221 if (msg_silent != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3222 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3223
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3224 #ifdef USE_ON_FLY_SCROLL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3225 dont_scroll = TRUE; /* disallow scrolling here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3226 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3227 ++no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3228 ++allow_keys; /* no mapping here, but recognize keys */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3229 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3230 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3231 windgoto(msg_row, msg_col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3232 c = safe_vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3233 if (VIM_ISDIGIT(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3234 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3235 n = n * 10 + c - '0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3236 msg_putchar(c);
810
9f345c48220b updated for version 7.0c
vimboss
parents: 777
diff changeset
3237 ++typed;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3238 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3239 else if (c == K_DEL || c == K_KDEL || c == K_BS || c == Ctrl_H)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3240 {
810
9f345c48220b updated for version 7.0c
vimboss
parents: 777
diff changeset
3241 if (typed > 0)
9f345c48220b updated for version 7.0c
vimboss
parents: 777
diff changeset
3242 {
9f345c48220b updated for version 7.0c
vimboss
parents: 777
diff changeset
3243 MSG_PUTS("\b \b");
9f345c48220b updated for version 7.0c
vimboss
parents: 777
diff changeset
3244 --typed;
9f345c48220b updated for version 7.0c
vimboss
parents: 777
diff changeset
3245 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3246 n /= 10;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3247 }
374
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3248 #ifdef FEAT_MOUSE
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3249 else if (mouse_used != NULL && c == K_LEFTMOUSE)
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3250 {
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3251 *mouse_used = TRUE;
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3252 n = mouse_row + 1;
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3253 break;
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3254 }
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3255 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3256 else if (n == 0 && c == ':' && colon)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3257 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3258 stuffcharReadbuff(':');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3259 if (!exmode_active)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3260 cmdline_row = msg_row;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3261 skip_redraw = TRUE; /* skip redraw once */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3262 do_redraw = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3263 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3264 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3265 else if (c == CAR || c == NL || c == Ctrl_C || c == ESC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3266 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3267 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3268 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3269 --allow_keys;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3270 return n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3271 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3272
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3273 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3274 * Ask the user to enter a number.
374
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3275 * When "mouse_used" is not NULL allow using the mouse and in that case return
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3276 * the line number.
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3277 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3278 int
374
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3279 prompt_for_number(mouse_used)
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3280 int *mouse_used;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3281 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3282 int i;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 323
diff changeset
3283 int save_cmdline_row;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 323
diff changeset
3284 int save_State;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3285
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3286 /* When using ":silent" assume that <CR> was entered. */
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 374
diff changeset
3287 if (mouse_used != NULL)
1733
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1624
diff changeset
3288 MSG_PUTS(_("Type number and <Enter> or click with mouse (empty cancels): "));
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 374
diff changeset
3289 else
1733
5a7384b9ca66 updated for version 7.2-031
vimboss
parents: 1624
diff changeset
3290 MSG_PUTS(_("Type number and <Enter> (empty cancels): "));
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 323
diff changeset
3291
957
3dc6072e0a25 updated for version 7.0-083
vimboss
parents: 927
diff changeset
3292 /* Set the state such that text can be selected/copied/pasted and we still
3dc6072e0a25 updated for version 7.0-083
vimboss
parents: 927
diff changeset
3293 * get mouse events. */
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 323
diff changeset
3294 save_cmdline_row = cmdline_row;
957
3dc6072e0a25 updated for version 7.0-083
vimboss
parents: 927
diff changeset
3295 cmdline_row = 0;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 323
diff changeset
3296 save_State = State;
957
3dc6072e0a25 updated for version 7.0-083
vimboss
parents: 927
diff changeset
3297 State = CMDLINE;
374
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3298
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3299 i = get_number(TRUE, mouse_used);
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3300 if (KeyTyped)
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3301 {
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3302 /* don't call wait_return() now */
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3303 /* msg_putchar('\n'); */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3304 cmdline_row = msg_row - 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3305 need_wait_return = FALSE;
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3306 msg_didany = FALSE;
1938
5ed9395c1864 updated for version 7.2-235
vimboss
parents: 1937
diff changeset
3307 msg_didout = FALSE;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3308 }
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 323
diff changeset
3309 else
7033303ea0c0 updated for version 7.0089
vimboss
parents: 323
diff changeset
3310 cmdline_row = save_cmdline_row;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 323
diff changeset
3311 State = save_State;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 323
diff changeset
3312
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3313 return i;
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3314 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3315
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3316 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3317 msgmore(n)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3318 long n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3319 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3320 long pn;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3321
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3322 if (global_busy /* no messages now, wait until global is finished */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3323 || !messaging()) /* 'lazyredraw' set, don't do messages now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3324 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3325
135
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 115
diff changeset
3326 /* We don't want to overwrite another important message, but do overwrite
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 115
diff changeset
3327 * a previous "more lines" or "fewer lines" message, so that "5dd" and
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 115
diff changeset
3328 * then "put" reports the last action. */
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 115
diff changeset
3329 if (keep_msg != NULL && !keep_msg_more)
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 115
diff changeset
3330 return;
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 115
diff changeset
3331
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3332 if (n > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3333 pn = n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3334 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3335 pn = -n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3336
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3337 if (pn > p_report)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3338 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3339 if (pn == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3340 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3341 if (n > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3342 STRCPY(msg_buf, _("1 more line"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3343 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3344 STRCPY(msg_buf, _("1 line less"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3345 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3346 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3347 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3348 if (n > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3349 sprintf((char *)msg_buf, _("%ld more lines"), pn);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3350 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3351 sprintf((char *)msg_buf, _("%ld fewer lines"), pn);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3352 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3353 if (got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3354 STRCAT(msg_buf, _(" (Interrupted)"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3355 if (msg(msg_buf))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3356 {
680
5b101ff9d4c4 updated for version 7.0203
vimboss
parents: 674
diff changeset
3357 set_keep_msg(msg_buf, 0);
135
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 115
diff changeset
3358 keep_msg_more = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3359 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3360 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3361 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3362
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3363 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3364 * flush map and typeahead buffers and give a warning for an error
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3365 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3366 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3367 beep_flush()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3368 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3369 if (emsg_silent == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3370 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3371 flush_buffers(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3372 vim_beep();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3373 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3374 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3375
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3376 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3377 * give a warning for an error
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3378 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3379 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3380 vim_beep()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3381 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3382 if (emsg_silent == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3383 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3384 if (p_vb
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3385 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3386 /* While the GUI is starting up the termcap is set for the GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3387 * but the output still goes to a terminal. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3388 && !(gui.in_use && gui.starting)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3389 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3390 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3391 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3392 out_str(T_VB);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3393 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3394 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3395 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3396 #ifdef MSDOS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3397 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3398 * The number of beeps outputted is reduced to avoid having to wait
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3399 * for all the beeps to finish. This is only a problem on systems
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3400 * where the beeps don't overlap.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3401 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3402 if (beep_count == 0 || beep_count == 10)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3403 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3404 out_char(BELL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3405 beep_count = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3406 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3407 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3408 ++beep_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3409 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3410 out_char(BELL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3411 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3412 }
169
0e902b8f511f updated for version 7.0051
vimboss
parents: 164
diff changeset
3413
0e902b8f511f updated for version 7.0051
vimboss
parents: 164
diff changeset
3414 /* When 'verbose' is set and we are sourcing a script or executing a
0e902b8f511f updated for version 7.0051
vimboss
parents: 164
diff changeset
3415 * function give the user a hint where the beep comes from. */
0e902b8f511f updated for version 7.0051
vimboss
parents: 164
diff changeset
3416 if (vim_strchr(p_debug, 'e') != NULL)
0e902b8f511f updated for version 7.0051
vimboss
parents: 164
diff changeset
3417 {
0e902b8f511f updated for version 7.0051
vimboss
parents: 164
diff changeset
3418 msg_source(hl_attr(HLF_W));
0e902b8f511f updated for version 7.0051
vimboss
parents: 164
diff changeset
3419 msg_attr((char_u *)_("Beep!"), hl_attr(HLF_W));
0e902b8f511f updated for version 7.0051
vimboss
parents: 164
diff changeset
3420 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3421 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3422 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3423
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3424 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3425 * To get the "real" home directory:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3426 * - get value of $HOME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3427 * For Unix:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3428 * - go to that directory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3429 * - do mch_dirname() to get the real name of that directory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3430 * This also works with mounts and links.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3431 * Don't do this for MS-DOS, it will change the "current dir" for a drive.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3432 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3433 static char_u *homedir = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3434
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3435 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3436 init_homedir()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3437 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3438 char_u *var;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3439
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3440 /* In case we are called a second time (when 'encoding' changes). */
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3441 vim_free(homedir);
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3442 homedir = NULL;
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3443
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3444 #ifdef VMS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3445 var = mch_getenv((char_u *)"SYS$LOGIN");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3446 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3447 var = mch_getenv((char_u *)"HOME");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3448 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3449
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3450 if (var != NULL && *var == NUL) /* empty is same as not set */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3451 var = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3452
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3453 #ifdef WIN3264
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3454 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3455 * Weird but true: $HOME may contain an indirect reference to another
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3456 * variable, esp. "%USERPROFILE%". Happens when $USERPROFILE isn't set
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3457 * when $HOME is being set.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3458 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3459 if (var != NULL && *var == '%')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3460 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3461 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3462 char_u *exp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3463
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3464 p = vim_strchr(var + 1, '%');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3465 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3466 {
419
f713fc55bf7b updated for version 7.0109
vimboss
parents: 410
diff changeset
3467 vim_strncpy(NameBuff, var + 1, p - (var + 1));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3468 exp = mch_getenv(NameBuff);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3469 if (exp != NULL && *exp != NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3470 && STRLEN(exp) + STRLEN(p) < MAXPATHL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3471 {
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 265
diff changeset
3472 vim_snprintf((char *)NameBuff, MAXPATHL, "%s%s", exp, p + 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3473 var = NameBuff;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3474 /* Also set $HOME, it's needed for _viminfo. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3475 vim_setenv((char_u *)"HOME", NameBuff);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3476 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3477 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3478 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3479
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3480 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3481 * Typically, $HOME is not defined on Windows, unless the user has
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3482 * specifically defined it for Vim's sake. However, on Windows NT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3483 * platforms, $HOMEDRIVE and $HOMEPATH are automatically defined for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3484 * each user. Try constructing $HOME from these.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3485 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3486 if (var == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3487 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3488 char_u *homedrive, *homepath;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3489
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3490 homedrive = mch_getenv((char_u *)"HOMEDRIVE");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3491 homepath = mch_getenv((char_u *)"HOMEPATH");
2030
66b1822ba176 updated for version 7.2.326
Bram Moolenaar <bram@zimbu.org>
parents: 2017
diff changeset
3492 if (homepath == NULL || *homepath == NUL)
66b1822ba176 updated for version 7.2.326
Bram Moolenaar <bram@zimbu.org>
parents: 2017
diff changeset
3493 homepath = "\\";
66b1822ba176 updated for version 7.2.326
Bram Moolenaar <bram@zimbu.org>
parents: 2017
diff changeset
3494 if (homedrive != NULL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3495 && STRLEN(homedrive) + STRLEN(homepath) < MAXPATHL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3496 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3497 sprintf((char *)NameBuff, "%s%s", homedrive, homepath);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3498 if (NameBuff[0] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3499 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3500 var = NameBuff;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3501 /* Also set $HOME, it's needed for _viminfo. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3502 vim_setenv((char_u *)"HOME", NameBuff);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3503 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3504 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3505 }
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3506
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3507 # if defined(FEAT_MBYTE)
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3508 if (enc_utf8 && var != NULL)
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3509 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3510 int len;
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3511 char_u *pp;
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3512
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3513 /* Convert from active codepage to UTF-8. Other conversions are
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3514 * not done, because they would fail for non-ASCII characters. */
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 834
diff changeset
3515 acp_to_enc(var, (int)STRLEN(var), &pp, &len);
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3516 if (pp != NULL)
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3517 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3518 homedir = pp;
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3519 return;
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3520 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3521 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3522 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3523 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3524
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3525 #if defined(OS2) || defined(MSDOS) || defined(MSWIN)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3526 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3527 * Default home dir is C:/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3528 * Best assumption we can make in such a situation.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3529 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3530 if (var == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3531 var = "C:/";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3532 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3533 if (var != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3534 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3535 #ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3536 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3537 * Change to the directory and get the actual path. This resolves
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3538 * links. Don't do it when we can't return.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3539 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3540 if (mch_dirname(NameBuff, MAXPATHL) == OK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3541 && mch_chdir((char *)NameBuff) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3542 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3543 if (!mch_chdir((char *)var) && mch_dirname(IObuff, IOSIZE) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3544 var = IObuff;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3545 if (mch_chdir((char *)NameBuff) != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3546 EMSG(_(e_prev_dir));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3547 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3548 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3549 homedir = vim_strsave(var);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3550 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3551 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3552
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 344
diff changeset
3553 #if defined(EXITFREE) || defined(PROTO)
6c62b9b939bd updated for version 7.0093
vimboss
parents: 344
diff changeset
3554 void
6c62b9b939bd updated for version 7.0093
vimboss
parents: 344
diff changeset
3555 free_homedir()
6c62b9b939bd updated for version 7.0093
vimboss
parents: 344
diff changeset
3556 {
6c62b9b939bd updated for version 7.0093
vimboss
parents: 344
diff changeset
3557 vim_free(homedir);
6c62b9b939bd updated for version 7.0093
vimboss
parents: 344
diff changeset
3558 }
6c62b9b939bd updated for version 7.0093
vimboss
parents: 344
diff changeset
3559 #endif
6c62b9b939bd updated for version 7.0093
vimboss
parents: 344
diff changeset
3560
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3561 /*
1408
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3562 * Call expand_env() and store the result in an allocated string.
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3563 * This is not very memory efficient, this expects the result to be freed
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3564 * again soon.
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3565 */
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3566 char_u *
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3567 expand_env_save(src)
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3568 char_u *src;
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3569 {
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3570 return expand_env_save_opt(src, FALSE);
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3571 }
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3572
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3573 /*
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3574 * Idem, but when "one" is TRUE handle the string as one file name, only
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3575 * expand "~" at the start.
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3576 */
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3577 char_u *
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3578 expand_env_save_opt(src, one)
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3579 char_u *src;
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3580 int one;
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3581 {
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3582 char_u *p;
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3583
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3584 p = alloc(MAXPATHL);
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3585 if (p != NULL)
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3586 expand_env_esc(src, p, MAXPATHL, FALSE, one, NULL);
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3587 return p;
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3588 }
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3589
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3590 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3591 * Expand environment variable with path name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3592 * "~/" is also expanded, using $HOME. For Unix "~user/" is expanded.
1408
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3593 * Skips over "\ ", "\~" and "\$" (not for Win32 though).
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3594 * If anything fails no expansion is done and dst equals src.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3595 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3596 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3597 expand_env(src, dst, dstlen)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3598 char_u *src; /* input string e.g. "$HOME/vim.hlp" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3599 char_u *dst; /* where to put the result */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3600 int dstlen; /* maximum length of the result */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3601 {
1408
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3602 expand_env_esc(src, dst, dstlen, FALSE, FALSE, NULL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3603 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3604
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3605 void
1408
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3606 expand_env_esc(srcp, dst, dstlen, esc, one, startstr)
374
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3607 char_u *srcp; /* input string e.g. "$HOME/vim.hlp" */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3608 char_u *dst; /* where to put the result */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3609 int dstlen; /* maximum length of the result */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3610 int esc; /* escape spaces in expanded variables */
1408
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3611 int one; /* "srcp" is one file name */
374
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3612 char_u *startstr; /* start again after this (can be NULL) */
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3613 {
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3614 char_u *src;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3615 char_u *tail;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3616 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3617 char_u *var;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3618 int copy_char;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3619 int mustfree; /* var was allocated, need to free it later */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3620 int at_start = TRUE; /* at start of a name */
374
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3621 int startstr_len = 0;
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3622
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3623 if (startstr != NULL)
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 834
diff changeset
3624 startstr_len = (int)STRLEN(startstr);
374
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3625
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3626 src = skipwhite(srcp);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3627 --dstlen; /* leave one char space for "\," */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3628 while (*src && dstlen > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3629 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3630 copy_char = TRUE;
22
cc049b00ee70 updated for version 7.0014
vimboss
parents: 17
diff changeset
3631 if ((*src == '$'
cc049b00ee70 updated for version 7.0014
vimboss
parents: 17
diff changeset
3632 #ifdef VMS
cc049b00ee70 updated for version 7.0014
vimboss
parents: 17
diff changeset
3633 && at_start
cc049b00ee70 updated for version 7.0014
vimboss
parents: 17
diff changeset
3634 #endif
cc049b00ee70 updated for version 7.0014
vimboss
parents: 17
diff changeset
3635 )
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3636 #if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3637 || *src == '%'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3638 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3639 || (*src == '~' && at_start))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3640 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3641 mustfree = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3642
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3643 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3644 * The variable name is copied into dst temporarily, because it may
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3645 * be a string in read-only memory and a NUL needs to be appended.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3646 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3647 if (*src != '~') /* environment var */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3648 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3649 tail = src + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3650 var = dst;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3651 c = dstlen - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3652
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3653 #ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3654 /* Unix has ${var-name} type environment vars */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3655 if (*tail == '{' && !vim_isIDc('{'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3656 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3657 tail++; /* ignore '{' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3658 while (c-- > 0 && *tail && *tail != '}')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3659 *var++ = *tail++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3660 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3661 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3662 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3663 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3664 while (c-- > 0 && *tail != NUL && ((vim_isIDc(*tail))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3665 #if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3666 || (*src == '%' && *tail != '%')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3667 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3668 ))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3669 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3670 #ifdef OS2 /* env vars only in uppercase */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3671 *var++ = TOUPPER_LOC(*tail);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3672 tail++; /* toupper() may be a macro! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3673 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3674 *var++ = *tail++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3675 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3676 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3677 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3678
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3679 #if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(UNIX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3680 # ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3681 if (src[1] == '{' && *tail != '}')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3682 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3683 if (*src == '%' && *tail != '%')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3684 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3685 var = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3686 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3687 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3688 # ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3689 if (src[1] == '{')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3690 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3691 if (*src == '%')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3692 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3693 ++tail;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3694 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3695 *var = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3696 var = vim_getenv(dst, &mustfree);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3697 #if defined(MSDOS) || defined(MSWIN) || defined(OS2) || defined(UNIX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3698 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3699 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3700 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3701 /* home directory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3702 else if ( src[1] == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3703 || vim_ispathsep(src[1])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3704 || vim_strchr((char_u *)" ,\t\n", src[1]) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3705 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3706 var = homedir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3707 tail = src + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3708 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3709 else /* user directory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3710 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3711 #if defined(UNIX) || (defined(VMS) && defined(USER_HOME))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3712 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3713 * Copy ~user to dst[], so we can put a NUL after it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3714 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3715 tail = src;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3716 var = dst;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3717 c = dstlen - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3718 while ( c-- > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3719 && *tail
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3720 && vim_isfilec(*tail)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3721 && !vim_ispathsep(*tail))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3722 *var++ = *tail++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3723 *var = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3724 # ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3725 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3726 * If the system supports getpwnam(), use it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3727 * Otherwise, or if getpwnam() fails, the shell is used to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3728 * expand ~user. This is slower and may fail if the shell
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3729 * does not support ~user (old versions of /bin/sh).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3730 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3731 # if defined(HAVE_GETPWNAM) && defined(HAVE_PWD_H)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3732 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3733 struct passwd *pw;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3734
626
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
3735 /* Note: memory allocated by getpwnam() is never freed.
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
3736 * Calling endpwent() apparently doesn't help. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3737 pw = getpwnam((char *)dst + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3738 if (pw != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3739 var = (char_u *)pw->pw_dir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3740 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3741 var = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3742 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3743 if (var == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3744 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3745 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3746 expand_T xpc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3747
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3748 ExpandInit(&xpc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3749 xpc.xp_context = EXPAND_FILES;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3750 var = ExpandOne(&xpc, dst, NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3751 WILD_ADD_SLASH|WILD_SILENT, WILD_EXPAND_FREE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3752 mustfree = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3753 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3754
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3755 # else /* !UNIX, thus VMS */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3756 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3757 * USER_HOME is a comma-separated list of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3758 * directories to search for the user account in.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3759 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3760 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3761 char_u test[MAXPATHL], paths[MAXPATHL];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3762 char_u *path, *next_path, *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3763 struct stat st;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3764
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3765 STRCPY(paths, USER_HOME);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3766 next_path = paths;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3767 while (*next_path)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3768 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3769 for (path = next_path; *next_path && *next_path != ',';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3770 next_path++);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3771 if (*next_path)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3772 *next_path++ = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3773 STRCPY(test, path);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3774 STRCAT(test, "/");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3775 STRCAT(test, dst + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3776 if (mch_stat(test, &st) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3777 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3778 var = alloc(STRLEN(test) + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3779 STRCPY(var, test);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3780 mustfree = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3781 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3782 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3783 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3784 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3785 # endif /* UNIX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3786 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3787 /* cannot expand user's home directory, so don't try */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3788 var = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3789 tail = (char_u *)""; /* for gcc */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3790 #endif /* UNIX || VMS */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3791 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3792
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3793 #ifdef BACKSLASH_IN_FILENAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3794 /* If 'shellslash' is set change backslashes to forward slashes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3795 * Can't use slash_adjust(), p_ssl may be set temporarily. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3796 if (p_ssl && var != NULL && vim_strchr(var, '\\') != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3797 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3798 char_u *p = vim_strsave(var);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3799
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3800 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3801 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3802 if (mustfree)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3803 vim_free(var);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3804 var = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3805 mustfree = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3806 forward_slash(var);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3807 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3808 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3809 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3810
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3811 /* If "var" contains white space, escape it with a backslash.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3812 * Required for ":e ~/tt" when $HOME includes a space. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3813 if (esc && var != NULL && vim_strpbrk(var, (char_u *)" \t") != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3814 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3815 char_u *p = vim_strsave_escaped(var, (char_u *)" \t");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3816
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3817 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3818 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3819 if (mustfree)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3820 vim_free(var);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3821 var = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3822 mustfree = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3823 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3824 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3825
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3826 if (var != NULL && *var != NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3827 && (STRLEN(var) + STRLEN(tail) + 1 < (unsigned)dstlen))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3828 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3829 STRCPY(dst, var);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3830 dstlen -= (int)STRLEN(var);
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 834
diff changeset
3831 c = (int)STRLEN(var);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3832 /* if var[] ends in a path separator and tail[] starts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3833 * with it, skip a character */
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
3834 if (*var != NUL && after_pathsep(dst, dst + c)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3835 #if defined(BACKSLASH_IN_FILENAME) || defined(AMIGA)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3836 && dst[-1] != ':'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3837 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3838 && vim_ispathsep(*tail))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3839 ++tail;
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
3840 dst += c;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3841 src = tail;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3842 copy_char = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3843 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3844 if (mustfree)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3845 vim_free(var);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3846 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3847
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3848 if (copy_char) /* copy at least one char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3849 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3850 /*
1224
edc1c9d6dab9 updated for version 7.1b
vimboss
parents: 1096
diff changeset
3851 * Recognize the start of a new name, for '~'.
1408
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3852 * Don't do this when "one" is TRUE, to avoid expanding "~" in
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3853 * ":edit foo ~ foo".
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3854 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3855 at_start = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3856 if (src[0] == '\\' && src[1] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3857 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3858 *dst++ = *src++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3859 --dstlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3860 }
1408
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3861 else if ((src[0] == ' ' || src[0] == ',') && !one)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3862 at_start = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3863 *dst++ = *src++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3864 --dstlen;
374
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3865
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3866 if (startstr != NULL && src - startstr_len >= srcp
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3867 && STRNCMP(src - startstr_len, startstr, startstr_len) == 0)
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3868 at_start = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3869 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3870 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3871 *dst = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3872 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3873
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3874 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3875 * Vim's version of getenv().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3876 * Special handling of $HOME, $VIM and $VIMRUNTIME.
196
991a7623a1fe updated for version 7.0058
vimboss
parents: 191
diff changeset
3877 * Also does ACP to 'enc' conversion for Win32.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3878 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3879 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3880 vim_getenv(name, mustfree)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3881 char_u *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3882 int *mustfree; /* set to TRUE when returned is allocated */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3883 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3884 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3885 char_u *pend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3886 int vimruntime;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3887
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3888 #if defined(OS2) || defined(MSDOS) || defined(MSWIN)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3889 /* use "C:/" when $HOME is not set */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3890 if (STRCMP(name, "HOME") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3891 return homedir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3892 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3893
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3894 p = mch_getenv(name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3895 if (p != NULL && *p == NUL) /* empty is the same as not set */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3896 p = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3897
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3898 if (p != NULL)
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3899 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3900 #if defined(FEAT_MBYTE) && defined(WIN3264)
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3901 if (enc_utf8)
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3902 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3903 int len;
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3904 char_u *pp;
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3905
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3906 /* Convert from active codepage to UTF-8. Other conversions are
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3907 * not done, because they would fail for non-ASCII characters. */
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 834
diff changeset
3908 acp_to_enc(p, (int)STRLEN(p), &pp, &len);
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3909 if (pp != NULL)
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3910 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3911 p = pp;
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3912 *mustfree = TRUE;
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3913 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3914 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3915 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3916 return p;
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3917 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3918
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3919 vimruntime = (STRCMP(name, "VIMRUNTIME") == 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3920 if (!vimruntime && STRCMP(name, "VIM") != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3921 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3922
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3923 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3924 * When expanding $VIMRUNTIME fails, try using $VIM/vim<version> or $VIM.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3925 * Don't do this when default_vimruntime_dir is non-empty.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3926 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3927 if (vimruntime
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3928 #ifdef HAVE_PATHDEF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3929 && *default_vimruntime_dir == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3930 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3931 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3932 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3933 p = mch_getenv((char_u *)"VIM");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3934 if (p != NULL && *p == NUL) /* empty is the same as not set */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3935 p = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3936 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3937 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3938 p = vim_version_dir(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3939 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3940 *mustfree = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3941 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3942 p = mch_getenv((char_u *)"VIM");
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3943
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3944 #if defined(FEAT_MBYTE) && defined(WIN3264)
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3945 if (enc_utf8)
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3946 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3947 int len;
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3948 char_u *pp;
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3949
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3950 /* Convert from active codepage to UTF-8. Other conversions
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3951 * are not done, because they would fail for non-ASCII
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3952 * characters. */
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 834
diff changeset
3953 acp_to_enc(p, (int)STRLEN(p), &pp, &len);
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3954 if (pp != NULL)
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3955 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3956 if (mustfree)
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3957 vim_free(p);
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3958 p = pp;
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3959 *mustfree = TRUE;
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3960 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3961 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3962 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3963 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3964 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3965
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3966 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3967 * When expanding $VIM or $VIMRUNTIME fails, try using:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3968 * - the directory name from 'helpfile' (unless it contains '$')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3969 * - the executable name from argv[0]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3970 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3971 if (p == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3972 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3973 if (p_hf != NULL && vim_strchr(p_hf, '$') == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3974 p = p_hf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3975 #ifdef USE_EXE_NAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3976 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3977 * Use the name of the executable, obtained from argv[0].
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3978 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3979 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3980 p = exe_name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3981 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3982 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3983 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3984 /* remove the file name */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3985 pend = gettail(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3986
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3987 /* remove "doc/" from 'helpfile', if present */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3988 if (p == p_hf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3989 pend = remove_tail(p, pend, (char_u *)"doc");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3990
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3991 #ifdef USE_EXE_NAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3992 # ifdef MACOS_X
768
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
3993 /* remove "MacOS" from exe_name and add "Resources/vim" */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3994 if (p == exe_name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3995 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3996 char_u *pend1;
768
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
3997 char_u *pnew;
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
3998
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
3999 pend1 = remove_tail(p, pend, (char_u *)"MacOS");
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4000 if (pend1 != pend)
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4001 {
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4002 pnew = alloc((unsigned)(pend1 - p) + 15);
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4003 if (pnew != NULL)
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4004 {
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4005 STRNCPY(pnew, p, (pend1 - p));
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4006 STRCPY(pnew + (pend1 - p), "Resources/vim");
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4007 p = pnew;
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4008 pend = p + STRLEN(p);
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4009 }
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4010 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4011 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4012 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4013 /* remove "src/" from exe_name, if present */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4014 if (p == exe_name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4015 pend = remove_tail(p, pend, (char_u *)"src");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4016 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4017
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4018 /* for $VIM, remove "runtime/" or "vim54/", if present */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4019 if (!vimruntime)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4020 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4021 pend = remove_tail(p, pend, (char_u *)RUNTIME_DIRNAME);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4022 pend = remove_tail(p, pend, (char_u *)VIM_VERSION_NODOT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4023 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4024
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4025 /* remove trailing path separator */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4026 #ifndef MACOS_CLASSIC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4027 /* With MacOS path (with colons) the final colon is required */
1532
87b9f21264a7 updated for version 7.1-247
vimboss
parents: 1521
diff changeset
4028 /* to avoid confusion between absolute and relative path */
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4029 if (pend > p && after_pathsep(p, pend))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4030 --pend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4031 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4032
768
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4033 #ifdef MACOS_X
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4034 if (p == exe_name || p == p_hf)
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4035 #endif
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4036 /* check that the result is a directory name */
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4037 p = vim_strnsave(p, (int)(pend - p));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4038
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4039 if (p != NULL && !mch_isdir(p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4040 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4041 vim_free(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4042 p = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4043 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4044 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4045 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4046 #ifdef USE_EXE_NAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4047 /* may add "/vim54" or "/runtime" if it exists */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4048 if (vimruntime && (pend = vim_version_dir(p)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4049 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4050 vim_free(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4051 p = pend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4052 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4053 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4054 *mustfree = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4055 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4056 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4057 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4058
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4059 #ifdef HAVE_PATHDEF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4060 /* When there is a pathdef.c file we can use default_vim_dir and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4061 * default_vimruntime_dir */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4062 if (p == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4063 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4064 /* Only use default_vimruntime_dir when it is not empty */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4065 if (vimruntime && *default_vimruntime_dir != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4066 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4067 p = default_vimruntime_dir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4068 *mustfree = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4069 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4070 else if (*default_vim_dir != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4071 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4072 if (vimruntime && (p = vim_version_dir(default_vim_dir)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4073 *mustfree = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4074 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4075 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4076 p = default_vim_dir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4077 *mustfree = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4078 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4079 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4080 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4081 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4082
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4083 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4084 * Set the environment variable, so that the new value can be found fast
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4085 * next time, and others can also use it (e.g. Perl).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4086 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4087 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4088 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4089 if (vimruntime)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4090 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4091 vim_setenv((char_u *)"VIMRUNTIME", p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4092 didset_vimruntime = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4093 #ifdef FEAT_GETTEXT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4094 {
115
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
4095 char_u *buf = concat_str(p, (char_u *)"/lang");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4096
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4097 if (buf != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4098 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4099 bindtextdomain(VIMPACKAGE, (char *)buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4100 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4101 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4102 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4103 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4104 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4105 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4106 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4107 vim_setenv((char_u *)"VIM", p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4108 didset_vim = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4109 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4110 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4111 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4112 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4113
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4114 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4115 * Check if the directory "vimdir/<version>" or "vimdir/runtime" exists.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4116 * Return NULL if not, return its name in allocated memory otherwise.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4117 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4118 static char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4119 vim_version_dir(vimdir)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4120 char_u *vimdir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4121 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4122 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4123
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4124 if (vimdir == NULL || *vimdir == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4125 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4126 p = concat_fnames(vimdir, (char_u *)VIM_VERSION_NODOT, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4127 if (p != NULL && mch_isdir(p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4128 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4129 vim_free(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4130 p = concat_fnames(vimdir, (char_u *)RUNTIME_DIRNAME, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4131 if (p != NULL && mch_isdir(p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4132 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4133 vim_free(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4134 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4135 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4136
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4137 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4138 * If the string between "p" and "pend" ends in "name/", return "pend" minus
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4139 * the length of "name/". Otherwise return "pend".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4140 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4141 static char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4142 remove_tail(p, pend, name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4143 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4144 char_u *pend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4145 char_u *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4146 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4147 int len = (int)STRLEN(name) + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4148 char_u *newend = pend - len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4149
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4150 if (newend >= p
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4151 && fnamencmp(newend, name, len - 1) == 0
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4152 && (newend == p || after_pathsep(p, newend)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4153 return newend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4154 return pend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4155 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4156
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4157 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4158 * Our portable version of setenv.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4159 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4160 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4161 vim_setenv(name, val)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4162 char_u *name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4163 char_u *val;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4164 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4165 #ifdef HAVE_SETENV
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4166 mch_setenv((char *)name, (char *)val, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4167 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4168 char_u *envbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4169
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4170 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4171 * Putenv does not copy the string, it has to remain
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4172 * valid. The allocated memory will never be freed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4173 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4174 envbuf = alloc((unsigned)(STRLEN(name) + STRLEN(val) + 2));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4175 if (envbuf != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4176 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4177 sprintf((char *)envbuf, "%s=%s", name, val);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4178 putenv((char *)envbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4179 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4180 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4181 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4182
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4183 #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4184 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4185 * Function given to ExpandGeneric() to obtain an environment variable name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4186 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4187 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4188 get_env_name(xp, idx)
1883
c8f343a465a2 updated for version 7.2-180
vimboss
parents: 1877
diff changeset
4189 expand_T *xp UNUSED;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4190 int idx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4191 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4192 # if defined(AMIGA) || defined(__MRC__) || defined(__SC__)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4193 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4194 * No environ[] on the Amiga and on the Mac (using MPW).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4195 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4196 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4197 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4198 # ifndef __WIN32__
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4199 /* Borland C++ 5.2 has this in a header file. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4200 extern char **environ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4201 # endif
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
4202 # define ENVNAMELEN 100
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
4203 static char_u name[ENVNAMELEN];
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4204 char_u *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4205 int n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4206
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4207 str = (char_u *)environ[idx];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4208 if (str == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4209 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4210
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
4211 for (n = 0; n < ENVNAMELEN - 1; ++n)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4212 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4213 if (str[n] == '=' || str[n] == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4214 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4215 name[n] = str[n];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4216 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4217 name[n] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4218 return name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4219 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4220 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4221 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4222
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4223 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4224 * Replace home directory by "~" in each space or comma separated file name in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4225 * 'src'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4226 * If anything fails (except when out of space) dst equals src.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4227 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4228 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4229 home_replace(buf, src, dst, dstlen, one)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4230 buf_T *buf; /* when not NULL, check for help files */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4231 char_u *src; /* input file name */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4232 char_u *dst; /* where to put the result */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4233 int dstlen; /* maximum length of the result */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4234 int one; /* if TRUE, only replace one file name, include
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4235 spaces and commas in the file name. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4236 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4237 size_t dirlen = 0, envlen = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4238 size_t len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4239 char_u *homedir_env;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4240 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4241
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4242 if (src == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4243 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4244 *dst = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4245 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4246 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4247
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4248 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4249 * If the file is a help file, remove the path completely.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4250 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4251 if (buf != NULL && buf->b_help)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4252 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4253 STRCPY(dst, gettail(src));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4254 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4255 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4256
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4257 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4258 * We check both the value of the $HOME environment variable and the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4259 * "real" home directory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4260 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4261 if (homedir != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4262 dirlen = STRLEN(homedir);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4263
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4264 #ifdef VMS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4265 homedir_env = mch_getenv((char_u *)"SYS$LOGIN");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4266 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4267 homedir_env = mch_getenv((char_u *)"HOME");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4268 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4269
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4270 if (homedir_env != NULL && *homedir_env == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4271 homedir_env = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4272 if (homedir_env != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4273 envlen = STRLEN(homedir_env);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4274
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4275 if (!one)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4276 src = skipwhite(src);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4277 while (*src && dstlen > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4278 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4279 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4280 * Here we are at the beginning of a file name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4281 * First, check to see if the beginning of the file name matches
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4282 * $HOME or the "real" home directory. Check that there is a '/'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4283 * after the match (so that if e.g. the file is "/home/pieter/bla",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4284 * and the home directory is "/home/piet", the file does not end up
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4285 * as "~er/bla" (which would seem to indicate the file "bla" in user
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4286 * er's home directory)).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4287 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4288 p = homedir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4289 len = dirlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4290 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4291 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4292 if ( len
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4293 && fnamencmp(src, p, len) == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4294 && (vim_ispathsep(src[len])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4295 || (!one && (src[len] == ',' || src[len] == ' '))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4296 || src[len] == NUL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4297 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4298 src += len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4299 if (--dstlen > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4300 *dst++ = '~';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4301
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4302 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4303 * If it's just the home directory, add "/".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4304 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4305 if (!vim_ispathsep(src[0]) && --dstlen > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4306 *dst++ = '/';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4307 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4308 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4309 if (p == homedir_env)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4310 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4311 p = homedir_env;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4312 len = envlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4313 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4314
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4315 /* if (!one) skip to separator: space or comma */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4316 while (*src && (one || (*src != ',' && *src != ' ')) && --dstlen > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4317 *dst++ = *src++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4318 /* skip separator */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4319 while ((*src == ' ' || *src == ',') && --dstlen > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4320 *dst++ = *src++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4321 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4322 /* if (dstlen == 0) out of space, what to do??? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4323
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4324 *dst = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4325 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4326
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4327 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4328 * Like home_replace, store the replaced string in allocated memory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4329 * When something fails, NULL is returned.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4330 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4331 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4332 home_replace_save(buf, src)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4333 buf_T *buf; /* when not NULL, check for help files */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4334 char_u *src; /* input file name */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4335 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4336 char_u *dst;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4337 unsigned len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4338
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4339 len = 3; /* space for "~/" and trailing NUL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4340 if (src != NULL) /* just in case */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4341 len += (unsigned)STRLEN(src);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4342 dst = alloc(len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4343 if (dst != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4344 home_replace(buf, src, dst, len, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4345 return dst;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4346 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4347
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4348 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4349 * Compare two file names and return:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4350 * FPC_SAME if they both exist and are the same file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4351 * FPC_SAMEX if they both don't exist and have the same file name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4352 * FPC_DIFF if they both exist and are different files.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4353 * FPC_NOTX if they both don't exist.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4354 * FPC_DIFFX if one of them doesn't exist.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4355 * For the first name environment variables are expanded
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4356 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4357 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4358 fullpathcmp(s1, s2, checkname)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4359 char_u *s1, *s2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4360 int checkname; /* when both don't exist, check file names */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4361 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4362 #ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4363 char_u exp1[MAXPATHL];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4364 char_u full1[MAXPATHL];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4365 char_u full2[MAXPATHL];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4366 struct stat st1, st2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4367 int r1, r2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4368
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4369 expand_env(s1, exp1, MAXPATHL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4370 r1 = mch_stat((char *)exp1, &st1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4371 r2 = mch_stat((char *)s2, &st2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4372 if (r1 != 0 && r2 != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4373 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4374 /* if mch_stat() doesn't work, may compare the names */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4375 if (checkname)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4376 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4377 if (fnamecmp(exp1, s2) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4378 return FPC_SAMEX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4379 r1 = vim_FullName(exp1, full1, MAXPATHL, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4380 r2 = vim_FullName(s2, full2, MAXPATHL, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4381 if (r1 == OK && r2 == OK && fnamecmp(full1, full2) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4382 return FPC_SAMEX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4383 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4384 return FPC_NOTX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4385 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4386 if (r1 != 0 || r2 != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4387 return FPC_DIFFX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4388 if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4389 return FPC_SAME;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4390 return FPC_DIFF;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4391 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4392 char_u *exp1; /* expanded s1 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4393 char_u *full1; /* full path of s1 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4394 char_u *full2; /* full path of s2 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4395 int retval = FPC_DIFF;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4396 int r1, r2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4397
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4398 /* allocate one buffer to store three paths (alloc()/free() is slow!) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4399 if ((exp1 = alloc(MAXPATHL * 3)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4400 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4401 full1 = exp1 + MAXPATHL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4402 full2 = full1 + MAXPATHL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4403
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4404 expand_env(s1, exp1, MAXPATHL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4405 r1 = vim_FullName(exp1, full1, MAXPATHL, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4406 r2 = vim_FullName(s2, full2, MAXPATHL, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4407
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4408 /* If vim_FullName() fails, the file probably doesn't exist. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4409 if (r1 != OK && r2 != OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4410 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4411 if (checkname && fnamecmp(exp1, s2) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4412 retval = FPC_SAMEX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4413 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4414 retval = FPC_NOTX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4415 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4416 else if (r1 != OK || r2 != OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4417 retval = FPC_DIFFX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4418 else if (fnamecmp(full1, full2))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4419 retval = FPC_DIFF;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4420 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4421 retval = FPC_SAME;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4422 vim_free(exp1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4423 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4424 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4425 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4426 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4427
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4428 /*
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
4429 * Get the tail of a path: the file name.
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
4430 * Fail safe: never returns NULL.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4431 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4432 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4433 gettail(fname)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4434 char_u *fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4435 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4436 char_u *p1, *p2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4437
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4438 if (fname == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4439 return (char_u *)"";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4440 for (p1 = p2 = fname; *p2; ) /* find last part of path */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4441 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4442 if (vim_ispathsep(*p2))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4443 p1 = p2 + 1;
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4444 mb_ptr_adv(p2);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4445 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4446 return p1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4447 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4448
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4449 /*
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4450 * Get pointer to tail of "fname", including path separators. Putting a NUL
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4451 * here leaves the directory name. Takes care of "c:/" and "//".
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4452 * Always returns a valid pointer.
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4453 */
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4454 char_u *
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4455 gettail_sep(fname)
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4456 char_u *fname;
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4457 {
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4458 char_u *p;
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4459 char_u *t;
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4460
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4461 p = get_past_head(fname); /* don't remove the '/' from "c:/file" */
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4462 t = gettail(fname);
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4463 while (t > p && after_pathsep(fname, t))
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4464 --t;
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4465 #ifdef VMS
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4466 /* path separator is part of the path */
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4467 ++t;
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4468 #endif
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4469 return t;
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4470 }
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4471
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4472 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4473 * get the next path component (just after the next path separator).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4474 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4475 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4476 getnextcomp(fname)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4477 char_u *fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4478 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4479 while (*fname && !vim_ispathsep(*fname))
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4480 mb_ptr_adv(fname);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4481 if (*fname)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4482 ++fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4483 return fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4484 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4485
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4486 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4487 * Get a pointer to one character past the head of a path name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4488 * Unix: after "/"; DOS: after "c:\"; Amiga: after "disk:/"; Mac: no head.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4489 * If there is no head, path is returned.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4490 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4491 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4492 get_past_head(path)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4493 char_u *path;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4494 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4495 char_u *retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4496
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4497 #if defined(MSDOS) || defined(MSWIN) || defined(OS2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4498 /* may skip "c:" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4499 if (isalpha(path[0]) && path[1] == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4500 retval = path + 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4501 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4502 retval = path;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4503 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4504 # if defined(AMIGA)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4505 /* may skip "label:" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4506 retval = vim_strchr(path, ':');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4507 if (retval == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4508 retval = path;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4509 # else /* Unix */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4510 retval = path;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4511 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4512 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4513
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4514 while (vim_ispathsep(*retval))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4515 ++retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4516
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4517 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4518 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4519
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4520 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4521 * return TRUE if 'c' is a path separator.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4522 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4523 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4524 vim_ispathsep(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4525 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4526 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4527 #ifdef RISCOS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4528 return (c == '.' || c == ':');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4529 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4530 # ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4531 return (c == '/'); /* UNIX has ':' inside file names */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4532 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4533 # ifdef BACKSLASH_IN_FILENAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4534 return (c == ':' || c == '/' || c == '\\');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4535 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4536 # ifdef VMS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4537 /* server"user passwd"::device:[full.path.name]fname.extension;version" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4538 return (c == ':' || c == '[' || c == ']' || c == '/'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4539 || c == '<' || c == '>' || c == '"' );
720
e180933b876a updated for version 7.0219
vimboss
parents: 716
diff changeset
4540 # else /* Amiga */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4541 return (c == ':' || c == '/');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4542 # endif /* VMS */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4543 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4544 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4545 #endif /* RISC OS */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4546 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4547
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4548 #if defined(FEAT_SEARCHPATH) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4549 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4550 * return TRUE if 'c' is a path list separator.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4551 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4552 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4553 vim_ispathlistsep(c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4554 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4555 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4556 #ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4557 return (c == ':');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4558 #else
1224
edc1c9d6dab9 updated for version 7.1b
vimboss
parents: 1096
diff changeset
4559 return (c == ';'); /* might not be right for every system... */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4560 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4561 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4562 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4563
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4564 #if defined(FEAT_GUI_TABLINE) || defined(FEAT_WINDOWS) \
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4565 || defined(FEAT_EVAL) || defined(PROTO)
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4566 /*
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4567 * Shorten the path of a file from "~/foo/../.bar/fname" to "~/f/../.b/fname"
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4568 * It's done in-place.
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4569 */
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4570 void
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4571 shorten_dir(str)
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4572 char_u *str;
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4573 {
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4574 char_u *tail, *s, *d;
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4575 int skip = FALSE;
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4576
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4577 tail = gettail(str);
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4578 d = str;
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4579 for (s = str; ; ++s)
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4580 {
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4581 if (s >= tail) /* copy the whole tail */
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4582 {
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4583 *d++ = *s;
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4584 if (*s == NUL)
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4585 break;
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4586 }
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4587 else if (vim_ispathsep(*s)) /* copy '/' and next char */
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4588 {
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4589 *d++ = *s;
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4590 skip = FALSE;
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4591 }
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4592 else if (!skip)
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4593 {
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4594 *d++ = *s; /* copy next char */
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4595 if (*s != '~' && *s != '.') /* and leading "~" and "." */
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4596 skip = TRUE;
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4597 # ifdef FEAT_MBYTE
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4598 if (has_mbyte)
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4599 {
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4600 int l = mb_ptr2len(s);
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4601
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4602 while (--l > 0)
927
6632670ff6fc updated for version 7.0-053
vimboss
parents: 856
diff changeset
4603 *d++ = *++s;
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4604 }
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4605 # endif
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4606 }
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4607 }
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4608 }
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4609 #endif
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
4610
594
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
4611 /*
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
4612 * Return TRUE if the directory of "fname" exists, FALSE otherwise.
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
4613 * Also returns TRUE if there is no directory name.
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
4614 * "fname" must be writable!.
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
4615 */
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
4616 int
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
4617 dir_of_file_exists(fname)
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
4618 char_u *fname;
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
4619 {
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
4620 char_u *p;
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
4621 int c;
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
4622 int retval;
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
4623
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
4624 p = gettail_sep(fname);
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
4625 if (p == fname)
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
4626 return TRUE;
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
4627 c = *p;
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
4628 *p = NUL;
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
4629 retval = mch_isdir(fname);
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
4630 *p = c;
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
4631 return retval;
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
4632 }
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
4633
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4634 #if (defined(CASE_INSENSITIVE_FILENAME) && defined(BACKSLASH_IN_FILENAME)) \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4635 || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4636 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4637 * Versions of fnamecmp() and fnamencmp() that handle '/' and '\' equally.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4638 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4639 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4640 vim_fnamecmp(x, y)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4641 char_u *x, *y;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4642 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4643 return vim_fnamencmp(x, y, MAXPATHL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4644 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4645
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4646 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4647 vim_fnamencmp(x, y, len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4648 char_u *x, *y;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4649 size_t len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4650 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4651 while (len > 0 && *x && *y)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4652 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4653 if (TOLOWER_LOC(*x) != TOLOWER_LOC(*y)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4654 && !(*x == '/' && *y == '\\')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4655 && !(*x == '\\' && *y == '/'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4656 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4657 ++x;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4658 ++y;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4659 --len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4660 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4661 if (len == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4662 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4663 return (*x - *y);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4664 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4665 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4666
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4667 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4668 * Concatenate file names fname1 and fname2 into allocated memory.
1224
edc1c9d6dab9 updated for version 7.1b
vimboss
parents: 1096
diff changeset
4669 * Only add a '/' or '\\' when 'sep' is TRUE and it is necessary.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4670 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4671 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4672 concat_fnames(fname1, fname2, sep)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4673 char_u *fname1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4674 char_u *fname2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4675 int sep;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4676 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4677 char_u *dest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4678
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4679 dest = alloc((unsigned)(STRLEN(fname1) + STRLEN(fname2) + 3));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4680 if (dest != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4681 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4682 STRCPY(dest, fname1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4683 if (sep)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4684 add_pathsep(dest);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4685 STRCAT(dest, fname2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4686 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4687 return dest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4688 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4689
115
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
4690 /*
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
4691 * Concatenate two strings and return the result in allocated memory.
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
4692 * Returns NULL when out of memory.
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
4693 */
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
4694 char_u *
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
4695 concat_str(str1, str2)
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
4696 char_u *str1;
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
4697 char_u *str2;
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
4698 {
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
4699 char_u *dest;
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
4700 size_t l = STRLEN(str1);
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
4701
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
4702 dest = alloc((unsigned)(l + STRLEN(str2) + 1L));
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
4703 if (dest != NULL)
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
4704 {
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
4705 STRCPY(dest, str1);
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
4706 STRCPY(dest + l, str2);
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
4707 }
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
4708 return dest;
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
4709 }
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
4710
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4711 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4712 * Add a path separator to a file name, unless it already ends in a path
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4713 * separator.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4714 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4715 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4716 add_pathsep(p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4717 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4718 {
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4719 if (*p != NUL && !after_pathsep(p, p + STRLEN(p)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4720 STRCAT(p, PATHSEPSTR);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4721 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4722
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4723 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4724 * FullName_save - Make an allocated copy of a full file name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4725 * Returns NULL when out of memory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4726 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4727 char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4728 FullName_save(fname, force)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4729 char_u *fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4730 int force; /* force expansion, even when it already looks
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4731 like a full path name */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4732 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4733 char_u *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4734 char_u *new_fname = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4735
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4736 if (fname == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4737 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4738
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4739 buf = alloc((unsigned)MAXPATHL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4740 if (buf != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4741 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4742 if (vim_FullName(fname, buf, MAXPATHL, force) != FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4743 new_fname = vim_strsave(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4744 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4745 new_fname = vim_strsave(fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4746 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4747 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4748 return new_fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4749 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4750
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4751 #if defined(FEAT_CINDENT) || defined(FEAT_SYN_HL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4752
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4753 static char_u *skip_string __ARGS((char_u *p));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4754
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4755 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4756 * Find the start of a comment, not knowing if we are in a comment right now.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4757 * Search starts at w_cursor.lnum and goes backwards.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4758 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4759 pos_T *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4760 find_start_comment(ind_maxcomment) /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4761 int ind_maxcomment;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4762 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4763 pos_T *pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4764 char_u *line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4765 char_u *p;
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
4766 int cur_maxcomment = ind_maxcomment;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
4767
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
4768 for (;;)
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
4769 {
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
4770 pos = findmatchlimit(NULL, '*', FM_BACKWARD, cur_maxcomment);
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
4771 if (pos == NULL)
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
4772 break;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
4773
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
4774 /*
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
4775 * Check if the comment start we found is inside a string.
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
4776 * If it is then restrict the search to below this line and try again.
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
4777 */
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
4778 line = ml_get(pos->lnum);
1883
c8f343a465a2 updated for version 7.2-180
vimboss
parents: 1877
diff changeset
4779 for (p = line; *p && (colnr_T)(p - line) < pos->col; ++p)
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
4780 p = skip_string(p);
1883
c8f343a465a2 updated for version 7.2-180
vimboss
parents: 1877
diff changeset
4781 if ((colnr_T)(p - line) <= pos->col)
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
4782 break;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
4783 cur_maxcomment = curwin->w_cursor.lnum - pos->lnum - 1;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
4784 if (cur_maxcomment <= 0)
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
4785 {
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
4786 pos = NULL;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
4787 break;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
4788 }
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
4789 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4790 return pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4791 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4792
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4793 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4794 * Skip to the end of a "string" and a 'c' character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4795 * If there is no string or character, return argument unmodified.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4796 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4797 static char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4798 skip_string(p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4799 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4800 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4801 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4802
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4803 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4804 * We loop, because strings may be concatenated: "date""time".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4805 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4806 for ( ; ; ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4807 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4808 if (p[0] == '\'') /* 'c' or '\n' or '\000' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4809 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4810 if (!p[1]) /* ' at end of line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4811 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4812 i = 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4813 if (p[1] == '\\') /* '\n' or '\000' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4814 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4815 ++i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4816 while (vim_isdigit(p[i - 1])) /* '\000' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4817 ++i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4818 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4819 if (p[i] == '\'') /* check for trailing ' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4820 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4821 p += i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4822 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4823 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4824 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4825 else if (p[0] == '"') /* start of string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4826 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4827 for (++p; p[0]; ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4828 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4829 if (p[0] == '\\' && p[1] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4830 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4831 else if (p[0] == '"') /* end of string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4832 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4833 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4834 if (p[0] == '"')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4835 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4836 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4837 break; /* no string found */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4838 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4839 if (!*p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4840 --p; /* backup from NUL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4841 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4842 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4843 #endif /* FEAT_CINDENT || FEAT_SYN_HL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4844
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4845 #if defined(FEAT_CINDENT) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4846
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4847 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4848 * Do C or expression indenting on the current line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4849 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4850 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4851 do_c_expr_indent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4852 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4853 # ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4854 if (*curbuf->b_p_inde != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4855 fixthisline(get_expr_indent);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4856 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4857 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4858 fixthisline(get_c_indent);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4859 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4860
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4861 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4862 * Functions for C-indenting.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4863 * Most of this originally comes from Eric Fischer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4864 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4865 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4866 * Below "XXX" means that this function may unlock the current line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4867 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4868
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4869 static char_u *cin_skipcomment __ARGS((char_u *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4870 static int cin_nocode __ARGS((char_u *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4871 static pos_T *find_line_comment __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4872 static int cin_islabel_skip __ARGS((char_u **));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4873 static int cin_isdefault __ARGS((char_u *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4874 static char_u *after_label __ARGS((char_u *l));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4875 static int get_indent_nolabel __ARGS((linenr_T lnum));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4876 static int skip_label __ARGS((linenr_T, char_u **pp, int ind_maxcomment));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4877 static int cin_first_id_amount __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4878 static int cin_get_equal_amount __ARGS((linenr_T lnum));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4879 static int cin_ispreproc __ARGS((char_u *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4880 static int cin_ispreproc_cont __ARGS((char_u **pp, linenr_T *lnump));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4881 static int cin_iscomment __ARGS((char_u *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4882 static int cin_islinecomment __ARGS((char_u *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4883 static int cin_isterminated __ARGS((char_u *, int, int));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4884 static int cin_isinit __ARGS((void));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4885 static int cin_isfuncdecl __ARGS((char_u **, linenr_T));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4886 static int cin_isif __ARGS((char_u *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4887 static int cin_iselse __ARGS((char_u *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4888 static int cin_isdo __ARGS((char_u *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4889 static int cin_iswhileofdo __ARGS((char_u *, linenr_T, int));
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
4890 static int cin_iswhileofdo_end __ARGS((int terminated, int ind_maxparen, int ind_maxcomment));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4891 static int cin_isbreak __ARGS((char_u *));
1336
b8ebbfa519b9 updated for version 7.1-050
vimboss
parents: 1324
diff changeset
4892 static int cin_is_cpp_baseclass __ARGS((colnr_T *col));
828
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
4893 static int get_baseclass_amount __ARGS((int col, int ind_maxparen, int ind_maxcomment, int ind_cpp_baseclass));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4894 static int cin_ends_in __ARGS((char_u *, char_u *, char_u *));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4895 static int cin_skip2pos __ARGS((pos_T *trypos));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4896 static pos_T *find_start_brace __ARGS((int));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4897 static pos_T *find_match_paren __ARGS((int, int));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4898 static int corr_ind_maxparen __ARGS((int ind_maxparen, pos_T *startpos));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4899 static int find_last_paren __ARGS((char_u *l, int start, int end));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4900 static int find_match __ARGS((int lookfor, linenr_T ourscope, int ind_maxparen, int ind_maxcomment));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4901
1096
83eda510dbc0 updated for version 7.0-222
vimboss
parents: 1023
diff changeset
4902 static int ind_hash_comment = 0; /* # starts a comment */
83eda510dbc0 updated for version 7.0-222
vimboss
parents: 1023
diff changeset
4903
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4904 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4905 * Skip over white space and C comments within the line.
1096
83eda510dbc0 updated for version 7.0-222
vimboss
parents: 1023
diff changeset
4906 * Also skip over Perl/shell comments if desired.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4907 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4908 static char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4909 cin_skipcomment(s)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4910 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4911 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4912 while (*s)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4913 {
1096
83eda510dbc0 updated for version 7.0-222
vimboss
parents: 1023
diff changeset
4914 char_u *prev_s = s;
83eda510dbc0 updated for version 7.0-222
vimboss
parents: 1023
diff changeset
4915
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4916 s = skipwhite(s);
1096
83eda510dbc0 updated for version 7.0-222
vimboss
parents: 1023
diff changeset
4917
83eda510dbc0 updated for version 7.0-222
vimboss
parents: 1023
diff changeset
4918 /* Perl/shell # comment comment continues until eol. Require a space
83eda510dbc0 updated for version 7.0-222
vimboss
parents: 1023
diff changeset
4919 * before # to avoid recognizing $#array. */
83eda510dbc0 updated for version 7.0-222
vimboss
parents: 1023
diff changeset
4920 if (ind_hash_comment != 0 && s != prev_s && *s == '#')
83eda510dbc0 updated for version 7.0-222
vimboss
parents: 1023
diff changeset
4921 {
83eda510dbc0 updated for version 7.0-222
vimboss
parents: 1023
diff changeset
4922 s += STRLEN(s);
83eda510dbc0 updated for version 7.0-222
vimboss
parents: 1023
diff changeset
4923 break;
83eda510dbc0 updated for version 7.0-222
vimboss
parents: 1023
diff changeset
4924 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4925 if (*s != '/')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4926 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4927 ++s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4928 if (*s == '/') /* slash-slash comment continues till eol */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4929 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4930 s += STRLEN(s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4931 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4932 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4933 if (*s != '*')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4934 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4935 for (++s; *s; ++s) /* skip slash-star comment */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4936 if (s[0] == '*' && s[1] == '/')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4937 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4938 s += 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4939 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4940 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4941 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4942 return s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4943 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4944
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4945 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4946 * Return TRUE if there there is no code at *s. White space and comments are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4947 * not considered code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4948 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4949 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4950 cin_nocode(s)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4951 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4952 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4953 return *cin_skipcomment(s) == NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4954 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4955
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4956 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4957 * Check previous lines for a "//" line comment, skipping over blank lines.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4958 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4959 static pos_T *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4960 find_line_comment() /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4961 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4962 static pos_T pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4963 char_u *line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4964 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4965
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4966 pos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4967 while (--pos.lnum > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4968 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4969 line = ml_get(pos.lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4970 p = skipwhite(line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4971 if (cin_islinecomment(p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4972 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4973 pos.col = (int)(p - line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4974 return &pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4975 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4976 if (*p != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4977 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4978 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4979 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4980 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4981
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4982 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4983 * Check if string matches "label:"; move to character after ':' if true.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4984 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4985 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4986 cin_islabel_skip(s)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4987 char_u **s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4988 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4989 if (!vim_isIDc(**s)) /* need at least one ID character */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4990 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4991
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4992 while (vim_isIDc(**s))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4993 (*s)++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4994
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4995 *s = cin_skipcomment(*s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4996
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4997 /* "::" is not a label, it's C++ */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4998 return (**s == ':' && *++*s != ':');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4999 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5000
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5001 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5002 * Recognize a label: "label:".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5003 * Note: curwin->w_cursor must be where we are looking for the label.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5004 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5005 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5006 cin_islabel(ind_maxcomment) /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5007 int ind_maxcomment;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5008 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5009 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5010
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5011 s = cin_skipcomment(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5012
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5013 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5014 * Exclude "default" from labels, since it should be indented
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5015 * like a switch label. Same for C++ scope declarations.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5016 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5017 if (cin_isdefault(s))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5018 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5019 if (cin_isscopedecl(s))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5020 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5021
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5022 if (cin_islabel_skip(&s))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5023 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5024 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5025 * Only accept a label if the previous line is terminated or is a case
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5026 * label.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5027 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5028 pos_T cursor_save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5029 pos_T *trypos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5030 char_u *line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5031
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5032 cursor_save = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5033 while (curwin->w_cursor.lnum > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5034 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5035 --curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5036
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5037 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5038 * If we're in a comment now, skip to the start of the comment.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5039 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5040 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5041 if ((trypos = find_start_comment(ind_maxcomment)) != NULL) /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5042 curwin->w_cursor = *trypos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5043
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5044 line = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5045 if (cin_ispreproc(line)) /* ignore #defines, #if, etc. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5046 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5047 if (*(line = cin_skipcomment(line)) == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5048 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5049
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5050 curwin->w_cursor = cursor_save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5051 if (cin_isterminated(line, TRUE, FALSE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5052 || cin_isscopedecl(line)
2297
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
5053 || cin_iscase(line, TRUE)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5054 || (cin_islabel_skip(&line) && cin_nocode(line)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5055 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5056 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5057 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5058 curwin->w_cursor = cursor_save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5059 return TRUE; /* label at start of file??? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5060 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5061 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5062 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5063
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5064 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5065 * Recognize structure initialization and enumerations.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5066 * Q&D-Implementation:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5067 * check for "=" at end or "[typedef] enum" at beginning of line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5068 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5069 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5070 cin_isinit(void)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5071 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5072 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5073
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5074 s = cin_skipcomment(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5075
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5076 if (STRNCMP(s, "typedef", 7) == 0 && !vim_isIDc(s[7]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5077 s = cin_skipcomment(s + 7);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5078
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5079 if (STRNCMP(s, "enum", 4) == 0 && !vim_isIDc(s[4]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5080 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5081
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5082 if (cin_ends_in(s, (char_u *)"=", (char_u *)"{"))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5083 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5084
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5085 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5086 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5087
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5088 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5089 * Recognize a switch label: "case .*:" or "default:".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5090 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5091 int
2297
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
5092 cin_iscase(s, strict)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5093 char_u *s;
2297
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
5094 int strict; /* Allow relaxed check of case statement for JS */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5095 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5096 s = cin_skipcomment(s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5097 if (STRNCMP(s, "case", 4) == 0 && !vim_isIDc(s[4]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5098 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5099 for (s += 4; *s; ++s)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5100 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5101 s = cin_skipcomment(s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5102 if (*s == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5103 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5104 if (s[1] == ':') /* skip over "::" for C++ */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5105 ++s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5106 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5107 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5108 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5109 if (*s == '\'' && s[1] && s[2] == '\'')
2297
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
5110 s += 2; /* skip over ':' */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5111 else if (*s == '/' && (s[1] == '*' || s[1] == '/'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5112 return FALSE; /* stop at comment */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5113 else if (*s == '"')
2297
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
5114 {
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
5115 /* JS etc. */
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
5116 if (strict)
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
5117 return FALSE; /* stop at string */
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
5118 else
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
5119 return TRUE;
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
5120 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5121 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5122 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5123 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5124
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5125 if (cin_isdefault(s))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5126 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5127 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5128 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5129
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5130 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5131 * Recognize a "default" switch label.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5132 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5133 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5134 cin_isdefault(s)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5135 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5136 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5137 return (STRNCMP(s, "default", 7) == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5138 && *(s = cin_skipcomment(s + 7)) == ':'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5139 && s[1] != ':');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5140 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5141
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5142 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5143 * Recognize a "public/private/proctected" scope declaration label.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5144 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5145 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5146 cin_isscopedecl(s)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5147 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5148 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5149 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5150
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5151 s = cin_skipcomment(s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5152 if (STRNCMP(s, "public", 6) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5153 i = 6;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5154 else if (STRNCMP(s, "protected", 9) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5155 i = 9;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5156 else if (STRNCMP(s, "private", 7) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5157 i = 7;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5158 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5159 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5160 return (*(s = cin_skipcomment(s + i)) == ':' && s[1] != ':');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5161 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5162
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5163 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5164 * Return a pointer to the first non-empty non-comment character after a ':'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5165 * Return NULL if not found.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5166 * case 234: a = b;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5167 * ^
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5168 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5169 static char_u *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5170 after_label(l)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5171 char_u *l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5172 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5173 for ( ; *l; ++l)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5174 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5175 if (*l == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5176 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5177 if (l[1] == ':') /* skip over "::" for C++ */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5178 ++l;
2297
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
5179 else if (!cin_iscase(l + 1, FALSE))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5180 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5181 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5182 else if (*l == '\'' && l[1] && l[2] == '\'')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5183 l += 2; /* skip over 'x' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5184 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5185 if (*l == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5186 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5187 l = cin_skipcomment(l + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5188 if (*l == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5189 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5190 return l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5191 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5192
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5193 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5194 * Get indent of line "lnum", skipping a label.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5195 * Return 0 if there is nothing after the label.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5196 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5197 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5198 get_indent_nolabel(lnum) /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5199 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5200 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5201 char_u *l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5202 pos_T fp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5203 colnr_T col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5204 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5205
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5206 l = ml_get(lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5207 p = after_label(l);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5208 if (p == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5209 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5210
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5211 fp.col = (colnr_T)(p - l);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5212 fp.lnum = lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5213 getvcol(curwin, &fp, &col, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5214 return (int)col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5215 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5216
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5217 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5218 * Find indent for line "lnum", ignoring any case or jump label.
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5219 * Also return a pointer to the text (after the label) in "pp".
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5220 * label: if (asdf && asdfasdf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5221 * ^
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5222 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5223 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5224 skip_label(lnum, pp, ind_maxcomment)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5225 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5226 char_u **pp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5227 int ind_maxcomment;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5228 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5229 char_u *l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5230 int amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5231 pos_T cursor_save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5232
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5233 cursor_save = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5234 curwin->w_cursor.lnum = lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5235 l = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5236 /* XXX */
2297
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
5237 if (cin_iscase(l, FALSE) || cin_isscopedecl(l)
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
5238 || cin_islabel(ind_maxcomment))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5239 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5240 amount = get_indent_nolabel(lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5241 l = after_label(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5242 if (l == NULL) /* just in case */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5243 l = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5244 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5245 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5246 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5247 amount = get_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5248 l = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5249 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5250 *pp = l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5251
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5252 curwin->w_cursor = cursor_save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5253 return amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5254 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5255
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5256 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5257 * Return the indent of the first variable name after a type in a declaration.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5258 * int a, indent of "a"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5259 * static struct foo b, indent of "b"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5260 * enum bla c, indent of "c"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5261 * Returns zero when it doesn't look like a declaration.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5262 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5263 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5264 cin_first_id_amount()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5265 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5266 char_u *line, *p, *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5267 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5268 pos_T fp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5269 colnr_T col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5270
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5271 line = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5272 p = skipwhite(line);
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 834
diff changeset
5273 len = (int)(skiptowhite(p) - p);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5274 if (len == 6 && STRNCMP(p, "static", 6) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5275 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5276 p = skipwhite(p + 6);
856
8cd729851562 updated for version 7.0g
vimboss
parents: 840
diff changeset
5277 len = (int)(skiptowhite(p) - p);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5278 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5279 if (len == 6 && STRNCMP(p, "struct", 6) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5280 p = skipwhite(p + 6);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5281 else if (len == 4 && STRNCMP(p, "enum", 4) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5282 p = skipwhite(p + 4);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5283 else if ((len == 8 && STRNCMP(p, "unsigned", 8) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5284 || (len == 6 && STRNCMP(p, "signed", 6) == 0))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5285 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5286 s = skipwhite(p + len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5287 if ((STRNCMP(s, "int", 3) == 0 && vim_iswhite(s[3]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5288 || (STRNCMP(s, "long", 4) == 0 && vim_iswhite(s[4]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5289 || (STRNCMP(s, "short", 5) == 0 && vim_iswhite(s[5]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5290 || (STRNCMP(s, "char", 4) == 0 && vim_iswhite(s[4])))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5291 p = s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5292 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5293 for (len = 0; vim_isIDc(p[len]); ++len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5294 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5295 if (len == 0 || !vim_iswhite(p[len]) || cin_nocode(p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5296 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5297
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5298 p = skipwhite(p + len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5299 fp.lnum = curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5300 fp.col = (colnr_T)(p - line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5301 getvcol(curwin, &fp, &col, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5302 return (int)col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5303 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5304
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5305 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5306 * Return the indent of the first non-blank after an equal sign.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5307 * char *foo = "here";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5308 * Return zero if no (useful) equal sign found.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5309 * Return -1 if the line above "lnum" ends in a backslash.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5310 * foo = "asdf\
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5311 * asdf\
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5312 * here";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5313 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5314 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5315 cin_get_equal_amount(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5316 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5317 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5318 char_u *line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5319 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5320 colnr_T col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5321 pos_T fp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5322
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5323 if (lnum > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5324 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5325 line = ml_get(lnum - 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5326 if (*line != NUL && line[STRLEN(line) - 1] == '\\')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5327 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5328 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5329
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5330 line = s = ml_get(lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5331 while (*s != NUL && vim_strchr((char_u *)"=;{}\"'", *s) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5332 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5333 if (cin_iscomment(s)) /* ignore comments */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5334 s = cin_skipcomment(s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5335 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5336 ++s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5337 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5338 if (*s != '=')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5339 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5340
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5341 s = skipwhite(s + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5342 if (cin_nocode(s))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5343 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5344
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5345 if (*s == '"') /* nice alignment for continued strings */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5346 ++s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5347
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5348 fp.lnum = lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5349 fp.col = (colnr_T)(s - line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5350 getvcol(curwin, &fp, &col, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5351 return (int)col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5352 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5353
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5354 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5355 * Recognize a preprocessor statement: Any line that starts with '#'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5356 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5357 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5358 cin_ispreproc(s)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5359 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5360 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5361 s = skipwhite(s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5362 if (*s == '#')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5363 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5364 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5365 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5366
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5367 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5368 * Return TRUE if line "*pp" at "*lnump" is a preprocessor statement or a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5369 * continuation line of a preprocessor statement. Decrease "*lnump" to the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5370 * start and return the line in "*pp".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5371 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5372 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5373 cin_ispreproc_cont(pp, lnump)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5374 char_u **pp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5375 linenr_T *lnump;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5376 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5377 char_u *line = *pp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5378 linenr_T lnum = *lnump;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5379 int retval = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5380
408
06234af3a8b7 updated for version 7.0106
vimboss
parents: 375
diff changeset
5381 for (;;)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5382 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5383 if (cin_ispreproc(line))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5384 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5385 retval = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5386 *lnump = lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5387 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5388 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5389 if (lnum == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5390 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5391 line = ml_get(--lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5392 if (*line == NUL || line[STRLEN(line) - 1] != '\\')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5393 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5394 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5395
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5396 if (lnum != *lnump)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5397 *pp = ml_get(*lnump);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5398 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5399 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5400
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5401 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5402 * Recognize the start of a C or C++ comment.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5403 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5404 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5405 cin_iscomment(p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5406 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5407 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5408 return (p[0] == '/' && (p[1] == '*' || p[1] == '/'));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5409 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5410
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5411 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5412 * Recognize the start of a "//" comment.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5413 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5414 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5415 cin_islinecomment(p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5416 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5417 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5418 return (p[0] == '/' && p[1] == '/');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5419 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5420
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5421 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5422 * Recognize a line that starts with '{' or '}', or ends with ';', '{' or '}'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5423 * Don't consider "} else" a terminated line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5424 * Return the character terminating the line (ending char's have precedence if
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5425 * both apply in order to determine initializations).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5426 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5427 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5428 cin_isterminated(s, incl_open, incl_comma)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5429 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5430 int incl_open; /* include '{' at the end as terminator */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5431 int incl_comma; /* recognize a trailing comma */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5432 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5433 char_u found_start = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5434
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5435 s = cin_skipcomment(s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5436
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5437 if (*s == '{' || (*s == '}' && !cin_iselse(s)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5438 found_start = *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5439
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5440 while (*s)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5441 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5442 /* skip over comments, "" strings and 'c'haracters */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5443 s = skip_string(cin_skipcomment(s));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5444 if ((*s == ';' || (incl_open && *s == '{') || *s == '}'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5445 || (incl_comma && *s == ','))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5446 && cin_nocode(s + 1))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5447 return *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5448
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5449 if (*s)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5450 s++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5451 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5452 return found_start;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5453 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5454
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5455 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5456 * Recognize the basic picture of a function declaration -- it needs to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5457 * have an open paren somewhere and a close paren at the end of the line and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5458 * no semicolons anywhere.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5459 * When a line ends in a comma we continue looking in the next line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5460 * "sp" points to a string with the line. When looking at other lines it must
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5461 * be restored to the line. When it's NULL fetch lines here.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5462 * "lnum" is where we start looking.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5463 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5464 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5465 cin_isfuncdecl(sp, first_lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5466 char_u **sp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5467 linenr_T first_lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5468 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5469 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5470 linenr_T lnum = first_lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5471 int retval = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5472
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5473 if (sp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5474 s = ml_get(lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5475 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5476 s = *sp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5477
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5478 while (*s && *s != '(' && *s != ';' && *s != '\'' && *s != '"')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5479 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5480 if (cin_iscomment(s)) /* ignore comments */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5481 s = cin_skipcomment(s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5482 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5483 ++s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5484 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5485 if (*s != '(')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5486 return FALSE; /* ';', ' or " before any () or no '(' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5487
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5488 while (*s && *s != ';' && *s != '\'' && *s != '"')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5489 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5490 if (*s == ')' && cin_nocode(s + 1))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5491 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5492 /* ')' at the end: may have found a match
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5493 * Check for he previous line not to end in a backslash:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5494 * #if defined(x) && \
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5495 * defined(y)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5496 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5497 lnum = first_lnum - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5498 s = ml_get(lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5499 if (*s == NUL || s[STRLEN(s) - 1] != '\\')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5500 retval = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5501 goto done;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5502 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5503 if (*s == ',' && cin_nocode(s + 1))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5504 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5505 /* ',' at the end: continue looking in the next line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5506 if (lnum >= curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5507 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5508
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5509 s = ml_get(++lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5510 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5511 else if (cin_iscomment(s)) /* ignore comments */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5512 s = cin_skipcomment(s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5513 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5514 ++s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5515 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5516
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5517 done:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5518 if (lnum != first_lnum && sp != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5519 *sp = ml_get(first_lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5520
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5521 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5522 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5523
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5524 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5525 cin_isif(p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5526 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5527 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5528 return (STRNCMP(p, "if", 2) == 0 && !vim_isIDc(p[2]));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5529 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5530
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5531 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5532 cin_iselse(p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5533 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5534 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5535 if (*p == '}') /* accept "} else" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5536 p = cin_skipcomment(p + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5537 return (STRNCMP(p, "else", 4) == 0 && !vim_isIDc(p[4]));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5538 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5539
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5540 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5541 cin_isdo(p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5542 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5543 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5544 return (STRNCMP(p, "do", 2) == 0 && !vim_isIDc(p[2]));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5545 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5546
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5547 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5548 * Check if this is a "while" that should have a matching "do".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5549 * We only accept a "while (condition) ;", with only white space between the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5550 * ')' and ';'. The condition may be spread over several lines.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5551 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5552 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5553 cin_iswhileofdo(p, lnum, ind_maxparen) /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5554 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5555 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5556 int ind_maxparen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5557 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5558 pos_T cursor_save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5559 pos_T *trypos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5560 int retval = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5561
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5562 p = cin_skipcomment(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5563 if (*p == '}') /* accept "} while (cond);" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5564 p = cin_skipcomment(p + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5565 if (STRNCMP(p, "while", 5) == 0 && !vim_isIDc(p[5]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5566 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5567 cursor_save = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5568 curwin->w_cursor.lnum = lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5569 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5570 p = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5571 while (*p && *p != 'w') /* skip any '}', until the 'w' of the "while" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5572 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5573 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5574 ++curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5575 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5576 if ((trypos = findmatchlimit(NULL, 0, 0, ind_maxparen)) != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5577 && *cin_skipcomment(ml_get_pos(trypos) + 1) == ';')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5578 retval = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5579 curwin->w_cursor = cursor_save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5580 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5581 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5582 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5583
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5584 /*
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5585 * Return TRUE if we are at the end of a do-while.
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5586 * do
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5587 * nothing;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5588 * while (foo
856
8cd729851562 updated for version 7.0g
vimboss
parents: 840
diff changeset
5589 * && bar); <-- here
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5590 * Adjust the cursor to the line with "while".
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5591 */
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5592 static int
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5593 cin_iswhileofdo_end(terminated, ind_maxparen, ind_maxcomment)
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5594 int terminated;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5595 int ind_maxparen;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5596 int ind_maxcomment;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5597 {
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5598 char_u *line;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5599 char_u *p;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5600 char_u *s;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5601 pos_T *trypos;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5602 int i;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5603
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5604 if (terminated != ';') /* there must be a ';' at the end */
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5605 return FALSE;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5606
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5607 p = line = ml_get_curline();
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5608 while (*p != NUL)
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5609 {
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5610 p = cin_skipcomment(p);
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5611 if (*p == ')')
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5612 {
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5613 s = skipwhite(p + 1);
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5614 if (*s == ';' && cin_nocode(s + 1))
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5615 {
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5616 /* Found ");" at end of the line, now check there is "while"
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5617 * before the matching '('. XXX */
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 834
diff changeset
5618 i = (int)(p - line);
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5619 curwin->w_cursor.col = i;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5620 trypos = find_match_paren(ind_maxparen, ind_maxcomment);
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5621 if (trypos != NULL)
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5622 {
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5623 s = cin_skipcomment(ml_get(trypos->lnum));
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5624 if (*s == '}') /* accept "} while (cond);" */
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5625 s = cin_skipcomment(s + 1);
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5626 if (STRNCMP(s, "while", 5) == 0 && !vim_isIDc(s[5]))
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5627 {
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5628 curwin->w_cursor.lnum = trypos->lnum;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5629 return TRUE;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5630 }
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5631 }
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5632
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5633 /* Searching may have made "line" invalid, get it again. */
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5634 line = ml_get_curline();
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5635 p = line + i;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5636 }
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5637 }
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5638 if (*p != NUL)
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5639 ++p;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5640 }
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5641 return FALSE;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5642 }
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5643
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5644 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5645 cin_isbreak(p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5646 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5647 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5648 return (STRNCMP(p, "break", 5) == 0 && !vim_isIDc(p[5]));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5649 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5650
828
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5651 /*
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5652 * Find the position of a C++ base-class declaration or
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5653 * constructor-initialization. eg:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5654 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5655 * class MyClass :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5656 * baseClass <-- here
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5657 * class MyClass : public baseClass,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5658 * anotherBaseClass <-- here (should probably lineup ??)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5659 * MyClass::MyClass(...) :
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5660 * baseClass(...) <-- here (constructor-initialization)
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
5661 *
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
5662 * This is a lot of guessing. Watch out for "cond ? func() : foo".
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5663 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5664 static int
1336
b8ebbfa519b9 updated for version 7.1-050
vimboss
parents: 1324
diff changeset
5665 cin_is_cpp_baseclass(col)
828
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5666 colnr_T *col; /* return: column to align with */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5667 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5668 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5669 int class_or_struct, lookfor_ctor_init, cpp_base_class;
828
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5670 linenr_T lnum = curwin->w_cursor.lnum;
1336
b8ebbfa519b9 updated for version 7.1-050
vimboss
parents: 1324
diff changeset
5671 char_u *line = ml_get_curline();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5672
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5673 *col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5674
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
5675 s = skipwhite(line);
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
5676 if (*s == '#') /* skip #define FOO x ? (x) : x */
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
5677 return FALSE;
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
5678 s = cin_skipcomment(s);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5679 if (*s == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5680 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5681
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5682 cpp_base_class = lookfor_ctor_init = class_or_struct = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5683
828
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5684 /* Search for a line starting with '#', empty, ending in ';' or containing
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5685 * '{' or '}' and start below it. This handles the following situations:
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5686 * a = cond ?
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5687 * func() :
856
8cd729851562 updated for version 7.0g
vimboss
parents: 840
diff changeset
5688 * asdf;
828
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5689 * func::foo()
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5690 * : something
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5691 * {}
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5692 * Foo::Foo (int one, int two)
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5693 * : something(4),
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5694 * somethingelse(3)
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5695 * {}
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5696 */
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5697 while (lnum > 1)
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5698 {
1336
b8ebbfa519b9 updated for version 7.1-050
vimboss
parents: 1324
diff changeset
5699 line = ml_get(lnum - 1);
b8ebbfa519b9 updated for version 7.1-050
vimboss
parents: 1324
diff changeset
5700 s = skipwhite(line);
828
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5701 if (*s == '#' || *s == NUL)
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5702 break;
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5703 while (*s != NUL)
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5704 {
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5705 s = cin_skipcomment(s);
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5706 if (*s == '{' || *s == '}'
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5707 || (*s == ';' && cin_nocode(s + 1)))
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5708 break;
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5709 if (*s != NUL)
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5710 ++s;
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5711 }
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5712 if (*s != NUL)
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5713 break;
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5714 --lnum;
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5715 }
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5716
1336
b8ebbfa519b9 updated for version 7.1-050
vimboss
parents: 1324
diff changeset
5717 line = ml_get(lnum);
b8ebbfa519b9 updated for version 7.1-050
vimboss
parents: 1324
diff changeset
5718 s = cin_skipcomment(line);
828
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5719 for (;;)
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5720 {
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5721 if (*s == NUL)
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5722 {
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5723 if (lnum == curwin->w_cursor.lnum)
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5724 break;
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5725 /* Continue in the cursor line. */
1336
b8ebbfa519b9 updated for version 7.1-050
vimboss
parents: 1324
diff changeset
5726 line = ml_get(++lnum);
b8ebbfa519b9 updated for version 7.1-050
vimboss
parents: 1324
diff changeset
5727 s = cin_skipcomment(line);
b8ebbfa519b9 updated for version 7.1-050
vimboss
parents: 1324
diff changeset
5728 if (*s == NUL)
b8ebbfa519b9 updated for version 7.1-050
vimboss
parents: 1324
diff changeset
5729 continue;
828
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5730 }
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5731
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5732 if (s[0] == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5733 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5734 if (s[1] == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5735 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5736 /* skip double colon. It can't be a constructor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5737 * initialization any more */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5738 lookfor_ctor_init = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5739 s = cin_skipcomment(s + 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5740 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5741 else if (lookfor_ctor_init || class_or_struct)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5742 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5743 /* we have something found, that looks like the start of
1532
87b9f21264a7 updated for version 7.1-247
vimboss
parents: 1521
diff changeset
5744 * cpp-base-class-declaration or constructor-initialization */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5745 cpp_base_class = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5746 lookfor_ctor_init = class_or_struct = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5747 *col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5748 s = cin_skipcomment(s + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5749 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5750 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5751 s = cin_skipcomment(s + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5752 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5753 else if ((STRNCMP(s, "class", 5) == 0 && !vim_isIDc(s[5]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5754 || (STRNCMP(s, "struct", 6) == 0 && !vim_isIDc(s[6])))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5755 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5756 class_or_struct = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5757 lookfor_ctor_init = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5758
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5759 if (*s == 'c')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5760 s = cin_skipcomment(s + 5);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5761 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5762 s = cin_skipcomment(s + 6);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5763 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5764 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5765 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5766 if (s[0] == '{' || s[0] == '}' || s[0] == ';')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5767 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5768 cpp_base_class = lookfor_ctor_init = class_or_struct = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5769 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5770 else if (s[0] == ')')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5771 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5772 /* Constructor-initialization is assumed if we come across
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5773 * something like "):" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5774 class_or_struct = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5775 lookfor_ctor_init = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5776 }
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
5777 else if (s[0] == '?')
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
5778 {
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
5779 /* Avoid seeing '() :' after '?' as constructor init. */
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
5780 return FALSE;
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
5781 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5782 else if (!vim_isIDc(s[0]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5783 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5784 /* if it is not an identifier, we are wrong */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5785 class_or_struct = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5786 lookfor_ctor_init = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5787 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5788 else if (*col == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5789 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5790 /* it can't be a constructor-initialization any more */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5791 lookfor_ctor_init = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5792
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5793 /* the first statement starts here: lineup with this one... */
828
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5794 if (cpp_base_class)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5795 *col = (colnr_T)(s - line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5796 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5797
828
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5798 /* When the line ends in a comma don't align with it. */
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5799 if (lnum == curwin->w_cursor.lnum && *s == ',' && cin_nocode(s + 1))
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5800 *col = 0;
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5801
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5802 s = cin_skipcomment(s + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5803 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5804 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5805
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5806 return cpp_base_class;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5807 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5808
828
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5809 static int
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5810 get_baseclass_amount(col, ind_maxparen, ind_maxcomment, ind_cpp_baseclass)
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5811 int col;
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5812 int ind_maxparen;
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5813 int ind_maxcomment;
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5814 int ind_cpp_baseclass;
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5815 {
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5816 int amount;
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5817 colnr_T vcol;
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5818 pos_T *trypos;
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5819
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5820 if (col == 0)
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5821 {
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5822 amount = get_indent();
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5823 if (find_last_paren(ml_get_curline(), '(', ')')
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5824 && (trypos = find_match_paren(ind_maxparen,
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5825 ind_maxcomment)) != NULL)
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5826 amount = get_indent_lnum(trypos->lnum); /* XXX */
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5827 if (!cin_ends_in(ml_get_curline(), (char_u *)",", NULL))
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5828 amount += ind_cpp_baseclass;
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5829 }
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5830 else
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5831 {
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5832 curwin->w_cursor.col = col;
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5833 getvcol(curwin, &curwin->w_cursor, &vcol, NULL, NULL);
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5834 amount = (int)vcol;
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5835 }
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5836 if (amount < ind_cpp_baseclass)
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5837 amount = ind_cpp_baseclass;
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5838 return amount;
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5839 }
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
5840
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5841 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5842 * Return TRUE if string "s" ends with the string "find", possibly followed by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5843 * white space and comments. Skip strings and comments.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5844 * Ignore "ignore" after "find" if it's not NULL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5845 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5846 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5847 cin_ends_in(s, find, ignore)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5848 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5849 char_u *find;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5850 char_u *ignore;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5851 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5852 char_u *p = s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5853 char_u *r;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5854 int len = (int)STRLEN(find);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5855
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5856 while (*p != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5857 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5858 p = cin_skipcomment(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5859 if (STRNCMP(p, find, len) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5860 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5861 r = skipwhite(p + len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5862 if (ignore != NULL && STRNCMP(r, ignore, STRLEN(ignore)) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5863 r = skipwhite(r + STRLEN(ignore));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5864 if (cin_nocode(r))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5865 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5866 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5867 if (*p != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5868 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5869 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5870 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5871 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5872
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5873 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5874 * Skip strings, chars and comments until at or past "trypos".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5875 * Return the column found.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5876 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5877 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5878 cin_skip2pos(trypos)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5879 pos_T *trypos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5880 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5881 char_u *line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5882 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5883
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5884 p = line = ml_get(trypos->lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5885 while (*p && (colnr_T)(p - line) < trypos->col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5886 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5887 if (cin_iscomment(p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5888 p = cin_skipcomment(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5889 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5890 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5891 p = skip_string(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5892 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5893 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5894 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5895 return (int)(p - line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5896 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5897
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5898 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5899 * Find the '{' at the start of the block we are in.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5900 * Return NULL if no match found.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5901 * Ignore a '{' that is in a comment, makes indenting the next three lines
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5902 * work. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5903 /* foo() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5904 /* { */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5905 /* } */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5906
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5907 static pos_T *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5908 find_start_brace(ind_maxcomment) /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5909 int ind_maxcomment;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5910 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5911 pos_T cursor_save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5912 pos_T *trypos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5913 pos_T *pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5914 static pos_T pos_copy;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5915
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5916 cursor_save = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5917 while ((trypos = findmatchlimit(NULL, '{', FM_BLOCKSTOP, 0)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5918 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5919 pos_copy = *trypos; /* copy pos_T, next findmatch will change it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5920 trypos = &pos_copy;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5921 curwin->w_cursor = *trypos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5922 pos = NULL;
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5923 /* ignore the { if it's in a // or / * * / comment */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5924 if ((colnr_T)cin_skip2pos(trypos) == trypos->col
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5925 && (pos = find_start_comment(ind_maxcomment)) == NULL) /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5926 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5927 if (pos != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5928 curwin->w_cursor.lnum = pos->lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5929 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5930 curwin->w_cursor = cursor_save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5931 return trypos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5932 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5933
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5934 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5935 * Find the matching '(', failing if it is in a comment.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5936 * Return NULL of no match found.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5937 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5938 static pos_T *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5939 find_match_paren(ind_maxparen, ind_maxcomment) /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5940 int ind_maxparen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5941 int ind_maxcomment;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5942 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5943 pos_T cursor_save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5944 pos_T *trypos;
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
5945 static pos_T pos_copy;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5946
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5947 cursor_save = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5948 if ((trypos = findmatchlimit(NULL, '(', 0, ind_maxparen)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5949 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5950 /* check if the ( is in a // comment */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5951 if ((colnr_T)cin_skip2pos(trypos) > trypos->col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5952 trypos = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5953 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5954 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5955 pos_copy = *trypos; /* copy trypos, findmatch will change it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5956 trypos = &pos_copy;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5957 curwin->w_cursor = *trypos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5958 if (find_start_comment(ind_maxcomment) != NULL) /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5959 trypos = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5960 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5961 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5962 curwin->w_cursor = cursor_save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5963 return trypos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5964 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5965
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5966 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5967 * Return ind_maxparen corrected for the difference in line number between the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5968 * cursor position and "startpos". This makes sure that searching for a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5969 * matching paren above the cursor line doesn't find a match because of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5970 * looking a few lines further.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5971 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5972 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5973 corr_ind_maxparen(ind_maxparen, startpos)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5974 int ind_maxparen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5975 pos_T *startpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5976 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5977 long n = (long)startpos->lnum - (long)curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5978
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5979 if (n > 0 && n < ind_maxparen / 2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5980 return ind_maxparen - (int)n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5981 return ind_maxparen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5982 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5983
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5984 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5985 * Set w_cursor.col to the column number of the last unmatched ')' or '{' in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5986 * line "l".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5987 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5988 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5989 find_last_paren(l, start, end)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5990 char_u *l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5991 int start, end;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5992 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5993 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5994 int retval = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5995 int open_count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5996
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5997 curwin->w_cursor.col = 0; /* default is start of line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5998
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5999 for (i = 0; l[i]; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6000 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6001 i = (int)(cin_skipcomment(l + i) - l); /* ignore parens in comments */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6002 i = (int)(skip_string(l + i) - l); /* ignore parens in quotes */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6003 if (l[i] == start)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6004 ++open_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6005 else if (l[i] == end)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6006 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6007 if (open_count > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6008 --open_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6009 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6010 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6011 curwin->w_cursor.col = i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6012 retval = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6013 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6014 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6015 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6016 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6017 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6018
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6019 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6020 get_c_indent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6021 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6022 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6023 * spaces from a block's opening brace the prevailing indent for that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6024 * block should be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6025 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6026 int ind_level = curbuf->b_p_sw;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6027
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6028 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6029 * spaces from the edge of the line an open brace that's at the end of a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6030 * line is imagined to be.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6031 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6032 int ind_open_imag = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6033
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6034 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6035 * spaces from the prevailing indent for a line that is not precededof by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6036 * an opening brace.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6037 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6038 int ind_no_brace = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6039
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6040 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6041 * column where the first { of a function should be located }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6042 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6043 int ind_first_open = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6044
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6045 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6046 * spaces from the prevailing indent a leftmost open brace should be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6047 * located
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6048 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6049 int ind_open_extra = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6050
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6051 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6052 * spaces from the matching open brace (real location for one at the left
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6053 * edge; imaginary location from one that ends a line) the matching close
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6054 * brace should be located
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6055 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6056 int ind_close_extra = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6057
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6058 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6059 * spaces from the edge of the line an open brace sitting in the leftmost
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6060 * column is imagined to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6061 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6062 int ind_open_left_imag = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6063
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6064 /*
2328
15379284e55a Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents: 2322
diff changeset
6065 * Spaces jump labels should be shifted to the left if N is non-negative,
15379284e55a Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents: 2322
diff changeset
6066 * otherwise the jump label will be put to column 1.
15379284e55a Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents: 2322
diff changeset
6067 */
15379284e55a Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents: 2322
diff changeset
6068 int ind_jump_label = -1;
15379284e55a Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents: 2322
diff changeset
6069
15379284e55a Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents: 2322
diff changeset
6070 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6071 * spaces from the switch() indent a "case xx" label should be located
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6072 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6073 int ind_case = curbuf->b_p_sw;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6074
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6075 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6076 * spaces from the "case xx:" code after a switch() should be located
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6077 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6078 int ind_case_code = curbuf->b_p_sw;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6079
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6080 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6081 * lineup break at end of case in switch() with case label
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6082 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6083 int ind_case_break = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6084
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6085 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6086 * spaces from the class declaration indent a scope declaration label
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6087 * should be located
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6088 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6089 int ind_scopedecl = curbuf->b_p_sw;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6090
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6091 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6092 * spaces from the scope declaration label code should be located
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6093 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6094 int ind_scopedecl_code = curbuf->b_p_sw;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6095
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6096 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6097 * amount K&R-style parameters should be indented
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6098 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6099 int ind_param = curbuf->b_p_sw;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6100
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6101 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6102 * amount a function type spec should be indented
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6103 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6104 int ind_func_type = curbuf->b_p_sw;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6105
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6106 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6107 * amount a cpp base class declaration or constructor initialization
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6108 * should be indented
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6109 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6110 int ind_cpp_baseclass = curbuf->b_p_sw;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6111
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6112 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6113 * additional spaces beyond the prevailing indent a continuation line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6114 * should be located
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6115 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6116 int ind_continuation = curbuf->b_p_sw;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6117
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6118 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6119 * spaces from the indent of the line with an unclosed parentheses
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6120 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6121 int ind_unclosed = curbuf->b_p_sw * 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6122
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6123 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6124 * spaces from the indent of the line with an unclosed parentheses, which
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6125 * itself is also unclosed
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6126 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6127 int ind_unclosed2 = curbuf->b_p_sw;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6128
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6129 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6130 * suppress ignoring spaces from the indent of a line starting with an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6131 * unclosed parentheses.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6132 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6133 int ind_unclosed_noignore = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6134
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6135 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6136 * If the opening paren is the last nonwhite character on the line, and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6137 * ind_unclosed_wrapped is nonzero, use this indent relative to the outer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6138 * context (for very long lines).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6139 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6140 int ind_unclosed_wrapped = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6141
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6142 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6143 * suppress ignoring white space when lining up with the character after
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6144 * an unclosed parentheses.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6145 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6146 int ind_unclosed_whiteok = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6147
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6148 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6149 * indent a closing parentheses under the line start of the matching
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6150 * opening parentheses.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6151 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6152 int ind_matching_paren = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6153
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6154 /*
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6155 * indent a closing parentheses under the previous line.
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6156 */
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6157 int ind_paren_prev = 0;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6158
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6159 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6160 * Extra indent for comments.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6161 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6162 int ind_comment = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6163
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6164 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6165 * spaces from the comment opener when there is nothing after it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6166 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6167 int ind_in_comment = 3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6168
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6169 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6170 * boolean: if non-zero, use ind_in_comment even if there is something
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6171 * after the comment opener.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6172 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6173 int ind_in_comment2 = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6174
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6175 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6176 * max lines to search for an open paren
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6177 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6178 int ind_maxparen = 20;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6179
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6180 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6181 * max lines to search for an open comment
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6182 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6183 int ind_maxcomment = 70;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6184
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6185 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6186 * handle braces for java code
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6187 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6188 int ind_java = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6189
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6190 /*
2297
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
6191 * not to confuse JS object properties with labels
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
6192 */
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
6193 int ind_js = 0;
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
6194
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
6195 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6196 * handle blocked cases correctly
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6197 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6198 int ind_keep_case_label = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6199
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6200 pos_T cur_curpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6201 int amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6202 int scope_amount;
834
5117153003bd updated for version 7.0e
vimboss
parents: 829
diff changeset
6203 int cur_amount = MAXCOL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6204 colnr_T col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6205 char_u *theline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6206 char_u *linecopy;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6207 pos_T *trypos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6208 pos_T *tryposBrace = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6209 pos_T our_paren_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6210 char_u *start;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6211 int start_brace;
1532
87b9f21264a7 updated for version 7.1-247
vimboss
parents: 1521
diff changeset
6212 #define BRACE_IN_COL0 1 /* '{' is in column 0 */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6213 #define BRACE_AT_START 2 /* '{' is at start of line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6214 #define BRACE_AT_END 3 /* '{' is at end of line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6215 linenr_T ourscope;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6216 char_u *l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6217 char_u *look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6218 char_u terminated;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6219 int lookfor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6220 #define LOOKFOR_INITIAL 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6221 #define LOOKFOR_IF 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6222 #define LOOKFOR_DO 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6223 #define LOOKFOR_CASE 3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6224 #define LOOKFOR_ANY 4
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6225 #define LOOKFOR_TERM 5
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6226 #define LOOKFOR_UNTERM 6
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6227 #define LOOKFOR_SCOPEDECL 7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6228 #define LOOKFOR_NOBREAK 8
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6229 #define LOOKFOR_CPP_BASECLASS 9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6230 #define LOOKFOR_ENUM_OR_INIT 10
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6231
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6232 int whilelevel;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6233 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6234 char_u *options;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6235 int fraction = 0; /* init for GCC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6236 int divider;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6237 int n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6238 int iscase;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6239 int lookfor_break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6240 int cont_amount = 0; /* amount for continuation line */
2328
15379284e55a Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents: 2322
diff changeset
6241 int original_line_islabel;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6242
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6243 for (options = curbuf->b_p_cino; *options; )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6244 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6245 l = options++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6246 if (*options == '-')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6247 ++options;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6248 n = getdigits(&options);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6249 divider = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6250 if (*options == '.') /* ".5s" means a fraction */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6251 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6252 fraction = atol((char *)++options);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6253 while (VIM_ISDIGIT(*options))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6254 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6255 ++options;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6256 if (divider)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6257 divider *= 10;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6258 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6259 divider = 10;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6260 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6261 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6262 if (*options == 's') /* "2s" means two times 'shiftwidth' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6263 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6264 if (n == 0 && fraction == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6265 n = curbuf->b_p_sw; /* just "s" is one 'shiftwidth' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6266 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6267 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6268 n *= curbuf->b_p_sw;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6269 if (divider)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6270 n += (curbuf->b_p_sw * fraction + divider / 2) / divider;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6271 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6272 ++options;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6273 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6274 if (l[1] == '-')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6275 n = -n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6276 /* When adding an entry here, also update the default 'cinoptions' in
1096
83eda510dbc0 updated for version 7.0-222
vimboss
parents: 1023
diff changeset
6277 * doc/indent.txt, and add explanation for it! */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6278 switch (*l)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6279 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6280 case '>': ind_level = n; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6281 case 'e': ind_open_imag = n; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6282 case 'n': ind_no_brace = n; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6283 case 'f': ind_first_open = n; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6284 case '{': ind_open_extra = n; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6285 case '}': ind_close_extra = n; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6286 case '^': ind_open_left_imag = n; break;
2328
15379284e55a Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents: 2322
diff changeset
6287 case 'L': ind_jump_label = n; break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6288 case ':': ind_case = n; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6289 case '=': ind_case_code = n; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6290 case 'b': ind_case_break = n; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6291 case 'p': ind_param = n; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6292 case 't': ind_func_type = n; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6293 case '/': ind_comment = n; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6294 case 'c': ind_in_comment = n; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6295 case 'C': ind_in_comment2 = n; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6296 case 'i': ind_cpp_baseclass = n; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6297 case '+': ind_continuation = n; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6298 case '(': ind_unclosed = n; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6299 case 'u': ind_unclosed2 = n; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6300 case 'U': ind_unclosed_noignore = n; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6301 case 'W': ind_unclosed_wrapped = n; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6302 case 'w': ind_unclosed_whiteok = n; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6303 case 'm': ind_matching_paren = n; break;
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6304 case 'M': ind_paren_prev = n; break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6305 case ')': ind_maxparen = n; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6306 case '*': ind_maxcomment = n; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6307 case 'g': ind_scopedecl = n; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6308 case 'h': ind_scopedecl_code = n; break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6309 case 'j': ind_java = n; break;
2297
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
6310 case 'J': ind_js = n; break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6311 case 'l': ind_keep_case_label = n; break;
1096
83eda510dbc0 updated for version 7.0-222
vimboss
parents: 1023
diff changeset
6312 case '#': ind_hash_comment = n; break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6313 }
2129
24100651daa9 updated for version 7.2.411
Bram Moolenaar <bram@zimbu.org>
parents: 2094
diff changeset
6314 if (*options == ',')
24100651daa9 updated for version 7.2.411
Bram Moolenaar <bram@zimbu.org>
parents: 2094
diff changeset
6315 ++options;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6316 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6317
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6318 /* remember where the cursor was when we started */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6319 cur_curpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6320
2297
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
6321 /* if we are at line 1 0 is fine, right? */
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
6322 if (cur_curpos.lnum == 1)
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
6323 return 0;
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
6324
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6325 /* Get a copy of the current contents of the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6326 * This is required, because only the most recent line obtained with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6327 * ml_get is valid! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6328 linecopy = vim_strsave(ml_get(cur_curpos.lnum));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6329 if (linecopy == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6330 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6331
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6332 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6333 * In insert mode and the cursor is on a ')' truncate the line at the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6334 * cursor position. We don't want to line up with the matching '(' when
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6335 * inserting new stuff.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6336 * For unknown reasons the cursor might be past the end of the line, thus
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6337 * check for that.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6338 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6339 if ((State & INSERT)
1883
c8f343a465a2 updated for version 7.2-180
vimboss
parents: 1877
diff changeset
6340 && curwin->w_cursor.col < (colnr_T)STRLEN(linecopy)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6341 && linecopy[curwin->w_cursor.col] == ')')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6342 linecopy[curwin->w_cursor.col] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6343
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6344 theline = skipwhite(linecopy);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6345
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6346 /* move the cursor to the start of the line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6347
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6348 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6349
2328
15379284e55a Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents: 2322
diff changeset
6350 original_line_islabel = cin_islabel(ind_maxcomment); /* XXX */
15379284e55a Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents: 2322
diff changeset
6351
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6352 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6353 * #defines and so on always go at the left when included in 'cinkeys'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6354 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6355 if (*theline == '#' && (*linecopy == '#' || in_cinkeys('#', ' ', TRUE)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6356 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6357 amount = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6358 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6359
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6360 /*
2328
15379284e55a Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents: 2322
diff changeset
6361 * Is it a non-case label? Then that goes at the left margin too unless:
15379284e55a Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents: 2322
diff changeset
6362 * - JS flag is set.
15379284e55a Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents: 2322
diff changeset
6363 * - 'L' item has a positive value.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6364 */
2328
15379284e55a Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents: 2322
diff changeset
6365 else if (original_line_islabel && !ind_js && ind_jump_label < 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6366 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6367 amount = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6368 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6369
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6370 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6371 * If we're inside a "//" comment and there is a "//" comment in a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6372 * previous line, lineup with that one.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6373 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6374 else if (cin_islinecomment(theline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6375 && (trypos = find_line_comment()) != NULL) /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6376 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6377 /* find how indented the line beginning the comment is */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6378 getvcol(curwin, trypos, &col, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6379 amount = col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6380 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6381
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6382 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6383 * If we're inside a comment and not looking at the start of the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6384 * comment, try using the 'comments' option.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6385 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6386 else if (!cin_iscomment(theline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6387 && (trypos = find_start_comment(ind_maxcomment)) != NULL) /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6388 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6389 int lead_start_len = 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6390 int lead_middle_len = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6391 char_u lead_start[COM_MAX_LEN]; /* start-comment string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6392 char_u lead_middle[COM_MAX_LEN]; /* middle-comment string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6393 char_u lead_end[COM_MAX_LEN]; /* end-comment string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6394 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6395 int start_align = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6396 int start_off = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6397 int done = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6398
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6399 /* find how indented the line beginning the comment is */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6400 getvcol(curwin, trypos, &col, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6401 amount = col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6402
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6403 p = curbuf->b_p_com;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6404 while (*p != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6405 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6406 int align = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6407 int off = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6408 int what = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6409
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6410 while (*p != NUL && *p != ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6411 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6412 if (*p == COM_START || *p == COM_END || *p == COM_MIDDLE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6413 what = *p++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6414 else if (*p == COM_LEFT || *p == COM_RIGHT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6415 align = *p++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6416 else if (VIM_ISDIGIT(*p) || *p == '-')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6417 off = getdigits(&p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6418 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6419 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6420 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6421
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6422 if (*p == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6423 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6424 (void)copy_option_part(&p, lead_end, COM_MAX_LEN, ",");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6425 if (what == COM_START)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6426 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6427 STRCPY(lead_start, lead_end);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6428 lead_start_len = (int)STRLEN(lead_start);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6429 start_off = off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6430 start_align = align;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6431 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6432 else if (what == COM_MIDDLE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6433 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6434 STRCPY(lead_middle, lead_end);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6435 lead_middle_len = (int)STRLEN(lead_middle);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6436 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6437 else if (what == COM_END)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6438 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6439 /* If our line starts with the middle comment string, line it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6440 * up with the comment opener per the 'comments' option. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6441 if (STRNCMP(theline, lead_middle, lead_middle_len) == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6442 && STRNCMP(theline, lead_end, STRLEN(lead_end)) != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6443 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6444 done = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6445 if (curwin->w_cursor.lnum > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6446 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6447 /* If the start comment string matches in the previous
1532
87b9f21264a7 updated for version 7.1-247
vimboss
parents: 1521
diff changeset
6448 * line, use the indent of that line plus offset. If
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6449 * the middle comment string matches in the previous
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6450 * line, use the indent of that line. XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6451 look = skipwhite(ml_get(curwin->w_cursor.lnum - 1));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6452 if (STRNCMP(look, lead_start, lead_start_len) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6453 amount = get_indent_lnum(curwin->w_cursor.lnum - 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6454 else if (STRNCMP(look, lead_middle,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6455 lead_middle_len) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6456 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6457 amount = get_indent_lnum(curwin->w_cursor.lnum - 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6458 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6459 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6460 /* If the start comment string doesn't match with the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6461 * start of the comment, skip this entry. XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6462 else if (STRNCMP(ml_get(trypos->lnum) + trypos->col,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6463 lead_start, lead_start_len) != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6464 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6465 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6466 if (start_off != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6467 amount += start_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6468 else if (start_align == COM_RIGHT)
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
6469 amount += vim_strsize(lead_start)
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
6470 - vim_strsize(lead_middle);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6471 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6472 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6473
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6474 /* If our line starts with the end comment string, line it up
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6475 * with the middle comment */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6476 if (STRNCMP(theline, lead_middle, lead_middle_len) != 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6477 && STRNCMP(theline, lead_end, STRLEN(lead_end)) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6478 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6479 amount = get_indent_lnum(curwin->w_cursor.lnum - 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6480 /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6481 if (off != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6482 amount += off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6483 else if (align == COM_RIGHT)
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
6484 amount += vim_strsize(lead_start)
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
6485 - vim_strsize(lead_middle);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6486 done = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6487 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6488 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6489 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6490 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6491
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6492 /* If our line starts with an asterisk, line up with the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6493 * asterisk in the comment opener; otherwise, line up
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6494 * with the first character of the comment text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6495 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6496 if (done)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6497 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6498 else if (theline[0] == '*')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6499 amount += 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6500 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6501 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6502 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6503 * If we are more than one line away from the comment opener, take
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6504 * the indent of the previous non-empty line. If 'cino' has "CO"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6505 * and we are just below the comment opener and there are any
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6506 * white characters after it line up with the text after it;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6507 * otherwise, add the amount specified by "c" in 'cino'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6508 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6509 amount = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6510 for (lnum = cur_curpos.lnum - 1; lnum > trypos->lnum; --lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6511 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6512 if (linewhite(lnum)) /* skip blank lines */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6513 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6514 amount = get_indent_lnum(lnum); /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6515 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6516 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6517 if (amount == -1) /* use the comment opener */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6518 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6519 if (!ind_in_comment2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6520 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6521 start = ml_get(trypos->lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6522 look = start + trypos->col + 2; /* skip / and * */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6523 if (*look != NUL) /* if something after it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6524 trypos->col = (colnr_T)(skipwhite(look) - start);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6525 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6526 getvcol(curwin, trypos, &col, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6527 amount = col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6528 if (ind_in_comment2 || *look == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6529 amount += ind_in_comment;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6530 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6531 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6532 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6533
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6534 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6535 * Are we inside parentheses or braces?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6536 */ /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6537 else if (((trypos = find_match_paren(ind_maxparen, ind_maxcomment)) != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6538 && ind_java == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6539 || (tryposBrace = find_start_brace(ind_maxcomment)) != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6540 || trypos != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6541 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6542 if (trypos != NULL && tryposBrace != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6543 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6544 /* Both an unmatched '(' and '{' is found. Use the one which is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6545 * closer to the current cursor position, set the other to NULL. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6546 if (trypos->lnum != tryposBrace->lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6547 ? trypos->lnum < tryposBrace->lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6548 : trypos->col < tryposBrace->col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6549 trypos = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6550 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6551 tryposBrace = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6552 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6553
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6554 if (trypos != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6555 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6556 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6557 * If the matching paren is more than one line away, use the indent of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6558 * a previous non-empty line that matches the same paren.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6559 */
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6560 if (theline[0] == ')' && ind_paren_prev)
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6561 {
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6562 /* Line up with the start of the matching paren line. */
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6563 amount = get_indent_lnum(curwin->w_cursor.lnum - 1); /* XXX */
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6564 }
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6565 else
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6566 {
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6567 amount = -1;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6568 our_paren_pos = *trypos;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6569 for (lnum = cur_curpos.lnum - 1; lnum > our_paren_pos.lnum; --lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6570 {
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6571 l = skipwhite(ml_get(lnum));
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6572 if (cin_nocode(l)) /* skip comment lines */
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6573 continue;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6574 if (cin_ispreproc_cont(&l, &lnum))
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6575 continue; /* ignore #define, #if, etc. */
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6576 curwin->w_cursor.lnum = lnum;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6577
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6578 /* Skip a comment. XXX */
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6579 if ((trypos = find_start_comment(ind_maxcomment)) != NULL)
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6580 {
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6581 lnum = trypos->lnum + 1;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6582 continue;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6583 }
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6584
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6585 /* XXX */
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6586 if ((trypos = find_match_paren(
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6587 corr_ind_maxparen(ind_maxparen, &cur_curpos),
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6588 ind_maxcomment)) != NULL
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6589 && trypos->lnum == our_paren_pos.lnum
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6590 && trypos->col == our_paren_pos.col)
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6591 {
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6592 amount = get_indent_lnum(lnum); /* XXX */
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6593
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6594 if (theline[0] == ')')
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6595 {
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6596 if (our_paren_pos.lnum != lnum
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6597 && cur_amount > amount)
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6598 cur_amount = amount;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6599 amount = -1;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6600 }
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6601 break;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6602 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6603 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6604 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6605
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6606 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6607 * Line up with line where the matching paren is. XXX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6608 * If the line starts with a '(' or the indent for unclosed
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6609 * parentheses is zero, line up with the unclosed parentheses.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6610 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6611 if (amount == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6612 {
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6613 int ignore_paren_col = 0;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6614
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6615 amount = skip_label(our_paren_pos.lnum, &look, ind_maxcomment);
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6616 look = skipwhite(look);
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6617 if (*look == '(')
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6618 {
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6619 linenr_T save_lnum = curwin->w_cursor.lnum;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6620 char_u *line;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6621 int look_col;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6622
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6623 /* Ignore a '(' in front of the line that has a match before
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6624 * our matching '('. */
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6625 curwin->w_cursor.lnum = our_paren_pos.lnum;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6626 line = ml_get_curline();
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 834
diff changeset
6627 look_col = (int)(look - line);
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6628 curwin->w_cursor.col = look_col + 1;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6629 if ((trypos = findmatchlimit(NULL, ')', 0, ind_maxparen))
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6630 != NULL
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6631 && trypos->lnum == our_paren_pos.lnum
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6632 && trypos->col < our_paren_pos.col)
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6633 ignore_paren_col = trypos->col + 1;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6634
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6635 curwin->w_cursor.lnum = save_lnum;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6636 look = ml_get(our_paren_pos.lnum) + look_col;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6637 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6638 if (theline[0] == ')' || ind_unclosed == 0
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6639 || (!ind_unclosed_noignore && *look == '('
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6640 && ignore_paren_col == 0))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6641 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6642 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6643 * If we're looking at a close paren, line up right there;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6644 * otherwise, line up with the next (non-white) character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6645 * When ind_unclosed_wrapped is set and the matching paren is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6646 * the last nonwhite character of the line, use either the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6647 * indent of the current line or the indentation of the next
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6648 * outer paren and add ind_unclosed_wrapped (for very long
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6649 * lines).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6650 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6651 if (theline[0] != ')')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6652 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6653 cur_amount = MAXCOL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6654 l = ml_get(our_paren_pos.lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6655 if (ind_unclosed_wrapped
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6656 && cin_ends_in(l, (char_u *)"(", NULL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6657 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6658 /* look for opening unmatched paren, indent one level
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6659 * for each additional level */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6660 n = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6661 for (col = 0; col < our_paren_pos.col; ++col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6662 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6663 switch (l[col])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6664 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6665 case '(':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6666 case '{': ++n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6667 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6668
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6669 case ')':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6670 case '}': if (n > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6671 --n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6672 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6673 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6674 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6675
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6676 our_paren_pos.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6677 amount += n * ind_unclosed_wrapped;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6678 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6679 else if (ind_unclosed_whiteok)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6680 our_paren_pos.col++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6681 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6682 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6683 col = our_paren_pos.col + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6684 while (vim_iswhite(l[col]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6685 col++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6686 if (l[col] != NUL) /* In case of trailing space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6687 our_paren_pos.col = col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6688 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6689 our_paren_pos.col++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6690 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6691 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6692
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6693 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6694 * Find how indented the paren is, or the character after it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6695 * if we did the above "if".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6696 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6697 if (our_paren_pos.col > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6698 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6699 getvcol(curwin, &our_paren_pos, &col, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6700 if (cur_amount > (int)col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6701 cur_amount = col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6702 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6703 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6704
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6705 if (theline[0] == ')' && ind_matching_paren)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6706 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6707 /* Line up with the start of the matching paren line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6708 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6709 else if (ind_unclosed == 0 || (!ind_unclosed_noignore
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6710 && *look == '(' && ignore_paren_col == 0))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6711 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6712 if (cur_amount != MAXCOL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6713 amount = cur_amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6714 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6715 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6716 {
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6717 /* Add ind_unclosed2 for each '(' before our matching one, but
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
6718 * ignore (void) before the line (ignore_paren_col). */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6719 col = our_paren_pos.col;
834
5117153003bd updated for version 7.0e
vimboss
parents: 829
diff changeset
6720 while ((int)our_paren_pos.col > ignore_paren_col)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6721 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6722 --our_paren_pos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6723 switch (*ml_get_pos(&our_paren_pos))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6724 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6725 case '(': amount += ind_unclosed2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6726 col = our_paren_pos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6727 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6728 case ')': amount -= ind_unclosed2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6729 col = MAXCOL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6730 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6731 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6732 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6733
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6734 /* Use ind_unclosed once, when the first '(' is not inside
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6735 * braces */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6736 if (col == MAXCOL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6737 amount += ind_unclosed;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6738 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6739 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6740 curwin->w_cursor.lnum = our_paren_pos.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6741 curwin->w_cursor.col = col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6742 if ((trypos = find_match_paren(ind_maxparen,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6743 ind_maxcomment)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6744 amount += ind_unclosed2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6745 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6746 amount += ind_unclosed;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6747 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6748 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6749 * For a line starting with ')' use the minimum of the two
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6750 * positions, to avoid giving it more indent than the previous
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6751 * lines:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6752 * func_long_name( if (x
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6753 * arg && yy
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6754 * ) ^ not here ) ^ not here
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6755 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6756 if (cur_amount < amount)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6757 amount = cur_amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6758 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6759 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6760
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6761 /* add extra indent for a comment */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6762 if (cin_iscomment(theline))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6763 amount += ind_comment;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6764 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6765
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6766 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6767 * Are we at least inside braces, then?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6768 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6769 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6770 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6771 trypos = tryposBrace;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6772
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6773 ourscope = trypos->lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6774 start = ml_get(ourscope);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6775
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6776 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6777 * Now figure out how indented the line is in general.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6778 * If the brace was at the start of the line, we use that;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6779 * otherwise, check out the indentation of the line as
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6780 * a whole and then add the "imaginary indent" to that.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6781 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6782 look = skipwhite(start);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6783 if (*look == '{')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6784 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6785 getvcol(curwin, trypos, &col, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6786 amount = col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6787 if (*start == '{')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6788 start_brace = BRACE_IN_COL0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6789 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6790 start_brace = BRACE_AT_START;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6791 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6792 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6793 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6794 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6795 * that opening brace might have been on a continuation
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6796 * line. if so, find the start of the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6797 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6798 curwin->w_cursor.lnum = ourscope;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6799
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6800 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6801 * position the cursor over the rightmost paren, so that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6802 * matching it will take us back to the start of the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6803 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6804 lnum = ourscope;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6805 if (find_last_paren(start, '(', ')')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6806 && (trypos = find_match_paren(ind_maxparen,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6807 ind_maxcomment)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6808 lnum = trypos->lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6809
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6810 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6811 * It could have been something like
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6812 * case 1: if (asdf &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6813 * ldfd) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6814 * }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6815 */
2297
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
6816 if ((ind_keep_case_label
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
6817 && cin_iscase(skipwhite(ml_get_curline()), FALSE)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6818 amount = get_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6819 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6820 amount = skip_label(lnum, &l, ind_maxcomment);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6821
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6822 start_brace = BRACE_AT_END;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6823 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6824
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6825 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6826 * if we're looking at a closing brace, that's where
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6827 * we want to be. otherwise, add the amount of room
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6828 * that an indent is supposed to be.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6829 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6830 if (theline[0] == '}')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6831 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6832 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6833 * they may want closing braces to line up with something
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6834 * other than the open brace. indulge them, if so.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6835 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6836 amount += ind_close_extra;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6837 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6838 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6839 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6840 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6841 * If we're looking at an "else", try to find an "if"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6842 * to match it with.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6843 * If we're looking at a "while", try to find a "do"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6844 * to match it with.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6845 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6846 lookfor = LOOKFOR_INITIAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6847 if (cin_iselse(theline))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6848 lookfor = LOOKFOR_IF;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6849 else if (cin_iswhileofdo(theline, cur_curpos.lnum, ind_maxparen))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6850 /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6851 lookfor = LOOKFOR_DO;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6852 if (lookfor != LOOKFOR_INITIAL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6853 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6854 curwin->w_cursor.lnum = cur_curpos.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6855 if (find_match(lookfor, ourscope, ind_maxparen,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6856 ind_maxcomment) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6857 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6858 amount = get_indent(); /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6859 goto theend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6860 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6861 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6862
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6863 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6864 * We get here if we are not on an "while-of-do" or "else" (or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6865 * failed to find a matching "if").
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6866 * Search backwards for something to line up with.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6867 * First set amount for when we don't find anything.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6868 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6869
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6870 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6871 * if the '{' is _really_ at the left margin, use the imaginary
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6872 * location of a left-margin brace. Otherwise, correct the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6873 * location for ind_open_extra.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6874 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6875
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6876 if (start_brace == BRACE_IN_COL0) /* '{' is in column 0 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6877 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6878 amount = ind_open_left_imag;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6879 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6880 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6881 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6882 if (start_brace == BRACE_AT_END) /* '{' is at end of line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6883 amount += ind_open_imag;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6884 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6885 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6886 /* Compensate for adding ind_open_extra later. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6887 amount -= ind_open_extra;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6888 if (amount < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6889 amount = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6890 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6891 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6892
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6893 lookfor_break = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6894
2297
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
6895 if (cin_iscase(theline, FALSE)) /* it's a switch() label */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6896 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6897 lookfor = LOOKFOR_CASE; /* find a previous switch() label */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6898 amount += ind_case;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6899 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6900 else if (cin_isscopedecl(theline)) /* private:, ... */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6901 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6902 lookfor = LOOKFOR_SCOPEDECL; /* class decl is this block */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6903 amount += ind_scopedecl;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6904 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6905 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6906 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6907 if (ind_case_break && cin_isbreak(theline)) /* break; ... */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6908 lookfor_break = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6909
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6910 lookfor = LOOKFOR_INITIAL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6911 amount += ind_level; /* ind_level from start of block */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6912 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6913 scope_amount = amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6914 whilelevel = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6915
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6916 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6917 * Search backwards. If we find something we recognize, line up
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6918 * with that.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6919 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6920 * if we're looking at an open brace, indent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6921 * the usual amount relative to the conditional
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6922 * that opens the block.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6923 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6924 curwin->w_cursor = cur_curpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6925 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6926 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6927 curwin->w_cursor.lnum--;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6928 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6929
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6930 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6931 * If we went all the way back to the start of our scope, line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6932 * up with it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6933 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6934 if (curwin->w_cursor.lnum <= ourscope)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6935 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6936 /* we reached end of scope:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6937 * if looking for a enum or structure initialization
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6938 * go further back:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6939 * if it is an initializer (enum xxx or xxx =), then
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6940 * don't add ind_continuation, otherwise it is a variable
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6941 * declaration:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6942 * int x,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6943 * here; <-- add ind_continuation
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6944 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6945 if (lookfor == LOOKFOR_ENUM_OR_INIT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6946 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6947 if (curwin->w_cursor.lnum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6948 || curwin->w_cursor.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6949 < ourscope - ind_maxparen)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6950 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6951 /* nothing found (abuse ind_maxparen as limit)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6952 * assume terminated line (i.e. a variable
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6953 * initialization) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6954 if (cont_amount > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6955 amount = cont_amount;
2297
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
6956 else if (!ind_js)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6957 amount += ind_continuation;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6958 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6959 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6960
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6961 l = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6962
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6963 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6964 * If we're in a comment now, skip to the start of the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6965 * comment.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6966 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6967 trypos = find_start_comment(ind_maxcomment);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6968 if (trypos != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6969 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6970 curwin->w_cursor.lnum = trypos->lnum + 1;
1550
d976f4da2a4d updated for version 7.1-264
vimboss
parents: 1532
diff changeset
6971 curwin->w_cursor.col = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6972 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6973 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6974
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6975 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6976 * Skip preprocessor directives and blank lines.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6977 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6978 if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6979 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6980
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6981 if (cin_nocode(l))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6982 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6983
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6984 terminated = cin_isterminated(l, FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6985
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6986 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6987 * If we are at top level and the line looks like a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6988 * function declaration, we are done
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6989 * (it's a variable declaration).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6990 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6991 if (start_brace != BRACE_IN_COL0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6992 || !cin_isfuncdecl(&l, curwin->w_cursor.lnum))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6993 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6994 /* if the line is terminated with another ','
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6995 * it is a continued variable initialization.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6996 * don't add extra indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6997 * TODO: does not work, if a function
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6998 * declaration is split over multiple lines:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6999 * cin_isfuncdecl returns FALSE then.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7000 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7001 if (terminated == ',')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7002 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7003
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7004 /* if it es a enum declaration or an assignment,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7005 * we are done.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7006 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7007 if (terminated != ';' && cin_isinit())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7008 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7009
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7010 /* nothing useful found */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7011 if (terminated == 0 || terminated == '{')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7012 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7013 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7014
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7015 if (terminated != ';')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7016 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7017 /* Skip parens and braces. Position the cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7018 * over the rightmost paren, so that matching it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7019 * will take us back to the start of the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7020 */ /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7021 trypos = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7022 if (find_last_paren(l, '(', ')'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7023 trypos = find_match_paren(ind_maxparen,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7024 ind_maxcomment);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7025
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7026 if (trypos == NULL && find_last_paren(l, '{', '}'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7027 trypos = find_start_brace(ind_maxcomment);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7028
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7029 if (trypos != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7030 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7031 curwin->w_cursor.lnum = trypos->lnum + 1;
1550
d976f4da2a4d updated for version 7.1-264
vimboss
parents: 1532
diff changeset
7032 curwin->w_cursor.col = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7033 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7034 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7035 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7036
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7037 /* it's a variable declaration, add indentation
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7038 * like in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7039 * int a,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7040 * b;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7041 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7042 if (cont_amount > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7043 amount = cont_amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7044 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7045 amount += ind_continuation;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7046 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7047 else if (lookfor == LOOKFOR_UNTERM)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7048 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7049 if (cont_amount > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7050 amount = cont_amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7051 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7052 amount += ind_continuation;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7053 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7054 else if (lookfor != LOOKFOR_TERM
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7055 && lookfor != LOOKFOR_CPP_BASECLASS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7056 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7057 amount = scope_amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7058 if (theline[0] == '{')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7059 amount += ind_open_extra;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7060 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7061 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7062 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7063
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7064 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7065 * If we're in a comment now, skip to the start of the comment.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7066 */ /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7067 if ((trypos = find_start_comment(ind_maxcomment)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7068 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7069 curwin->w_cursor.lnum = trypos->lnum + 1;
1550
d976f4da2a4d updated for version 7.1-264
vimboss
parents: 1532
diff changeset
7070 curwin->w_cursor.col = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7071 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7072 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7073
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7074 l = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7075
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7076 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7077 * If this is a switch() label, may line up relative to that.
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7078 * If this is a C++ scope declaration, do the same.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7079 */
2297
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
7080 iscase = cin_iscase(l, FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7081 if (iscase || cin_isscopedecl(l))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7082 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7083 /* we are only looking for cpp base class
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7084 * declaration/initialization any longer */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7085 if (lookfor == LOOKFOR_CPP_BASECLASS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7086 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7087
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7088 /* When looking for a "do" we are not interested in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7089 * labels. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7090 if (whilelevel > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7091 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7092
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7093 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7094 * case xx:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7095 * c = 99 + <- this indent plus continuation
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7096 *-> here;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7097 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7098 if (lookfor == LOOKFOR_UNTERM
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7099 || lookfor == LOOKFOR_ENUM_OR_INIT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7100 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7101 if (cont_amount > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7102 amount = cont_amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7103 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7104 amount += ind_continuation;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7105 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7106 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7107
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7108 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7109 * case xx: <- line up with this case
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7110 * x = 333;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7111 * case yy:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7112 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7113 if ( (iscase && lookfor == LOOKFOR_CASE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7114 || (iscase && lookfor_break)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7115 || (!iscase && lookfor == LOOKFOR_SCOPEDECL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7116 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7117 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7118 * Check that this case label is not for another
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7119 * switch()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7120 */ /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7121 if ((trypos = find_start_brace(ind_maxcomment)) ==
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7122 NULL || trypos->lnum == ourscope)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7123 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7124 amount = get_indent(); /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7125 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7126 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7127 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7128 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7129
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7130 n = get_indent_nolabel(curwin->w_cursor.lnum); /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7131
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7132 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7133 * case xx: if (cond) <- line up with this if
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7134 * y = y + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7135 * -> s = 99;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7136 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7137 * case xx:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7138 * if (cond) <- line up with this line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7139 * y = y + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7140 * -> s = 99;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7141 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7142 if (lookfor == LOOKFOR_TERM)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7143 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7144 if (n)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7145 amount = n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7146
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7147 if (!lookfor_break)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7148 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7149 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7150
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7151 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7152 * case xx: x = x + 1; <- line up with this x
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7153 * -> y = y + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7154 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7155 * case xx: if (cond) <- line up with this if
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7156 * -> y = y + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7157 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7158 if (n)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7159 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7160 amount = n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7161 l = after_label(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7162 if (l != NULL && cin_is_cinword(l))
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
7163 {
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
7164 if (theline[0] == '{')
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
7165 amount += ind_open_extra;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
7166 else
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
7167 amount += ind_level + ind_no_brace;
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
7168 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7169 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7170 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7171
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7172 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7173 * Try to get the indent of a statement before the switch
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7174 * label. If nothing is found, line up relative to the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7175 * switch label.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7176 * break; <- may line up with this line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7177 * case xx:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7178 * -> y = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7179 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7180 scope_amount = get_indent() + (iscase /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7181 ? ind_case_code : ind_scopedecl_code);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7182 lookfor = ind_case_break ? LOOKFOR_NOBREAK : LOOKFOR_ANY;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7183 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7184 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7185
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7186 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7187 * Looking for a switch() label or C++ scope declaration,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7188 * ignore other lines, skip {}-blocks.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7189 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7190 if (lookfor == LOOKFOR_CASE || lookfor == LOOKFOR_SCOPEDECL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7191 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7192 if (find_last_paren(l, '{', '}') && (trypos =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7193 find_start_brace(ind_maxcomment)) != NULL)
1550
d976f4da2a4d updated for version 7.1-264
vimboss
parents: 1532
diff changeset
7194 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7195 curwin->w_cursor.lnum = trypos->lnum + 1;
1550
d976f4da2a4d updated for version 7.1-264
vimboss
parents: 1532
diff changeset
7196 curwin->w_cursor.col = 0;
d976f4da2a4d updated for version 7.1-264
vimboss
parents: 1532
diff changeset
7197 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7198 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7199 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7200
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7201 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7202 * Ignore jump labels with nothing after them.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7203 */
2297
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
7204 if (!ind_js && cin_islabel(ind_maxcomment))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7205 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7206 l = after_label(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7207 if (l == NULL || cin_nocode(l))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7208 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7209 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7210
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7211 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7212 * Ignore #defines, #if, etc.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7213 * Ignore comment and empty lines.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7214 * (need to get the line again, cin_islabel() may have
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7215 * unlocked it)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7216 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7217 l = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7218 if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7219 || cin_nocode(l))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7220 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7221
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7222 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7223 * Are we at the start of a cpp base class declaration or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7224 * constructor initialization?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7225 */ /* XXX */
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7226 n = FALSE;
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7227 if (lookfor != LOOKFOR_TERM && ind_cpp_baseclass > 0)
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7228 {
1336
b8ebbfa519b9 updated for version 7.1-050
vimboss
parents: 1324
diff changeset
7229 n = cin_is_cpp_baseclass(&col);
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7230 l = ml_get_curline();
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7231 }
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7232 if (n)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7233 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7234 if (lookfor == LOOKFOR_UNTERM)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7235 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7236 if (cont_amount > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7237 amount = cont_amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7238 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7239 amount += ind_continuation;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7240 }
828
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
7241 else if (theline[0] == '{')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7242 {
828
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
7243 /* Need to find start of the declaration. */
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
7244 lookfor = LOOKFOR_UNTERM;
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
7245 ind_continuation = 0;
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
7246 continue;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7247 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7248 else
828
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
7249 /* XXX */
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
7250 amount = get_baseclass_amount(col, ind_maxparen,
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
7251 ind_maxcomment, ind_cpp_baseclass);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7252 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7253 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7254 else if (lookfor == LOOKFOR_CPP_BASECLASS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7255 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7256 /* only look, whether there is a cpp base class
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7257 * declaration or initialization before the opening brace.
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7258 */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7259 if (cin_isterminated(l, TRUE, FALSE))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7260 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7261 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7262 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7263 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7264
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7265 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7266 * What happens next depends on the line being terminated.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7267 * If terminated with a ',' only consider it terminating if
1224
edc1c9d6dab9 updated for version 7.1b
vimboss
parents: 1096
diff changeset
7268 * there is another unterminated statement behind, eg:
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7269 * 123,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7270 * sizeof
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7271 * here
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7272 * Otherwise check whether it is a enumeration or structure
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7273 * initialisation (not indented) or a variable declaration
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7274 * (indented).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7275 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7276 terminated = cin_isterminated(l, FALSE, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7277
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7278 if (terminated == 0 || (lookfor != LOOKFOR_UNTERM
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7279 && terminated == ','))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7280 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7281 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7282 * if we're in the middle of a paren thing,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7283 * go back to the line that starts it so
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7284 * we can get the right prevailing indent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7285 * if ( foo &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7286 * bar )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7287 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7288 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7289 * position the cursor over the rightmost paren, so that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7290 * matching it will take us back to the start of the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7291 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7292 (void)find_last_paren(l, '(', ')');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7293 trypos = find_match_paren(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7294 corr_ind_maxparen(ind_maxparen, &cur_curpos),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7295 ind_maxcomment);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7296
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7297 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7298 * If we are looking for ',', we also look for matching
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7299 * braces.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7300 */
828
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
7301 if (trypos == NULL && terminated == ','
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
7302 && find_last_paren(l, '{', '}'))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7303 trypos = find_start_brace(ind_maxcomment);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7304
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7305 if (trypos != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7306 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7307 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7308 * Check if we are on a case label now. This is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7309 * handled above.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7310 * case xx: if ( asdf &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7311 * asdf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7312 */
1550
d976f4da2a4d updated for version 7.1-264
vimboss
parents: 1532
diff changeset
7313 curwin->w_cursor = *trypos;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7314 l = ml_get_curline();
2297
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
7315 if (cin_iscase(l, FALSE) || cin_isscopedecl(l))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7316 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7317 ++curwin->w_cursor.lnum;
1550
d976f4da2a4d updated for version 7.1-264
vimboss
parents: 1532
diff changeset
7318 curwin->w_cursor.col = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7319 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7320 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7321 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7322
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7323 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7324 * Skip over continuation lines to find the one to get the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7325 * indent from
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7326 * char *usethis = "bla\
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7327 * bla",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7328 * here;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7329 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7330 if (terminated == ',')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7331 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7332 while (curwin->w_cursor.lnum > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7333 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7334 l = ml_get(curwin->w_cursor.lnum - 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7335 if (*l == NUL || l[STRLEN(l) - 1] != '\\')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7336 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7337 --curwin->w_cursor.lnum;
1550
d976f4da2a4d updated for version 7.1-264
vimboss
parents: 1532
diff changeset
7338 curwin->w_cursor.col = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7339 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7340 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7341
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7342 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7343 * Get indent and pointer to text for current line,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7344 * ignoring any jump label. XXX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7345 */
2297
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
7346 if (!ind_js)
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
7347 cur_amount = skip_label(curwin->w_cursor.lnum,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7348 &l, ind_maxcomment);
2297
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
7349 else
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
7350 cur_amount = get_indent();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7351 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7352 * If this is just above the line we are indenting, and it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7353 * starts with a '{', line it up with this line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7354 * while (not)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7355 * -> {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7356 * }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7357 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7358 if (terminated != ',' && lookfor != LOOKFOR_TERM
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7359 && theline[0] == '{')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7360 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7361 amount = cur_amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7362 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7363 * Only add ind_open_extra when the current line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7364 * doesn't start with a '{', which must have a match
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7365 * in the same line (scope is the same). Probably:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7366 * { 1, 2 },
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7367 * -> { 3, 4 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7368 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7369 if (*skipwhite(l) != '{')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7370 amount += ind_open_extra;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7371
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7372 if (ind_cpp_baseclass)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7373 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7374 /* have to look back, whether it is a cpp base
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7375 * class declaration or initialization */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7376 lookfor = LOOKFOR_CPP_BASECLASS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7377 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7378 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7379 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7380 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7381
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7382 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7383 * Check if we are after an "if", "while", etc.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7384 * Also allow " } else".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7385 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7386 if (cin_is_cinword(l) || cin_iselse(skipwhite(l)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7387 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7388 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7389 * Found an unterminated line after an if (), line up
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7390 * with the last one.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7391 * if (cond)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7392 * 100 +
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7393 * -> here;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7394 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7395 if (lookfor == LOOKFOR_UNTERM
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7396 || lookfor == LOOKFOR_ENUM_OR_INIT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7397 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7398 if (cont_amount > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7399 amount = cont_amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7400 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7401 amount += ind_continuation;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7402 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7403 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7404
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7405 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7406 * If this is just above the line we are indenting, we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7407 * are finished.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7408 * while (not)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7409 * -> here;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7410 * Otherwise this indent can be used when the line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7411 * before this is terminated.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7412 * yyy;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7413 * if (stat)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7414 * while (not)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7415 * xxx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7416 * -> here;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7417 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7418 amount = cur_amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7419 if (theline[0] == '{')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7420 amount += ind_open_extra;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7421 if (lookfor != LOOKFOR_TERM)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7422 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7423 amount += ind_level + ind_no_brace;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7424 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7425 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7426
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7427 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7428 * Special trick: when expecting the while () after a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7429 * do, line up with the while()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7430 * do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7431 * x = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7432 * -> here
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7433 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7434 l = skipwhite(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7435 if (cin_isdo(l))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7436 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7437 if (whilelevel == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7438 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7439 --whilelevel;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7440 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7441
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7442 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7443 * When searching for a terminated line, don't use the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7444 * one between the "if" and the "else".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7445 * Need to use the scope of this "else". XXX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7446 * If whilelevel != 0 continue looking for a "do {".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7447 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7448 if (cin_iselse(l)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7449 && whilelevel == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7450 && ((trypos = find_start_brace(ind_maxcomment))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7451 == NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7452 || find_match(LOOKFOR_IF, trypos->lnum,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7453 ind_maxparen, ind_maxcomment) == FAIL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7454 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7455 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7456
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7457 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7458 * If we're below an unterminated line that is not an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7459 * "if" or something, we may line up with this line or
1224
edc1c9d6dab9 updated for version 7.1b
vimboss
parents: 1096
diff changeset
7460 * add something for a continuation line, depending on
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7461 * the line before this one.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7462 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7463 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7464 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7465 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7466 * Found two unterminated lines on a row, line up with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7467 * the last one.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7468 * c = 99 +
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7469 * 100 +
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7470 * -> here;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7471 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7472 if (lookfor == LOOKFOR_UNTERM)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7473 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7474 /* When line ends in a comma add extra indent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7475 if (terminated == ',')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7476 amount += ind_continuation;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7477 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7478 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7479
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7480 if (lookfor == LOOKFOR_ENUM_OR_INIT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7481 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7482 /* Found two lines ending in ',', lineup with the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7483 * lowest one, but check for cpp base class
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7484 * declaration/initialization, if it is an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7485 * opening brace or we are looking just for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7486 * enumerations/initializations. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7487 if (terminated == ',')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7488 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7489 if (ind_cpp_baseclass == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7490 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7491
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7492 lookfor = LOOKFOR_CPP_BASECLASS;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7493 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7494 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7495
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7496 /* Ignore unterminated lines in between, but
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7497 * reduce indent. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7498 if (amount > cur_amount)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7499 amount = cur_amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7500 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7501 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7502 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7503 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7504 * Found first unterminated line on a row, may
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7505 * line up with this line, remember its indent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7506 * 100 +
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7507 * -> here;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7508 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7509 amount = cur_amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7510
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7511 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7512 * If previous line ends in ',', check whether we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7513 * are in an initialization or enum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7514 * struct xxx =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7515 * {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7516 * sizeof a,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7517 * 124 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7518 * or a normal possible continuation line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7519 * but only, of no other statement has been found
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7520 * yet.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7521 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7522 if (lookfor == LOOKFOR_INITIAL && terminated == ',')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7523 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7524 lookfor = LOOKFOR_ENUM_OR_INIT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7525 cont_amount = cin_first_id_amount();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7526 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7527 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7528 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7529 if (lookfor == LOOKFOR_INITIAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7530 && *l != NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7531 && l[STRLEN(l) - 1] == '\\')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7532 /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7533 cont_amount = cin_get_equal_amount(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7534 curwin->w_cursor.lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7535 if (lookfor != LOOKFOR_TERM)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7536 lookfor = LOOKFOR_UNTERM;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7537 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7538 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7539 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7540 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7541
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7542 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7543 * Check if we are after a while (cond);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7544 * If so: Ignore until the matching "do".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7545 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7546 /* XXX */
829
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
7547 else if (cin_iswhileofdo_end(terminated, ind_maxparen,
dc8197342755 updated for version 7.0d04
vimboss
parents: 828
diff changeset
7548 ind_maxcomment))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7549 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7550 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7551 * Found an unterminated line after a while ();, line up
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7552 * with the last one.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7553 * while (cond);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7554 * 100 + <- line up with this one
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7555 * -> here;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7556 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7557 if (lookfor == LOOKFOR_UNTERM
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7558 || lookfor == LOOKFOR_ENUM_OR_INIT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7559 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7560 if (cont_amount > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7561 amount = cont_amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7562 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7563 amount += ind_continuation;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7564 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7565 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7566
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7567 if (whilelevel == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7568 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7569 lookfor = LOOKFOR_TERM;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7570 amount = get_indent(); /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7571 if (theline[0] == '{')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7572 amount += ind_open_extra;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7573 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7574 ++whilelevel;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7575 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7576
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7577 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7578 * We are after a "normal" statement.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7579 * If we had another statement we can stop now and use the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7580 * indent of that other statement.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7581 * Otherwise the indent of the current statement may be used,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7582 * search backwards for the next "normal" statement.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7583 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7584 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7585 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7586 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7587 * Skip single break line, if before a switch label. It
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7588 * may be lined up with the case label.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7589 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7590 if (lookfor == LOOKFOR_NOBREAK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7591 && cin_isbreak(skipwhite(ml_get_curline())))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7592 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7593 lookfor = LOOKFOR_ANY;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7594 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7595 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7596
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7597 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7598 * Handle "do {" line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7599 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7600 if (whilelevel > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7601 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7602 l = cin_skipcomment(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7603 if (cin_isdo(l))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7604 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7605 amount = get_indent(); /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7606 --whilelevel;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7607 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7608 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7609 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7610
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7611 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7612 * Found a terminated line above an unterminated line. Add
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7613 * the amount for a continuation line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7614 * x = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7615 * y = foo +
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7616 * -> here;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7617 * or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7618 * int x = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7619 * int foo,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7620 * -> here;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7621 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7622 if (lookfor == LOOKFOR_UNTERM
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7623 || lookfor == LOOKFOR_ENUM_OR_INIT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7624 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7625 if (cont_amount > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7626 amount = cont_amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7627 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7628 amount += ind_continuation;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7629 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7630 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7631
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7632 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7633 * Found a terminated line above a terminated line or "if"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7634 * etc. line. Use the amount of the line below us.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7635 * x = 1; x = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7636 * if (asdf) y = 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7637 * while (asdf) ->here;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7638 * here;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7639 * ->foo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7640 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7641 if (lookfor == LOOKFOR_TERM)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7642 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7643 if (!lookfor_break && whilelevel == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7644 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7645 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7646
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7647 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7648 * First line above the one we're indenting is terminated.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7649 * To know what needs to be done look further backward for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7650 * a terminated line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7651 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7652 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7653 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7654 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7655 * position the cursor over the rightmost paren, so
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7656 * that matching it will take us back to the start of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7657 * the line. Helps for:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7658 * func(asdr,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7659 * asdfasdf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7660 * here;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7661 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7662 term_again:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7663 l = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7664 if (find_last_paren(l, '(', ')')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7665 && (trypos = find_match_paren(ind_maxparen,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7666 ind_maxcomment)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7667 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7668 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7669 * Check if we are on a case label now. This is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7670 * handled above.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7671 * case xx: if ( asdf &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7672 * asdf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7673 */
1550
d976f4da2a4d updated for version 7.1-264
vimboss
parents: 1532
diff changeset
7674 curwin->w_cursor = *trypos;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7675 l = ml_get_curline();
2297
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
7676 if (cin_iscase(l, FALSE) || cin_isscopedecl(l))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7677 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7678 ++curwin->w_cursor.lnum;
1550
d976f4da2a4d updated for version 7.1-264
vimboss
parents: 1532
diff changeset
7679 curwin->w_cursor.col = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7680 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7681 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7682 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7683
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7684 /* When aligning with the case statement, don't align
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7685 * with a statement after it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7686 * case 1: { <-- don't use this { position
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7687 * stat;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7688 * }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7689 * case 2:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7690 * stat;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7691 * }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7692 */
2297
5ffe000a9ecf Improve Javascript indenting. Add "J" flag to 'cino'. (Hari Kumar G)
Bram Moolenaar <bram@vim.org>
parents: 2288
diff changeset
7693 iscase = (ind_keep_case_label && cin_iscase(l, FALSE));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7694
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7695 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7696 * Get indent and pointer to text for current line,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7697 * ignoring any jump label.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7698 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7699 amount = skip_label(curwin->w_cursor.lnum,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7700 &l, ind_maxcomment);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7701
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7702 if (theline[0] == '{')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7703 amount += ind_open_extra;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7704 /* See remark above: "Only add ind_open_extra.." */
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7705 l = skipwhite(l);
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7706 if (*l == '{')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7707 amount -= ind_open_extra;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7708 lookfor = iscase ? LOOKFOR_ANY : LOOKFOR_TERM;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7709
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7710 /*
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7711 * When a terminated line starts with "else" skip to
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7712 * the matching "if":
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7713 * else 3;
856
8cd729851562 updated for version 7.0g
vimboss
parents: 840
diff changeset
7714 * indent this;
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7715 * Need to use the scope of this "else". XXX
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7716 * If whilelevel != 0 continue looking for a "do {".
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7717 */
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7718 if (lookfor == LOOKFOR_TERM
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7719 && *l != '}'
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7720 && cin_iselse(l)
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7721 && whilelevel == 0)
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7722 {
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7723 if ((trypos = find_start_brace(ind_maxcomment))
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7724 == NULL
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7725 || find_match(LOOKFOR_IF, trypos->lnum,
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7726 ind_maxparen, ind_maxcomment) == FAIL)
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7727 break;
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7728 continue;
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7729 }
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7730
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7731 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7732 * If we're at the end of a block, skip to the start of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7733 * that block.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7734 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7735 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7736 if (*cin_skipcomment(l) == '}'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7737 && (trypos = find_start_brace(ind_maxcomment))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7738 != NULL) /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7739 {
1550
d976f4da2a4d updated for version 7.1-264
vimboss
parents: 1532
diff changeset
7740 curwin->w_cursor = *trypos;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7741 /* if not "else {" check for terminated again */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7742 /* but skip block for "} else {" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7743 l = cin_skipcomment(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7744 if (*l == '}' || !cin_iselse(l))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7745 goto term_again;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7746 ++curwin->w_cursor.lnum;
1550
d976f4da2a4d updated for version 7.1-264
vimboss
parents: 1532
diff changeset
7747 curwin->w_cursor.col = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7748 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7749 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7750 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7751 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7752 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7753 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7754
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7755 /* add extra indent for a comment */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7756 if (cin_iscomment(theline))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7757 amount += ind_comment;
2328
15379284e55a Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents: 2322
diff changeset
7758
15379284e55a Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents: 2322
diff changeset
7759 /* subtract extra left-shift for jump labels */
15379284e55a Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents: 2322
diff changeset
7760 if (ind_jump_label > 0 && original_line_islabel)
15379284e55a Add the 'L' item to 'cinoptions'. (Manuel Konig)
Bram Moolenaar <bram@vim.org>
parents: 2322
diff changeset
7761 amount -= ind_jump_label;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7762 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7763
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7764 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7765 * ok -- we're not inside any sort of structure at all!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7766 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7767 * this means we're at the top level, and everything should
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7768 * basically just match where the previous line is, except
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7769 * for the lines immediately following a function declaration,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7770 * which are K&R-style parameters and need to be indented.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7771 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7772 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7773 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7774 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7775 * if our line starts with an open brace, forget about any
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7776 * prevailing indent and make sure it looks like the start
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7777 * of a function
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7778 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7779
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7780 if (theline[0] == '{')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7781 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7782 amount = ind_first_open;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7783 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7784
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7785 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7786 * If the NEXT line is a function declaration, the current
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7787 * line needs to be indented as a function type spec.
2094
e319a4fe6e32 updated for version 7.2.378
Bram Moolenaar <bram@zimbu.org>
parents: 2030
diff changeset
7788 * Don't do this if the current line looks like a comment or if the
e319a4fe6e32 updated for version 7.2.378
Bram Moolenaar <bram@zimbu.org>
parents: 2030
diff changeset
7789 * current line is terminated, ie. ends in ';', or if the current line
e319a4fe6e32 updated for version 7.2.378
Bram Moolenaar <bram@zimbu.org>
parents: 2030
diff changeset
7790 * contains { or }: "void f() {\n if (1)"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7791 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7792 else if (cur_curpos.lnum < curbuf->b_ml.ml_line_count
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7793 && !cin_nocode(theline)
2094
e319a4fe6e32 updated for version 7.2.378
Bram Moolenaar <bram@zimbu.org>
parents: 2030
diff changeset
7794 && vim_strchr(theline, '{') == NULL
e319a4fe6e32 updated for version 7.2.378
Bram Moolenaar <bram@zimbu.org>
parents: 2030
diff changeset
7795 && vim_strchr(theline, '}') == NULL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7796 && !cin_ends_in(theline, (char_u *)":", NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7797 && !cin_ends_in(theline, (char_u *)",", NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7798 && cin_isfuncdecl(NULL, cur_curpos.lnum + 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7799 && !cin_isterminated(theline, FALSE, TRUE))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7800 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7801 amount = ind_func_type;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7802 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7803 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7804 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7805 amount = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7806 curwin->w_cursor = cur_curpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7807
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7808 /* search backwards until we find something we recognize */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7809
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7810 while (curwin->w_cursor.lnum > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7811 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7812 curwin->w_cursor.lnum--;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7813 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7814
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7815 l = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7816
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7817 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7818 * If we're in a comment now, skip to the start of the comment.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7819 */ /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7820 if ((trypos = find_start_comment(ind_maxcomment)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7821 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7822 curwin->w_cursor.lnum = trypos->lnum + 1;
1550
d976f4da2a4d updated for version 7.1-264
vimboss
parents: 1532
diff changeset
7823 curwin->w_cursor.col = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7824 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7825 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7826
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7827 /*
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7828 * Are we at the start of a cpp base class declaration or
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7829 * constructor initialization?
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7830 */ /* XXX */
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7831 n = FALSE;
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7832 if (ind_cpp_baseclass != 0 && theline[0] != '{')
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7833 {
1336
b8ebbfa519b9 updated for version 7.1-050
vimboss
parents: 1324
diff changeset
7834 n = cin_is_cpp_baseclass(&col);
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7835 l = ml_get_curline();
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7836 }
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
7837 if (n)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7838 {
828
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
7839 /* XXX */
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
7840 amount = get_baseclass_amount(col, ind_maxparen,
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
7841 ind_maxcomment, ind_cpp_baseclass);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7842 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7843 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7844
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7845 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7846 * Skip preprocessor directives and blank lines.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7847 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7848 if (cin_ispreproc_cont(&l, &curwin->w_cursor.lnum))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7849 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7850
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7851 if (cin_nocode(l))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7852 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7853
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7854 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7855 * If the previous line ends in ',', use one level of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7856 * indentation:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7857 * int foo,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7858 * bar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7859 * do this before checking for '}' in case of eg.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7860 * enum foobar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7861 * {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7862 * ...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7863 * } foo,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7864 * bar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7865 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7866 n = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7867 if (cin_ends_in(l, (char_u *)",", NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7868 || (*l != NUL && (n = l[STRLEN(l) - 1]) == '\\'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7869 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7870 /* take us back to opening paren */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7871 if (find_last_paren(l, '(', ')')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7872 && (trypos = find_match_paren(ind_maxparen,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7873 ind_maxcomment)) != NULL)
1550
d976f4da2a4d updated for version 7.1-264
vimboss
parents: 1532
diff changeset
7874 curwin->w_cursor = *trypos;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7875
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7876 /* For a line ending in ',' that is a continuation line go
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7877 * back to the first line with a backslash:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7878 * char *foo = "bla\
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7879 * bla",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7880 * here;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7881 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7882 while (n == 0 && curwin->w_cursor.lnum > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7883 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7884 l = ml_get(curwin->w_cursor.lnum - 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7885 if (*l == NUL || l[STRLEN(l) - 1] != '\\')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7886 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7887 --curwin->w_cursor.lnum;
1550
d976f4da2a4d updated for version 7.1-264
vimboss
parents: 1532
diff changeset
7888 curwin->w_cursor.col = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7889 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7890
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7891 amount = get_indent(); /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7892
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7893 if (amount == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7894 amount = cin_first_id_amount();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7895 if (amount == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7896 amount = ind_continuation;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7897 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7898 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7899
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7900 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7901 * If the line looks like a function declaration, and we're
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7902 * not in a comment, put it the left margin.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7903 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7904 if (cin_isfuncdecl(NULL, cur_curpos.lnum)) /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7905 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7906 l = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7907
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7908 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7909 * Finding the closing '}' of a previous function. Put
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7910 * current line at the left margin. For when 'cino' has "fs".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7911 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7912 if (*skipwhite(l) == '}')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7913 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7914
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7915 /* (matching {)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7916 * If the previous line ends on '};' (maybe followed by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7917 * comments) align at column 0. For example:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7918 * char *string_array[] = { "foo",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7919 * / * x * / "b};ar" }; / * foobar * /
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7920 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7921 if (cin_ends_in(l, (char_u *)"};", NULL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7922 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7923
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7924 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7925 * If the PREVIOUS line is a function declaration, the current
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7926 * line (and the ones that follow) needs to be indented as
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7927 * parameters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7928 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7929 if (cin_isfuncdecl(&l, curwin->w_cursor.lnum))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7930 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7931 amount = ind_param;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7932 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7933 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7934
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7935 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7936 * If the previous line ends in ';' and the line before the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7937 * previous line ends in ',' or '\', ident to column zero:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7938 * int foo,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7939 * bar;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7940 * indent_to_0 here;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7941 */
828
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
7942 if (cin_ends_in(l, (char_u *)";", NULL))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7943 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7944 l = ml_get(curwin->w_cursor.lnum - 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7945 if (cin_ends_in(l, (char_u *)",", NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7946 || (*l != NUL && l[STRLEN(l) - 1] == '\\'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7947 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7948 l = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7949 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7950
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7951 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7952 * Doesn't look like anything interesting -- so just
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7953 * use the indent of this line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7954 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7955 * Position the cursor over the rightmost paren, so that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7956 * matching it will take us back to the start of the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7957 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7958 find_last_paren(l, '(', ')');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7959
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7960 if ((trypos = find_match_paren(ind_maxparen,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7961 ind_maxcomment)) != NULL)
1550
d976f4da2a4d updated for version 7.1-264
vimboss
parents: 1532
diff changeset
7962 curwin->w_cursor = *trypos;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7963 amount = get_indent(); /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7964 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7965 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7966
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7967 /* add extra indent for a comment */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7968 if (cin_iscomment(theline))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7969 amount += ind_comment;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7970
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7971 /* add extra indent if the previous line ended in a backslash:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7972 * "asdfasdf\
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7973 * here";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7974 * char *foo = "asdf\
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7975 * here";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7976 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7977 if (cur_curpos.lnum > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7978 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7979 l = ml_get(cur_curpos.lnum - 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7980 if (*l != NUL && l[STRLEN(l) - 1] == '\\')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7981 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7982 cur_amount = cin_get_equal_amount(cur_curpos.lnum - 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7983 if (cur_amount > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7984 amount = cur_amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7985 else if (cur_amount == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7986 amount += ind_continuation;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7987 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7988 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7989 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7990 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7991
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7992 theend:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7993 /* put the cursor back where it belongs */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7994 curwin->w_cursor = cur_curpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7995
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7996 vim_free(linecopy);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7997
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7998 if (amount < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7999 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8000 return amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8001 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8002
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8003 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8004 find_match(lookfor, ourscope, ind_maxparen, ind_maxcomment)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8005 int lookfor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8006 linenr_T ourscope;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8007 int ind_maxparen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8008 int ind_maxcomment;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8009 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8010 char_u *look;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8011 pos_T *theirscope;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8012 char_u *mightbeif;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8013 int elselevel;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8014 int whilelevel;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8015
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8016 if (lookfor == LOOKFOR_IF)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8017 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8018 elselevel = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8019 whilelevel = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8020 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8021 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8022 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8023 elselevel = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8024 whilelevel = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8025 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8026
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8027 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8028
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8029 while (curwin->w_cursor.lnum > ourscope + 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8030 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8031 curwin->w_cursor.lnum--;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8032 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8033
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8034 look = cin_skipcomment(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8035 if (cin_iselse(look)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8036 || cin_isif(look)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8037 || cin_isdo(look) /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8038 || cin_iswhileofdo(look, curwin->w_cursor.lnum, ind_maxparen))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8039 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8040 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8041 * if we've gone outside the braces entirely,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8042 * we must be out of scope...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8043 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8044 theirscope = find_start_brace(ind_maxcomment); /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8045 if (theirscope == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8046 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8047
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8048 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8049 * and if the brace enclosing this is further
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8050 * back than the one enclosing the else, we're
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8051 * out of luck too.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8052 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8053 if (theirscope->lnum < ourscope)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8054 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8055
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8056 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8057 * and if they're enclosed in a *deeper* brace,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8058 * then we can ignore it because it's in a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8059 * different scope...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8060 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8061 if (theirscope->lnum > ourscope)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8062 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8063
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8064 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8065 * if it was an "else" (that's not an "else if")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8066 * then we need to go back to another if, so
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8067 * increment elselevel
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8068 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8069 look = cin_skipcomment(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8070 if (cin_iselse(look))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8071 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8072 mightbeif = cin_skipcomment(look + 4);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8073 if (!cin_isif(mightbeif))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8074 ++elselevel;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8075 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8076 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8077
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8078 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8079 * if it was a "while" then we need to go back to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8080 * another "do", so increment whilelevel. XXX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8081 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8082 if (cin_iswhileofdo(look, curwin->w_cursor.lnum, ind_maxparen))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8083 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8084 ++whilelevel;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8085 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8086 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8087
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8088 /* If it's an "if" decrement elselevel */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8089 look = cin_skipcomment(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8090 if (cin_isif(look))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8091 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8092 elselevel--;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8093 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8094 * When looking for an "if" ignore "while"s that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8095 * get in the way.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8096 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8097 if (elselevel == 0 && lookfor == LOOKFOR_IF)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8098 whilelevel = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8099 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8100
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8101 /* If it's a "do" decrement whilelevel */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8102 if (cin_isdo(look))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8103 whilelevel--;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8104
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8105 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8106 * if we've used up all the elses, then
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8107 * this must be the if that we want!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8108 * match the indent level of that if.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8109 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8110 if (elselevel <= 0 && whilelevel <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8111 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8112 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8113 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8114 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8115 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8116 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8117 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8118
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8119 # if defined(FEAT_EVAL) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8120 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8121 * Get indent level from 'indentexpr'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8122 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8123 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8124 get_expr_indent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8125 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8126 int indent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8127 pos_T pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8128 int save_State;
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 680
diff changeset
8129 int use_sandbox = was_set_insecurely((char_u *)"indentexpr",
9364d114ed8d updated for version 7.0204
vimboss
parents: 680
diff changeset
8130 OPT_LOCAL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8131
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8132 pos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8133 set_vim_var_nr(VV_LNUM, curwin->w_cursor.lnum);
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 626
diff changeset
8134 if (use_sandbox)
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 626
diff changeset
8135 ++sandbox;
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 626
diff changeset
8136 ++textlock;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8137 indent = eval_to_number(curbuf->b_p_inde);
634
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 626
diff changeset
8138 if (use_sandbox)
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 626
diff changeset
8139 --sandbox;
1c586ee8dd45 updated for version 7.0183
vimboss
parents: 626
diff changeset
8140 --textlock;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8141
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8142 /* Restore the cursor position so that 'indentexpr' doesn't need to.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8143 * Pretend to be in Insert mode, allow cursor past end of line for "o"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8144 * command. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8145 save_State = State;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8146 State = INSERT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8147 curwin->w_cursor = pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8148 check_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8149 State = save_State;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8150
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8151 /* If there is an error, just keep the current indent. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8152 if (indent < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8153 indent = get_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8154
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8155 return indent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8156 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8157 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8158
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8159 #endif /* FEAT_CINDENT */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8160
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8161 #if defined(FEAT_LISP) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8162
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8163 static int lisp_match __ARGS((char_u *p));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8164
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8165 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8166 lisp_match(p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8167 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8168 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8169 char_u buf[LSIZE];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8170 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8171 char_u *word = p_lispwords;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8172
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8173 while (*word != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8174 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8175 (void)copy_option_part(&word, buf, LSIZE, ",");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8176 len = (int)STRLEN(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8177 if (STRNCMP(buf, p, len) == 0 && p[len] == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8178 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8179 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8180 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8181 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8182
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8183 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8184 * When 'p' is present in 'cpoptions, a Vi compatible method is used.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8185 * The incompatible newer method is quite a bit better at indenting
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8186 * code in lisp-like languages than the traditional one; it's still
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8187 * mostly heuristics however -- Dirk van Deun, dirk@rave.org
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8188 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8189 * TODO:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8190 * Findmatch() should be adapted for lisp, also to make showmatch
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8191 * work correctly: now (v5.3) it seems all C/C++ oriented:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8192 * - it does not recognize the #\( and #\) notations as character literals
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8193 * - it doesn't know about comments starting with a semicolon
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8194 * - it incorrectly interprets '(' as a character literal
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8195 * All this messes up get_lisp_indent in some rare cases.
14
946da5994c01 updated for version 7.0006
vimboss
parents: 11
diff changeset
8196 * Update from Sergey Khorev:
946da5994c01 updated for version 7.0006
vimboss
parents: 11
diff changeset
8197 * I tried to fix the first two issues.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8198 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8199 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8200 get_lisp_indent()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8201 {
14
946da5994c01 updated for version 7.0006
vimboss
parents: 11
diff changeset
8202 pos_T *pos, realpos, paren;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8203 int amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8204 char_u *that;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8205 colnr_T col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8206 colnr_T firsttry;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8207 int parencount, quotecount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8208 int vi_lisp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8209
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8210 /* Set vi_lisp to use the vi-compatible method */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8211 vi_lisp = (vim_strchr(p_cpo, CPO_LISP) != NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8212
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8213 realpos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8214 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8215
14
946da5994c01 updated for version 7.0006
vimboss
parents: 11
diff changeset
8216 if ((pos = findmatch(NULL, '(')) == NULL)
946da5994c01 updated for version 7.0006
vimboss
parents: 11
diff changeset
8217 pos = findmatch(NULL, '[');
946da5994c01 updated for version 7.0006
vimboss
parents: 11
diff changeset
8218 else
946da5994c01 updated for version 7.0006
vimboss
parents: 11
diff changeset
8219 {
946da5994c01 updated for version 7.0006
vimboss
parents: 11
diff changeset
8220 paren = *pos;
946da5994c01 updated for version 7.0006
vimboss
parents: 11
diff changeset
8221 pos = findmatch(NULL, '[');
946da5994c01 updated for version 7.0006
vimboss
parents: 11
diff changeset
8222 if (pos == NULL || ltp(pos, &paren))
946da5994c01 updated for version 7.0006
vimboss
parents: 11
diff changeset
8223 pos = &paren;
946da5994c01 updated for version 7.0006
vimboss
parents: 11
diff changeset
8224 }
946da5994c01 updated for version 7.0006
vimboss
parents: 11
diff changeset
8225 if (pos != NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8226 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8227 /* Extra trick: Take the indent of the first previous non-white
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8228 * line that is at the same () level. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8229 amount = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8230 parencount = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8231
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8232 while (--curwin->w_cursor.lnum >= pos->lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8233 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8234 if (linewhite(curwin->w_cursor.lnum))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8235 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8236 for (that = ml_get_curline(); *that != NUL; ++that)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8237 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8238 if (*that == ';')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8239 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8240 while (*(that + 1) != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8241 ++that;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8242 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8243 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8244 if (*that == '\\')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8245 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8246 if (*(that + 1) != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8247 ++that;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8248 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8249 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8250 if (*that == '"' && *(that + 1) != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8251 {
983
f3669fbc9a31 updated for version 7.0-109
vimboss
parents: 964
diff changeset
8252 while (*++that && *that != '"')
f3669fbc9a31 updated for version 7.0-109
vimboss
parents: 964
diff changeset
8253 {
f3669fbc9a31 updated for version 7.0-109
vimboss
parents: 964
diff changeset
8254 /* skipping escaped characters in the string */
f3669fbc9a31 updated for version 7.0-109
vimboss
parents: 964
diff changeset
8255 if (*that == '\\')
f3669fbc9a31 updated for version 7.0-109
vimboss
parents: 964
diff changeset
8256 {
f3669fbc9a31 updated for version 7.0-109
vimboss
parents: 964
diff changeset
8257 if (*++that == NUL)
f3669fbc9a31 updated for version 7.0-109
vimboss
parents: 964
diff changeset
8258 break;
f3669fbc9a31 updated for version 7.0-109
vimboss
parents: 964
diff changeset
8259 if (that[1] == NUL)
f3669fbc9a31 updated for version 7.0-109
vimboss
parents: 964
diff changeset
8260 {
f3669fbc9a31 updated for version 7.0-109
vimboss
parents: 964
diff changeset
8261 ++that;
f3669fbc9a31 updated for version 7.0-109
vimboss
parents: 964
diff changeset
8262 break;
f3669fbc9a31 updated for version 7.0-109
vimboss
parents: 964
diff changeset
8263 }
f3669fbc9a31 updated for version 7.0-109
vimboss
parents: 964
diff changeset
8264 }
f3669fbc9a31 updated for version 7.0-109
vimboss
parents: 964
diff changeset
8265 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8266 }
14
946da5994c01 updated for version 7.0006
vimboss
parents: 11
diff changeset
8267 if (*that == '(' || *that == '[')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8268 ++parencount;
14
946da5994c01 updated for version 7.0006
vimboss
parents: 11
diff changeset
8269 else if (*that == ')' || *that == ']')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8270 --parencount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8271 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8272 if (parencount == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8273 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8274 amount = get_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8275 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8276 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8277 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8278
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8279 if (amount == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8280 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8281 curwin->w_cursor.lnum = pos->lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8282 curwin->w_cursor.col = pos->col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8283 col = pos->col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8284
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8285 that = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8286
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8287 if (vi_lisp && get_indent() == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8288 amount = 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8289 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8290 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8291 amount = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8292 while (*that && col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8293 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8294 amount += lbr_chartabsize_adv(&that, (colnr_T)amount);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8295 col--;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8296 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8297
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8298 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8299 * Some keywords require "body" indenting rules (the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8300 * non-standard-lisp ones are Scheme special forms):
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8301 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8302 * (let ((a 1)) instead (let ((a 1))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8303 * (...)) of (...))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8304 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8305
14
946da5994c01 updated for version 7.0006
vimboss
parents: 11
diff changeset
8306 if (!vi_lisp && (*that == '(' || *that == '[')
946da5994c01 updated for version 7.0006
vimboss
parents: 11
diff changeset
8307 && lisp_match(that + 1))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8308 amount += 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8309 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8310 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8311 that++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8312 amount++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8313 firsttry = amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8314
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8315 while (vim_iswhite(*that))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8316 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8317 amount += lbr_chartabsize(that, (colnr_T)amount);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8318 ++that;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8319 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8320
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8321 if (*that && *that != ';') /* not a comment line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8322 {
1532
87b9f21264a7 updated for version 7.1-247
vimboss
parents: 1521
diff changeset
8323 /* test *that != '(' to accommodate first let/do
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8324 * argument if it is more than one line */
14
946da5994c01 updated for version 7.0006
vimboss
parents: 11
diff changeset
8325 if (!vi_lisp && *that != '(' && *that != '[')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8326 firsttry++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8327
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8328 parencount = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8329 quotecount = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8330
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8331 if (vi_lisp
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8332 || (*that != '"'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8333 && *that != '\''
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8334 && *that != '#'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8335 && (*that < '0' || *that > '9')))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8336 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8337 while (*that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8338 && (!vim_iswhite(*that)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8339 || quotecount
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8340 || parencount)
14
946da5994c01 updated for version 7.0006
vimboss
parents: 11
diff changeset
8341 && (!((*that == '(' || *that == '[')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8342 && !quotecount
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8343 && !parencount
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8344 && vi_lisp)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8345 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8346 if (*that == '"')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8347 quotecount = !quotecount;
14
946da5994c01 updated for version 7.0006
vimboss
parents: 11
diff changeset
8348 if ((*that == '(' || *that == '[')
946da5994c01 updated for version 7.0006
vimboss
parents: 11
diff changeset
8349 && !quotecount)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8350 ++parencount;
14
946da5994c01 updated for version 7.0006
vimboss
parents: 11
diff changeset
8351 if ((*that == ')' || *that == ']')
946da5994c01 updated for version 7.0006
vimboss
parents: 11
diff changeset
8352 && !quotecount)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8353 --parencount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8354 if (*that == '\\' && *(that+1) != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8355 amount += lbr_chartabsize_adv(&that,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8356 (colnr_T)amount);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8357 amount += lbr_chartabsize_adv(&that,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8358 (colnr_T)amount);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8359 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8360 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8361 while (vim_iswhite(*that))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8362 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8363 amount += lbr_chartabsize(that, (colnr_T)amount);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8364 that++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8365 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8366 if (!*that || *that == ';')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8367 amount = firsttry;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8368 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8369 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8370 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8371 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8372 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8373 else
14
946da5994c01 updated for version 7.0006
vimboss
parents: 11
diff changeset
8374 amount = 0; /* no matching '(' or '[' found, use zero indent */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8375
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8376 curwin->w_cursor = realpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8377
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8378 return amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8379 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8380 #endif /* FEAT_LISP */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8381
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8382 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8383 prepare_to_exit()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8384 {
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
8385 #if defined(SIGHUP) && defined(SIG_IGN)
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
8386 /* Ignore SIGHUP, because a dropped connection causes a read error, which
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
8387 * makes Vim exit and then handling SIGHUP causes various reentrance
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
8388 * problems. */
36
125e80798a85 updated for version 7.0021
vimboss
parents: 24
diff changeset
8389 signal(SIGHUP, SIG_IGN);
125e80798a85 updated for version 7.0021
vimboss
parents: 24
diff changeset
8390 #endif
125e80798a85 updated for version 7.0021
vimboss
parents: 24
diff changeset
8391
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8392 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8393 if (gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8394 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8395 gui.dying = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8396 out_trash(); /* trash any pending output */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8397 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8398 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8399 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8400 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8401 windgoto((int)Rows - 1, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8402
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8403 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8404 * Switch terminal mode back now, so messages end up on the "normal"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8405 * screen (if there are two screens).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8406 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8407 settmode(TMODE_COOK);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8408 #ifdef WIN3264
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8409 if (can_end_termcap_mode(FALSE) == TRUE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8410 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8411 stoptermcap();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8412 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8413 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8414 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8415
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8416 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8417 * Preserve files and exit.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8418 * When called IObuff must contain a message.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8419 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8420 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8421 preserve_exit()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8422 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8423 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8424
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8425 prepare_to_exit();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8426
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 613
diff changeset
8427 /* Setting this will prevent free() calls. That avoids calling free()
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 613
diff changeset
8428 * recursively when free() was invoked with a bad pointer. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 613
diff changeset
8429 really_exiting = TRUE;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 613
diff changeset
8430
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8431 out_str(IObuff);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8432 screen_start(); /* don't know where cursor is now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8433 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8434
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8435 ml_close_notmod(); /* close all not-modified buffers */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8436
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8437 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8438 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8439 if (buf->b_ml.ml_mfp != NULL && buf->b_ml.ml_mfp->mf_fname != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8440 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8441 OUT_STR(_("Vim: preserving files...\n"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8442 screen_start(); /* don't know where cursor is now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8443 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8444 ml_sync_all(FALSE, FALSE); /* preserve all swap files */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8445 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8446 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8447 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8448
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8449 ml_close_all(FALSE); /* close all memfiles, without deleting */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8450
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8451 OUT_STR(_("Vim: Finished.\n"));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8452
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8453 getout(1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8454 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8455
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8456 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8457 * return TRUE if "fname" exists.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8458 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8459 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8460 vim_fexists(fname)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8461 char_u *fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8462 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8463 struct stat st;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8464
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8465 if (mch_stat((char *)fname, &st))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8466 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8467 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8468 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8469
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8470 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8471 * Check for CTRL-C pressed, but only once in a while.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8472 * Should be used instead of ui_breakcheck() for functions that check for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8473 * each line in the file. Calling ui_breakcheck() each time takes too much
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8474 * time, because it can be a system call.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8475 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8476
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8477 #ifndef BREAKCHECK_SKIP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8478 # ifdef FEAT_GUI /* assume the GUI only runs on fast computers */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8479 # define BREAKCHECK_SKIP 200
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8480 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8481 # define BREAKCHECK_SKIP 32
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8482 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8483 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8484
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8485 static int breakcheck_count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8486
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8487 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8488 line_breakcheck()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8489 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8490 if (++breakcheck_count >= BREAKCHECK_SKIP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8491 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8492 breakcheck_count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8493 ui_breakcheck();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8494 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8495 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8496
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8497 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8498 * Like line_breakcheck() but check 10 times less often.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8499 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8500 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8501 fast_breakcheck()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8502 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8503 if (++breakcheck_count >= BREAKCHECK_SKIP * 10)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8504 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8505 breakcheck_count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8506 ui_breakcheck();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8507 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8508 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8509
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8510 /*
2016
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8511 * Invoke expand_wildcards() for one pattern.
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8512 * Expand items like "%:h" before the expansion.
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8513 * Returns OK or FAIL.
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8514 */
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8515 int
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8516 expand_wildcards_eval(pat, num_file, file, flags)
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8517 char_u **pat; /* pointer to input pattern */
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8518 int *num_file; /* resulting number of files */
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8519 char_u ***file; /* array of resulting files */
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8520 int flags; /* EW_DIR, etc. */
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8521 {
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8522 int ret = FAIL;
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8523 char_u *eval_pat = NULL;
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8524 char_u *exp_pat = *pat;
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8525 char_u *ignored_msg;
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8526 int usedlen;
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8527
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8528 if (*exp_pat == '%' || *exp_pat == '#' || *exp_pat == '<')
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8529 {
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8530 ++emsg_off;
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8531 eval_pat = eval_vars(exp_pat, exp_pat, &usedlen,
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8532 NULL, &ignored_msg, NULL);
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8533 --emsg_off;
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8534 if (eval_pat != NULL)
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8535 exp_pat = concat_str(eval_pat, exp_pat + usedlen);
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8536 }
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8537
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8538 if (exp_pat != NULL)
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8539 ret = expand_wildcards(1, &exp_pat, num_file, file, flags);
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8540
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8541 if (eval_pat != NULL)
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8542 {
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8543 vim_free(exp_pat);
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8544 vim_free(eval_pat);
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8545 }
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8546
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8547 return ret;
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8548 }
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8549
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
8550 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8551 * Expand wildcards. Calls gen_expand_wildcards() and removes files matching
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8552 * 'wildignore'.
2354
f4440cdd59ae Fixed: crash with ":find " completion, using uninitialized count.
Bram Moolenaar <bram@vim.org>
parents: 2328
diff changeset
8553 * Returns OK or FAIL. When FAIL then "num_file" won't be set.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8554 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8555 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8556 expand_wildcards(num_pat, pat, num_file, file, flags)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8557 int num_pat; /* number of input patterns */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8558 char_u **pat; /* array of input patterns */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8559 int *num_file; /* resulting number of files */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8560 char_u ***file; /* array of resulting files */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8561 int flags; /* EW_DIR, etc. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8562 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8563 int retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8564 int i, j;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8565 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8566 int non_suf_match; /* number without matching suffix */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8567
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8568 retval = gen_expand_wildcards(num_pat, pat, num_file, file, flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8569
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8570 /* When keeping all matches, return here */
2354
f4440cdd59ae Fixed: crash with ":find " completion, using uninitialized count.
Bram Moolenaar <bram@vim.org>
parents: 2328
diff changeset
8571 if ((flags & EW_KEEPALL) || retval == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8572 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8573
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8574 #ifdef FEAT_WILDIGN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8575 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8576 * Remove names that match 'wildignore'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8577 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8578 if (*p_wig)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8579 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8580 char_u *ffname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8581
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8582 /* check all files in (*file)[] */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8583 for (i = 0; i < *num_file; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8584 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8585 ffname = FullName_save((*file)[i], FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8586 if (ffname == NULL) /* out of memory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8587 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8588 # ifdef VMS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8589 vms_remove_version(ffname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8590 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8591 if (match_file_list(p_wig, (*file)[i], ffname))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8592 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8593 /* remove this matching file from the list */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8594 vim_free((*file)[i]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8595 for (j = i; j + 1 < *num_file; ++j)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8596 (*file)[j] = (*file)[j + 1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8597 --*num_file;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8598 --i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8599 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8600 vim_free(ffname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8601 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8602 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8603 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8604
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8605 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8606 * Move the names where 'suffixes' match to the end.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8607 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8608 if (*num_file > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8609 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8610 non_suf_match = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8611 for (i = 0; i < *num_file; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8612 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8613 if (!match_suffix((*file)[i]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8614 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8615 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8616 * Move the name without matching suffix to the front
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8617 * of the list.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8618 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8619 p = (*file)[i];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8620 for (j = i; j > non_suf_match; --j)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8621 (*file)[j] = (*file)[j - 1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8622 (*file)[non_suf_match++] = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8623 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8624 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8625 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8626
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8627 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8628 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8629
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8630 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8631 * Return TRUE if "fname" matches with an entry in 'suffixes'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8632 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8633 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8634 match_suffix(fname)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8635 char_u *fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8636 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8637 int fnamelen, setsuflen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8638 char_u *setsuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8639 #define MAXSUFLEN 30 /* maximum length of a file suffix */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8640 char_u suf_buf[MAXSUFLEN];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8641
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8642 fnamelen = (int)STRLEN(fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8643 setsuflen = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8644 for (setsuf = p_su; *setsuf; )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8645 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8646 setsuflen = copy_option_part(&setsuf, suf_buf, MAXSUFLEN, ".,");
1937
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
8647 if (setsuflen == 0)
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
8648 {
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
8649 char_u *tail = gettail(fname);
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
8650
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
8651 /* empty entry: match name without a '.' */
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
8652 if (vim_strchr(tail, '.') == NULL)
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
8653 {
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
8654 setsuflen = 1;
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
8655 break;
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
8656 }
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
8657 }
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
8658 else
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
8659 {
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
8660 if (fnamelen >= setsuflen
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
8661 && fnamencmp(suf_buf, fname + fnamelen - setsuflen,
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
8662 (size_t)setsuflen) == 0)
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
8663 break;
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
8664 setsuflen = 0;
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
8665 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8666 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8667 return (setsuflen != 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8668 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8669
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8670 #if !defined(NO_EXPANDPATH) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8671
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8672 # ifdef VIM_BACKTICK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8673 static int vim_backtick __ARGS((char_u *p));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8674 static int expand_backtick __ARGS((garray_T *gap, char_u *pat, int flags));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8675 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8676
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8677 # if defined(MSDOS) || defined(FEAT_GUI_W16) || defined(WIN3264)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8678 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8679 * File name expansion code for MS-DOS, Win16 and Win32. It's here because
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8680 * it's shared between these systems.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8681 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8682 # if defined(DJGPP) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8683 # define _cdecl /* DJGPP doesn't have this */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8684 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8685 # ifdef __BORLANDC__
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8686 # define _cdecl _RTLENTRYF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8687 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8688 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8689
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8690 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8691 * comparison function for qsort in dos_expandpath()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8692 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8693 static int _cdecl
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8694 pstrcmp(const void *a, const void *b)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8695 {
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
8696 return (pathcmp(*(char **)a, *(char **)b, -1));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8697 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8698
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8699 # ifndef WIN3264
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8700 static void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8701 namelowcpy(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8702 char_u *d,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8703 char_u *s)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8704 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8705 # ifdef DJGPP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8706 if (USE_LONG_FNAME) /* don't lower case on Windows 95/NT systems */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8707 while (*s)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8708 *d++ = *s++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8709 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8710 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8711 while (*s)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8712 *d++ = TOLOWER_LOC(*s++);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8713 *d = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8714 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8715 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8716
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8717 /*
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8718 * Recursively expand one path component into all matching files and/or
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8719 * directories. Adds matches to "gap". Handles "*", "?", "[a-z]", "**", etc.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8720 * Return the number of matches found.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8721 * "path" has backslashes before chars that are not to be expanded, starting
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8722 * at "path[wildoff]".
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8723 * Return the number of matches found.
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8724 * NOTE: much of this is identical to unix_expandpath(), keep in sync!
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8725 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8726 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8727 dos_expandpath(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8728 garray_T *gap,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8729 char_u *path,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8730 int wildoff,
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8731 int flags, /* EW_* flags */
1224
edc1c9d6dab9 updated for version 7.1b
vimboss
parents: 1096
diff changeset
8732 int didstar) /* expanded "**" once already */
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8733 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8734 char_u *buf;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8735 char_u *path_end;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8736 char_u *p, *s, *e;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8737 int start_len = gap->ga_len;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8738 char_u *pat;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8739 regmatch_T regmatch;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8740 int starts_with_dot;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8741 int matches;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8742 int len;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8743 int starstar = FALSE;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8744 static int stardepth = 0; /* depth for "**" expansion */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8745 #ifdef WIN3264
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8746 WIN32_FIND_DATA fb;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8747 HANDLE hFind = (HANDLE)0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8748 # ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8749 WIN32_FIND_DATAW wfb;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8750 WCHAR *wn = NULL; /* UCS-2 name, NULL when not used. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8751 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8752 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8753 struct ffblk fb;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8754 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8755 char_u *matchname;
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8756 int ok;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8757
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8758 /* Expanding "**" may take a long time, check for CTRL-C. */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8759 if (stardepth > 0)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8760 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8761 ui_breakcheck();
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8762 if (got_int)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8763 return 0;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8764 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8765
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8766 /* make room for file name */
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8767 buf = alloc((int)STRLEN(path) + BASENAMELEN + 5);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8768 if (buf == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8769 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8770
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8771 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8772 * Find the first part in the path name that contains a wildcard or a ~1.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8773 * Copy it into buf, including the preceding characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8774 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8775 p = buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8776 s = buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8777 e = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8778 path_end = path;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8779 while (*path_end != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8780 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8781 /* May ignore a wildcard that has a backslash before it; it will
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8782 * be removed by rem_backslash() or file_pat_to_reg_pat() below. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8783 if (path_end >= path + wildoff && rem_backslash(path_end))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8784 *p++ = *path_end++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8785 else if (*path_end == '\\' || *path_end == ':' || *path_end == '/')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8786 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8787 if (e != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8788 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8789 s = p + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8790 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8791 else if (path_end >= path + wildoff
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8792 && vim_strchr((char_u *)"*?[~", *path_end) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8793 e = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8794 #ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8795 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8796 {
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 445
diff changeset
8797 len = (*mb_ptr2len)(path_end);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8798 STRNCPY(p, path_end, len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8799 p += len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8800 path_end += len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8801 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8802 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8803 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8804 *p++ = *path_end++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8805 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8806 e = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8807 *e = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8808
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8809 /* now we have one wildcard component between s and e */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8810 /* Remove backslashes between "wildoff" and the start of the wildcard
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8811 * component. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8812 for (p = buf + wildoff; p < s; ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8813 if (rem_backslash(p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8814 {
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1617
diff changeset
8815 STRMOVE(p, p + 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8816 --e;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8817 --s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8818 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8819
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8820 /* Check for "**" between "s" and "e". */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8821 for (p = s; p < e; ++p)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8822 if (p[0] == '*' && p[1] == '*')
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8823 starstar = TRUE;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8824
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8825 starts_with_dot = (*s == '.');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8826 pat = file_pat_to_reg_pat(s, e, NULL, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8827 if (pat == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8828 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8829 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8830 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8831 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8832
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8833 /* compile the regexp into a program */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8834 regmatch.rm_ic = TRUE; /* Always ignore case */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8835 regmatch.regprog = vim_regcomp(pat, RE_MAGIC);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8836 vim_free(pat);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8837
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8838 if (regmatch.regprog == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8839 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8840 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8841 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8842 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8843
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8844 /* remember the pattern or file name being looked for */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8845 matchname = vim_strsave(s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8846
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8847 /* If "**" is by itself, this is the first time we encounter it and more
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8848 * is following then find matches without any directory. */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8849 if (!didstar && stardepth < 100 && starstar && e - s == 2
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8850 && *path_end == '/')
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8851 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8852 STRCPY(s, path_end + 1);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8853 ++stardepth;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8854 (void)dos_expandpath(gap, buf, (int)(s - buf), flags, TRUE);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8855 --stardepth;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8856 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8857
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8858 /* Scan all files in the directory with "dir/ *.*" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8859 STRCPY(s, "*.*");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8860 #ifdef WIN3264
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8861 # ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8862 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8863 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8864 /* The active codepage differs from 'encoding'. Attempt using the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8865 * wide function. If it fails because it is not implemented fall back
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8866 * to the non-wide version (for Windows 98) */
1752
a8aae2e1d2ae updated for version 7.2-049
vimboss
parents: 1733
diff changeset
8867 wn = enc_to_utf16(buf, NULL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8868 if (wn != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8869 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8870 hFind = FindFirstFileW(wn, &wfb);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8871 if (hFind == INVALID_HANDLE_VALUE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8872 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8873 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8874 vim_free(wn);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8875 wn = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8876 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8877 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8878 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8879
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8880 if (wn == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8881 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8882 hFind = FindFirstFile(buf, &fb);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8883 ok = (hFind != INVALID_HANDLE_VALUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8884 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8885 /* If we are expanding wildcards we try both files and directories */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8886 ok = (findfirst((char *)buf, &fb,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8887 (*path_end != NUL || (flags & EW_DIR)) ? FA_DIREC : 0) == 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8888 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8889
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8890 while (ok)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8891 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8892 #ifdef WIN3264
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8893 # ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8894 if (wn != NULL)
1752
a8aae2e1d2ae updated for version 7.2-049
vimboss
parents: 1733
diff changeset
8895 p = utf16_to_enc(wfb.cFileName, NULL); /* p is allocated here */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8896 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8897 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8898 p = (char_u *)fb.cFileName;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8899 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8900 p = (char_u *)fb.ff_name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8901 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8902 /* Ignore entries starting with a dot, unless when asked for. Accept
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8903 * all entries found with "matchname". */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8904 if ((p[0] != '.' || starts_with_dot)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8905 && (matchname == NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8906 || vim_regexec(&regmatch, p, (colnr_T)0)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8907 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8908 #ifdef WIN3264
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8909 STRCPY(s, p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8910 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8911 namelowcpy(s, p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8912 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8913 len = (int)STRLEN(buf);
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8914
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8915 if (starstar && stardepth < 100)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8916 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8917 /* For "**" in the pattern first go deeper in the tree to
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8918 * find matches. */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8919 STRCPY(buf + len, "/**");
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8920 STRCPY(buf + len + 3, path_end);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8921 ++stardepth;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8922 (void)dos_expandpath(gap, buf, len + 1, flags, TRUE);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8923 --stardepth;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8924 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8925
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8926 STRCPY(buf + len, path_end);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8927 if (mch_has_exp_wildcard(path_end))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8928 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8929 /* need to expand another component of the path */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8930 /* remove backslashes for the remaining components only */
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
8931 (void)dos_expandpath(gap, buf, len + 1, flags, FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8932 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8933 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8934 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8935 /* no more wildcards, check if there is a match */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8936 /* remove backslashes for the remaining components only */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8937 if (*path_end != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8938 backslash_halve(buf + len + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8939 if (mch_getperm(buf) >= 0) /* add existing file */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8940 addfile(gap, buf, flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8941 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8942 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8943
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8944 #ifdef WIN3264
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8945 # ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8946 if (wn != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8947 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8948 vim_free(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8949 ok = FindNextFileW(hFind, &wfb);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8950 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8951 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8952 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8953 ok = FindNextFile(hFind, &fb);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8954 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8955 ok = (findnext(&fb) == 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8956 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8957
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8958 /* If no more matches and no match was used, try expanding the name
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8959 * itself. Finds the long name of a short filename. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8960 if (!ok && matchname != NULL && gap->ga_len == start_len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8961 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8962 STRCPY(s, matchname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8963 #ifdef WIN3264
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8964 FindClose(hFind);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8965 # ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8966 if (wn != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8967 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8968 vim_free(wn);
1752
a8aae2e1d2ae updated for version 7.2-049
vimboss
parents: 1733
diff changeset
8969 wn = enc_to_utf16(buf, NULL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8970 if (wn != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8971 hFind = FindFirstFileW(wn, &wfb);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8972 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8973 if (wn == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8974 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8975 hFind = FindFirstFile(buf, &fb);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8976 ok = (hFind != INVALID_HANDLE_VALUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8977 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8978 ok = (findfirst((char *)buf, &fb,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8979 (*path_end != NUL || (flags & EW_DIR)) ? FA_DIREC : 0) == 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8980 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8981 vim_free(matchname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8982 matchname = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8983 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8984 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8985
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8986 #ifdef WIN3264
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8987 FindClose(hFind);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8988 # ifdef FEAT_MBYTE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8989 vim_free(wn);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8990 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8991 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8992 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8993 vim_free(regmatch.regprog);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8994 vim_free(matchname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8995
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8996 matches = gap->ga_len - start_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8997 if (matches > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8998 qsort(((char_u **)gap->ga_data) + start_len, (size_t)matches,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8999 sizeof(char_u *), pstrcmp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9000 return matches;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9001 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9002
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9003 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9004 mch_expandpath(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9005 garray_T *gap,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9006 char_u *path,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9007 int flags) /* EW_* flags */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9008 {
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9009 return dos_expandpath(gap, path, 0, flags, FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9010 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9011 # endif /* MSDOS || FEAT_GUI_W16 || WIN3264 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9012
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9013 #if (defined(UNIX) && !defined(VMS)) || defined(USE_UNIXFILENAME) \
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9014 || defined(PROTO)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9015 /*
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9016 * Unix style wildcard expansion code.
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9017 * It's here because it's used both for Unix and Mac.
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9018 */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9019 static int pstrcmp __ARGS((const void *, const void *));
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9020
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9021 static int
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9022 pstrcmp(a, b)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9023 const void *a, *b;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9024 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9025 return (pathcmp(*(char **)a, *(char **)b, -1));
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9026 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9027
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9028 /*
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9029 * Recursively expand one path component into all matching files and/or
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9030 * directories. Adds matches to "gap". Handles "*", "?", "[a-z]", "**", etc.
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9031 * "path" has backslashes before chars that are not to be expanded, starting
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9032 * at "path + wildoff".
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9033 * Return the number of matches found.
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9034 * NOTE: much of this is identical to dos_expandpath(), keep in sync!
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9035 */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9036 int
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9037 unix_expandpath(gap, path, wildoff, flags, didstar)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9038 garray_T *gap;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9039 char_u *path;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9040 int wildoff;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9041 int flags; /* EW_* flags */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9042 int didstar; /* expanded "**" once already */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9043 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9044 char_u *buf;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9045 char_u *path_end;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9046 char_u *p, *s, *e;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9047 int start_len = gap->ga_len;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9048 char_u *pat;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9049 regmatch_T regmatch;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9050 int starts_with_dot;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9051 int matches;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9052 int len;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9053 int starstar = FALSE;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9054 static int stardepth = 0; /* depth for "**" expansion */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9055
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9056 DIR *dirp;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9057 struct dirent *dp;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9058
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9059 /* Expanding "**" may take a long time, check for CTRL-C. */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9060 if (stardepth > 0)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9061 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9062 ui_breakcheck();
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9063 if (got_int)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9064 return 0;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9065 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9066
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9067 /* make room for file name */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9068 buf = alloc((int)STRLEN(path) + BASENAMELEN + 5);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9069 if (buf == NULL)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9070 return 0;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9071
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9072 /*
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9073 * Find the first part in the path name that contains a wildcard.
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9074 * Copy it into "buf", including the preceding characters.
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9075 */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9076 p = buf;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9077 s = buf;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9078 e = NULL;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9079 path_end = path;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9080 while (*path_end != NUL)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9081 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9082 /* May ignore a wildcard that has a backslash before it; it will
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9083 * be removed by rem_backslash() or file_pat_to_reg_pat() below. */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9084 if (path_end >= path + wildoff && rem_backslash(path_end))
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9085 *p++ = *path_end++;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9086 else if (*path_end == '/')
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9087 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9088 if (e != NULL)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9089 break;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9090 s = p + 1;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9091 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9092 else if (path_end >= path + wildoff
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9093 && vim_strchr((char_u *)"*?[{~$", *path_end) != NULL)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9094 e = p;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9095 #ifdef FEAT_MBYTE
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9096 if (has_mbyte)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9097 {
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 445
diff changeset
9098 len = (*mb_ptr2len)(path_end);
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9099 STRNCPY(p, path_end, len);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9100 p += len;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9101 path_end += len;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9102 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9103 else
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9104 #endif
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9105 *p++ = *path_end++;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9106 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9107 e = p;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9108 *e = NUL;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9109
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9110 /* now we have one wildcard component between "s" and "e" */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9111 /* Remove backslashes between "wildoff" and the start of the wildcard
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9112 * component. */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9113 for (p = buf + wildoff; p < s; ++p)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9114 if (rem_backslash(p))
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9115 {
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1617
diff changeset
9116 STRMOVE(p, p + 1);
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9117 --e;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9118 --s;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9119 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9120
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9121 /* Check for "**" between "s" and "e". */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9122 for (p = s; p < e; ++p)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9123 if (p[0] == '*' && p[1] == '*')
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9124 starstar = TRUE;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9125
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9126 /* convert the file pattern to a regexp pattern */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9127 starts_with_dot = (*s == '.');
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9128 pat = file_pat_to_reg_pat(s, e, NULL, FALSE);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9129 if (pat == NULL)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9130 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9131 vim_free(buf);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9132 return 0;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9133 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9134
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9135 /* compile the regexp into a program */
587
3686831cf3da updated for version 7.0166
vimboss
parents: 548
diff changeset
9136 #ifdef CASE_INSENSITIVE_FILENAME
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9137 regmatch.rm_ic = TRUE; /* Behave like Terminal.app */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9138 #else
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9139 regmatch.rm_ic = FALSE; /* Don't ever ignore case */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9140 #endif
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9141 regmatch.regprog = vim_regcomp(pat, RE_MAGIC);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9142 vim_free(pat);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9143
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9144 if (regmatch.regprog == NULL)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9145 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9146 vim_free(buf);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9147 return 0;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9148 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9149
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9150 /* If "**" is by itself, this is the first time we encounter it and more
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9151 * is following then find matches without any directory. */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9152 if (!didstar && stardepth < 100 && starstar && e - s == 2
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9153 && *path_end == '/')
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9154 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9155 STRCPY(s, path_end + 1);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9156 ++stardepth;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9157 (void)unix_expandpath(gap, buf, (int)(s - buf), flags, TRUE);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9158 --stardepth;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9159 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9160
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9161 /* open the directory for scanning */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9162 *s = NUL;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9163 dirp = opendir(*buf == NUL ? "." : (char *)buf);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9164
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9165 /* Find all matching entries */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9166 if (dirp != NULL)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9167 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9168 for (;;)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9169 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9170 dp = readdir(dirp);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9171 if (dp == NULL)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9172 break;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9173 if ((dp->d_name[0] != '.' || starts_with_dot)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9174 && vim_regexec(&regmatch, (char_u *)dp->d_name, (colnr_T)0))
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9175 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9176 STRCPY(s, dp->d_name);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9177 len = STRLEN(buf);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9178
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9179 if (starstar && stardepth < 100)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9180 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9181 /* For "**" in the pattern first go deeper in the tree to
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9182 * find matches. */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9183 STRCPY(buf + len, "/**");
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9184 STRCPY(buf + len + 3, path_end);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9185 ++stardepth;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9186 (void)unix_expandpath(gap, buf, len + 1, flags, TRUE);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9187 --stardepth;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9188 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9189
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9190 STRCPY(buf + len, path_end);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9191 if (mch_has_exp_wildcard(path_end)) /* handle more wildcards */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9192 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9193 /* need to expand another component of the path */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9194 /* remove backslashes for the remaining components only */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9195 (void)unix_expandpath(gap, buf, len + 1, flags, FALSE);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9196 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9197 else
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9198 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9199 /* no more wildcards, check if there is a match */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9200 /* remove backslashes for the remaining components only */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9201 if (*path_end != NUL)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9202 backslash_halve(buf + len + 1);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9203 if (mch_getperm(buf) >= 0) /* add existing file */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9204 {
768
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
9205 #ifdef MACOS_CONVERT
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9206 size_t precomp_len = STRLEN(buf)+1;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9207 char_u *precomp_buf =
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9208 mac_precompose_path(buf, precomp_len, &precomp_len);
768
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
9209
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9210 if (precomp_buf)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9211 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9212 mch_memmove(buf, precomp_buf, precomp_len);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9213 vim_free(precomp_buf);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9214 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9215 #endif
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9216 addfile(gap, buf, flags);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9217 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9218 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9219 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9220 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9221
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9222 closedir(dirp);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9223 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9224
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9225 vim_free(buf);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9226 vim_free(regmatch.regprog);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9227
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9228 matches = gap->ga_len - start_len;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9229 if (matches > 0)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9230 qsort(((char_u **)gap->ga_data) + start_len, matches,
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9231 sizeof(char_u *), pstrcmp);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9232 return matches;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9233 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9234 #endif
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
9235
2311
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9236 #if defined(FEAT_SEARCHPATH)
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9237 static int find_previous_pathsep __ARGS((char_u *path, char_u **psep));
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9238 static int is_unique __ARGS((char_u *maybe_unique, garray_T *gap, int i));
2361
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9239 static void remove_duplicates __ARGS((garray_T *gap));
2311
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9240 static void uniquefy_paths __ARGS((garray_T *gap, char_u *pattern));
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9241 static int expand_in_path __ARGS((garray_T *gap, char_u *pattern, int flags));
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9242
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9243 /*
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9244 * Moves psep to the previous path separator in path, starting from the
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9245 * end of path.
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9246 * Returns FAIL is psep ends up at the beginning of path.
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9247 */
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9248 static int
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9249 find_previous_pathsep(path, psep)
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9250 char_u *path;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9251 char_u **psep;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9252 {
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9253 /* skip the current separator */
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9254 if (*psep > path && vim_ispathsep(**psep))
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9255 (*psep)--;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9256
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9257 /* find the previous separator */
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9258 while (*psep > path && !vim_ispathsep(**psep))
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9259 (*psep)--;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9260
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9261 if (*psep != path && vim_ispathsep(**psep))
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9262 return OK;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9263
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9264 return FAIL;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9265 }
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9266
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9267 /*
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9268 * Returns TRUE if maybe_unique is unique wrt other_paths in gap. maybe_unique
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9269 * is the end portion of ((char_u **)gap->ga_data)[i].
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9270 */
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9271 static int
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9272 is_unique(maybe_unique, gap, i)
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9273 char_u *maybe_unique;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9274 garray_T *gap;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9275 int i;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9276 {
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9277 int j;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9278 int candidate_len;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9279 int other_path_len;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9280 char_u *rival;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9281 char_u **other_paths;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9282
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9283 other_paths = (gap->ga_data != NULL) ? (char_u **)gap->ga_data
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9284 : (char_u **)"";
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9285
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9286 for (j = 0; j < gap->ga_len && !got_int; j++)
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9287 {
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9288 ui_breakcheck();
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9289 /* don't compare it with itself */
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9290 if (j == i)
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9291 continue;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9292
2322
70be008dff4f Avoid compiler warnings for size_t to int conversions.
Bram Moolenaar <bram@vim.org>
parents: 2313
diff changeset
9293 candidate_len = (int)STRLEN(maybe_unique);
70be008dff4f Avoid compiler warnings for size_t to int conversions.
Bram Moolenaar <bram@vim.org>
parents: 2313
diff changeset
9294 other_path_len = (int)STRLEN(other_paths[j]);
2311
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9295
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9296 if (other_path_len < candidate_len)
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9297 continue; /* it's different */
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9298
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9299 rival = other_paths[j] + other_path_len - candidate_len;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9300
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9301 if (fnamecmp(maybe_unique, rival) == 0)
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9302 return FALSE;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9303 }
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9304
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9305 return TRUE;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9306 }
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9307
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9308 /*
2361
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9309 * Remove adjecent duplicate entries from "gap", which is a list of file names
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9310 * in allocated memory.
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9311 */
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9312 static void
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9313 remove_duplicates(gap)
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9314 garray_T *gap;
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9315 {
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9316 int i;
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9317 int j;
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9318 char_u **fnames = (char_u **)gap->ga_data;
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9319
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9320 for (i = 1; i < gap->ga_len; ++i)
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9321 if (fnamecmp(fnames[i - 1], fnames[i]) == 0)
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9322 {
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9323 vim_free(fnames[i]);
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9324 for (j = i + 1; j < gap->ga_len; ++j)
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9325 fnames[j - 1] = fnames[j];
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9326 --gap->ga_len;
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9327 --i;
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9328 }
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9329 }
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9330
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9331 /*
2311
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9332 * Sorts, removes duplicates and modifies all the fullpath names in gap so that
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9333 * they are unique with respect to each other while conserving the part that
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9334 * matches the pattern. Beware, this is at least O(n^2) wrt gap->ga_len.
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9335 */
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9336 static void
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9337 uniquefy_paths(gap, pattern)
2361
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9338 garray_T *gap;
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9339 char_u *pattern;
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9340 {
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9341 int i;
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9342 int len;
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9343 char_u *pathsep_p;
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9344 char_u *path;
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9345 char_u **fnames = (char_u **) gap->ga_data;
2311
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9346 int sort_again = 0;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9347 char_u *pat;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9348 char_u *file_pattern;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9349 regmatch_T regmatch;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9350
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9351 sort_strings(fnames, gap->ga_len);
2361
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9352 remove_duplicates(gap);
2311
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9353
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9354 /*
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9355 * We need to prepend a '*' at the beginning of file_pattern so that the
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9356 * regex matches anywhere in the path. FIXME: is this valid for all
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9357 * possible pattern?
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9358 */
2322
70be008dff4f Avoid compiler warnings for size_t to int conversions.
Bram Moolenaar <bram@vim.org>
parents: 2313
diff changeset
9359 len = (int)STRLEN(pattern);
2311
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9360 file_pattern = alloc(len + 2);
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9361 file_pattern[0] = '*';
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9362 file_pattern[1] = '\0';
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9363 STRCAT(file_pattern, pattern);
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9364 pat = file_pat_to_reg_pat(file_pattern, NULL, NULL, TRUE);
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9365 vim_free(file_pattern);
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9366 regmatch.rm_ic = TRUE; /* always ignore case */
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9367
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9368 if (pat != NULL)
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9369 {
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9370 regmatch.regprog = vim_regcomp(pat, RE_MAGIC + RE_STRING);
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9371 vim_free(pat);
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9372 }
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9373 if (pat == NULL || regmatch.regprog == NULL)
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9374 return;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9375
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9376 for (i = 0; i < gap->ga_len; i++)
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9377 {
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9378 path = fnames[i];
2322
70be008dff4f Avoid compiler warnings for size_t to int conversions.
Bram Moolenaar <bram@vim.org>
parents: 2313
diff changeset
9379 len = (int)STRLEN(path);
2311
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9380
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9381 /* we start at the end of the path */
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9382 pathsep_p = path + len - 1;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9383
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9384 while (find_previous_pathsep(path, &pathsep_p))
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9385 if (vim_regexec(&regmatch, pathsep_p + 1, (colnr_T)0)
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9386 && is_unique(pathsep_p, gap, i))
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9387 {
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9388 sort_again = 1;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9389 mch_memmove(path, pathsep_p + 1, STRLEN(pathsep_p));
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9390 break;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9391 }
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9392 }
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9393
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9394 if (sort_again)
2361
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9395 {
2311
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9396 sort_strings(fnames, gap->ga_len);
2361
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9397 remove_duplicates(gap);
e12685c50982 Fix some duplicates in ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2354
diff changeset
9398 }
2311
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9399 }
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9400
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9401 /*
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9402 * Calls globpath with 'path' values for the given pattern and stores
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9403 * the result in gap.
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9404 * Returns the total number of matches.
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9405 */
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9406 static int
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9407 expand_in_path(gap, pattern, flags)
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9408 garray_T *gap;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9409 char_u *pattern;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9410 int flags; /* EW_* flags */
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9411 {
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9412 int c = 0;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9413 char_u *path_option = *curbuf->b_p_path == NUL
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9414 ? p_path : curbuf->b_p_path;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9415 char_u *files;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9416 char_u *s; /* start */
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9417 char_u *e; /* end */
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9418
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9419 files = globpath(path_option, pattern, 0);
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9420 if (files == NULL)
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9421 return 0;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9422
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9423 /* Copy each path in files into gap */
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9424 s = e = files;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9425 while (*s != '\0')
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9426 {
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9427 while (*e != '\n' && *e != '\0')
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9428 e++;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9429 if (*e == '\0')
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9430 {
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9431 addfile(gap, s, flags);
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9432 break;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9433 }
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9434 else
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9435 {
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9436 /* *e is '\n' */
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9437 *e = '\0';
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9438 addfile(gap, s, flags);
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9439 e++;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9440 s = e;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9441 }
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9442 }
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9443
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9444 c = gap->ga_len;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9445 vim_free(files);
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9446
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9447 return c;
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9448 }
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9449 #endif
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9450
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9451 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9452 * Generic wildcard expansion code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9453 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9454 * Characters in "pat" that should not be expanded must be preceded with a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9455 * backslash. E.g., "/path\ with\ spaces/my\*star*"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9456 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9457 * Return FAIL when no single file was found. In this case "num_file" is not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9458 * set, and "file" may contain an error message.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9459 * Return OK when some files found. "num_file" is set to the number of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9460 * matches, "file" to the array of matches. Call FreeWild() later.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9461 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9462 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9463 gen_expand_wildcards(num_pat, pat, num_file, file, flags)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9464 int num_pat; /* number of input patterns */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9465 char_u **pat; /* array of input patterns */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9466 int *num_file; /* resulting number of files */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9467 char_u ***file; /* array of resulting files */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9468 int flags; /* EW_* flags */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9469 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9470 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9471 garray_T ga;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9472 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9473 static int recursive = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9474 int add_pat;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9475
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9476 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9477 * expand_env() is called to expand things like "~user". If this fails,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9478 * it calls ExpandOne(), which brings us back here. In this case, always
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9479 * call the machine specific expansion function, if possible. Otherwise,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9480 * return FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9481 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9482 if (recursive)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9483 #ifdef SPECIAL_WILDCHAR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9484 return mch_expand_wildcards(num_pat, pat, num_file, file, flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9485 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9486 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9487 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9488
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9489 #ifdef SPECIAL_WILDCHAR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9490 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9491 * If there are any special wildcard characters which we cannot handle
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9492 * here, call machine specific function for all the expansion. This
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9493 * avoids starting the shell for each argument separately.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9494 * For `=expr` do use the internal function.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9495 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9496 for (i = 0; i < num_pat; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9497 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9498 if (vim_strpbrk(pat[i], (char_u *)SPECIAL_WILDCHAR) != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9499 # ifdef VIM_BACKTICK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9500 && !(vim_backtick(pat[i]) && pat[i][1] == '=')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9501 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9502 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9503 return mch_expand_wildcards(num_pat, pat, num_file, file, flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9504 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9505 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9506
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9507 recursive = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9508
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9509 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9510 * The matching file names are stored in a growarray. Init it empty.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9511 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9512 ga_init2(&ga, (int)sizeof(char_u *), 30);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9513
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9514 for (i = 0; i < num_pat; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9515 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9516 add_pat = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9517 p = pat[i];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9518
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9519 #ifdef VIM_BACKTICK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9520 if (vim_backtick(p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9521 add_pat = expand_backtick(&ga, p, flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9522 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9523 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9524 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9525 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9526 * First expand environment variables, "~/" and "~user/".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9527 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9528 if (vim_strpbrk(p, (char_u *)"$~") != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9529 {
1408
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
9530 p = expand_env_save_opt(p, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9531 if (p == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9532 p = pat[i];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9533 #ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9534 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9535 * On Unix, if expand_env() can't expand an environment
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9536 * variable, use the shell to do that. Discard previously
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9537 * found file names and start all over again.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9538 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9539 else if (vim_strpbrk(p, (char_u *)"$~") != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9540 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9541 vim_free(p);
1914
28641f0ed9de updated for version 7.2-211
vimboss
parents: 1883
diff changeset
9542 ga_clear_strings(&ga);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9543 i = mch_expand_wildcards(num_pat, pat, num_file, file,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9544 flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9545 recursive = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9546 return i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9547 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9548 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9549 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9550
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9551 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9552 * If there are wildcards: Expand file names and add each match to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9553 * the list. If there is no match, and EW_NOTFOUND is given, add
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9554 * the pattern.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9555 * If there are no wildcards: Add the file name if it exists or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9556 * when EW_NOTFOUND is given.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9557 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9558 if (mch_has_exp_wildcard(p))
2311
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9559 {
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9560 #if defined(FEAT_SEARCHPATH)
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9561 if (*p != '.' && !vim_ispathsep(*p) && (flags & EW_PATH))
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9562 add_pat = expand_in_path(&ga, p, flags);
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9563 else
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9564 #endif
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9565 add_pat = mch_expandpath(&ga, p, flags);
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
9566 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9567 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9568
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9569 if (add_pat == -1 || (add_pat == 0 && (flags & EW_NOTFOUND)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9570 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9571 char_u *t = backslash_halve_save(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9572
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9573 #if defined(MACOS_CLASSIC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9574 slash_to_colon(t);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9575 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9576 /* When EW_NOTFOUND is used, always add files and dirs. Makes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9577 * "vim c:/" work. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9578 if (flags & EW_NOTFOUND)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9579 addfile(&ga, t, flags | EW_DIR | EW_FILE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9580 else if (mch_getperm(t) >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9581 addfile(&ga, t, flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9582 vim_free(t);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9583 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9584
2313
e382b66b936d Fix using freed memory in :find completion.
Bram Moolenaar <bram@vim.org>
parents: 2311
diff changeset
9585 #if defined(FEAT_SEARCHPATH)
e382b66b936d Fix using freed memory in :find completion.
Bram Moolenaar <bram@vim.org>
parents: 2311
diff changeset
9586 if (flags & EW_PATH)
e382b66b936d Fix using freed memory in :find completion.
Bram Moolenaar <bram@vim.org>
parents: 2311
diff changeset
9587 uniquefy_paths(&ga, p);
e382b66b936d Fix using freed memory in :find completion.
Bram Moolenaar <bram@vim.org>
parents: 2311
diff changeset
9588 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9589 if (p != pat[i])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9590 vim_free(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9591 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9592
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9593 *num_file = ga.ga_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9594 *file = (ga.ga_data != NULL) ? (char_u **)ga.ga_data : (char_u **)"";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9595
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9596 recursive = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9597
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9598 return (ga.ga_data != NULL) ? OK : FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9599 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9600
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9601 # ifdef VIM_BACKTICK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9602
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9603 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9604 * Return TRUE if we can expand this backtick thing here.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9605 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9606 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9607 vim_backtick(p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9608 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9609 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9610 return (*p == '`' && *(p + 1) != NUL && *(p + STRLEN(p) - 1) == '`');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9611 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9612
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9613 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9614 * Expand an item in `backticks` by executing it as a command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9615 * Currently only works when pat[] starts and ends with a `.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9616 * Returns number of file names found.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9617 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9618 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9619 expand_backtick(gap, pat, flags)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9620 garray_T *gap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9621 char_u *pat;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9622 int flags; /* EW_* flags */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9623 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9624 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9625 char_u *cmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9626 char_u *buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9627 int cnt = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9628 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9629
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9630 /* Create the command: lop off the backticks. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9631 cmd = vim_strnsave(pat + 1, (int)STRLEN(pat) - 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9632 if (cmd == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9633 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9634
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9635 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9636 if (*cmd == '=') /* `={expr}`: Expand expression */
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 694
diff changeset
9637 buffer = eval_to_string(cmd + 1, &p, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9638 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9639 #endif
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 22
diff changeset
9640 buffer = get_cmd_output(cmd, NULL,
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 22
diff changeset
9641 (flags & EW_SILENT) ? SHELL_SILENT : 0);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9642 vim_free(cmd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9643 if (buffer == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9644 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9645
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9646 cmd = buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9647 while (*cmd != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9648 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9649 cmd = skipwhite(cmd); /* skip over white space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9650 p = cmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9651 while (*p != NUL && *p != '\r' && *p != '\n') /* skip over entry */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9652 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9653 /* add an entry if it is not empty */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9654 if (p > cmd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9655 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9656 i = *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9657 *p = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9658 addfile(gap, cmd, flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9659 *p = i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9660 ++cnt;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9661 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9662 cmd = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9663 while (*cmd != NUL && (*cmd == '\r' || *cmd == '\n'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9664 ++cmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9665 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9666
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9667 vim_free(buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9668 return cnt;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9669 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9670 # endif /* VIM_BACKTICK */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9671
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9672 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9673 * Add a file to a file list. Accepted flags:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9674 * EW_DIR add directories
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9675 * EW_FILE add files
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
9676 * EW_EXEC add executable files
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9677 * EW_NOTFOUND add even when it doesn't exist
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9678 * EW_ADDSLASH add slash after directory name
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9679 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9680 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9681 addfile(gap, f, flags)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9682 garray_T *gap;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9683 char_u *f; /* filename */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9684 int flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9685 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9686 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9687 int isdir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9688
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9689 /* if the file/dir doesn't exist, may not add it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9690 if (!(flags & EW_NOTFOUND) && mch_getperm(f) < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9691 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9692
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9693 #ifdef FNAME_ILLEGAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9694 /* if the file/dir contains illegal characters, don't add it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9695 if (vim_strpbrk(f, (char_u *)FNAME_ILLEGAL) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9696 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9697 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9698
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9699 isdir = mch_isdir(f);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9700 if ((isdir && !(flags & EW_DIR)) || (!isdir && !(flags & EW_FILE)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9701 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9702
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
9703 /* If the file isn't executable, may not add it. Do accept directories. */
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
9704 if (!isdir && (flags & EW_EXEC) && !mch_can_exe(f))
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
9705 return;
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
9706
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9707 /* Make room for another item in the file list. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9708 if (ga_grow(gap, 1) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9709 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9710
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9711 p = alloc((unsigned)(STRLEN(f) + 1 + isdir));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9712 if (p == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9713 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9714
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9715 STRCPY(p, f);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9716 #ifdef BACKSLASH_IN_FILENAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9717 slash_adjust(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9718 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9719 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9720 * Append a slash or backslash after directory names if none is present.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9721 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9722 #ifndef DONT_ADD_PATHSEP_TO_DIR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9723 if (isdir && (flags & EW_ADDSLASH))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9724 add_pathsep(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9725 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9726 ((char_u **)gap->ga_data)[gap->ga_len++] = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9727 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9728 #endif /* !NO_EXPANDPATH */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9729
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9730 #if defined(VIM_BACKTICK) || defined(FEAT_EVAL) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9731
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9732 #ifndef SEEK_SET
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9733 # define SEEK_SET 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9734 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9735 #ifndef SEEK_END
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9736 # define SEEK_END 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9737 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9738
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9739 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9740 * Get the stdout of an external command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9741 * Returns an allocated string, or NULL for error.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9742 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9743 char_u *
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 22
diff changeset
9744 get_cmd_output(cmd, infile, flags)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9745 char_u *cmd;
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 22
diff changeset
9746 char_u *infile; /* optional input file name */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9747 int flags; /* can be SHELL_SILENT */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9748 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9749 char_u *tempname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9750 char_u *command;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9751 char_u *buffer = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9752 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9753 int i = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9754 FILE *fd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9755
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9756 if (check_restricted() || check_secure())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9757 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9758
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9759 /* get a name for the temp file */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9760 if ((tempname = vim_tempname('o')) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9761 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9762 EMSG(_(e_notmp));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9763 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9764 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9765
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9766 /* Add the redirection stuff */
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 22
diff changeset
9767 command = make_filter_cmd(cmd, infile, tempname);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9768 if (command == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9769 goto done;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9770
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9771 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9772 * Call the shell to execute the command (errors are ignored).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9773 * Don't check timestamps here.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9774 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9775 ++no_check_timestamps;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9776 call_shell(command, SHELL_DOOUT | SHELL_EXPAND | flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9777 --no_check_timestamps;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9778
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9779 vim_free(command);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9780
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9781 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9782 * read the names from the file into memory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9783 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9784 # ifdef VMS
1224
edc1c9d6dab9 updated for version 7.1b
vimboss
parents: 1096
diff changeset
9785 /* created temporary file is not always readable as binary */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9786 fd = mch_fopen((char *)tempname, "r");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9787 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9788 fd = mch_fopen((char *)tempname, READBIN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9789 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9790
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9791 if (fd == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9792 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9793 EMSG2(_(e_notopen), tempname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9794 goto done;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9795 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9796
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9797 fseek(fd, 0L, SEEK_END);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9798 len = ftell(fd); /* get size of temp file */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9799 fseek(fd, 0L, SEEK_SET);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9800
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9801 buffer = alloc(len + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9802 if (buffer != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9803 i = (int)fread((char *)buffer, (size_t)1, (size_t)len, fd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9804 fclose(fd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9805 mch_remove(tempname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9806 if (buffer == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9807 goto done;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9808 #ifdef VMS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9809 len = i; /* VMS doesn't give us what we asked for... */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9810 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9811 if (i != len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9812 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9813 EMSG2(_(e_notread), tempname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9814 vim_free(buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9815 buffer = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9816 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9817 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9818 buffer[len] = '\0'; /* make sure the buffer is terminated */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9819
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9820 done:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9821 vim_free(tempname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9822 return buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9823 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9824 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9825
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9826 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9827 * Free the list of files returned by expand_wildcards() or other expansion
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9828 * functions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9829 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9830 void
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9831 FreeWild(count, files)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9832 int count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9833 char_u **files;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9834 {
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
9835 if (count <= 0 || files == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9836 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9837 #if defined(__EMX__) && defined(__ALWAYS_HAS_TRAILING_NULL_POINTER) /* XXX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9838 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9839 * Is this still OK for when other functions than expand_wildcards() have
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9840 * been used???
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9841 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9842 _fnexplodefree((char **)files);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9843 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9844 while (count--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9845 vim_free(files[count]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9846 vim_free(files);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9847 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9848 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9849
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9850 /*
2302
488be8cbe19c Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents: 2297
diff changeset
9851 * Return TRUE when need to go to Insert mode because of 'insertmode'.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9852 * Don't do this when still processing a command or a mapping.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9853 * Don't do this when inside a ":normal" command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9854 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9855 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9856 goto_im()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9857 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9858 return (p_im && stuff_empty() && typebuf_typed());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9859 }