Mercurial > vim
annotate src/ex_cmds.c @ 14194:6fbb8dfb3389 v8.1.0114
patch 8.1.0114: confusing variable name
commit https://github.com/vim/vim/commit/0119a59ffdfb21cf1c0a56e7ed6105e875150163
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jun 24 23:53:28 2018 +0200
patch 8.1.0114: confusing variable name
Problem: Confusing variable name.
Solution: Rename new_ts to new_vts_array. Change zero to NULL.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Mon, 25 Jun 2018 00:00:07 +0200 |
parents | 20468fb49f9b |
children | f2ab259ef88a |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
10021
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * ex_cmds.c: some functions for command line commands | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 #include "version.h" | |
16 | |
7691
fd4175b669e2
commit https://github.com/vim/vim/commit/17576a1e33d71b5602cee86bf220a806c8412605
Christian Brabandt <cb@256bit.org>
parents:
7689
diff
changeset
|
17 #ifdef FEAT_FLOAT |
fd4175b669e2
commit https://github.com/vim/vim/commit/17576a1e33d71b5602cee86bf220a806c8412605
Christian Brabandt <cb@256bit.org>
parents:
7689
diff
changeset
|
18 # include <float.h> |
fd4175b669e2
commit https://github.com/vim/vim/commit/17576a1e33d71b5602cee86bf220a806c8412605
Christian Brabandt <cb@256bit.org>
parents:
7689
diff
changeset
|
19 #endif |
fd4175b669e2
commit https://github.com/vim/vim/commit/17576a1e33d71b5602cee86bf220a806c8412605
Christian Brabandt <cb@256bit.org>
parents:
7689
diff
changeset
|
20 |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
21 static int linelen(int *has_tab); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
22 static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char_u *cmd, int do_in, int do_out); |
7 | 23 #ifdef FEAT_VIMINFO |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
24 static char_u *viminfo_filename(char_u *); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
25 static void do_viminfo(FILE *fp_in, FILE *fp_out, int flags); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
26 static int viminfo_encoding(vir_T *virp); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
27 static int read_viminfo_up_to_marks(vir_T *virp, int forceit, int writing); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
28 #endif |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
29 |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
30 static int check_readonly(int *forceit, buf_T *buf); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
31 static void delbuf_msg(char_u *name); |
7 | 32 static int |
33 #ifdef __BORLANDC__ | |
34 _RTLENTRYF | |
35 #endif | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
36 help_compare(const void *s1, const void *s2); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
37 static void prepare_help_buffer(void); |
7 | 38 |
39 /* | |
40 * ":ascii" and "ga". | |
41 */ | |
42 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
43 do_ascii(exarg_T *eap UNUSED) |
7 | 44 { |
45 int c; | |
1784 | 46 int cval; |
7 | 47 char buf1[20]; |
48 char buf2[20]; | |
49 char_u buf3[7]; | |
13359
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
50 #ifdef FEAT_DIGRAPHS |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
51 char_u *dig; |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
52 #endif |
7 | 53 #ifdef FEAT_MBYTE |
714 | 54 int cc[MAX_MCO]; |
55 int ci = 0; | |
7 | 56 int len; |
57 | |
58 if (enc_utf8) | |
714 | 59 c = utfc_ptr2char(ml_get_cursor(), cc); |
7 | 60 else |
61 #endif | |
62 c = gchar_cursor(); | |
63 if (c == NUL) | |
64 { | |
65 MSG("NUL"); | |
66 return; | |
67 } | |
68 | |
69 #ifdef FEAT_MBYTE | |
70 IObuff[0] = NUL; | |
71 if (!has_mbyte || (enc_dbcs != 0 && c < 0x100) || c < 0x80) | |
72 #endif | |
73 { | |
74 if (c == NL) /* NUL is stored as NL */ | |
75 c = NUL; | |
1784 | 76 if (c == CAR && get_fileformat(curbuf) == EOL_MAC) |
77 cval = NL; /* NL is stored as CR */ | |
78 else | |
79 cval = c; | |
7 | 80 if (vim_isprintc_strict(c) && (c < ' ' |
81 #ifndef EBCDIC | |
82 || c > '~' | |
83 #endif | |
84 )) | |
85 { | |
86 transchar_nonprint(buf3, c); | |
1872 | 87 vim_snprintf(buf1, sizeof(buf1), " <%s>", (char *)buf3); |
7 | 88 } |
89 else | |
90 buf1[0] = NUL; | |
91 #ifndef EBCDIC | |
92 if (c >= 0x80) | |
1872 | 93 vim_snprintf(buf2, sizeof(buf2), " <M-%s>", |
94 (char *)transchar(c & 0x7f)); | |
7 | 95 else |
96 #endif | |
97 buf2[0] = NUL; | |
13359
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
98 #ifdef FEAT_DIGRAPHS |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
99 dig = get_digraph_for_char(cval); |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
100 if (dig != NULL) |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
101 vim_snprintf((char *)IObuff, IOSIZE, |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
102 _("<%s>%s%s %d, Hex %02x, Oct %03o, Digr %s"), |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
103 transchar(c), buf1, buf2, cval, cval, cval, dig); |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
104 else |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
105 #endif |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
106 vim_snprintf((char *)IObuff, IOSIZE, |
274 | 107 _("<%s>%s%s %d, Hex %02x, Octal %03o"), |
1784 | 108 transchar(c), buf1, buf2, cval, cval, cval); |
7 | 109 #ifdef FEAT_MBYTE |
963 | 110 if (enc_utf8) |
111 c = cc[ci++]; | |
112 else | |
113 c = 0; | |
7 | 114 #endif |
115 } | |
116 | |
117 #ifdef FEAT_MBYTE | |
118 /* Repeat for combining characters. */ | |
119 while (has_mbyte && (c >= 0x100 || (enc_utf8 && c >= 0x80))) | |
120 { | |
121 len = (int)STRLEN(IObuff); | |
122 /* This assumes every multi-byte char is printable... */ | |
123 if (len > 0) | |
124 IObuff[len++] = ' '; | |
125 IObuff[len++] = '<'; | |
963 | 126 if (enc_utf8 && utf_iscomposing(c) |
625 | 127 # ifdef USE_GUI |
7 | 128 && !gui.in_use |
625 | 129 # endif |
7 | 130 ) |
131 IObuff[len++] = ' '; /* draw composing char on top of a space */ | |
274 | 132 len += (*mb_char2bytes)(c, IObuff + len); |
13359
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
133 #ifdef FEAT_DIGRAPHS |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
134 dig = get_digraph_for_char(c); |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
135 if (dig != NULL) |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
136 vim_snprintf((char *)IObuff + len, IOSIZE - len, |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
137 c < 0x10000 ? _("> %d, Hex %04x, Oct %o, Digr %s") |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
138 : _("> %d, Hex %08x, Oct %o, Digr %s"), |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
139 c, c, c, dig); |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
140 else |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
141 #endif |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
142 vim_snprintf((char *)IObuff + len, IOSIZE - len, |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
143 c < 0x10000 ? _("> %d, Hex %04x, Octal %o") |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
144 : _("> %d, Hex %08x, Octal %o"), |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
145 c, c, c); |
714 | 146 if (ci == MAX_MCO) |
147 break; | |
963 | 148 if (enc_utf8) |
149 c = cc[ci++]; | |
150 else | |
151 c = 0; | |
7 | 152 } |
153 #endif | |
154 | |
155 msg(IObuff); | |
156 } | |
157 | |
158 /* | |
159 * ":left", ":center" and ":right": align text. | |
160 */ | |
161 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
162 ex_align(exarg_T *eap) |
7 | 163 { |
164 pos_T save_curpos; | |
165 int len; | |
166 int indent = 0; | |
167 int new_indent; | |
168 int has_tab; | |
169 int width; | |
170 | |
171 #ifdef FEAT_RIGHTLEFT | |
172 if (curwin->w_p_rl) | |
173 { | |
174 /* switch left and right aligning */ | |
175 if (eap->cmdidx == CMD_right) | |
176 eap->cmdidx = CMD_left; | |
177 else if (eap->cmdidx == CMD_left) | |
178 eap->cmdidx = CMD_right; | |
179 } | |
180 #endif | |
181 | |
182 width = atoi((char *)eap->arg); | |
183 save_curpos = curwin->w_cursor; | |
184 if (eap->cmdidx == CMD_left) /* width is used for new indent */ | |
185 { | |
186 if (width >= 0) | |
187 indent = width; | |
188 } | |
189 else | |
190 { | |
191 /* | |
192 * if 'textwidth' set, use it | |
193 * else if 'wrapmargin' set, use it | |
194 * if invalid value, use 80 | |
195 */ | |
196 if (width <= 0) | |
197 width = curbuf->b_p_tw; | |
198 if (width == 0 && curbuf->b_p_wm > 0) | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
199 width = curwin->w_width - curbuf->b_p_wm; |
7 | 200 if (width <= 0) |
201 width = 80; | |
202 } | |
203 | |
204 if (u_save((linenr_T)(eap->line1 - 1), (linenr_T)(eap->line2 + 1)) == FAIL) | |
205 return; | |
206 | |
207 for (curwin->w_cursor.lnum = eap->line1; | |
208 curwin->w_cursor.lnum <= eap->line2; ++curwin->w_cursor.lnum) | |
209 { | |
210 if (eap->cmdidx == CMD_left) /* left align */ | |
211 new_indent = indent; | |
212 else | |
213 { | |
944 | 214 has_tab = FALSE; /* avoid uninit warnings */ |
7 | 215 len = linelen(eap->cmdidx == CMD_right ? &has_tab |
216 : NULL) - get_indent(); | |
217 | |
218 if (len <= 0) /* skip blank lines */ | |
219 continue; | |
220 | |
221 if (eap->cmdidx == CMD_center) | |
222 new_indent = (width - len) / 2; | |
223 else | |
224 { | |
225 new_indent = width - len; /* right align */ | |
226 | |
227 /* | |
228 * Make sure that embedded TABs don't make the text go too far | |
229 * to the right. | |
230 */ | |
231 if (has_tab) | |
232 while (new_indent > 0) | |
233 { | |
234 (void)set_indent(new_indent, 0); | |
235 if (linelen(NULL) <= width) | |
236 { | |
237 /* | |
238 * Now try to move the line as much as possible to | |
239 * the right. Stop when it moves too far. | |
240 */ | |
241 do | |
242 (void)set_indent(++new_indent, 0); | |
243 while (linelen(NULL) <= width); | |
244 --new_indent; | |
245 break; | |
246 } | |
247 --new_indent; | |
248 } | |
249 } | |
250 } | |
251 if (new_indent < 0) | |
252 new_indent = 0; | |
253 (void)set_indent(new_indent, 0); /* set indent */ | |
254 } | |
255 changed_lines(eap->line1, 0, eap->line2 + 1, 0L); | |
256 curwin->w_cursor = save_curpos; | |
257 beginline(BL_WHITE | BL_FIX); | |
258 } | |
259 | |
260 /* | |
261 * Get the length of the current line, excluding trailing white space. | |
262 */ | |
263 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
264 linelen(int *has_tab) |
7 | 265 { |
266 char_u *line; | |
267 char_u *first; | |
268 char_u *last; | |
269 int save; | |
270 int len; | |
271 | |
272 /* find the first non-blank character */ | |
273 line = ml_get_curline(); | |
274 first = skipwhite(line); | |
275 | |
276 /* find the character after the last non-blank character */ | |
277 for (last = first + STRLEN(first); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
278 last > first && VIM_ISWHITE(last[-1]); --last) |
7 | 279 ; |
280 save = *last; | |
281 *last = NUL; | |
282 len = linetabsize(line); /* get line length */ | |
283 if (has_tab != NULL) /* check for embedded TAB */ | |
284 *has_tab = (vim_strrchr(first, TAB) != NULL); | |
285 *last = save; | |
286 | |
287 return len; | |
288 } | |
289 | |
826 | 290 /* Buffer for two lines used during sorting. They are allocated to |
291 * contain the longest line being sorted. */ | |
292 static char_u *sortbuf1; | |
293 static char_u *sortbuf2; | |
284 | 294 |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
295 static int sort_ic; /* ignore case */ |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
296 static int sort_nr; /* sort on number */ |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
297 static int sort_rx; /* sort on regex instead of skipping it */ |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
298 #ifdef FEAT_FLOAT |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
299 static int sort_flt; /* sort on floating number */ |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
300 #endif |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
301 |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
302 static int sort_abort; /* flag to indicate if sorting has been interrupted */ |
294 | 303 |
304 /* Struct to store info to be sorted. */ | |
305 typedef struct | |
306 { | |
307 linenr_T lnum; /* line number */ | |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
308 union { |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
309 struct |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
310 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
311 varnumber_T start_col_nr; /* starting column number */ |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
312 varnumber_T end_col_nr; /* ending column number */ |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
313 } line; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
314 varnumber_T value; /* value if sorting by integer */ |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
315 #ifdef FEAT_FLOAT |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
316 float_T value_flt; /* value if sorting by float */ |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
317 #endif |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
318 } st_u; |
294 | 319 } sorti_T; |
284 | 320 |
321 static int | |
322 #ifdef __BORLANDC__ | |
323 _RTLENTRYF | |
324 #endif | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
325 sort_compare(const void *s1, const void *s2); |
284 | 326 |
327 static int | |
328 #ifdef __BORLANDC__ | |
329 _RTLENTRYF | |
330 #endif | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
331 sort_compare(const void *s1, const void *s2) |
284 | 332 { |
294 | 333 sorti_T l1 = *(sorti_T *)s1; |
334 sorti_T l2 = *(sorti_T *)s2; | |
826 | 335 int result = 0; |
336 | |
337 /* If the user interrupts, there's no way to stop qsort() immediately, but | |
834 | 338 * if we return 0 every time, qsort will assume it's done sorting and |
339 * exit. */ | |
826 | 340 if (sort_abort) |
341 return 0; | |
342 fast_breakcheck(); | |
343 if (got_int) | |
344 sort_abort = TRUE; | |
345 | |
834 | 346 /* When sorting numbers "start_col_nr" is the number, not the column |
347 * number. */ | |
294 | 348 if (sort_nr) |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
349 result = l1.st_u.value == l2.st_u.value ? 0 |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
350 : l1.st_u.value > l2.st_u.value ? 1 : -1; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
351 #ifdef FEAT_FLOAT |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
352 else if (sort_flt) |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
353 result = l1.st_u.value_flt == l2.st_u.value_flt ? 0 |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
354 : l1.st_u.value_flt > l2.st_u.value_flt ? 1 : -1; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
355 #endif |
826 | 356 else |
357 { | |
834 | 358 /* We need to copy one line into "sortbuf1", because there is no |
359 * guarantee that the first pointer becomes invalid when obtaining the | |
360 * second one. */ | |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
361 STRNCPY(sortbuf1, ml_get(l1.lnum) + l1.st_u.line.start_col_nr, |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
362 l1.st_u.line.end_col_nr - l1.st_u.line.start_col_nr + 1); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
363 sortbuf1[l1.st_u.line.end_col_nr - l1.st_u.line.start_col_nr] = 0; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
364 STRNCPY(sortbuf2, ml_get(l2.lnum) + l2.st_u.line.start_col_nr, |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
365 l2.st_u.line.end_col_nr - l2.st_u.line.start_col_nr + 1); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
366 sortbuf2[l2.st_u.line.end_col_nr - l2.st_u.line.start_col_nr] = 0; |
826 | 367 |
834 | 368 result = sort_ic ? STRICMP(sortbuf1, sortbuf2) |
369 : STRCMP(sortbuf1, sortbuf2); | |
370 } | |
371 | |
372 /* If two lines have the same value, preserve the original line order. */ | |
826 | 373 if (result == 0) |
834 | 374 return (int)(l1.lnum - l2.lnum); |
375 return result; | |
284 | 376 } |
377 | |
378 /* | |
379 * ":sort". | |
380 */ | |
381 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
382 ex_sort(exarg_T *eap) |
284 | 383 { |
384 regmatch_T regmatch; | |
385 int len; | |
386 linenr_T lnum; | |
387 long maxlen = 0; | |
294 | 388 sorti_T *nrs; |
1872 | 389 size_t count = (size_t)(eap->line2 - eap->line1 + 1); |
294 | 390 size_t i; |
284 | 391 char_u *p; |
392 char_u *s; | |
826 | 393 char_u *s2; |
394 char_u c; /* temporary character storage */ | |
284 | 395 int unique = FALSE; |
396 long deleted; | |
826 | 397 colnr_T start_col; |
398 colnr_T end_col; | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
399 int sort_what = 0; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
400 int format_found = 0; |
284 | 401 |
1538 | 402 /* Sorting one line is really quick! */ |
403 if (count <= 1) | |
404 return; | |
405 | |
284 | 406 if (u_save((linenr_T)(eap->line1 - 1), (linenr_T)(eap->line2 + 1)) == FAIL) |
407 return; | |
826 | 408 sortbuf1 = NULL; |
409 sortbuf2 = NULL; | |
284 | 410 regmatch.regprog = NULL; |
294 | 411 nrs = (sorti_T *)lalloc((long_u)(count * sizeof(sorti_T)), TRUE); |
284 | 412 if (nrs == NULL) |
826 | 413 goto sortend; |
414 | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
415 sort_abort = sort_ic = sort_rx = sort_nr = 0; |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
416 #ifdef FEAT_FLOAT |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
417 sort_flt = 0; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
418 #endif |
294 | 419 |
284 | 420 for (p = eap->arg; *p != NUL; ++p) |
421 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
422 if (VIM_ISWHITE(*p)) |
284 | 423 ; |
424 else if (*p == 'i') | |
425 sort_ic = TRUE; | |
826 | 426 else if (*p == 'r') |
427 sort_rx = TRUE; | |
294 | 428 else if (*p == 'n') |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
429 { |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
430 sort_nr = 1; |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
431 ++format_found; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
432 } |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
433 #ifdef FEAT_FLOAT |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
434 else if (*p == 'f') |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
435 { |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
436 sort_flt = 1; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
437 ++format_found; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
438 } |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
439 #endif |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
440 else if (*p == 'b') |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
441 { |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
442 sort_what = STR2NR_BIN + STR2NR_FORCE; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
443 ++format_found; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
444 } |
294 | 445 else if (*p == 'o') |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
446 { |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
447 sort_what = STR2NR_OCT + STR2NR_FORCE; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
448 ++format_found; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
449 } |
294 | 450 else if (*p == 'x') |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
451 { |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
452 sort_what = STR2NR_HEX + STR2NR_FORCE; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
453 ++format_found; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
454 } |
284 | 455 else if (*p == 'u') |
456 unique = TRUE; | |
289 | 457 else if (*p == '"') /* comment start */ |
458 break; | |
459 else if (check_nextcmd(p) != NULL) | |
460 { | |
461 eap->nextcmd = check_nextcmd(p); | |
462 break; | |
463 } | |
464 else if (!ASCII_ISALPHA(*p) && regmatch.regprog == NULL) | |
284 | 465 { |
466 s = skip_regexp(p + 1, *p, TRUE, NULL); | |
467 if (*s != *p) | |
468 { | |
469 EMSG(_(e_invalpat)); | |
826 | 470 goto sortend; |
284 | 471 } |
472 *s = NUL; | |
1314 | 473 /* Use last search pattern if sort pattern is empty. */ |
4199 | 474 if (s == p + 1) |
475 { | |
476 if (last_search_pat() == NULL) | |
477 { | |
478 EMSG(_(e_noprevre)); | |
479 goto sortend; | |
480 } | |
1314 | 481 regmatch.regprog = vim_regcomp(last_search_pat(), RE_MAGIC); |
4199 | 482 } |
1314 | 483 else |
484 regmatch.regprog = vim_regcomp(p + 1, RE_MAGIC); | |
284 | 485 if (regmatch.regprog == NULL) |
826 | 486 goto sortend; |
289 | 487 p = s; /* continue after the regexp */ |
284 | 488 regmatch.rm_ic = p_ic; |
489 } | |
490 else | |
491 { | |
492 EMSG2(_(e_invarg2), p); | |
826 | 493 goto sortend; |
284 | 494 } |
495 } | |
496 | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
497 /* Can only have one of 'n', 'b', 'o' and 'x'. */ |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
498 if (format_found > 1) |
294 | 499 { |
500 EMSG(_(e_invarg)); | |
826 | 501 goto sortend; |
294 | 502 } |
503 | |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
504 /* From here on "sort_nr" is used as a flag for any integer number |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
505 * sorting. */ |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
506 sort_nr += sort_what; |
294 | 507 |
284 | 508 /* |
294 | 509 * Make an array with all line numbers. This avoids having to copy all |
284 | 510 * the lines into allocated memory. |
826 | 511 * When sorting on strings "start_col_nr" is the offset in the line, for |
512 * numbers sorting it's the number to sort on. This means the pattern | |
513 * matching and number conversion only has to be done once per line. | |
294 | 514 * Also get the longest line length for allocating "sortbuf". |
284 | 515 */ |
516 for (lnum = eap->line1; lnum <= eap->line2; ++lnum) | |
517 { | |
518 s = ml_get(lnum); | |
835 | 519 len = (int)STRLEN(s); |
284 | 520 if (maxlen < len) |
521 maxlen = len; | |
294 | 522 |
826 | 523 start_col = 0; |
524 end_col = len; | |
294 | 525 if (regmatch.regprog != NULL && vim_regexec(®match, s, 0)) |
826 | 526 { |
527 if (sort_rx) | |
528 { | |
835 | 529 start_col = (colnr_T)(regmatch.startp[0] - s); |
530 end_col = (colnr_T)(regmatch.endp[0] - s); | |
826 | 531 } |
532 else | |
835 | 533 start_col = (colnr_T)(regmatch.endp[0] - s); |
826 | 534 } |
294 | 535 else |
826 | 536 if (regmatch.regprog != NULL) |
537 end_col = 0; | |
294 | 538 |
7844
6669966db9e9
commit https://github.com/vim/vim/commit/937204a9175d0fe2f13c8bc4ebeb043003d7e7d7
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
539 if (sort_nr |
6669966db9e9
commit https://github.com/vim/vim/commit/937204a9175d0fe2f13c8bc4ebeb043003d7e7d7
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
540 #ifdef FEAT_FLOAT |
6669966db9e9
commit https://github.com/vim/vim/commit/937204a9175d0fe2f13c8bc4ebeb043003d7e7d7
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
541 || sort_flt |
6669966db9e9
commit https://github.com/vim/vim/commit/937204a9175d0fe2f13c8bc4ebeb043003d7e7d7
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
542 #endif |
6669966db9e9
commit https://github.com/vim/vim/commit/937204a9175d0fe2f13c8bc4ebeb043003d7e7d7
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
543 ) |
294 | 544 { |
826 | 545 /* Make sure vim_str2nr doesn't read any digits past the end |
546 * of the match, by temporarily terminating the string there */ | |
547 s2 = s + end_col; | |
548 c = *s2; | |
2606 | 549 *s2 = NUL; |
294 | 550 /* Sorting on number: Store the number itself. */ |
1687 | 551 p = s + start_col; |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
552 if (sort_nr) |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
553 { |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
554 if (sort_what & STR2NR_HEX) |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
555 s = skiptohex(p); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
556 else if (sort_what & STR2NR_BIN) |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
557 s = skiptobin(p); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
558 else |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
559 s = skiptodigit(p); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
560 if (s > p && s[-1] == '-') |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
561 --s; /* include preceding negative sign */ |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
562 if (*s == NUL) |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
563 /* empty line should sort before any number */ |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
564 nrs[lnum - eap->line1].st_u.value = -MAXLNUM; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
565 else |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
566 vim_str2nr(s, NULL, NULL, sort_what, |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
567 &nrs[lnum - eap->line1].st_u.value, NULL, 0); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
568 } |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
569 #ifdef FEAT_FLOAT |
294 | 570 else |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
571 { |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
572 s = skipwhite(p); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
573 if (*s == '+') |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
574 s = skipwhite(s + 1); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
575 |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
576 if (*s == NUL) |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
577 /* empty line should sort before any number */ |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
578 nrs[lnum - eap->line1].st_u.value_flt = -DBL_MAX; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
579 else |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
580 nrs[lnum - eap->line1].st_u.value_flt = |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
581 strtod((char *)s, NULL); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
582 } |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
583 #endif |
2606 | 584 *s2 = c; |
294 | 585 } |
586 else | |
826 | 587 { |
294 | 588 /* Store the column to sort at. */ |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
589 nrs[lnum - eap->line1].st_u.line.start_col_nr = start_col; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
590 nrs[lnum - eap->line1].st_u.line.end_col_nr = end_col; |
826 | 591 } |
294 | 592 |
593 nrs[lnum - eap->line1].lnum = lnum; | |
481 | 594 |
595 if (regmatch.regprog != NULL) | |
596 fast_breakcheck(); | |
597 if (got_int) | |
826 | 598 goto sortend; |
284 | 599 } |
600 | |
294 | 601 /* Allocate a buffer that can hold the longest line. */ |
826 | 602 sortbuf1 = alloc((unsigned)maxlen + 1); |
603 if (sortbuf1 == NULL) | |
604 goto sortend; | |
605 sortbuf2 = alloc((unsigned)maxlen + 1); | |
606 if (sortbuf2 == NULL) | |
607 goto sortend; | |
284 | 608 |
481 | 609 /* Sort the array of line numbers. Note: can't be interrupted! */ |
294 | 610 qsort((void *)nrs, count, sizeof(sorti_T), sort_compare); |
284 | 611 |
826 | 612 if (sort_abort) |
613 goto sortend; | |
614 | |
284 | 615 /* Insert the lines in the sorted order below the last one. */ |
616 lnum = eap->line2; | |
617 for (i = 0; i < count; ++i) | |
618 { | |
619 s = ml_get(nrs[eap->forceit ? count - i - 1 : i].lnum); | |
620 if (!unique || i == 0 | |
826 | 621 || (sort_ic ? STRICMP(s, sortbuf1) : STRCMP(s, sortbuf1)) != 0) |
284 | 622 { |
7340
645abb8d8daf
commit https://github.com/vim/vim/commit/75e3ad019933f4879137775549261bf51985ab7d
Christian Brabandt <cb@256bit.org>
parents:
7226
diff
changeset
|
623 /* Copy the line into a buffer, it may become invalid in |
645abb8d8daf
commit https://github.com/vim/vim/commit/75e3ad019933f4879137775549261bf51985ab7d
Christian Brabandt <cb@256bit.org>
parents:
7226
diff
changeset
|
624 * ml_append(). And it's needed for "unique". */ |
645abb8d8daf
commit https://github.com/vim/vim/commit/75e3ad019933f4879137775549261bf51985ab7d
Christian Brabandt <cb@256bit.org>
parents:
7226
diff
changeset
|
625 STRCPY(sortbuf1, s); |
645abb8d8daf
commit https://github.com/vim/vim/commit/75e3ad019933f4879137775549261bf51985ab7d
Christian Brabandt <cb@256bit.org>
parents:
7226
diff
changeset
|
626 if (ml_append(lnum++, sortbuf1, (colnr_T)0, FALSE) == FAIL) |
284 | 627 break; |
628 } | |
481 | 629 fast_breakcheck(); |
630 if (got_int) | |
826 | 631 goto sortend; |
284 | 632 } |
633 | |
634 /* delete the original lines if appending worked */ | |
635 if (i == count) | |
636 for (i = 0; i < count; ++i) | |
637 ml_delete(eap->line1, FALSE); | |
638 else | |
639 count = 0; | |
640 | |
294 | 641 /* Adjust marks for deleted (or added) lines and prepare for displaying. */ |
835 | 642 deleted = (long)(count - (lnum - eap->line2)); |
284 | 643 if (deleted > 0) |
644 mark_adjust(eap->line2 - deleted, eap->line2, (long)MAXLNUM, -deleted); | |
645 else if (deleted < 0) | |
646 mark_adjust(eap->line2, MAXLNUM, -deleted, 0L); | |
647 changed_lines(eap->line1, 0, eap->line2 + 1, -deleted); | |
294 | 648 |
284 | 649 curwin->w_cursor.lnum = eap->line1; |
650 beginline(BL_WHITE | BL_FIX); | |
651 | |
826 | 652 sortend: |
284 | 653 vim_free(nrs); |
826 | 654 vim_free(sortbuf1); |
655 vim_free(sortbuf2); | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4613
diff
changeset
|
656 vim_regfree(regmatch.regprog); |
481 | 657 if (got_int) |
658 EMSG(_(e_interr)); | |
284 | 659 } |
660 | |
7 | 661 /* |
662 * ":retab". | |
663 */ | |
664 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
665 ex_retab(exarg_T *eap) |
7 | 666 { |
667 linenr_T lnum; | |
668 int got_tab = FALSE; | |
669 long num_spaces = 0; | |
670 long num_tabs; | |
671 long len; | |
672 long col; | |
673 long vcol; | |
674 long start_col = 0; /* For start of white-space string */ | |
675 long start_vcol = 0; /* For start of white-space string */ | |
676 long old_len; | |
677 char_u *ptr; | |
678 char_u *new_line = (char_u *)1; /* init to non-NULL */ | |
679 int did_undo; /* called u_save for current line */ | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
680 #ifdef FEAT_VARTABS |
14194
6fbb8dfb3389
patch 8.1.0114: confusing variable name
Christian Brabandt <cb@256bit.org>
parents:
14185
diff
changeset
|
681 int *new_vts_array = NULL; |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
682 char_u *new_ts_str; /* string value of tab argument */ |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
683 #else |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
684 int temp; |
7 | 685 int new_ts; |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
686 #endif |
7 | 687 int save_list; |
688 linenr_T first_line = 0; /* first changed line */ | |
689 linenr_T last_line = 0; /* last changed line */ | |
690 | |
691 save_list = curwin->w_p_list; | |
692 curwin->w_p_list = 0; /* don't want list mode here */ | |
693 | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
694 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
695 new_ts_str = eap->arg; |
14194
6fbb8dfb3389
patch 8.1.0114: confusing variable name
Christian Brabandt <cb@256bit.org>
parents:
14185
diff
changeset
|
696 if (!tabstop_set(eap->arg, &new_vts_array)) |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
697 return; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
698 while (vim_isdigit(*(eap->arg)) || *(eap->arg) == ',') |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
699 ++(eap->arg); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
700 |
14194
6fbb8dfb3389
patch 8.1.0114: confusing variable name
Christian Brabandt <cb@256bit.org>
parents:
14185
diff
changeset
|
701 // This ensures that either new_vts_array and new_ts_str are freshly |
6fbb8dfb3389
patch 8.1.0114: confusing variable name
Christian Brabandt <cb@256bit.org>
parents:
14185
diff
changeset
|
702 // allocated, or new_vts_array points to an existing array and new_ts_str |
6fbb8dfb3389
patch 8.1.0114: confusing variable name
Christian Brabandt <cb@256bit.org>
parents:
14185
diff
changeset
|
703 // is null. |
6fbb8dfb3389
patch 8.1.0114: confusing variable name
Christian Brabandt <cb@256bit.org>
parents:
14185
diff
changeset
|
704 if (new_vts_array == NULL) |
6fbb8dfb3389
patch 8.1.0114: confusing variable name
Christian Brabandt <cb@256bit.org>
parents:
14185
diff
changeset
|
705 { |
6fbb8dfb3389
patch 8.1.0114: confusing variable name
Christian Brabandt <cb@256bit.org>
parents:
14185
diff
changeset
|
706 new_vts_array = curbuf->b_p_vts_array; |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
707 new_ts_str = NULL; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
708 } |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
709 else |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
710 new_ts_str = vim_strnsave(new_ts_str, eap->arg - new_ts_str); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
711 #else |
7 | 712 new_ts = getdigits(&(eap->arg)); |
713 if (new_ts < 0) | |
714 { | |
715 EMSG(_(e_positive)); | |
716 return; | |
717 } | |
718 if (new_ts == 0) | |
719 new_ts = curbuf->b_p_ts; | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
720 #endif |
7 | 721 for (lnum = eap->line1; !got_int && lnum <= eap->line2; ++lnum) |
722 { | |
723 ptr = ml_get(lnum); | |
724 col = 0; | |
725 vcol = 0; | |
726 did_undo = FALSE; | |
727 for (;;) | |
728 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
729 if (VIM_ISWHITE(ptr[col])) |
7 | 730 { |
731 if (!got_tab && num_spaces == 0) | |
732 { | |
733 /* First consecutive white-space */ | |
734 start_vcol = vcol; | |
735 start_col = col; | |
736 } | |
737 if (ptr[col] == ' ') | |
738 num_spaces++; | |
739 else | |
740 got_tab = TRUE; | |
741 } | |
742 else | |
743 { | |
744 if (got_tab || (eap->forceit && num_spaces > 1)) | |
745 { | |
746 /* Retabulate this string of white-space */ | |
747 | |
748 /* len is virtual length of white string */ | |
749 len = num_spaces = vcol - start_vcol; | |
750 num_tabs = 0; | |
751 if (!curbuf->b_p_et) | |
752 { | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
753 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
754 int t, s; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
755 |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
756 tabstop_fromto(start_vcol, vcol, |
14194
6fbb8dfb3389
patch 8.1.0114: confusing variable name
Christian Brabandt <cb@256bit.org>
parents:
14185
diff
changeset
|
757 curbuf->b_p_ts, new_vts_array, &t, &s); |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
758 num_tabs = t; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
759 num_spaces = s; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
760 #else |
7 | 761 temp = new_ts - (start_vcol % new_ts); |
762 if (num_spaces >= temp) | |
763 { | |
764 num_spaces -= temp; | |
765 num_tabs++; | |
766 } | |
767 num_tabs += num_spaces / new_ts; | |
768 num_spaces -= (num_spaces / new_ts) * new_ts; | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
769 #endif |
7 | 770 } |
771 if (curbuf->b_p_et || got_tab || | |
772 (num_spaces + num_tabs < len)) | |
773 { | |
774 if (did_undo == FALSE) | |
775 { | |
776 did_undo = TRUE; | |
777 if (u_save((linenr_T)(lnum - 1), | |
778 (linenr_T)(lnum + 1)) == FAIL) | |
779 { | |
780 new_line = NULL; /* flag out-of-memory */ | |
781 break; | |
782 } | |
783 } | |
784 | |
785 /* len is actual number of white characters used */ | |
786 len = num_spaces + num_tabs; | |
787 old_len = (long)STRLEN(ptr); | |
788 new_line = lalloc(old_len - col + start_col + len + 1, | |
789 TRUE); | |
790 if (new_line == NULL) | |
791 break; | |
792 if (start_col > 0) | |
793 mch_memmove(new_line, ptr, (size_t)start_col); | |
794 mch_memmove(new_line + start_col + len, | |
795 ptr + col, (size_t)(old_len - col + 1)); | |
796 ptr = new_line + start_col; | |
797 for (col = 0; col < len; col++) | |
798 ptr[col] = (col < num_tabs) ? '\t' : ' '; | |
799 ml_replace(lnum, new_line, FALSE); | |
800 if (first_line == 0) | |
801 first_line = lnum; | |
802 last_line = lnum; | |
803 ptr = new_line; | |
804 col = start_col + len; | |
805 } | |
806 } | |
807 got_tab = FALSE; | |
808 num_spaces = 0; | |
809 } | |
810 if (ptr[col] == NUL) | |
811 break; | |
812 vcol += chartabsize(ptr + col, (colnr_T)vcol); | |
813 #ifdef FEAT_MBYTE | |
814 if (has_mbyte) | |
474 | 815 col += (*mb_ptr2len)(ptr + col); |
7 | 816 else |
817 #endif | |
818 ++col; | |
819 } | |
820 if (new_line == NULL) /* out of memory */ | |
821 break; | |
822 line_breakcheck(); | |
823 } | |
824 if (got_int) | |
825 EMSG(_(e_interr)); | |
826 | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
827 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
828 // If a single value was given then it can be considered equal to |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
829 // either the value of 'tabstop' or the value of 'vartabstop'. |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
830 if (tabstop_count(curbuf->b_p_vts_array) == 0 |
14194
6fbb8dfb3389
patch 8.1.0114: confusing variable name
Christian Brabandt <cb@256bit.org>
parents:
14185
diff
changeset
|
831 && tabstop_count(new_vts_array) == 1 |
6fbb8dfb3389
patch 8.1.0114: confusing variable name
Christian Brabandt <cb@256bit.org>
parents:
14185
diff
changeset
|
832 && curbuf->b_p_ts == tabstop_first(new_vts_array)) |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
833 ; /* not changed */ |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
834 else if (tabstop_count(curbuf->b_p_vts_array) > 0 |
14194
6fbb8dfb3389
patch 8.1.0114: confusing variable name
Christian Brabandt <cb@256bit.org>
parents:
14185
diff
changeset
|
835 && tabstop_eq(curbuf->b_p_vts_array, new_vts_array)) |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
836 ; /* not changed */ |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
837 else |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
838 redraw_curbuf_later(NOT_VALID); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
839 #else |
7 | 840 if (curbuf->b_p_ts != new_ts) |
841 redraw_curbuf_later(NOT_VALID); | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
842 #endif |
7 | 843 if (first_line != 0) |
844 changed_lines(first_line, 0, last_line + 1, 0L); | |
845 | |
846 curwin->w_p_list = save_list; /* restore 'list' */ | |
847 | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
848 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
849 if (new_ts_str != NULL) /* set the new tabstop */ |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
850 { |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
851 // If 'vartabstop' is in use or if the value given to retab has more |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
852 // than one tabstop then update 'vartabstop'. |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
853 int *old_vts_ary = curbuf->b_p_vts_array; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
854 |
14194
6fbb8dfb3389
patch 8.1.0114: confusing variable name
Christian Brabandt <cb@256bit.org>
parents:
14185
diff
changeset
|
855 if (tabstop_count(old_vts_ary) > 0 || tabstop_count(new_vts_array) > 1) |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
856 { |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
857 set_string_option_direct((char_u *)"vts", -1, new_ts_str, |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
858 OPT_FREE|OPT_LOCAL, 0); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
859 vim_free(new_ts_str); |
14194
6fbb8dfb3389
patch 8.1.0114: confusing variable name
Christian Brabandt <cb@256bit.org>
parents:
14185
diff
changeset
|
860 curbuf->b_p_vts_array = new_vts_array; |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
861 vim_free(old_vts_ary); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
862 } |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
863 else |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
864 { |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
865 // 'vartabstop' wasn't in use and a single value was given to |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
866 // retab then update 'tabstop'. |
14194
6fbb8dfb3389
patch 8.1.0114: confusing variable name
Christian Brabandt <cb@256bit.org>
parents:
14185
diff
changeset
|
867 curbuf->b_p_ts = tabstop_first(new_vts_array); |
6fbb8dfb3389
patch 8.1.0114: confusing variable name
Christian Brabandt <cb@256bit.org>
parents:
14185
diff
changeset
|
868 vim_free(new_vts_array); |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
869 } |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
870 } |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
871 #else |
7 | 872 curbuf->b_p_ts = new_ts; |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
873 #endif |
7 | 874 coladvance(curwin->w_curswant); |
875 | |
876 u_clearline(); | |
877 } | |
878 | |
879 /* | |
880 * :move command - move lines line1-line2 to line dest | |
881 * | |
882 * return FAIL for failure, OK otherwise | |
883 */ | |
884 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
885 do_move(linenr_T line1, linenr_T line2, linenr_T dest) |
7 | 886 { |
887 char_u *str; | |
888 linenr_T l; | |
889 linenr_T extra; /* Num lines added before line1 */ | |
890 linenr_T num_lines; /* Num lines moved */ | |
891 linenr_T last_line; /* Last line in file after adding new text */ | |
6755 | 892 #ifdef FEAT_FOLDING |
11140
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
893 win_T *win; |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
894 tabpage_T *tp; |
6755 | 895 #endif |
7 | 896 |
897 if (dest >= line1 && dest < line2) | |
898 { | |
899 EMSG(_("E134: Move lines into themselves")); | |
900 return FAIL; | |
901 } | |
902 | |
903 num_lines = line2 - line1 + 1; | |
904 | |
905 /* | |
906 * First we copy the old text to its new location -- webb | |
907 * Also copy the flag that ":global" command uses. | |
908 */ | |
909 if (u_save(dest, dest + 1) == FAIL) | |
910 return FAIL; | |
911 for (extra = 0, l = line1; l <= line2; l++) | |
912 { | |
913 str = vim_strsave(ml_get(l + extra)); | |
914 if (str != NULL) | |
915 { | |
916 ml_append(dest + l - line1, str, (colnr_T)0, FALSE); | |
917 vim_free(str); | |
918 if (dest < line1) | |
919 extra++; | |
920 } | |
921 } | |
922 | |
923 /* | |
924 * Now we must be careful adjusting our marks so that we don't overlap our | |
925 * mark_adjust() calls. | |
926 * | |
927 * We adjust the marks within the old text so that they refer to the | |
928 * last lines of the file (temporarily), because we know no other marks | |
929 * will be set there since these line numbers did not exist until we added | |
930 * our new lines. | |
931 * | |
932 * Then we adjust the marks on lines between the old and new text positions | |
933 * (either forwards or backwards). | |
934 * | |
935 * And Finally we adjust the marks we put at the end of the file back to | |
936 * their final destination at the new text position -- webb | |
937 */ | |
938 last_line = curbuf->b_ml.ml_line_count; | |
11140
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
939 mark_adjust_nofold(line1, line2, last_line - line2, 0L); |
7 | 940 if (dest >= line2) |
941 { | |
11140
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
942 mark_adjust_nofold(line2 + 1, dest, -num_lines, 0L); |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
943 #ifdef FEAT_FOLDING |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
944 FOR_ALL_TAB_WINDOWS(tp, win) { |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
945 if (win->w_buffer == curbuf) |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
946 foldMoveRange(&win->w_folds, line1, line2, dest); |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
947 } |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
948 #endif |
7 | 949 curbuf->b_op_start.lnum = dest - num_lines + 1; |
950 curbuf->b_op_end.lnum = dest; | |
951 } | |
952 else | |
953 { | |
11140
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
954 mark_adjust_nofold(dest + 1, line1 - 1, num_lines, 0L); |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
955 #ifdef FEAT_FOLDING |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
956 FOR_ALL_TAB_WINDOWS(tp, win) { |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
957 if (win->w_buffer == curbuf) |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
958 foldMoveRange(&win->w_folds, dest + 1, line1 - 1, line2); |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
959 } |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
960 #endif |
7 | 961 curbuf->b_op_start.lnum = dest + 1; |
962 curbuf->b_op_end.lnum = dest + num_lines; | |
963 } | |
964 curbuf->b_op_start.col = curbuf->b_op_end.col = 0; | |
11140
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
965 mark_adjust_nofold(last_line - num_lines + 1, last_line, |
7 | 966 -(last_line - dest - extra), 0L); |
967 | |
968 /* | |
969 * Now we delete the original text -- webb | |
970 */ | |
971 if (u_save(line1 + extra - 1, line2 + extra + 1) == FAIL) | |
972 return FAIL; | |
973 | |
974 for (l = line1; l <= line2; l++) | |
975 ml_delete(line1 + extra, TRUE); | |
976 | |
977 if (!global_busy && num_lines > p_report) | |
978 { | |
979 if (num_lines == 1) | |
980 MSG(_("1 line moved")); | |
981 else | |
982 smsg((char_u *)_("%ld lines moved"), num_lines); | |
983 } | |
984 | |
985 /* | |
986 * Leave the cursor on the last of the moved lines. | |
987 */ | |
988 if (dest >= line1) | |
989 curwin->w_cursor.lnum = dest; | |
990 else | |
991 curwin->w_cursor.lnum = dest + (line2 - line1) + 1; | |
992 | |
993 if (line1 < dest) | |
3184 | 994 { |
995 dest += num_lines + 1; | |
996 last_line = curbuf->b_ml.ml_line_count; | |
997 if (dest > last_line + 1) | |
998 dest = last_line + 1; | |
999 changed_lines(line1, 0, dest, 0L); | |
1000 } | |
7 | 1001 else |
1002 changed_lines(dest + 1, 0, line1 + num_lines, 0L); | |
1003 | |
1004 return OK; | |
1005 } | |
1006 | |
1007 /* | |
1008 * ":copy" | |
1009 */ | |
1010 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1011 ex_copy(linenr_T line1, linenr_T line2, linenr_T n) |
7 | 1012 { |
1013 linenr_T count; | |
1014 char_u *p; | |
1015 | |
1016 count = line2 - line1 + 1; | |
1017 curbuf->b_op_start.lnum = n + 1; | |
1018 curbuf->b_op_end.lnum = n + count; | |
1019 curbuf->b_op_start.col = curbuf->b_op_end.col = 0; | |
1020 | |
1021 /* | |
1022 * there are three situations: | |
1023 * 1. destination is above line1 | |
1024 * 2. destination is between line1 and line2 | |
1025 * 3. destination is below line2 | |
1026 * | |
1027 * n = destination (when starting) | |
1028 * curwin->w_cursor.lnum = destination (while copying) | |
1029 * line1 = start of source (while copying) | |
1030 * line2 = end of source (while copying) | |
1031 */ | |
1032 if (u_save(n, n + 1) == FAIL) | |
1033 return; | |
1034 | |
1035 curwin->w_cursor.lnum = n; | |
1036 while (line1 <= line2) | |
1037 { | |
1038 /* need to use vim_strsave() because the line will be unlocked within | |
1039 * ml_append() */ | |
1040 p = vim_strsave(ml_get(line1)); | |
1041 if (p != NULL) | |
1042 { | |
1043 ml_append(curwin->w_cursor.lnum, p, (colnr_T)0, FALSE); | |
1044 vim_free(p); | |
1045 } | |
1046 /* situation 2: skip already copied lines */ | |
1047 if (line1 == n) | |
1048 line1 = curwin->w_cursor.lnum; | |
1049 ++line1; | |
1050 if (curwin->w_cursor.lnum < line1) | |
1051 ++line1; | |
1052 if (curwin->w_cursor.lnum < line2) | |
1053 ++line2; | |
1054 ++curwin->w_cursor.lnum; | |
1055 } | |
1056 | |
1057 appended_lines_mark(n, count); | |
1058 | |
1059 msgmore((long)count); | |
1060 } | |
1061 | |
359 | 1062 static char_u *prevcmd = NULL; /* the previous command */ |
1063 | |
1064 #if defined(EXITFREE) || defined(PROTO) | |
1065 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1066 free_prev_shellcmd(void) |
359 | 1067 { |
1068 vim_free(prevcmd); | |
1069 } | |
1070 #endif | |
1071 | |
7 | 1072 /* |
1073 * Handle the ":!cmd" command. Also for ":r !cmd" and ":w !cmd" | |
1074 * Bangs in the argument are replaced with the previously entered command. | |
1075 * Remember the argument. | |
1076 */ | |
1077 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1078 do_bang( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1079 int addr_count, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1080 exarg_T *eap, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1081 int forceit, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1082 int do_in, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1083 int do_out) |
7 | 1084 { |
1085 char_u *arg = eap->arg; /* command */ | |
1086 linenr_T line1 = eap->line1; /* start of range */ | |
1087 linenr_T line2 = eap->line2; /* end of range */ | |
1088 char_u *newcmd = NULL; /* the new command */ | |
1089 int free_newcmd = FALSE; /* need to free() newcmd */ | |
1090 int ins_prevcmd; | |
1091 char_u *t; | |
1092 char_u *p; | |
1093 char_u *trailarg; | |
1094 int len; | |
1095 int scroll_save = msg_scroll; | |
1096 | |
1097 /* | |
1098 * Disallow shell commands for "rvim". | |
1099 * Disallow shell commands from .exrc and .vimrc in current directory for | |
1100 * security reasons. | |
1101 */ | |
1102 if (check_restricted() || check_secure()) | |
1103 return; | |
1104 | |
1105 if (addr_count == 0) /* :! */ | |
1106 { | |
1107 msg_scroll = FALSE; /* don't scroll here */ | |
1108 autowrite_all(); | |
1109 msg_scroll = scroll_save; | |
1110 } | |
1111 | |
1112 /* | |
1113 * Try to find an embedded bang, like in :!<cmd> ! [args] | |
1114 * (:!! is indicated by the 'forceit' variable) | |
1115 */ | |
1116 ins_prevcmd = forceit; | |
1117 trailarg = arg; | |
1118 do | |
1119 { | |
1120 len = (int)STRLEN(trailarg) + 1; | |
1121 if (newcmd != NULL) | |
1122 len += (int)STRLEN(newcmd); | |
1123 if (ins_prevcmd) | |
1124 { | |
1125 if (prevcmd == NULL) | |
1126 { | |
1127 EMSG(_(e_noprev)); | |
1128 vim_free(newcmd); | |
1129 return; | |
1130 } | |
1131 len += (int)STRLEN(prevcmd); | |
1132 } | |
1872 | 1133 if ((t = alloc((unsigned)len)) == NULL) |
7 | 1134 { |
1135 vim_free(newcmd); | |
1136 return; | |
1137 } | |
1138 *t = NUL; | |
1139 if (newcmd != NULL) | |
1140 STRCAT(t, newcmd); | |
1141 if (ins_prevcmd) | |
1142 STRCAT(t, prevcmd); | |
1143 p = t + STRLEN(t); | |
1144 STRCAT(t, trailarg); | |
1145 vim_free(newcmd); | |
1146 newcmd = t; | |
1147 | |
1148 /* | |
1149 * Scan the rest of the argument for '!', which is replaced by the | |
1150 * previous command. "\!" is replaced by "!" (this is vi compatible). | |
1151 */ | |
1152 trailarg = NULL; | |
1153 while (*p) | |
1154 { | |
2823 | 1155 if (*p == '!') |
7 | 1156 { |
1157 if (p > newcmd && p[-1] == '\\') | |
1624 | 1158 STRMOVE(p - 1, p); |
7 | 1159 else |
1160 { | |
1161 trailarg = p; | |
1162 *trailarg++ = NUL; | |
1163 ins_prevcmd = TRUE; | |
1164 break; | |
1165 } | |
1166 } | |
1167 ++p; | |
1168 } | |
1169 } while (trailarg != NULL); | |
1170 | |
1171 vim_free(prevcmd); | |
1172 prevcmd = newcmd; | |
1173 | |
1174 if (bangredo) /* put cmd in redo buffer for ! command */ | |
1175 { | |
5728 | 1176 /* If % or # appears in the command, it must have been escaped. |
1177 * Reescape them, so that redoing them does not substitute them by the | |
1178 * buffername. */ | |
1179 char_u *cmd = vim_strsave_escaped(prevcmd, (char_u *)"%#"); | |
1180 | |
1181 if (cmd != NULL) | |
1182 { | |
1183 AppendToRedobuffLit(cmd, -1); | |
1184 vim_free(cmd); | |
1185 } | |
1186 else | |
1187 AppendToRedobuffLit(prevcmd, -1); | |
7 | 1188 AppendToRedobuff((char_u *)"\n"); |
1189 bangredo = FALSE; | |
1190 } | |
1191 /* | |
1192 * Add quotes around the command, for shells that need them. | |
1193 */ | |
1194 if (*p_shq != NUL) | |
1195 { | |
1196 newcmd = alloc((unsigned)(STRLEN(prevcmd) + 2 * STRLEN(p_shq) + 1)); | |
1197 if (newcmd == NULL) | |
1198 return; | |
1199 STRCPY(newcmd, p_shq); | |
1200 STRCAT(newcmd, prevcmd); | |
1201 STRCAT(newcmd, p_shq); | |
1202 free_newcmd = TRUE; | |
1203 } | |
1204 if (addr_count == 0) /* :! */ | |
1205 { | |
1206 /* echo the command */ | |
1207 msg_start(); | |
1208 msg_putchar(':'); | |
1209 msg_putchar('!'); | |
1210 msg_outtrans(newcmd); | |
1211 msg_clr_eos(); | |
1212 windgoto(msg_row, msg_col); | |
1213 | |
1214 do_shell(newcmd, 0); | |
1215 } | |
1216 else /* :range! */ | |
725 | 1217 { |
7 | 1218 /* Careful: This may recursively call do_bang() again! (because of |
1219 * autocommands) */ | |
1220 do_filter(line1, line2, eap, newcmd, do_in, do_out); | |
725 | 1221 apply_autocmds(EVENT_SHELLFILTERPOST, NULL, NULL, FALSE, curbuf); |
1222 } | |
7 | 1223 if (free_newcmd) |
1224 vim_free(newcmd); | |
1225 } | |
1226 | |
1227 /* | |
1228 * do_filter: filter lines through a command given by the user | |
1229 * | |
169 | 1230 * We mostly use temp files and the call_shell() routine here. This would |
1231 * normally be done using pipes on a UNIX machine, but this is more portable | |
1232 * to non-unix machines. The call_shell() routine needs to be able | |
7 | 1233 * to deal with redirection somehow, and should handle things like looking |
1234 * at the PATH env. variable, and adding reasonable extensions to the | |
1235 * command name given by the user. All reasonable versions of call_shell() | |
1236 * do this. | |
169 | 1237 * Alternatively, if on Unix and redirecting input or output, but not both, |
1238 * and the 'shelltemp' option isn't set, use pipes. | |
7 | 1239 * We use input redirection if do_in is TRUE. |
1240 * We use output redirection if do_out is TRUE. | |
1241 */ | |
1242 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1243 do_filter( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1244 linenr_T line1, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1245 linenr_T line2, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1246 exarg_T *eap, /* for forced 'ff' and 'fenc' */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1247 char_u *cmd, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1248 int do_in, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1249 int do_out) |
7 | 1250 { |
1251 char_u *itmp = NULL; | |
1252 char_u *otmp = NULL; | |
1253 linenr_T linecount; | |
1254 linenr_T read_linecount; | |
1255 pos_T cursor_save; | |
1256 char_u *cmd_buf; | |
1257 buf_T *old_curbuf = curbuf; | |
169 | 1258 int shell_flags = 0; |
7 | 1259 |
1260 if (*cmd == NUL) /* no filter command */ | |
1261 return; | |
1262 | |
1263 cursor_save = curwin->w_cursor; | |
1264 linecount = line2 - line1 + 1; | |
1265 curwin->w_cursor.lnum = line1; | |
1266 curwin->w_cursor.col = 0; | |
1267 changed_line_abv_curs(); | |
1268 invalidate_botline(); | |
1269 | |
1270 /* | |
169 | 1271 * When using temp files: |
1272 * 1. * Form temp file names | |
1273 * 2. * Write the lines to a temp file | |
1274 * 3. Run the filter command on the temp file | |
1275 * 4. * Read the output of the command into the buffer | |
1276 * 5. * Delete the original lines to be filtered | |
1277 * 6. * Remove the temp files | |
1278 * | |
1279 * When writing the input with a pipe or when catching the output with a | |
1280 * pipe only need to do 3. | |
7 | 1281 */ |
1282 | |
169 | 1283 if (do_out) |
1284 shell_flags |= SHELL_DOOUT; | |
1285 | |
3482 | 1286 #ifdef FEAT_FILTERPIPE |
169 | 1287 if (!do_in && do_out && !p_stmp) |
1288 { | |
1289 /* Use a pipe to fetch stdout of the command, do not use a temp file. */ | |
1290 shell_flags |= SHELL_READ; | |
1291 curwin->w_cursor.lnum = line2; | |
1292 } | |
1293 else if (do_in && !do_out && !p_stmp) | |
7 | 1294 { |
169 | 1295 /* Use a pipe to write stdin of the command, do not use a temp file. */ |
1296 shell_flags |= SHELL_WRITE; | |
1297 curbuf->b_op_start.lnum = line1; | |
1298 curbuf->b_op_end.lnum = line2; | |
7 | 1299 } |
169 | 1300 else if (do_in && do_out && !p_stmp) |
1301 { | |
1302 /* Use a pipe to write stdin and fetch stdout of the command, do not | |
1303 * use a temp file. */ | |
1304 shell_flags |= SHELL_READ|SHELL_WRITE; | |
1305 curbuf->b_op_start.lnum = line1; | |
1306 curbuf->b_op_end.lnum = line2; | |
1307 curwin->w_cursor.lnum = line2; | |
1308 } | |
1309 else | |
1310 #endif | |
6721 | 1311 if ((do_in && (itmp = vim_tempname('i', FALSE)) == NULL) |
1312 || (do_out && (otmp = vim_tempname('o', FALSE)) == NULL)) | |
169 | 1313 { |
1314 EMSG(_(e_notmp)); | |
1315 goto filterend; | |
1316 } | |
7 | 1317 |
1318 /* | |
1319 * The writing and reading of temp files will not be shown. | |
1320 * Vi also doesn't do this and the messages are not very informative. | |
1321 */ | |
1322 ++no_wait_return; /* don't call wait_return() while busy */ | |
169 | 1323 if (itmp != NULL && buf_write(curbuf, itmp, NULL, line1, line2, eap, |
7 | 1324 FALSE, FALSE, FALSE, TRUE) == FAIL) |
1325 { | |
1326 msg_putchar('\n'); /* keep message from buf_write() */ | |
1327 --no_wait_return; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
1328 #if defined(FEAT_EVAL) |
7 | 1329 if (!aborting()) |
1330 #endif | |
1331 (void)EMSG2(_(e_notcreate), itmp); /* will call wait_return */ | |
1332 goto filterend; | |
1333 } | |
1334 if (curbuf != old_curbuf) | |
1335 goto filterend; | |
1336 | |
1337 if (!do_out) | |
1338 msg_putchar('\n'); | |
1339 | |
1581 | 1340 /* Create the shell command in allocated memory. */ |
7 | 1341 cmd_buf = make_filter_cmd(cmd, itmp, otmp); |
1342 if (cmd_buf == NULL) | |
1343 goto filterend; | |
1344 | |
1345 windgoto((int)Rows - 1, 0); | |
1346 cursor_on(); | |
1347 | |
1348 /* | |
1349 * When not redirecting the output the command can write anything to the | |
1350 * screen. If 'shellredir' is equal to ">", screen may be messed up by | |
1351 * stderr output of external command. Clear the screen later. | |
1352 * If do_in is FALSE, this could be something like ":r !cat", which may | |
1353 * also mess up the screen, clear it later. | |
1354 */ | |
1355 if (!do_out || STRCMP(p_srr, ">") == 0 || !do_in) | |
1356 redraw_later_clear(); | |
1357 | |
169 | 1358 if (do_out) |
1359 { | |
1360 if (u_save((linenr_T)(line2), (linenr_T)(line2 + 1)) == FAIL) | |
1581 | 1361 { |
1362 vim_free(cmd_buf); | |
169 | 1363 goto error; |
1581 | 1364 } |
169 | 1365 redraw_curbuf_later(VALID); |
1366 } | |
1367 read_linecount = curbuf->b_ml.ml_line_count; | |
1368 | |
7 | 1369 /* |
1370 * When call_shell() fails wait_return() is called to give the user a | |
1371 * chance to read the error messages. Otherwise errors are ignored, so you | |
1372 * can see the error messages from the command that appear on stdout; use | |
1373 * 'u' to fix the text | |
1374 * Switch to cooked mode when not redirecting stdin, avoids that something | |
1375 * like ":r !cat" hangs. | |
1376 * Pass on the SHELL_DOOUT flag when the output is being redirected. | |
1377 */ | |
169 | 1378 if (call_shell(cmd_buf, SHELL_FILTER | SHELL_COOKED | shell_flags)) |
7 | 1379 { |
1380 redraw_later_clear(); | |
1381 wait_return(FALSE); | |
1382 } | |
1383 vim_free(cmd_buf); | |
1384 | |
1385 did_check_timestamps = FALSE; | |
1386 need_check_timestamps = TRUE; | |
1387 | |
1388 /* When interrupting the shell command, it may still have produced some | |
1389 * useful output. Reset got_int here, so that readfile() won't cancel | |
1390 * reading. */ | |
1391 ui_breakcheck(); | |
1392 got_int = FALSE; | |
1393 | |
1394 if (do_out) | |
1395 { | |
169 | 1396 if (otmp != NULL) |
7 | 1397 { |
169 | 1398 if (readfile(otmp, NULL, line2, (linenr_T)0, (linenr_T)MAXLNUM, |
10575
01a5f64a7a20
patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents:
10482
diff
changeset
|
1399 eap, READ_FILTER) != OK) |
169 | 1400 { |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
1401 #if defined(FEAT_EVAL) |
169 | 1402 if (!aborting()) |
1403 #endif | |
1404 { | |
1405 msg_putchar('\n'); | |
1406 EMSG2(_(e_notread), otmp); | |
1407 } | |
1408 goto error; | |
7 | 1409 } |
169 | 1410 if (curbuf != old_curbuf) |
1411 goto filterend; | |
7 | 1412 } |
169 | 1413 |
1414 read_linecount = curbuf->b_ml.ml_line_count - read_linecount; | |
1415 | |
1416 if (shell_flags & SHELL_READ) | |
1417 { | |
1418 curbuf->b_op_start.lnum = line2 + 1; | |
1419 curbuf->b_op_end.lnum = curwin->w_cursor.lnum; | |
1420 appended_lines_mark(line2, read_linecount); | |
1421 } | |
7 | 1422 |
1423 if (do_in) | |
1424 { | |
1425 if (cmdmod.keepmarks || vim_strchr(p_cpo, CPO_REMMARK) == NULL) | |
1426 { | |
1427 if (read_linecount >= linecount) | |
1428 /* move all marks from old lines to new lines */ | |
1429 mark_adjust(line1, line2, linecount, 0L); | |
1430 else | |
1431 { | |
1432 /* move marks from old lines to new lines, delete marks | |
1433 * that are in deleted lines */ | |
1434 mark_adjust(line1, line1 + read_linecount - 1, | |
1435 linecount, 0L); | |
1436 mark_adjust(line1 + read_linecount, line2, MAXLNUM, 0L); | |
1437 } | |
1438 } | |
1439 | |
1440 /* | |
1441 * Put cursor on first filtered line for ":range!cmd". | |
1442 * Adjust '[ and '] (set by buf_write()). | |
1443 */ | |
1444 curwin->w_cursor.lnum = line1; | |
1445 del_lines(linecount, TRUE); | |
1446 curbuf->b_op_start.lnum -= linecount; /* adjust '[ */ | |
1447 curbuf->b_op_end.lnum -= linecount; /* adjust '] */ | |
1448 write_lnum_adjust(-linecount); /* adjust last line | |
1449 for next write */ | |
100 | 1450 #ifdef FEAT_FOLDING |
1451 foldUpdate(curwin, curbuf->b_op_start.lnum, curbuf->b_op_end.lnum); | |
1452 #endif | |
7 | 1453 } |
1454 else | |
1455 { | |
1456 /* | |
1457 * Put cursor on last new line for ":r !cmd". | |
1458 */ | |
169 | 1459 linecount = curbuf->b_op_end.lnum - curbuf->b_op_start.lnum + 1; |
7 | 1460 curwin->w_cursor.lnum = curbuf->b_op_end.lnum; |
1461 } | |
100 | 1462 |
7 | 1463 beginline(BL_WHITE | BL_FIX); /* cursor on first non-blank */ |
1464 --no_wait_return; | |
1465 | |
1466 if (linecount > p_report) | |
1467 { | |
1468 if (do_in) | |
1469 { | |
274 | 1470 vim_snprintf((char *)msg_buf, sizeof(msg_buf), |
1471 _("%ld lines filtered"), (long)linecount); | |
7 | 1472 if (msg(msg_buf) && !msg_scroll) |
1473 /* save message to display it after redraw */ | |
680 | 1474 set_keep_msg(msg_buf, 0); |
7 | 1475 } |
1476 else | |
1477 msgmore((long)linecount); | |
1478 } | |
1479 } | |
1480 else | |
1481 { | |
1482 error: | |
1483 /* put cursor back in same position for ":w !cmd" */ | |
1484 curwin->w_cursor = cursor_save; | |
1485 --no_wait_return; | |
1486 wait_return(FALSE); | |
1487 } | |
1488 | |
1489 filterend: | |
1490 | |
1491 if (curbuf != old_curbuf) | |
1492 { | |
1493 --no_wait_return; | |
1494 EMSG(_("E135: *Filter* Autocommands must not change current buffer")); | |
1495 } | |
1496 if (itmp != NULL) | |
1497 mch_remove(itmp); | |
1498 if (otmp != NULL) | |
1499 mch_remove(otmp); | |
1500 vim_free(itmp); | |
1501 vim_free(otmp); | |
1502 } | |
1503 | |
1504 /* | |
1505 * Call a shell to execute a command. | |
1506 * When "cmd" is NULL start an interactive shell. | |
1507 */ | |
1508 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1509 do_shell( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1510 char_u *cmd, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1511 int flags) /* may be SHELL_DOOUT when output is redirected */ |
7 | 1512 { |
1513 buf_T *buf; | |
1514 #ifndef FEAT_GUI_MSWIN | |
1515 int save_nwr; | |
1516 #endif | |
1517 #ifdef MSWIN | |
1518 int winstart = FALSE; | |
1519 #endif | |
1520 | |
1521 /* | |
1522 * Disallow shell commands for "rvim". | |
1523 * Disallow shell commands from .exrc and .vimrc in current directory for | |
1524 * security reasons. | |
1525 */ | |
1526 if (check_restricted() || check_secure()) | |
1527 { | |
1528 msg_end(); | |
1529 return; | |
1530 } | |
1531 | |
1532 #ifdef MSWIN | |
1533 /* | |
1534 * Check if ":!start" is used. | |
1535 */ | |
1536 if (cmd != NULL) | |
1537 winstart = (STRNICMP(cmd, "start ", 6) == 0); | |
1538 #endif | |
1539 | |
1540 /* | |
1541 * For autocommands we want to get the output on the current screen, to | |
1542 * avoid having to type return below. | |
1543 */ | |
1544 msg_putchar('\r'); /* put cursor at start of line */ | |
1545 if (!autocmd_busy) | |
1546 { | |
1547 #ifdef MSWIN | |
1548 if (!winstart) | |
1549 #endif | |
1550 stoptermcap(); | |
1551 } | |
1552 #ifdef MSWIN | |
1553 if (!winstart) | |
1554 #endif | |
1555 msg_putchar('\n'); /* may shift screen one line up */ | |
1556 | |
1557 /* warning message before calling the shell */ | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
1558 if (p_warn && !autocmd_busy && msg_silent == 0) |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1559 FOR_ALL_BUFFERS(buf) |
13012
8d5b451d7bab
patch 8.0.1382: get "no write since last change" message if terminal is open
Christian Brabandt <cb@256bit.org>
parents:
12942
diff
changeset
|
1560 if (bufIsChangedNotTerm(buf)) |
7 | 1561 { |
1562 #ifdef FEAT_GUI_MSWIN | |
1563 if (!winstart) | |
1564 starttermcap(); /* don't want a message box here */ | |
1565 #endif | |
1566 MSG_PUTS(_("[No write since last change]\n")); | |
1567 #ifdef FEAT_GUI_MSWIN | |
1568 if (!winstart) | |
1569 stoptermcap(); | |
1570 #endif | |
1571 break; | |
1572 } | |
1573 | |
1574 /* This windgoto is required for when the '\n' resulted in a "delete line | |
1575 * 1" command to the terminal. */ | |
1576 if (!swapping_screen()) | |
1577 windgoto(msg_row, msg_col); | |
1578 cursor_on(); | |
1579 (void)call_shell(cmd, SHELL_COOKED | flags); | |
1580 did_check_timestamps = FALSE; | |
1581 need_check_timestamps = TRUE; | |
1582 | |
1583 /* | |
1584 * put the message cursor at the end of the screen, avoids wait_return() | |
1585 * to overwrite the text that the external command showed | |
1586 */ | |
1587 if (!swapping_screen()) | |
1588 { | |
1589 msg_row = Rows - 1; | |
1590 msg_col = 0; | |
1591 } | |
1592 | |
1593 if (autocmd_busy) | |
1594 { | |
1595 if (msg_silent == 0) | |
1596 redraw_later_clear(); | |
1597 } | |
1598 else | |
1599 { | |
1600 /* | |
1601 * For ":sh" there is no need to call wait_return(), just redraw. | |
1602 * Also for the Win32 GUI (the output is in a console window). | |
1603 * Otherwise there is probably text on the screen that the user wants | |
1604 * to read before redrawing, so call wait_return(). | |
1605 */ | |
1606 #ifndef FEAT_GUI_MSWIN | |
1607 if (cmd == NULL | |
1608 # ifdef WIN3264 | |
1609 || (winstart && !need_wait_return) | |
1610 # endif | |
1611 ) | |
1612 { | |
1613 if (msg_silent == 0) | |
1614 redraw_later_clear(); | |
1615 need_wait_return = FALSE; | |
1616 } | |
1617 else | |
1618 { | |
1619 /* | |
1620 * If we switch screens when starttermcap() is called, we really | |
1621 * want to wait for "hit return to continue". | |
1622 */ | |
1623 save_nwr = no_wait_return; | |
1624 if (swapping_screen()) | |
1625 no_wait_return = FALSE; | |
1626 # ifdef AMIGA | |
1627 wait_return(term_console ? -1 : msg_silent == 0); /* see below */ | |
1628 # else | |
1629 wait_return(msg_silent == 0); | |
1630 # endif | |
1631 no_wait_return = save_nwr; | |
1632 } | |
1633 #endif /* FEAT_GUI_W32 */ | |
1634 | |
1635 #ifdef MSWIN | |
1636 if (!winstart) /* if winstart==TRUE, never stopped termcap! */ | |
1637 #endif | |
1638 starttermcap(); /* start termcap if not done by wait_return() */ | |
1639 | |
1640 /* | |
1641 * In an Amiga window redrawing is caused by asking the window size. | |
1642 * If we got an interrupt this will not work. The chance that the | |
1643 * window size is wrong is very small, but we need to redraw the | |
1644 * screen. Don't do this if ':' hit in wait_return(). THIS IS UGLY | |
1645 * but it saves an extra redraw. | |
1646 */ | |
1647 #ifdef AMIGA | |
1648 if (skip_redraw) /* ':' hit in wait_return() */ | |
1649 { | |
1650 if (msg_silent == 0) | |
1651 redraw_later_clear(); | |
1652 } | |
1653 else if (term_console) | |
1654 { | |
1655 OUT_STR(IF_EB("\033[0 q", ESC_STR "[0 q")); /* get window size */ | |
1656 if (got_int && msg_silent == 0) | |
1657 redraw_later_clear(); /* if got_int is TRUE, redraw needed */ | |
1658 else | |
1659 must_redraw = 0; /* no extra redraw needed */ | |
1660 } | |
1661 #endif | |
1662 } | |
1663 | |
1664 /* display any error messages now */ | |
1665 display_errors(); | |
725 | 1666 |
1667 apply_autocmds(EVENT_SHELLCMDPOST, NULL, NULL, FALSE, curbuf); | |
7 | 1668 } |
1669 | |
1670 /* | |
1671 * Create a shell command from a command string, input redirection file and | |
1672 * output redirection file. | |
1673 * Returns an allocated string with the shell command, or NULL for failure. | |
1674 */ | |
1675 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1676 make_filter_cmd( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1677 char_u *cmd, /* command */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1678 char_u *itmp, /* NULL or name of input file */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1679 char_u *otmp) /* NULL or name of output file */ |
7 | 1680 { |
1681 char_u *buf; | |
1682 long_u len; | |
5867 | 1683 |
7410
08e62c4fc17d
commit https://github.com/vim/vim/commit/53076830fea6df737455523f7e235bfe4f79864d
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
1684 #if defined(UNIX) |
5881 | 1685 int is_fish_shell; |
5911 | 1686 char_u *shell_name = get_isolated_shell_name(); |
5881 | 1687 |
5867 | 1688 /* Account for fish's different syntax for subshells */ |
5911 | 1689 is_fish_shell = (fnamecmp(shell_name, "fish") == 0); |
1690 vim_free(shell_name); | |
5867 | 1691 if (is_fish_shell) |
1692 len = (long_u)STRLEN(cmd) + 13; /* "begin; " + "; end" + NUL */ | |
1693 else | |
1694 #endif | |
1695 len = (long_u)STRLEN(cmd) + 3; /* "()" + NUL */ | |
7 | 1696 if (itmp != NULL) |
1697 len += (long_u)STRLEN(itmp) + 9; /* " { < " + " } " */ | |
1698 if (otmp != NULL) | |
1699 len += (long_u)STRLEN(otmp) + (long_u)STRLEN(p_srr) + 2; /* " " */ | |
1700 buf = lalloc(len, TRUE); | |
1701 if (buf == NULL) | |
1702 return NULL; | |
1703 | |
7410
08e62c4fc17d
commit https://github.com/vim/vim/commit/53076830fea6df737455523f7e235bfe4f79864d
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
1704 #if defined(UNIX) |
7 | 1705 /* |
169 | 1706 * Put braces around the command (for concatenated commands) when |
1707 * redirecting input and/or output. | |
7 | 1708 */ |
169 | 1709 if (itmp != NULL || otmp != NULL) |
5867 | 1710 { |
1711 if (is_fish_shell) | |
1712 vim_snprintf((char *)buf, len, "begin; %s; end", (char *)cmd); | |
1713 else | |
1714 vim_snprintf((char *)buf, len, "(%s)", (char *)cmd); | |
1715 } | |
169 | 1716 else |
1717 STRCPY(buf, cmd); | |
7 | 1718 if (itmp != NULL) |
1719 { | |
1720 STRCAT(buf, " < "); | |
1721 STRCAT(buf, itmp); | |
1722 } | |
1723 #else | |
1724 /* | |
5867 | 1725 * For shells that don't understand braces around commands, at least allow |
7 | 1726 * the use of commands in a pipe. |
1727 */ | |
1728 STRCPY(buf, cmd); | |
1729 if (itmp != NULL) | |
1730 { | |
1731 char_u *p; | |
1732 | |
1733 /* | |
1734 * If there is a pipe, we have to put the '<' in front of it. | |
1735 * Don't do this when 'shellquote' is not empty, otherwise the | |
1736 * redirection would be inside the quotes. | |
1737 */ | |
1738 if (*p_shq == NUL) | |
1739 { | |
1740 p = vim_strchr(buf, '|'); | |
1741 if (p != NULL) | |
1742 *p = NUL; | |
1743 } | |
1744 STRCAT(buf, " <"); /* " < " causes problems on Amiga */ | |
1745 STRCAT(buf, itmp); | |
1746 if (*p_shq == NUL) | |
1747 { | |
1748 p = vim_strchr(cmd, '|'); | |
1749 if (p != NULL) | |
1750 { | |
1751 STRCAT(buf, " "); /* insert a space before the '|' for DOS */ | |
1752 STRCAT(buf, p); | |
1753 } | |
1754 } | |
1755 } | |
1756 #endif | |
1757 if (otmp != NULL) | |
1872 | 1758 append_redir(buf, (int)len, p_srr, otmp); |
7 | 1759 |
1760 return buf; | |
1761 } | |
1762 | |
1763 /* | |
1872 | 1764 * Append output redirection for file "fname" to the end of string buffer |
1765 * "buf[buflen]" | |
7 | 1766 * Works with the 'shellredir' and 'shellpipe' options. |
1767 * The caller should make sure that there is enough room: | |
1768 * STRLEN(opt) + STRLEN(fname) + 3 | |
1769 */ | |
1770 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1771 append_redir( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1772 char_u *buf, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1773 int buflen, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1774 char_u *opt, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1775 char_u *fname) |
7 | 1776 { |
1777 char_u *p; | |
1872 | 1778 char_u *end; |
1779 | |
1780 end = buf + STRLEN(buf); | |
5257
e63e4b4be923
updated for version 7.4b.005
Bram Moolenaar <bram@vim.org>
parents:
5242
diff
changeset
|
1781 /* find "%s" */ |
7 | 1782 for (p = opt; (p = vim_strchr(p, '%')) != NULL; ++p) |
5257
e63e4b4be923
updated for version 7.4b.005
Bram Moolenaar <bram@vim.org>
parents:
5242
diff
changeset
|
1783 { |
e63e4b4be923
updated for version 7.4b.005
Bram Moolenaar <bram@vim.org>
parents:
5242
diff
changeset
|
1784 if (p[1] == 's') /* found %s */ |
7 | 1785 break; |
5257
e63e4b4be923
updated for version 7.4b.005
Bram Moolenaar <bram@vim.org>
parents:
5242
diff
changeset
|
1786 if (p[1] == '%') /* skip %% */ |
e63e4b4be923
updated for version 7.4b.005
Bram Moolenaar <bram@vim.org>
parents:
5242
diff
changeset
|
1787 ++p; |
e63e4b4be923
updated for version 7.4b.005
Bram Moolenaar <bram@vim.org>
parents:
5242
diff
changeset
|
1788 } |
7 | 1789 if (p != NULL) |
1790 { | |
1872 | 1791 *end = ' '; /* not really needed? Not with sh, ksh or bash */ |
1792 vim_snprintf((char *)end + 1, (size_t)(buflen - (end + 1 - buf)), | |
1793 (char *)opt, (char *)fname); | |
7 | 1794 } |
1795 else | |
1872 | 1796 vim_snprintf((char *)end, (size_t)(buflen - (end - buf)), |
7 | 1797 #ifdef FEAT_QUICKFIX |
1798 " %s %s", | |
1799 #else | |
1800 " %s%s", /* " > %s" causes problems on Amiga */ | |
1801 #endif | |
1802 (char *)opt, (char *)fname); | |
1803 } | |
1804 | |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
1805 #if defined(FEAT_VIMINFO) || defined(PROTO) |
7 | 1806 |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
1807 static int no_viminfo(void); |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
1808 static int read_viminfo_barline(vir_T *virp, int got_encoding, int force, int writing); |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
1809 static void write_viminfo_version(FILE *fp_out); |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
1810 static void write_viminfo_barlines(vir_T *virp, FILE *fp_out); |
7 | 1811 static int viminfo_errcnt; |
1812 | |
1813 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1814 no_viminfo(void) |
7 | 1815 { |
1816 /* "vim -i NONE" does not read or write a viminfo file */ | |
11666
5cd9ba96561d
patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents:
11649
diff
changeset
|
1817 return STRCMP(p_viminfofile, "NONE") == 0; |
7 | 1818 } |
1819 | |
1820 /* | |
1821 * Report an error for reading a viminfo file. | |
1822 * Count the number of errors. When there are more than 10, return TRUE. | |
1823 */ | |
1824 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1825 viminfo_error(char *errnum, char *message, char_u *line) |
7 | 1826 { |
274 | 1827 vim_snprintf((char *)IObuff, IOSIZE, _("%sviminfo: %s in line: "), |
1828 errnum, message); | |
1459 | 1829 STRNCAT(IObuff, line, IOSIZE - STRLEN(IObuff) - 1); |
156 | 1830 if (IObuff[STRLEN(IObuff) - 1] == '\n') |
1831 IObuff[STRLEN(IObuff) - 1] = NUL; | |
7 | 1832 emsg(IObuff); |
1833 if (++viminfo_errcnt >= 10) | |
1834 { | |
1835 EMSG(_("E136: viminfo: Too many errors, skipping rest of file")); | |
1836 return TRUE; | |
1837 } | |
1838 return FALSE; | |
1839 } | |
1840 | |
1841 /* | |
1842 * read_viminfo() -- Read the viminfo file. Registers etc. which are already | |
1733 | 1843 * set are not over-written unless "flags" includes VIF_FORCEIT. -- webb |
7 | 1844 */ |
1845 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1846 read_viminfo( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1847 char_u *file, /* file name or NULL to use default name */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1848 int flags) /* VIF_WANT_INFO et al. */ |
7 | 1849 { |
1850 FILE *fp; | |
1851 char_u *fname; | |
1852 | |
1853 if (no_viminfo()) | |
1854 return FAIL; | |
1855 | |
1733 | 1856 fname = viminfo_filename(file); /* get file name in allocated buffer */ |
7 | 1857 if (fname == NULL) |
1858 return FAIL; | |
1859 fp = mch_fopen((char *)fname, READBIN); | |
1860 | |
1861 if (p_verbose > 0) | |
294 | 1862 { |
1863 verbose_enter(); | |
274 | 1864 smsg((char_u *)_("Reading viminfo file \"%s\"%s%s%s"), |
1865 fname, | |
1733 | 1866 (flags & VIF_WANT_INFO) ? _(" info") : "", |
1867 (flags & VIF_WANT_MARKS) ? _(" marks") : "", | |
1868 (flags & VIF_GET_OLDFILES) ? _(" oldfiles") : "", | |
274 | 1869 fp == NULL ? _(" FAILED") : ""); |
294 | 1870 verbose_leave(); |
1871 } | |
7 | 1872 |
1873 vim_free(fname); | |
1874 if (fp == NULL) | |
1875 return FAIL; | |
1876 | |
1877 viminfo_errcnt = 0; | |
1733 | 1878 do_viminfo(fp, NULL, flags); |
7 | 1879 |
1880 fclose(fp); | |
1881 return OK; | |
1882 } | |
1883 | |
1884 /* | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1885 * Write the viminfo file. The old one is read in first so that effectively a |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1886 * merge of current info and old info is done. This allows multiple vims to |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1887 * run simultaneously, without losing any marks etc. |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1888 * If "forceit" is TRUE, then the old file is not read in, and only internal |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1889 * info is written to the file. |
7 | 1890 */ |
1891 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1892 write_viminfo(char_u *file, int forceit) |
7 | 1893 { |
1894 char_u *fname; | |
1895 FILE *fp_in = NULL; /* input viminfo file, if any */ | |
1896 FILE *fp_out = NULL; /* output viminfo file */ | |
1897 char_u *tempname = NULL; /* name of temp viminfo file */ | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9377
diff
changeset
|
1898 stat_T st_new; /* mch_stat() of potential new file */ |
7 | 1899 #if defined(UNIX) || defined(VMS) |
1900 mode_t umask_save; | |
1901 #endif | |
1902 #ifdef UNIX | |
1903 int shortname = FALSE; /* use 8.3 file name */ | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9377
diff
changeset
|
1904 stat_T st_old; /* mch_stat() of existing viminfo file */ |
7 | 1905 #endif |
601 | 1906 #ifdef WIN3264 |
7194
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1907 int hidden = FALSE; |
601 | 1908 #endif |
7 | 1909 |
1910 if (no_viminfo()) | |
1911 return; | |
1912 | |
1913 fname = viminfo_filename(file); /* may set to default if NULL */ | |
1914 if (fname == NULL) | |
1915 return; | |
1916 | |
1917 fp_in = mch_fopen((char *)fname, READBIN); | |
1918 if (fp_in == NULL) | |
1919 { | |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1920 int fd; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1921 |
7 | 1922 /* if it does exist, but we can't read it, don't try writing */ |
1923 if (mch_stat((char *)fname, &st_new) == 0) | |
1924 goto end; | |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1925 |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1926 /* Create the new .viminfo non-accessible for others, because it may |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1927 * contain text from non-accessible documents. It is up to the user to |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1928 * widen access (e.g. to a group). This may also fail if there is a |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1929 * race condition, then just give up. */ |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1930 fd = mch_open((char *)fname, |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1931 O_CREAT|O_EXTRA|O_EXCL|O_WRONLY|O_NOFOLLOW, 0600); |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1932 if (fd < 0) |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1933 goto end; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1934 fp_out = fdopen(fd, WRITEBIN); |
7 | 1935 } |
1936 else | |
1937 { | |
1938 /* | |
1939 * There is an existing viminfo file. Create a temporary file to | |
1940 * write the new viminfo into, in the same directory as the | |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1941 * existing viminfo file, which will be renamed once all writing is |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1942 * successful. |
7 | 1943 */ |
1944 #ifdef UNIX | |
1945 /* | |
1946 * For Unix we check the owner of the file. It's not very nice to | |
1947 * overwrite a user's viminfo file after a "su root", with a | |
1948 * viminfo file that the user can't read. | |
1949 */ | |
1869 | 1950 st_old.st_dev = (dev_t)0; |
1438 | 1951 st_old.st_ino = 0; |
7 | 1952 st_old.st_mode = 0600; |
1076 | 1953 if (mch_stat((char *)fname, &st_old) == 0 |
1954 && getuid() != ROOT_UID | |
560 | 1955 && !(st_old.st_uid == getuid() |
7 | 1956 ? (st_old.st_mode & 0200) |
1957 : (st_old.st_gid == getgid() | |
1958 ? (st_old.st_mode & 0020) | |
1959 : (st_old.st_mode & 0002)))) | |
1960 { | |
944 | 1961 int tt = msg_didany; |
7 | 1962 |
1963 /* avoid a wait_return for this message, it's annoying */ | |
1964 EMSG2(_("E137: Viminfo file is not writable: %s"), fname); | |
1965 msg_didany = tt; | |
840 | 1966 fclose(fp_in); |
7 | 1967 goto end; |
1968 } | |
1969 #endif | |
601 | 1970 #ifdef WIN3264 |
1971 /* Get the file attributes of the existing viminfo file. */ | |
7194
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1972 hidden = mch_ishidden(fname); |
601 | 1973 #endif |
7 | 1974 |
1975 /* | |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1976 * Make tempname, find one that does not exist yet. |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1977 * Beware of a race condition: If someone logs out and all Vim |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1978 * instances exit at the same time a temp file might be created between |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1979 * stat() and open(). Use mch_open() with O_EXCL to avoid that. |
7 | 1980 * May try twice: Once normal and once with shortname set, just in |
1981 * case somebody puts his viminfo file in an 8.3 filesystem. | |
1982 */ | |
1983 for (;;) | |
1984 { | |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1985 int next_char = 'z'; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1986 char_u *wp; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1987 |
7 | 1988 tempname = buf_modname( |
1989 #ifdef UNIX | |
1990 shortname, | |
1991 #else | |
1992 FALSE, | |
1993 #endif | |
1994 fname, | |
1995 #ifdef VMS | |
1996 (char_u *)"-tmp", | |
1997 #else | |
1998 (char_u *)".tmp", | |
1999 #endif | |
2000 FALSE); | |
2001 if (tempname == NULL) /* out of memory */ | |
2002 break; | |
2003 | |
2004 /* | |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2005 * Try a series of names. Change one character, just before |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2006 * the extension. This should also work for an 8.3 |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2007 * file name, when after adding the extension it still is |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2008 * the same file as the original. |
7 | 2009 */ |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2010 wp = tempname + STRLEN(tempname) - 5; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2011 if (wp < gettail(tempname)) /* empty file name? */ |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2012 wp = gettail(tempname); |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2013 for (;;) |
7 | 2014 { |
2015 /* | |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2016 * Check if tempfile already exists. Never overwrite an |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2017 * existing file! |
7 | 2018 */ |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2019 if (mch_stat((char *)tempname, &st_new) == 0) |
7 | 2020 { |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2021 #ifdef UNIX |
7 | 2022 /* |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2023 * Check if tempfile is same as original file. May happen |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2024 * when modname() gave the same file back. E.g. silly |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2025 * link, or file name-length reached. Try again with |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2026 * shortname set. |
7 | 2027 */ |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2028 if (!shortname && st_new.st_dev == st_old.st_dev |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2029 && st_new.st_ino == st_old.st_ino) |
7 | 2030 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13174
diff
changeset
|
2031 VIM_CLEAR(tempname); |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2032 shortname = TRUE; |
7 | 2033 break; |
2034 } | |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2035 #endif |
7 | 2036 } |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2037 else |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2038 { |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2039 /* Try creating the file exclusively. This may fail if |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2040 * another Vim tries to do it at the same time. */ |
762 | 2041 #ifdef VMS |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2042 /* fdopen() fails for some reason */ |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2043 umask_save = umask(077); |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2044 fp_out = mch_fopen((char *)tempname, WRITEBIN); |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2045 (void)umask(umask_save); |
762 | 2046 #else |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2047 int fd; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2048 |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2049 /* Use mch_open() to be able to use O_NOFOLLOW and set file |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2050 * protection: |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2051 * Unix: same as original file, but strip s-bit. Reset |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2052 * umask to avoid it getting in the way. |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2053 * Others: r&w for user only. */ |
762 | 2054 # ifdef UNIX |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2055 umask_save = umask(0); |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2056 fd = mch_open((char *)tempname, |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2057 O_CREAT|O_EXTRA|O_EXCL|O_WRONLY|O_NOFOLLOW, |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2058 (int)((st_old.st_mode & 0777) | 0600)); |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2059 (void)umask(umask_save); |
762 | 2060 # else |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2061 fd = mch_open((char *)tempname, |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2062 O_CREAT|O_EXTRA|O_EXCL|O_WRONLY|O_NOFOLLOW, 0600); |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2063 # endif |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2064 if (fd < 0) |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2065 { |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2066 fp_out = NULL; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2067 # ifdef EEXIST |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2068 /* Avoid trying lots of names while the problem is lack |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2069 * of premission, only retry if the file already |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2070 * exists. */ |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2071 if (errno != EEXIST) |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2072 break; |
762 | 2073 # endif |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2074 } |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2075 else |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2076 fp_out = fdopen(fd, WRITEBIN); |
762 | 2077 #endif /* VMS */ |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2078 if (fp_out != NULL) |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2079 break; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2080 } |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2081 |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2082 /* Assume file exists, try again with another name. */ |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2083 if (next_char == 'a' - 1) |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2084 { |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2085 /* They all exist? Must be something wrong! Don't write |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2086 * the viminfo file then. */ |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2087 EMSG2(_("E929: Too many viminfo temp files, like %s!"), |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2088 tempname); |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2089 break; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2090 } |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2091 *wp = next_char; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2092 --next_char; |
7 | 2093 } |
557 | 2094 |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2095 if (tempname != NULL) |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2096 break; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2097 /* continue if shortname was set */ |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2098 } |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2099 |
557 | 2100 #if defined(UNIX) && defined(HAVE_FCHOWN) |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2101 if (tempname != NULL && fp_out != NULL) |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2102 { |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2103 stat_T tmp_st; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2104 |
7 | 2105 /* |
12820
63d87ba12c34
patch 8.0.1287: temp file used for viminfo may have wrong permissions
Christian Brabandt <cb@256bit.org>
parents:
12676
diff
changeset
|
2106 * Make sure the original owner can read/write the tempfile and |
63d87ba12c34
patch 8.0.1287: temp file used for viminfo may have wrong permissions
Christian Brabandt <cb@256bit.org>
parents:
12676
diff
changeset
|
2107 * otherwise preserve permissions, making sure the group matches. |
7 | 2108 */ |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2109 if (mch_stat((char *)tempname, &tmp_st) >= 0) |
12820
63d87ba12c34
patch 8.0.1287: temp file used for viminfo may have wrong permissions
Christian Brabandt <cb@256bit.org>
parents:
12676
diff
changeset
|
2110 { |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2111 if (st_old.st_uid != tmp_st.st_uid) |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2112 /* Changing the owner might fail, in which case the |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2113 * file will now owned by the current user, oh well. */ |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2114 ignored = fchown(fileno(fp_out), st_old.st_uid, -1); |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2115 if (st_old.st_gid != tmp_st.st_gid |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2116 && fchown(fileno(fp_out), -1, st_old.st_gid) == -1) |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2117 /* can't set the group to what it should be, remove |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2118 * group permissions */ |
12820
63d87ba12c34
patch 8.0.1287: temp file used for viminfo may have wrong permissions
Christian Brabandt <cb@256bit.org>
parents:
12676
diff
changeset
|
2119 (void)mch_setperm(tempname, 0600); |
63d87ba12c34
patch 8.0.1287: temp file used for viminfo may have wrong permissions
Christian Brabandt <cb@256bit.org>
parents:
12676
diff
changeset
|
2120 } |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2121 else |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2122 /* can't stat the file, set conservative permissions */ |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2123 (void)mch_setperm(tempname, 0600); |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2124 } |
12942
914fbd1d269f
patch 8.0.1347: MS-Windows: build broken by misplaced curly
Christian Brabandt <cb@256bit.org>
parents:
12938
diff
changeset
|
2125 #endif |
914fbd1d269f
patch 8.0.1347: MS-Windows: build broken by misplaced curly
Christian Brabandt <cb@256bit.org>
parents:
12938
diff
changeset
|
2126 } |
7 | 2127 |
2128 /* | |
2129 * Check if the new viminfo file can be written to. | |
2130 */ | |
2131 if (fp_out == NULL) | |
2132 { | |
2133 EMSG2(_("E138: Can't write viminfo file %s!"), | |
301 | 2134 (fp_in == NULL || tempname == NULL) ? fname : tempname); |
7 | 2135 if (fp_in != NULL) |
2136 fclose(fp_in); | |
2137 goto end; | |
2138 } | |
2139 | |
2140 if (p_verbose > 0) | |
294 | 2141 { |
2142 verbose_enter(); | |
274 | 2143 smsg((char_u *)_("Writing viminfo file \"%s\""), fname); |
294 | 2144 verbose_leave(); |
2145 } | |
7 | 2146 |
2147 viminfo_errcnt = 0; | |
1733 | 2148 do_viminfo(fp_in, fp_out, forceit ? 0 : (VIF_WANT_INFO | VIF_WANT_MARKS)); |
7 | 2149 |
8573
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2150 if (fclose(fp_out) == EOF) |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2151 ++viminfo_errcnt; |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2152 |
7 | 2153 if (fp_in != NULL) |
2154 { | |
2155 fclose(fp_in); | |
601 | 2156 |
6049 | 2157 /* In case of an error keep the original viminfo file. Otherwise |
2158 * rename the newly written file. Give an error if that fails. */ | |
8573
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2159 if (viminfo_errcnt == 0) |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2160 { |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2161 if (vim_rename(tempname, fname) == -1) |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2162 { |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2163 ++viminfo_errcnt; |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2164 EMSG2(_("E886: Can't rename viminfo file to %s!"), fname); |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2165 } |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2166 # ifdef WIN3264 |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2167 /* If the viminfo file was hidden then also hide the new file. */ |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2168 else if (hidden) |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2169 mch_hide(fname); |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2170 # endif |
6049 | 2171 } |
2172 if (viminfo_errcnt > 0) | |
7 | 2173 mch_remove(tempname); |
601 | 2174 } |
2175 | |
7 | 2176 end: |
2177 vim_free(fname); | |
2178 vim_free(tempname); | |
2179 } | |
2180 | |
2181 /* | |
2182 * Get the viminfo file name to use. | |
2183 * If "file" is given and not empty, use it (has already been expanded by | |
2184 * cmdline functions). | |
2185 * Otherwise use "-i file_name", value from 'viminfo' or the default, and | |
2186 * expand environment variables. | |
2187 * Returns an allocated string. NULL when out of memory. | |
2188 */ | |
2189 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2190 viminfo_filename(char_u *file) |
7 | 2191 { |
2192 if (file == NULL || *file == NUL) | |
2193 { | |
11666
5cd9ba96561d
patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents:
11649
diff
changeset
|
2194 if (*p_viminfofile != NUL) |
5cd9ba96561d
patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents:
11649
diff
changeset
|
2195 file = p_viminfofile; |
7 | 2196 else if ((file = find_viminfo_parameter('n')) == NULL || *file == NUL) |
2197 { | |
2198 #ifdef VIMINFO_FILE2 | |
2199 # ifdef VMS | |
2200 if (mch_getenv((char_u *)"SYS$LOGIN") == NULL) | |
2201 # else | |
12297
98586656fcae
patch 8.0.1028: MS-Windows: viminfo uses $VIM/_viminfo if $HOME not set
Christian Brabandt <cb@256bit.org>
parents:
12146
diff
changeset
|
2202 # ifdef MSWIN |
98586656fcae
patch 8.0.1028: MS-Windows: viminfo uses $VIM/_viminfo if $HOME not set
Christian Brabandt <cb@256bit.org>
parents:
12146
diff
changeset
|
2203 /* Use $VIM only if $HOME is the default "C:/". */ |
98586656fcae
patch 8.0.1028: MS-Windows: viminfo uses $VIM/_viminfo if $HOME not set
Christian Brabandt <cb@256bit.org>
parents:
12146
diff
changeset
|
2204 if (STRCMP(vim_getenv((char_u *)"HOME", NULL), "C:/") == 0 |
98586656fcae
patch 8.0.1028: MS-Windows: viminfo uses $VIM/_viminfo if $HOME not set
Christian Brabandt <cb@256bit.org>
parents:
12146
diff
changeset
|
2205 && mch_getenv((char_u *)"HOME") == NULL) |
98586656fcae
patch 8.0.1028: MS-Windows: viminfo uses $VIM/_viminfo if $HOME not set
Christian Brabandt <cb@256bit.org>
parents:
12146
diff
changeset
|
2206 # else |
7 | 2207 if (mch_getenv((char_u *)"HOME") == NULL) |
12297
98586656fcae
patch 8.0.1028: MS-Windows: viminfo uses $VIM/_viminfo if $HOME not set
Christian Brabandt <cb@256bit.org>
parents:
12146
diff
changeset
|
2208 # endif |
7 | 2209 # endif |
2210 { | |
2211 /* don't use $VIM when not available. */ | |
2212 expand_env((char_u *)"$VIM", NameBuff, MAXPATHL); | |
2213 if (STRCMP("$VIM", NameBuff) != 0) /* $VIM was expanded */ | |
2214 file = (char_u *)VIMINFO_FILE2; | |
2215 else | |
2216 file = (char_u *)VIMINFO_FILE; | |
2217 } | |
2218 else | |
2219 #endif | |
2220 file = (char_u *)VIMINFO_FILE; | |
2221 } | |
2222 expand_env(file, NameBuff, MAXPATHL); | |
2223 file = NameBuff; | |
2224 } | |
2225 return vim_strsave(file); | |
2226 } | |
2227 | |
2228 /* | |
2229 * do_viminfo() -- Should only be called from read_viminfo() & write_viminfo(). | |
2230 */ | |
2231 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2232 do_viminfo(FILE *fp_in, FILE *fp_out, int flags) |
7 | 2233 { |
2234 int eof = FALSE; | |
2235 vir_T vir; | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2236 int merge = FALSE; |
9414
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2237 int do_copy_marks = FALSE; |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2238 garray_T buflist; |
7 | 2239 |
2240 if ((vir.vir_line = alloc(LSIZE)) == NULL) | |
2241 return; | |
2242 vir.vir_fd = fp_in; | |
2243 #ifdef FEAT_MBYTE | |
2244 vir.vir_conv.vc_type = CONV_NONE; | |
2245 #endif | |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2246 ga_init2(&vir.vir_barlines, (int)sizeof(char_u *), 100); |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2247 vir.vir_version = -1; |
7 | 2248 |
2249 if (fp_in != NULL) | |
2250 { | |
1733 | 2251 if (flags & VIF_WANT_INFO) |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2252 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2253 if (fp_out != NULL) |
9284
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2254 { |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2255 /* Registers and marks are read and kept separate from what |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2256 * this Vim is using. They are merged when writing. */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2257 prepare_viminfo_registers(); |
9284
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2258 prepare_viminfo_marks(); |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2259 } |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2260 |
1733 | 2261 eof = read_viminfo_up_to_marks(&vir, |
2262 flags & VIF_FORCEIT, fp_out != NULL); | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2263 merge = TRUE; |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2264 } |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2265 else if (flags != 0) |
7 | 2266 /* Skip info, find start of marks */ |
2267 while (!(eof = viminfo_readline(&vir)) | |
2268 && vir.vir_line[0] != '>') | |
2269 ; | |
9414
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2270 |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2271 do_copy_marks = (flags & |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2272 (VIF_WANT_MARKS | VIF_GET_OLDFILES | VIF_FORCEIT)); |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2273 } |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2274 |
7 | 2275 if (fp_out != NULL) |
2276 { | |
2277 /* Write the info: */ | |
2278 fprintf(fp_out, _("# This viminfo file was generated by Vim %s.\n"), | |
2279 VIM_VERSION_MEDIUM); | |
2545
298d8d6e69be
Avoid warnings from the clang compiler. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2394
diff
changeset
|
2280 fputs(_("# You may edit it if you're careful!\n\n"), fp_out); |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2281 write_viminfo_version(fp_out); |
7 | 2282 #ifdef FEAT_MBYTE |
2545
298d8d6e69be
Avoid warnings from the clang compiler. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2394
diff
changeset
|
2283 fputs(_("# Value of 'encoding' when this file was written\n"), fp_out); |
7 | 2284 fprintf(fp_out, "*encoding=%s\n\n", p_enc); |
2285 #endif | |
2286 write_viminfo_search_pattern(fp_out); | |
2287 write_viminfo_sub_string(fp_out); | |
2288 #ifdef FEAT_CMDHIST | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2289 write_viminfo_history(fp_out, merge); |
7 | 2290 #endif |
2291 write_viminfo_registers(fp_out); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2292 finish_viminfo_registers(); |
7 | 2293 #ifdef FEAT_EVAL |
2294 write_viminfo_varlist(fp_out); | |
2295 #endif | |
2296 write_viminfo_filemarks(fp_out); | |
9284
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2297 finish_viminfo_marks(); |
7 | 2298 write_viminfo_bufferlist(fp_out); |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2299 write_viminfo_barlines(&vir, fp_out); |
9414
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2300 |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2301 if (do_copy_marks) |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2302 ga_init2(&buflist, sizeof(buf_T *), 50); |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2303 write_viminfo_marks(fp_out, do_copy_marks ? &buflist : NULL); |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2304 } |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2305 |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2306 if (do_copy_marks) |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2307 { |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2308 copy_viminfo_marks(&vir, fp_out, &buflist, eof, flags); |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2309 if (fp_out != NULL) |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2310 ga_clear(&buflist); |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2311 } |
7 | 2312 |
2313 vim_free(vir.vir_line); | |
2314 #ifdef FEAT_MBYTE | |
2315 if (vir.vir_conv.vc_type != CONV_NONE) | |
2316 convert_setup(&vir.vir_conv, NULL, NULL); | |
2317 #endif | |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2318 ga_clear_strings(&vir.vir_barlines); |
7 | 2319 } |
2320 | |
2321 /* | |
2322 * read_viminfo_up_to_marks() -- Only called from do_viminfo(). Reads in the | |
2323 * first part of the viminfo file which contains everything but the marks that | |
2324 * are local to a file. Returns TRUE when end-of-file is reached. -- webb | |
2325 */ | |
2326 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2327 read_viminfo_up_to_marks( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2328 vir_T *virp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2329 int forceit, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2330 int writing) |
7 | 2331 { |
2332 int eof; | |
2333 buf_T *buf; | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2334 int got_encoding = FALSE; |
7 | 2335 |
2336 #ifdef FEAT_CMDHIST | |
4285 | 2337 prepare_viminfo_history(forceit ? 9999 : 0, writing); |
7 | 2338 #endif |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2339 |
7 | 2340 eof = viminfo_readline(virp); |
2341 while (!eof && virp->vir_line[0] != '>') | |
2342 { | |
2343 switch (virp->vir_line[0]) | |
2344 { | |
2345 /* Characters reserved for future expansion, ignored now */ | |
2346 case '+': /* "+40 /path/dir file", for running vim without args */ | |
2347 case '^': /* to be defined */ | |
2348 case '<': /* long line - ignored */ | |
2349 /* A comment or empty line. */ | |
2350 case NUL: | |
2351 case '\r': | |
2352 case '\n': | |
2353 case '#': | |
2354 eof = viminfo_readline(virp); | |
2355 break; | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2356 case '|': |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2357 eof = read_viminfo_barline(virp, got_encoding, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2358 forceit, writing); |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2359 break; |
7 | 2360 case '*': /* "*encoding=value" */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2361 got_encoding = TRUE; |
7 | 2362 eof = viminfo_encoding(virp); |
2363 break; | |
2364 case '!': /* global variable */ | |
2365 #ifdef FEAT_EVAL | |
2366 eof = read_viminfo_varlist(virp, writing); | |
2367 #else | |
2368 eof = viminfo_readline(virp); | |
2369 #endif | |
2370 break; | |
2371 case '%': /* entry for buffer list */ | |
2372 eof = read_viminfo_bufferlist(virp, writing); | |
2373 break; | |
2374 case '"': | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2375 /* When registers are in bar lines skip the old style register |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2376 * lines. */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2377 if (virp->vir_version < VIMINFO_VERSION_WITH_REGISTERS) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2378 eof = read_viminfo_register(virp, forceit); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2379 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2380 do { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2381 eof = viminfo_readline(virp); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2382 } while (!eof && (virp->vir_line[0] == TAB |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2383 || virp->vir_line[0] == '<')); |
7 | 2384 break; |
2385 case '/': /* Search string */ | |
2386 case '&': /* Substitute search string */ | |
2387 case '~': /* Last search string, followed by '/' or '&' */ | |
2388 eof = read_viminfo_search_pattern(virp, forceit); | |
2389 break; | |
2390 case '$': | |
2391 eof = read_viminfo_sub_string(virp, forceit); | |
2392 break; | |
2393 case ':': | |
2394 case '?': | |
2395 case '=': | |
2396 case '@': | |
2397 #ifdef FEAT_CMDHIST | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2398 /* When history is in bar lines skip the old style history |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2399 * lines. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2400 if (virp->vir_version < VIMINFO_VERSION_WITH_HISTORY) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2401 eof = read_viminfo_history(virp, writing); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2402 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2403 #endif |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2404 eof = viminfo_readline(virp); |
7 | 2405 break; |
2406 case '-': | |
2407 case '\'': | |
9297
9c663cda189f
commit https://github.com/vim/vim/commit/a641e1d4da3f9152c489318c06a93fcd1c746637
Christian Brabandt <cb@256bit.org>
parents:
9284
diff
changeset
|
2408 /* When file marks are in bar lines skip the old style lines. */ |
9c663cda189f
commit https://github.com/vim/vim/commit/a641e1d4da3f9152c489318c06a93fcd1c746637
Christian Brabandt <cb@256bit.org>
parents:
9284
diff
changeset
|
2409 if (virp->vir_version < VIMINFO_VERSION_WITH_MARKS) |
9c663cda189f
commit https://github.com/vim/vim/commit/a641e1d4da3f9152c489318c06a93fcd1c746637
Christian Brabandt <cb@256bit.org>
parents:
9284
diff
changeset
|
2410 eof = read_viminfo_filemark(virp, forceit); |
9c663cda189f
commit https://github.com/vim/vim/commit/a641e1d4da3f9152c489318c06a93fcd1c746637
Christian Brabandt <cb@256bit.org>
parents:
9284
diff
changeset
|
2411 else |
9c663cda189f
commit https://github.com/vim/vim/commit/a641e1d4da3f9152c489318c06a93fcd1c746637
Christian Brabandt <cb@256bit.org>
parents:
9284
diff
changeset
|
2412 eof = viminfo_readline(virp); |
7 | 2413 break; |
2414 default: | |
2415 if (viminfo_error("E575: ", _("Illegal starting char"), | |
2416 virp->vir_line)) | |
2417 eof = TRUE; | |
2418 else | |
2419 eof = viminfo_readline(virp); | |
2420 break; | |
2421 } | |
2422 } | |
2423 | |
2424 #ifdef FEAT_CMDHIST | |
2425 /* Finish reading history items. */ | |
4285 | 2426 if (!writing) |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9248
diff
changeset
|
2427 finish_viminfo_history(virp); |
7 | 2428 #endif |
2429 | |
2430 /* Change file names to buffer numbers for fmarks. */ | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2431 FOR_ALL_BUFFERS(buf) |
7 | 2432 fmarks_check_names(buf); |
2433 | |
2434 return eof; | |
2435 } | |
2436 | |
2437 /* | |
2438 * Compare the 'encoding' value in the viminfo file with the current value of | |
2439 * 'encoding'. If different and the 'c' flag is in 'viminfo', setup for | |
2440 * conversion of text with iconv() in viminfo_readstring(). | |
2441 */ | |
2442 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2443 viminfo_encoding(vir_T *virp) |
7 | 2444 { |
2445 #ifdef FEAT_MBYTE | |
2446 char_u *p; | |
2447 int i; | |
2448 | |
2449 if (get_viminfo_parameter('c') != 0) | |
2450 { | |
2451 p = vim_strchr(virp->vir_line, '='); | |
2452 if (p != NULL) | |
2453 { | |
2454 /* remove trailing newline */ | |
2455 ++p; | |
2456 for (i = 0; vim_isprintc(p[i]); ++i) | |
2457 ; | |
2458 p[i] = NUL; | |
2459 | |
2460 convert_setup(&virp->vir_conv, p, p_enc); | |
2461 } | |
2462 } | |
2463 #endif | |
2464 return viminfo_readline(virp); | |
2465 } | |
2466 | |
2467 /* | |
2468 * Read a line from the viminfo file. | |
2469 * Returns TRUE for end-of-file; | |
2470 */ | |
2471 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2472 viminfo_readline(vir_T *virp) |
7 | 2473 { |
2474 return vim_fgets(virp->vir_line, LSIZE, virp->vir_fd); | |
2475 } | |
2476 | |
2477 /* | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2478 * Check string read from viminfo file. |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2479 * Remove '\n' at the end of the line. |
7 | 2480 * - replace CTRL-V CTRL-V with CTRL-V |
2481 * - replace CTRL-V 'n' with '\n' | |
2482 * | |
2483 * Check for a long line as written by viminfo_writestring(). | |
2484 * | |
2485 * Return the string in allocated memory (NULL when out of memory). | |
2486 */ | |
2487 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2488 viminfo_readstring( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2489 vir_T *virp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2490 int off, /* offset for virp->vir_line */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2491 int convert UNUSED) /* convert the string */ |
7 | 2492 { |
2493 char_u *retval; | |
2494 char_u *s, *d; | |
2495 long len; | |
2496 | |
2497 if (virp->vir_line[off] == Ctrl_V && vim_isdigit(virp->vir_line[off + 1])) | |
2498 { | |
2499 len = atol((char *)virp->vir_line + off + 1); | |
2500 retval = lalloc(len, TRUE); | |
2501 if (retval == NULL) | |
2502 { | |
2503 /* Line too long? File messed up? Skip next line. */ | |
2504 (void)vim_fgets(virp->vir_line, 10, virp->vir_fd); | |
2505 return NULL; | |
2506 } | |
2507 (void)vim_fgets(retval, (int)len, virp->vir_fd); | |
2508 s = retval + 1; /* Skip the leading '<' */ | |
2509 } | |
2510 else | |
2511 { | |
2512 retval = vim_strsave(virp->vir_line + off); | |
2513 if (retval == NULL) | |
2514 return NULL; | |
2515 s = retval; | |
2516 } | |
2517 | |
2518 /* Change CTRL-V CTRL-V to CTRL-V and CTRL-V n to \n in-place. */ | |
2519 d = retval; | |
2520 while (*s != NUL && *s != '\n') | |
2521 { | |
2522 if (s[0] == Ctrl_V && s[1] != NUL) | |
2523 { | |
2524 if (s[1] == 'n') | |
2525 *d++ = '\n'; | |
2526 else | |
2527 *d++ = Ctrl_V; | |
2528 s += 2; | |
2529 } | |
2530 else | |
2531 *d++ = *s++; | |
2532 } | |
2533 *d = NUL; | |
2534 | |
2535 #ifdef FEAT_MBYTE | |
2536 if (convert && virp->vir_conv.vc_type != CONV_NONE && *retval != NUL) | |
2537 { | |
2538 d = string_convert(&virp->vir_conv, retval, NULL); | |
2539 if (d != NULL) | |
2540 { | |
2541 vim_free(retval); | |
2542 retval = d; | |
2543 } | |
2544 } | |
2545 #endif | |
2546 | |
2547 return retval; | |
2548 } | |
2549 | |
2550 /* | |
2551 * write string to viminfo file | |
2552 * - replace CTRL-V with CTRL-V CTRL-V | |
2553 * - replace '\n' with CTRL-V 'n' | |
2554 * - add a '\n' at the end | |
2555 * | |
2556 * For a long line: | |
2557 * - write " CTRL-V <length> \n " in first line | |
2558 * - write " < <string> \n " in second line | |
2559 */ | |
2560 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2561 viminfo_writestring(FILE *fd, char_u *p) |
7 | 2562 { |
2563 int c; | |
2564 char_u *s; | |
2565 int len = 0; | |
2566 | |
2567 for (s = p; *s != NUL; ++s) | |
2568 { | |
2569 if (*s == Ctrl_V || *s == '\n') | |
2570 ++len; | |
2571 ++len; | |
2572 } | |
2573 | |
2574 /* If the string will be too long, write its length and put it in the next | |
2575 * line. Take into account that some room is needed for what comes before | |
2576 * the string (e.g., variable name). Add something to the length for the | |
2577 * '<', NL and trailing NUL. */ | |
2578 if (len > LSIZE / 2) | |
2579 fprintf(fd, IF_EB("\026%d\n<", CTRL_V_STR "%d\n<"), len + 3); | |
2580 | |
2581 while ((c = *p++) != NUL) | |
2582 { | |
2583 if (c == Ctrl_V || c == '\n') | |
2584 { | |
2585 putc(Ctrl_V, fd); | |
2586 if (c == '\n') | |
2587 c = 'n'; | |
2588 } | |
2589 putc(c, fd); | |
2590 } | |
2591 putc('\n', fd); | |
2592 } | |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2593 |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2594 /* |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2595 * Write a string in quotes that barline_parse() can read back. |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2596 * Breaks the line in less than LSIZE pieces when needed. |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2597 * Returns remaining characters in the line. |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2598 */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2599 int |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2600 barline_writestring(FILE *fd, char_u *s, int remaining_start) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2601 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2602 char_u *p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2603 int remaining = remaining_start; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2604 int len = 2; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2605 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2606 /* Count the number of characters produced, including quotes. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2607 for (p = s; *p != NUL; ++p) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2608 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2609 if (*p == NL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2610 len += 2; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2611 else if (*p == '"' || *p == '\\') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2612 len += 2; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2613 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2614 ++len; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2615 } |
9978
baad324e9fbc
commit https://github.com/vim/vim/commit/257095760732597983bdd026e791907b7980e295
Christian Brabandt <cb@256bit.org>
parents:
9959
diff
changeset
|
2616 if (len > remaining - 2) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2617 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2618 fprintf(fd, ">%d\n|<", len); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2619 remaining = LSIZE - 20; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2620 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2621 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2622 putc('"', fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2623 for (p = s; *p != NUL; ++p) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2624 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2625 if (*p == NL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2626 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2627 putc('\\', fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2628 putc('n', fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2629 --remaining; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2630 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2631 else if (*p == '"' || *p == '\\') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2632 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2633 putc('\\', fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2634 putc(*p, fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2635 --remaining; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2636 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2637 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2638 putc(*p, fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2639 --remaining; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2640 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2641 if (remaining < 3) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2642 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2643 putc('\n', fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2644 putc('|', fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2645 putc('<', fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2646 /* Leave enough space for another continuation. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2647 remaining = LSIZE - 20; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2648 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2649 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2650 putc('"', fd); |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2651 return remaining - 2; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2652 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2653 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2654 /* |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2655 * Parse a viminfo line starting with '|'. |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2656 * Add each decoded value to "values". |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2657 * Returns TRUE if the next line is to be read after using the parsed values. |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2658 */ |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2659 static int |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2660 barline_parse(vir_T *virp, char_u *text, garray_T *values) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2661 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2662 char_u *p = text; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2663 char_u *nextp = NULL; |
9244
931bbf7b6ee3
commit https://github.com/vim/vim/commit/fdd82fe365d0e287bafc71f98c039cb5af8ed827
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
2664 char_u *buf = NULL; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2665 bval_T *value; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2666 int i; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2667 int allocated = FALSE; |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2668 int eof; |
9268
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2669 #ifdef FEAT_MBYTE |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2670 char_u *sconv; |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2671 int converted; |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2672 #endif |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2673 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2674 while (*p == ',') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2675 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2676 ++p; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2677 if (ga_grow(values, 1) == FAIL) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2678 break; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2679 value = (bval_T *)(values->ga_data) + values->ga_len; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2680 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2681 if (*p == '>') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2682 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2683 /* Need to read a continuation line. Put strings in allocated |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2684 * memory, because virp->vir_line is overwritten. */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2685 if (!allocated) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2686 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2687 for (i = 0; i < values->ga_len; ++i) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2688 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2689 bval_T *vp = (bval_T *)(values->ga_data) + i; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2690 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2691 if (vp->bv_type == BVAL_STRING && !vp->bv_allocated) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2692 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2693 vp->bv_string = vim_strnsave(vp->bv_string, vp->bv_len); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2694 vp->bv_allocated = TRUE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2695 } |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2696 } |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2697 allocated = TRUE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2698 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2699 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2700 if (vim_isdigit(p[1])) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2701 { |
9248
9c751c33dc0f
commit https://github.com/vim/vim/commit/1d5f1d07aedb6f149f5de145b1dfd6528a769c93
Christian Brabandt <cb@256bit.org>
parents:
9244
diff
changeset
|
2702 size_t len; |
9c751c33dc0f
commit https://github.com/vim/vim/commit/1d5f1d07aedb6f149f5de145b1dfd6528a769c93
Christian Brabandt <cb@256bit.org>
parents:
9244
diff
changeset
|
2703 size_t todo; |
9c751c33dc0f
commit https://github.com/vim/vim/commit/1d5f1d07aedb6f149f5de145b1dfd6528a769c93
Christian Brabandt <cb@256bit.org>
parents:
9244
diff
changeset
|
2704 size_t n; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2705 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2706 /* String value was split into lines that are each shorter |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2707 * than LSIZE: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2708 * |{bartype},>{length of "{text}{text2}"} |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2709 * |<"{text1} |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2710 * |<{text2}",{value} |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2711 * Length includes the quotes. |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2712 */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2713 ++p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2714 len = getdigits(&p); |
9248
9c751c33dc0f
commit https://github.com/vim/vim/commit/1d5f1d07aedb6f149f5de145b1dfd6528a769c93
Christian Brabandt <cb@256bit.org>
parents:
9244
diff
changeset
|
2715 buf = alloc((int)(len + 1)); |
9270
79cb08f0d812
commit https://github.com/vim/vim/commit/62f8b4e18014b259bcde4a2845c602b0a44a3714
Christian Brabandt <cb@256bit.org>
parents:
9268
diff
changeset
|
2716 if (buf == NULL) |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2717 return TRUE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2718 p = buf; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2719 for (todo = len; todo > 0; todo -= n) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2720 { |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2721 eof = viminfo_readline(virp); |
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2722 if (eof || virp->vir_line[0] != '|' |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2723 || virp->vir_line[1] != '<') |
9270
79cb08f0d812
commit https://github.com/vim/vim/commit/62f8b4e18014b259bcde4a2845c602b0a44a3714
Christian Brabandt <cb@256bit.org>
parents:
9268
diff
changeset
|
2724 { |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2725 /* File was truncated or garbled. Read another line if |
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2726 * this one starts with '|'. */ |
9270
79cb08f0d812
commit https://github.com/vim/vim/commit/62f8b4e18014b259bcde4a2845c602b0a44a3714
Christian Brabandt <cb@256bit.org>
parents:
9268
diff
changeset
|
2727 vim_free(buf); |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2728 return eof || virp->vir_line[0] == '|'; |
9270
79cb08f0d812
commit https://github.com/vim/vim/commit/62f8b4e18014b259bcde4a2845c602b0a44a3714
Christian Brabandt <cb@256bit.org>
parents:
9268
diff
changeset
|
2729 } |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2730 /* Get length of text, excluding |< and NL chars. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2731 n = STRLEN(virp->vir_line); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2732 while (n > 0 && (virp->vir_line[n - 1] == NL |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2733 || virp->vir_line[n - 1] == CAR)) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2734 --n; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2735 n -= 2; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2736 if (n > todo) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2737 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2738 /* more values follow after the string */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2739 nextp = virp->vir_line + 2 + todo; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2740 n = todo; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2741 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2742 mch_memmove(p, virp->vir_line + 2, n); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2743 p += n; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2744 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2745 *p = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2746 p = buf; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2747 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2748 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2749 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2750 /* Line ending in ">" continues in the next line: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2751 * |{bartype},{lots of values},> |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2752 * |<{value},{value} |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2753 */ |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2754 eof = viminfo_readline(virp); |
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2755 if (eof || virp->vir_line[0] != '|' |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2756 || virp->vir_line[1] != '<') |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2757 /* File was truncated or garbled. Read another line if |
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2758 * this one starts with '|'. */ |
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2759 return eof || virp->vir_line[0] == '|'; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2760 p = virp->vir_line + 2; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2761 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2762 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2763 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2764 if (isdigit(*p)) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2765 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2766 value->bv_type = BVAL_NR; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2767 value->bv_nr = getdigits(&p); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2768 ++values->ga_len; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2769 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2770 else if (*p == '"') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2771 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2772 int len = 0; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2773 char_u *s = p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2774 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2775 /* Unescape special characters in-place. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2776 ++p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2777 while (*p != '"') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2778 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2779 if (*p == NL || *p == NUL) |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2780 return TRUE; /* syntax error, drop the value */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2781 if (*p == '\\') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2782 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2783 ++p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2784 if (*p == 'n') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2785 s[len++] = '\n'; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2786 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2787 s[len++] = *p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2788 ++p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2789 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2790 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2791 s[len++] = *p++; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2792 } |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2793 ++p; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2794 s[len] = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2795 |
9268
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2796 #ifdef FEAT_MBYTE |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2797 converted = FALSE; |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2798 if (virp->vir_conv.vc_type != CONV_NONE && *s != NUL) |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2799 { |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2800 sconv = string_convert(&virp->vir_conv, s, NULL); |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2801 if (sconv != NULL) |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2802 { |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2803 if (s == buf) |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2804 vim_free(s); |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2805 s = sconv; |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2806 buf = s; |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2807 converted = TRUE; |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2808 } |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2809 } |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2810 #endif |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2811 /* Need to copy in allocated memory if the string wasn't allocated |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2812 * above and we did allocate before, thus vir_line may change. */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2813 if (s != buf && allocated) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2814 s = vim_strsave(s); |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2815 value->bv_string = s; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2816 value->bv_type = BVAL_STRING; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2817 value->bv_len = len; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2818 value->bv_allocated = allocated |
9268
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2819 #ifdef FEAT_MBYTE |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2820 || converted |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2821 #endif |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2822 ; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2823 ++values->ga_len; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2824 if (nextp != NULL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2825 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2826 /* values following a long string */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2827 p = nextp; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2828 nextp = NULL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2829 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2830 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2831 else if (*p == ',') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2832 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2833 value->bv_type = BVAL_EMPTY; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2834 ++values->ga_len; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2835 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2836 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2837 break; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2838 } |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2839 return TRUE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2840 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2841 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2842 static int |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2843 read_viminfo_barline(vir_T *virp, int got_encoding, int force, int writing) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2844 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2845 char_u *p = virp->vir_line + 1; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2846 int bartype; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2847 garray_T values; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2848 bval_T *vp; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2849 int i; |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2850 int read_next = TRUE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2851 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2852 /* The format is: |{bartype},{value},... |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2853 * For a very long string: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2854 * |{bartype},>{length of "{text}{text2}"} |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2855 * |<{text1} |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2856 * |<{text2},{value} |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2857 * For a long line not using a string |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2858 * |{bartype},{lots of values},> |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2859 * |<{value},{value} |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2860 */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2861 if (*p == '<') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2862 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2863 /* Continuation line of an unrecognized item. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2864 if (writing) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2865 ga_add_string(&virp->vir_barlines, virp->vir_line); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2866 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2867 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2868 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2869 ga_init2(&values, sizeof(bval_T), 20); |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2870 bartype = getdigits(&p); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2871 switch (bartype) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2872 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2873 case BARTYPE_VERSION: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2874 /* Only use the version when it comes before the encoding. |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2875 * If it comes later it was copied by a Vim version that |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2876 * doesn't understand the version. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2877 if (!got_encoding) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2878 { |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2879 read_next = barline_parse(virp, p, &values); |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2880 vp = (bval_T *)values.ga_data; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2881 if (values.ga_len > 0 && vp->bv_type == BVAL_NR) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2882 virp->vir_version = vp->bv_nr; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2883 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2884 break; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2885 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2886 case BARTYPE_HISTORY: |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2887 read_next = barline_parse(virp, p, &values); |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2888 handle_viminfo_history(&values, writing); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2889 break; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2890 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2891 case BARTYPE_REGISTER: |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2892 read_next = barline_parse(virp, p, &values); |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2893 handle_viminfo_register(&values, force); |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2894 break; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2895 |
9284
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2896 case BARTYPE_MARK: |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2897 read_next = barline_parse(virp, p, &values); |
9284
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2898 handle_viminfo_mark(&values, force); |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2899 break; |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2900 |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2901 default: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2902 /* copy unrecognized line (for future use) */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2903 if (writing) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2904 ga_add_string(&virp->vir_barlines, virp->vir_line); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2905 } |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2906 for (i = 0; i < values.ga_len; ++i) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2907 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2908 vp = (bval_T *)values.ga_data + i; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2909 if (vp->bv_type == BVAL_STRING && vp->bv_allocated) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2910 vim_free(vp->bv_string); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2911 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2912 ga_clear(&values); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2913 } |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2914 |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2915 if (read_next) |
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2916 return viminfo_readline(virp); |
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2917 return FALSE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2918 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2919 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2920 static void |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2921 write_viminfo_version(FILE *fp_out) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2922 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2923 fprintf(fp_out, "# Viminfo version\n|%d,%d\n\n", |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2924 BARTYPE_VERSION, VIMINFO_VERSION); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2925 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2926 |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2927 static void |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2928 write_viminfo_barlines(vir_T *virp, FILE *fp_out) |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2929 { |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2930 int i; |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2931 garray_T *gap = &virp->vir_barlines; |
9412
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2932 int seen_useful = FALSE; |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2933 char *line; |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2934 |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2935 if (gap->ga_len > 0) |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2936 { |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2937 fputs(_("\n# Bar lines, copied verbatim:\n"), fp_out); |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2938 |
9412
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2939 /* Skip over continuation lines until seeing a useful line. */ |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2940 for (i = 0; i < gap->ga_len; ++i) |
9412
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2941 { |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2942 line = ((char **)(gap->ga_data))[i]; |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2943 if (seen_useful || line[1] != '<') |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2944 { |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2945 fputs(line, fp_out); |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2946 seen_useful = TRUE; |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2947 } |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2948 } |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2949 } |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2950 } |
7 | 2951 #endif /* FEAT_VIMINFO */ |
2952 | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2953 /* |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2954 * Return the current time in seconds. Calls time(), unless test_settime() |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2955 * was used. |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2956 */ |
9347
25c562442f8c
commit https://github.com/vim/vim/commit/f4fba6dcd508cb369ffa6916d9cb3fcf3d7ed548
Christian Brabandt <cb@256bit.org>
parents:
9330
diff
changeset
|
2957 time_T |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2958 vim_time(void) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2959 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2960 # ifdef FEAT_EVAL |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2961 return time_for_testing == 0 ? time(NULL) : time_for_testing; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2962 # else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2963 return time(NULL); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2964 # endif |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2965 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2966 |
7 | 2967 /* |
2968 * Implementation of ":fixdel", also used by get_stty(). | |
2969 * <BS> resulting <Del> | |
2970 * ^? ^H | |
2971 * not ^? ^? | |
2972 */ | |
2973 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2974 do_fixdel(exarg_T *eap UNUSED) |
7 | 2975 { |
2976 char_u *p; | |
2977 | |
2978 p = find_termcode((char_u *)"kb"); | |
2979 add_termcode((char_u *)"kD", p != NULL | |
2980 && *p == DEL ? (char_u *)CTRL_H_STR : DEL_STR, FALSE); | |
2981 } | |
2982 | |
2983 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2984 print_line_no_prefix( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2985 linenr_T lnum, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2986 int use_number, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2987 int list) |
7 | 2988 { |
13 | 2989 char_u numbuf[30]; |
7 | 2990 |
2991 if (curwin->w_p_nu || use_number) | |
2992 { | |
1872 | 2993 vim_snprintf((char *)numbuf, sizeof(numbuf), |
2994 "%*ld ", number_width(curwin), (long)lnum); | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11144
diff
changeset
|
2995 msg_puts_attr(numbuf, HL_ATTR(HLF_N)); /* Highlight line nrs */ |
7 | 2996 } |
169 | 2997 msg_prt_line(ml_get(lnum), list); |
7 | 2998 } |
2999 | |
3000 /* | |
3001 * Print a text line. Also in silent mode ("ex -s"). | |
3002 */ | |
3003 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3004 print_line(linenr_T lnum, int use_number, int list) |
7 | 3005 { |
3006 int save_silent = silent_mode; | |
3007 | |
9980
b222552cf0c4
commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents:
9978
diff
changeset
|
3008 /* apply :filter /pat/ */ |
b222552cf0c4
commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents:
9978
diff
changeset
|
3009 if (message_filtered(ml_get(lnum))) |
b222552cf0c4
commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents:
9978
diff
changeset
|
3010 return; |
b222552cf0c4
commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents:
9978
diff
changeset
|
3011 |
169 | 3012 msg_start(); |
7 | 3013 silent_mode = FALSE; |
169 | 3014 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */ |
3015 print_line_no_prefix(lnum, use_number, list); | |
7 | 3016 if (save_silent) |
3017 { | |
3018 msg_putchar('\n'); | |
3019 cursor_on(); /* msg_start() switches it off */ | |
3020 out_flush(); | |
3021 silent_mode = save_silent; | |
1798 | 3022 } |
3023 info_message = FALSE; | |
7 | 3024 } |
3025 | |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3026 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3027 rename_buffer(char_u *new_fname) |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3028 { |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3029 char_u *fname, *sfname, *xfname; |
4613
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3030 buf_T *buf; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3031 |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3032 buf = curbuf; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3033 apply_autocmds(EVENT_BUFFILEPRE, NULL, NULL, FALSE, curbuf); |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3034 /* buffer changed, don't change name now */ |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3035 if (buf != curbuf) |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3036 return FAIL; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3037 #ifdef FEAT_EVAL |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3038 if (aborting()) /* autocmds may abort script processing */ |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3039 return FAIL; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3040 #endif |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3041 /* |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3042 * The name of the current buffer will be changed. |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3043 * A new (unlisted) buffer entry needs to be made to hold the old file |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3044 * name, which will become the alternate file name. |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3045 * But don't set the alternate file name if the buffer didn't have a |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3046 * name. |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3047 */ |
4613
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3048 fname = curbuf->b_ffname; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3049 sfname = curbuf->b_sfname; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3050 xfname = curbuf->b_fname; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3051 curbuf->b_ffname = NULL; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3052 curbuf->b_sfname = NULL; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3053 if (setfname(curbuf, new_fname, NULL, TRUE) == FAIL) |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3054 { |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3055 curbuf->b_ffname = fname; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3056 curbuf->b_sfname = sfname; |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3057 return FAIL; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3058 } |
4613
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3059 curbuf->b_flags |= BF_NOTEDITED; |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3060 if (xfname != NULL && *xfname != NUL) |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3061 { |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3062 buf = buflist_new(fname, xfname, curwin->w_cursor.lnum, 0); |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3063 if (buf != NULL && !cmdmod.keepalt) |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3064 curwin->w_alt_fnum = buf->b_fnum; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3065 } |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3066 vim_free(fname); |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3067 vim_free(sfname); |
4613
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3068 apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, curbuf); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3069 |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3070 /* Change directories when the 'acd' option is set. */ |
13632
cec5137d5332
patch 8.0.1688: some macros are used without a semicolon
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
3071 DO_AUTOCHDIR; |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3072 return OK; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3073 } |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3074 |
7 | 3075 /* |
3076 * ":file[!] [fname]". | |
3077 */ | |
3078 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3079 ex_file(exarg_T *eap) |
7 | 3080 { |
14 | 3081 /* ":0file" removes the file name. Check for illegal uses ":3file", |
3082 * "0file name", etc. */ | |
3083 if (eap->addr_count > 0 | |
3084 && (*eap->arg != NUL | |
3085 || eap->line2 > 0 | |
3086 || eap->addr_count > 1)) | |
3087 { | |
3088 EMSG(_(e_invarg)); | |
3089 return; | |
3090 } | |
3091 | |
3092 if (*eap->arg != NUL || eap->addr_count == 1) | |
7 | 3093 { |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3094 if (rename_buffer(eap->arg) == FAIL) |
7 | 3095 return; |
14185
20468fb49f9b
patch 8.1.0110: file name not displayed with ":file"
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
3096 redraw_tabline = TRUE; |
20468fb49f9b
patch 8.1.0110: file name not displayed with ":file"
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
3097 } |
20468fb49f9b
patch 8.1.0110: file name not displayed with ":file"
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
3098 |
20468fb49f9b
patch 8.1.0110: file name not displayed with ":file"
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
3099 // print file name if no argument or 'F' is not in 'shortmess' |
20468fb49f9b
patch 8.1.0110: file name not displayed with ":file"
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
3100 if (*eap->arg == NUL || !shortmess(SHM_FILEINFO)) |
8560
f3c636c673f7
commit https://github.com/vim/vim/commit/426dd0219512af5f4abeb0901b533159253ffba3
Christian Brabandt <cb@256bit.org>
parents:
8556
diff
changeset
|
3101 fileinfo(FALSE, FALSE, eap->forceit); |
7 | 3102 } |
3103 | |
3104 /* | |
3105 * ":update". | |
3106 */ | |
3107 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3108 ex_update(exarg_T *eap) |
7 | 3109 { |
3110 if (curbufIsChanged()) | |
3111 (void)do_write(eap); | |
3112 } | |
3113 | |
3114 /* | |
3115 * ":write" and ":saveas". | |
3116 */ | |
3117 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3118 ex_write(exarg_T *eap) |
7 | 3119 { |
3120 if (eap->usefilter) /* input lines to shell command */ | |
3121 do_bang(1, eap, FALSE, TRUE, FALSE); | |
3122 else | |
3123 (void)do_write(eap); | |
3124 } | |
3125 | |
3126 /* | |
3127 * write current buffer to file 'eap->arg' | |
3128 * if 'eap->append' is TRUE, append to the file | |
3129 * | |
3130 * if *eap->arg == NUL write to current file | |
3131 * | |
3132 * return FAIL for failure, OK otherwise | |
3133 */ | |
3134 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3135 do_write(exarg_T *eap) |
7 | 3136 { |
3137 int other; | |
3138 char_u *fname = NULL; /* init to shut up gcc */ | |
3139 char_u *ffname; | |
3140 int retval = FAIL; | |
3141 char_u *free_fname = NULL; | |
3142 #ifdef FEAT_BROWSE | |
3143 char_u *browse_file = NULL; | |
3144 #endif | |
3145 buf_T *alt_buf = NULL; | |
9469
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
3146 int name_was_missing; |
7 | 3147 |
3148 if (not_writing()) /* check 'write' option */ | |
3149 return FAIL; | |
3150 | |
3151 ffname = eap->arg; | |
3152 #ifdef FEAT_BROWSE | |
3153 if (cmdmod.browse) | |
3154 { | |
29 | 3155 browse_file = do_browse(BROWSE_SAVE, (char_u *)_("Save As"), ffname, |
7 | 3156 NULL, NULL, NULL, curbuf); |
3157 if (browse_file == NULL) | |
3158 goto theend; | |
3159 ffname = browse_file; | |
3160 } | |
3161 #endif | |
3162 if (*ffname == NUL) | |
3163 { | |
3164 if (eap->cmdidx == CMD_saveas) | |
3165 { | |
3166 EMSG(_(e_argreq)); | |
3167 goto theend; | |
3168 } | |
3169 other = FALSE; | |
3170 } | |
3171 else | |
3172 { | |
3173 fname = ffname; | |
3174 free_fname = fix_fname(ffname); | |
3175 /* | |
3176 * When out-of-memory, keep unexpanded file name, because we MUST be | |
3177 * able to write the file in this situation. | |
3178 */ | |
3179 if (free_fname != NULL) | |
3180 ffname = free_fname; | |
3181 other = otherfile(ffname); | |
3182 } | |
3183 | |
3184 /* | |
3185 * If we have a new file, put its name in the list of alternate file names. | |
3186 */ | |
3187 if (other) | |
3188 { | |
3189 if (vim_strchr(p_cpo, CPO_ALTWRITE) != NULL | |
3190 || eap->cmdidx == CMD_saveas) | |
3191 alt_buf = setaltfname(ffname, fname, (linenr_T)1); | |
3192 else | |
3193 alt_buf = buflist_findname(ffname); | |
3194 if (alt_buf != NULL && alt_buf->b_ml.ml_mfp != NULL) | |
3195 { | |
3196 /* Overwriting a file that is loaded in another buffer is not a | |
3197 * good idea. */ | |
315 | 3198 EMSG(_(e_bufloaded)); |
7 | 3199 goto theend; |
3200 } | |
3201 } | |
3202 | |
3203 /* | |
3204 * Writing to the current file is not allowed in readonly mode | |
3205 * and a file name is required. | |
3206 * "nofile" and "nowrite" buffers cannot be written implicitly either. | |
3207 */ | |
3208 if (!other && ( | |
3209 #ifdef FEAT_QUICKFIX | |
3210 bt_dontwrite_msg(curbuf) || | |
3211 #endif | |
3212 check_fname() == FAIL || check_readonly(&eap->forceit, curbuf))) | |
3213 goto theend; | |
3214 | |
3215 if (!other) | |
3216 { | |
3217 ffname = curbuf->b_ffname; | |
3218 fname = curbuf->b_fname; | |
3219 /* | |
3220 * Not writing the whole file is only allowed with '!'. | |
3221 */ | |
3222 if ( (eap->line1 != 1 | |
3223 || eap->line2 != curbuf->b_ml.ml_line_count) | |
3224 && !eap->forceit | |
3225 && !eap->append | |
3226 && !p_wa) | |
3227 { | |
3228 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
3229 if (p_confirm || cmdmod.confirm) | |
3230 { | |
3231 if (vim_dialog_yesno(VIM_QUESTION, NULL, | |
3232 (char_u *)_("Write partial file?"), 2) != VIM_YES) | |
3233 goto theend; | |
3234 eap->forceit = TRUE; | |
3235 } | |
3236 else | |
3237 #endif | |
3238 { | |
3239 EMSG(_("E140: Use ! to write partial buffer")); | |
3240 goto theend; | |
3241 } | |
3242 } | |
3243 } | |
3244 | |
3245 if (check_overwrite(eap, curbuf, fname, ffname, other) == OK) | |
3246 { | |
3247 if (eap->cmdidx == CMD_saveas && alt_buf != NULL) | |
3248 { | |
3249 buf_T *was_curbuf = curbuf; | |
3250 | |
3251 apply_autocmds(EVENT_BUFFILEPRE, NULL, NULL, FALSE, curbuf); | |
21 | 3252 apply_autocmds(EVENT_BUFFILEPRE, NULL, NULL, FALSE, alt_buf); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3253 #ifdef FEAT_EVAL |
7 | 3254 if (curbuf != was_curbuf || aborting()) |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3255 #else |
7 | 3256 if (curbuf != was_curbuf) |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3257 #endif |
7 | 3258 { |
3259 /* buffer changed, don't change name now */ | |
3260 retval = FAIL; | |
3261 goto theend; | |
3262 } | |
3263 /* Exchange the file names for the current and the alternate | |
3264 * buffer. This makes it look like we are now editing the buffer | |
3265 * under the new name. Must be done before buf_write(), because | |
3266 * if there is no file name and 'cpo' contains 'F', it will set | |
3267 * the file name. */ | |
3268 fname = alt_buf->b_fname; | |
3269 alt_buf->b_fname = curbuf->b_fname; | |
3270 curbuf->b_fname = fname; | |
3271 fname = alt_buf->b_ffname; | |
3272 alt_buf->b_ffname = curbuf->b_ffname; | |
3273 curbuf->b_ffname = fname; | |
3274 fname = alt_buf->b_sfname; | |
3275 alt_buf->b_sfname = curbuf->b_sfname; | |
3276 curbuf->b_sfname = fname; | |
3277 buf_name_changed(curbuf); | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3278 |
7 | 3279 apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, curbuf); |
21 | 3280 apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, alt_buf); |
7 | 3281 if (!alt_buf->b_p_bl) |
3282 { | |
3283 alt_buf->b_p_bl = TRUE; | |
3284 apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, alt_buf); | |
3285 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3286 #ifdef FEAT_EVAL |
7 | 3287 if (curbuf != was_curbuf || aborting()) |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3288 #else |
7 | 3289 if (curbuf != was_curbuf) |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3290 #endif |
7 | 3291 { |
3292 /* buffer changed, don't write the file */ | |
3293 retval = FAIL; | |
3294 goto theend; | |
3295 } | |
634 | 3296 |
3297 /* If 'filetype' was empty try detecting it now. */ | |
3298 if (*curbuf->b_p_ft == NUL) | |
3299 { | |
819 | 3300 if (au_has_group((char_u *)"filetypedetect")) |
3301 (void)do_doautocmd((char_u *)"filetypedetect BufRead", | |
9260
ac8180818504
commit https://github.com/vim/vim/commit/1610d052413e0ed664498853a47acc2d677a22d1
Christian Brabandt <cb@256bit.org>
parents:
9256
diff
changeset
|
3302 TRUE, NULL); |
717 | 3303 do_modelines(0); |
634 | 3304 } |
2648 | 3305 |
3306 /* Autocommands may have changed buffer names, esp. when | |
3307 * 'autochdir' is set. */ | |
3308 fname = curbuf->b_sfname; | |
7 | 3309 } |
3310 | |
9469
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
3311 name_was_missing = curbuf->b_ffname == NULL; |
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
3312 |
7 | 3313 retval = buf_write(curbuf, ffname, fname, eap->line1, eap->line2, |
3314 eap, eap->append, eap->forceit, TRUE, FALSE); | |
634 | 3315 |
819 | 3316 /* After ":saveas fname" reset 'readonly'. */ |
961 | 3317 if (eap->cmdidx == CMD_saveas) |
3318 { | |
3319 if (retval == OK) | |
1806 | 3320 { |
961 | 3321 curbuf->b_p_ro = FALSE; |
1806 | 3322 redraw_tabline = TRUE; |
3323 } | |
9469
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
3324 } |
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
3325 |
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
3326 /* Change directories when the 'acd' option is set and the file name |
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
3327 * got changed or set. */ |
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
3328 if (eap->cmdidx == CMD_saveas || name_was_missing) |
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
3329 { |
13632
cec5137d5332
patch 8.0.1688: some macros are used without a semicolon
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
3330 DO_AUTOCHDIR; |
961 | 3331 } |
7 | 3332 } |
3333 | |
3334 theend: | |
3335 #ifdef FEAT_BROWSE | |
3336 vim_free(browse_file); | |
3337 #endif | |
3338 vim_free(free_fname); | |
3339 return retval; | |
3340 } | |
3341 | |
3342 /* | |
3343 * Check if it is allowed to overwrite a file. If b_flags has BF_NOTEDITED, | |
3344 * BF_NEW or BF_READERR, check for overwriting current file. | |
3345 * May set eap->forceit if a dialog says it's OK to overwrite. | |
3346 * Return OK if it's OK, FAIL if it is not. | |
3347 */ | |
3486 | 3348 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3349 check_overwrite( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3350 exarg_T *eap, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3351 buf_T *buf, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3352 char_u *fname, /* file name to be used (can differ from |
7 | 3353 buf->ffname) */ |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3354 char_u *ffname, /* full path version of fname */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3355 int other) /* writing under other name */ |
7 | 3356 { |
3357 /* | |
3358 * write to other file or b_flags set or not writing the whole file: | |
3359 * overwriting only allowed with '!' | |
3360 */ | |
3361 if ( (other | |
3362 || (buf->b_flags & BF_NOTEDITED) | |
3363 || ((buf->b_flags & BF_NEW) | |
3364 && vim_strchr(p_cpo, CPO_OVERNEW) == NULL) | |
3365 || (buf->b_flags & BF_READERR)) | |
3366 && !p_wa | |
1457 | 3367 #ifdef FEAT_QUICKFIX |
3368 && !bt_nofile(buf) | |
3369 #endif | |
7 | 3370 && vim_fexists(ffname)) |
3371 { | |
460 | 3372 if (!eap->forceit && !eap->append) |
7 | 3373 { |
460 | 3374 #ifdef UNIX |
637 | 3375 /* with UNIX it is possible to open a directory */ |
460 | 3376 if (mch_isdir(ffname)) |
3377 { | |
3378 EMSG2(_(e_isadir2), ffname); | |
3379 return FAIL; | |
3380 } | |
7 | 3381 #endif |
3382 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
460 | 3383 if (p_confirm || cmdmod.confirm) |
3384 { | |
2770 | 3385 char_u buff[DIALOG_MSG_SIZE]; |
460 | 3386 |
3387 dialog_msg(buff, _("Overwrite existing file \"%s\"?"), fname); | |
3388 if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) != VIM_YES) | |
3389 return FAIL; | |
3390 eap->forceit = TRUE; | |
3391 } | |
3392 else | |
3393 #endif | |
3394 { | |
3395 EMSG(_(e_exists)); | |
7 | 3396 return FAIL; |
460 | 3397 } |
7 | 3398 } |
460 | 3399 |
3400 /* For ":w! filename" check that no swap file exists for "filename". */ | |
3401 if (other && !emsg_silent) | |
7 | 3402 { |
2770 | 3403 char_u *dir; |
460 | 3404 char_u *p; |
3405 int r; | |
3406 char_u *swapname; | |
3407 | |
3408 /* We only try the first entry in 'directory', without checking if | |
3409 * it's writable. If the "." directory is not writable the write | |
3410 * will probably fail anyway. | |
3411 * Use 'shortname' of the current buffer, since there is no buffer | |
3412 * for the written file. */ | |
3413 if (*p_dir == NUL) | |
2770 | 3414 { |
3415 dir = alloc(5); | |
3416 if (dir == NULL) | |
3417 return FAIL; | |
460 | 3418 STRCPY(dir, "."); |
2770 | 3419 } |
460 | 3420 else |
3421 { | |
2770 | 3422 dir = alloc(MAXPATHL); |
3423 if (dir == NULL) | |
3424 return FAIL; | |
460 | 3425 p = p_dir; |
3426 copy_option_part(&p, dir, MAXPATHL, ","); | |
3427 } | |
3428 swapname = makeswapname(fname, ffname, curbuf, dir); | |
2770 | 3429 vim_free(dir); |
460 | 3430 r = vim_fexists(swapname); |
3431 if (r) | |
3432 { | |
3433 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
3434 if (p_confirm || cmdmod.confirm) | |
3435 { | |
2770 | 3436 char_u buff[DIALOG_MSG_SIZE]; |
460 | 3437 |
3438 dialog_msg(buff, | |
3439 _("Swap file \"%s\" exists, overwrite anyway?"), | |
3440 swapname); | |
3441 if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) | |
3442 != VIM_YES) | |
819 | 3443 { |
3444 vim_free(swapname); | |
460 | 3445 return FAIL; |
819 | 3446 } |
460 | 3447 eap->forceit = TRUE; |
3448 } | |
3449 else | |
3450 #endif | |
3451 { | |
3452 EMSG2(_("E768: Swap file exists: %s (:silent! overrides)"), | |
3453 swapname); | |
819 | 3454 vim_free(swapname); |
460 | 3455 return FAIL; |
3456 } | |
3457 } | |
819 | 3458 vim_free(swapname); |
7 | 3459 } |
3460 } | |
3461 return OK; | |
3462 } | |
3463 | |
3464 /* | |
3465 * Handle ":wnext", ":wNext" and ":wprevious" commands. | |
3466 */ | |
3467 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3468 ex_wnext(exarg_T *eap) |
7 | 3469 { |
3470 int i; | |
3471 | |
3472 if (eap->cmd[1] == 'n') | |
3473 i = curwin->w_arg_idx + (int)eap->line2; | |
3474 else | |
3475 i = curwin->w_arg_idx - (int)eap->line2; | |
3476 eap->line1 = 1; | |
3477 eap->line2 = curbuf->b_ml.ml_line_count; | |
3478 if (do_write(eap) != FAIL) | |
3479 do_argfile(eap, i); | |
3480 } | |
3481 | |
3482 /* | |
3483 * ":wall", ":wqall" and ":xall": Write all changed files (and exit). | |
3484 */ | |
3485 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3486 do_wqall(exarg_T *eap) |
7 | 3487 { |
3488 buf_T *buf; | |
3489 int error = 0; | |
3490 int save_forceit = eap->forceit; | |
3491 | |
3492 if (eap->cmdidx == CMD_xall || eap->cmdidx == CMD_wqall) | |
3493 exiting = TRUE; | |
3494 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
3495 FOR_ALL_BUFFERS(buf) |
7 | 3496 { |
13302
b5806be0b36d
patch 8.0.1525: using :wqa exits even if a job runs in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13276
diff
changeset
|
3497 #ifdef FEAT_TERMINAL |
b5806be0b36d
patch 8.0.1525: using :wqa exits even if a job runs in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13276
diff
changeset
|
3498 if (exiting && term_job_running(buf->b_term)) |
b5806be0b36d
patch 8.0.1525: using :wqa exits even if a job runs in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13276
diff
changeset
|
3499 { |
b5806be0b36d
patch 8.0.1525: using :wqa exits even if a job runs in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13276
diff
changeset
|
3500 no_write_message_nobang(buf); |
b5806be0b36d
patch 8.0.1525: using :wqa exits even if a job runs in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13276
diff
changeset
|
3501 ++error; |
b5806be0b36d
patch 8.0.1525: using :wqa exits even if a job runs in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13276
diff
changeset
|
3502 } |
b5806be0b36d
patch 8.0.1525: using :wqa exits even if a job runs in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13276
diff
changeset
|
3503 else |
b5806be0b36d
patch 8.0.1525: using :wqa exits even if a job runs in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13276
diff
changeset
|
3504 #endif |
12648
cdfd6eb8bb80
patch 8.0.1202: :wall gives an errof for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
3505 if (bufIsChanged(buf) && !bt_dontwrite(buf)) |
7 | 3506 { |
3507 /* | |
3508 * Check if there is a reason the buffer cannot be written: | |
3509 * 1. if the 'write' option is set | |
3510 * 2. if there is no file name (even after browsing) | |
3511 * 3. if the 'readonly' is set (even after a dialog) | |
3512 * 4. if overwriting is allowed (even after a dialog) | |
3513 */ | |
3514 if (not_writing()) | |
3515 { | |
3516 ++error; | |
3517 break; | |
3518 } | |
3519 #ifdef FEAT_BROWSE | |
3520 /* ":browse wall": ask for file name if there isn't one */ | |
3521 if (buf->b_ffname == NULL && cmdmod.browse) | |
3522 browse_save_fname(buf); | |
3523 #endif | |
3524 if (buf->b_ffname == NULL) | |
3525 { | |
3526 EMSGN(_("E141: No file name for buffer %ld"), (long)buf->b_fnum); | |
3527 ++error; | |
3528 } | |
3529 else if (check_readonly(&eap->forceit, buf) | |
3530 || check_overwrite(eap, buf, buf->b_fname, buf->b_ffname, | |
3531 FALSE) == FAIL) | |
3532 { | |
3533 ++error; | |
3534 } | |
3535 else | |
3536 { | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3537 bufref_T bufref; |
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3538 |
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3539 set_bufref(&bufref, buf); |
7 | 3540 if (buf_write_all(buf, eap->forceit) == FAIL) |
3541 ++error; | |
3542 /* an autocommand may have deleted the buffer */ | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3543 if (!bufref_valid(&bufref)) |
7 | 3544 buf = firstbuf; |
3545 } | |
3546 eap->forceit = save_forceit; /* check_overwrite() may set it */ | |
3547 } | |
3548 } | |
3549 if (exiting) | |
3550 { | |
3551 if (!error) | |
3552 getout(0); /* exit Vim */ | |
3553 not_exiting(); | |
3554 } | |
3555 } | |
3556 | |
3557 /* | |
3558 * Check the 'write' option. | |
3559 * Return TRUE and give a message when it's not st. | |
3560 */ | |
3561 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3562 not_writing(void) |
7 | 3563 { |
3564 if (p_write) | |
3565 return FALSE; | |
3566 EMSG(_("E142: File not written: Writing is disabled by 'write' option")); | |
3567 return TRUE; | |
3568 } | |
3569 | |
3570 /* | |
1303 | 3571 * Check if a buffer is read-only (either 'readonly' option is set or file is |
3572 * read-only). Ask for overruling in a dialog. Return TRUE and give an error | |
3573 * message when the buffer is readonly. | |
7 | 3574 */ |
3575 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3576 check_readonly(int *forceit, buf_T *buf) |
7 | 3577 { |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9377
diff
changeset
|
3578 stat_T st; |
1303 | 3579 |
3580 /* Handle a file being readonly when the 'readonly' option is set or when | |
3581 * the file exists and permissions are read-only. | |
3582 * We will send 0777 to check_file_readonly(), as the "perm" variable is | |
3583 * important for device checks but not here. */ | |
3584 if (!*forceit && (buf->b_p_ro | |
3585 || (mch_stat((char *)buf->b_ffname, &st) >= 0 | |
3586 && check_file_readonly(buf->b_ffname, 0777)))) | |
7 | 3587 { |
3588 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
3589 if ((p_confirm || cmdmod.confirm) && buf->b_fname != NULL) | |
3590 { | |
2770 | 3591 char_u buff[DIALOG_MSG_SIZE]; |
7 | 3592 |
1303 | 3593 if (buf->b_p_ro) |
3594 dialog_msg(buff, _("'readonly' option is set for \"%s\".\nDo you wish to write anyway?"), | |
3595 buf->b_fname); | |
3596 else | |
3597 dialog_msg(buff, _("File permissions of \"%s\" are read-only.\nIt may still be possible to write it.\nDo you wish to try?"), | |
7 | 3598 buf->b_fname); |
3599 | |
3600 if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) == VIM_YES) | |
3601 { | |
3602 /* Set forceit, to force the writing of a readonly file */ | |
3603 *forceit = TRUE; | |
3604 return FALSE; | |
3605 } | |
3606 else | |
3607 return TRUE; | |
3608 } | |
3609 else | |
3610 #endif | |
1303 | 3611 if (buf->b_p_ro) |
7 | 3612 EMSG(_(e_readonly)); |
1303 | 3613 else |
3614 EMSG2(_("E505: \"%s\" is read-only (add ! to override)"), | |
3615 buf->b_fname); | |
7 | 3616 return TRUE; |
3617 } | |
1303 | 3618 |
7 | 3619 return FALSE; |
3620 } | |
3621 | |
3622 /* | |
632 | 3623 * Try to abandon current file and edit a new or existing file. |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3624 * "fnum" is the number of the file, if zero use ffname/sfname. |
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3625 * "lnum" is the line number for the cursor in the new file (if non-zero). |
7 | 3626 * |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3627 * Return: |
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3628 * GETFILE_ERROR for "normal" error, |
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3629 * GETFILE_NOT_WRITTEN for "not written" error, |
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3630 * GETFILE_SAME_FILE for success |
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3631 * GETFILE_OPEN_OTHER for successfully opening another file. |
7 | 3632 */ |
3633 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3634 getfile( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3635 int fnum, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3636 char_u *ffname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3637 char_u *sfname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3638 int setpm, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3639 linenr_T lnum, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3640 int forceit) |
7 | 3641 { |
3642 int other; | |
3643 int retval; | |
3644 char_u *free_me = NULL; | |
3645 | |
634 | 3646 if (text_locked()) |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3647 return GETFILE_ERROR; |
819 | 3648 if (curbuf_locked()) |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3649 return GETFILE_ERROR; |
7 | 3650 |
3651 if (fnum == 0) | |
3652 { | |
3653 /* make ffname full path, set sfname */ | |
3654 fname_expand(curbuf, &ffname, &sfname); | |
3655 other = otherfile(ffname); | |
3656 free_me = ffname; /* has been allocated, free() later */ | |
3657 } | |
3658 else | |
3659 other = (fnum != curbuf->b_fnum); | |
3660 | |
3661 if (other) | |
3662 ++no_wait_return; /* don't wait for autowrite message */ | |
11957
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11800
diff
changeset
|
3663 if (other && !forceit && curbuf->b_nwindows == 1 && !buf_hide(curbuf) |
7 | 3664 && curbufIsChanged() && autowrite(curbuf, forceit) == FAIL) |
3665 { | |
3666 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
3667 if (p_confirm && p_write) | |
3668 dialog_changed(curbuf, FALSE); | |
3669 if (curbufIsChanged()) | |
3670 #endif | |
3671 { | |
3672 if (other) | |
3673 --no_wait_return; | |
12146
59c1e09cf1a9
patch 8.0.0953: get "no write since last change" error in terminal window
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
3674 no_write_message(); |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3675 retval = GETFILE_NOT_WRITTEN; /* file has been changed */ |
7 | 3676 goto theend; |
3677 } | |
3678 } | |
3679 if (other) | |
3680 --no_wait_return; | |
3681 if (setpm) | |
3682 setpcmark(); | |
3683 if (!other) | |
3684 { | |
3685 if (lnum != 0) | |
3686 curwin->w_cursor.lnum = lnum; | |
3687 check_cursor_lnum(); | |
3688 beginline(BL_SOL | BL_FIX); | |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3689 retval = GETFILE_SAME_FILE; /* it's in the same file */ |
7 | 3690 } |
3691 else if (do_ecmd(fnum, ffname, sfname, NULL, lnum, | |
11957
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11800
diff
changeset
|
3692 (buf_hide(curbuf) ? ECMD_HIDE : 0) + (forceit ? ECMD_FORCEIT : 0), |
1743 | 3693 curwin) == OK) |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3694 retval = GETFILE_OPEN_OTHER; /* opened another file */ |
7 | 3695 else |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3696 retval = GETFILE_ERROR; /* error encountered */ |
7 | 3697 |
3698 theend: | |
3699 vim_free(free_me); | |
3700 return retval; | |
3701 } | |
3702 | |
3703 /* | |
3704 * start editing a new file | |
3705 * | |
3706 * fnum: file number; if zero use ffname/sfname | |
3707 * ffname: the file name | |
3708 * - full path if sfname used, | |
3709 * - any file name if sfname is NULL | |
3710 * - empty string to re-edit with the same file name (but may be | |
3711 * in a different directory) | |
3712 * - NULL to start an empty buffer | |
3713 * sfname: the short file name (or NULL) | |
3714 * eap: contains the command to be executed after loading the file and | |
3715 * forced 'ff' and 'fenc' | |
3716 * newlnum: if > 0: put cursor on this line number (if possible) | |
3717 * if ECMD_LASTL: use last position in loaded file | |
3718 * if ECMD_LAST: use last position in all files | |
3719 * if ECMD_ONE: use first line | |
3720 * flags: | |
3721 * ECMD_HIDE: if TRUE don't free the current buffer | |
3722 * ECMD_SET_HELP: set b_help flag of (new) buffer before opening file | |
3723 * ECMD_OLDBUF: use existing buffer if it exists | |
3724 * ECMD_FORCEIT: ! used for Ex command | |
3725 * ECMD_ADDBUF: don't edit, just add to buffer list | |
1743 | 3726 * oldwin: Should be "curwin" when editing a new buffer in the current |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2290
diff
changeset
|
3727 * window, NULL when splitting the window first. When not NULL info |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2290
diff
changeset
|
3728 * of the previous buffer for "oldwin" is stored. |
7 | 3729 * |
3730 * return FAIL for failure, OK otherwise | |
3731 */ | |
3732 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3733 do_ecmd( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3734 int fnum, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3735 char_u *ffname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3736 char_u *sfname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3737 exarg_T *eap, /* can be NULL! */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3738 linenr_T newlnum, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3739 int flags, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3740 win_T *oldwin) |
7 | 3741 { |
3742 int other_file; /* TRUE if editing another file */ | |
3743 int oldbuf; /* TRUE if using existing buffer */ | |
3744 int auto_buf = FALSE; /* TRUE if autocommands brought us | |
3745 into the buffer unexpectedly */ | |
3746 char_u *new_name = NULL; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3747 #if defined(FEAT_EVAL) |
716 | 3748 int did_set_swapcommand = FALSE; |
7 | 3749 #endif |
3750 buf_T *buf; | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3751 bufref_T bufref; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9481
diff
changeset
|
3752 bufref_T old_curbuf; |
7 | 3753 char_u *free_fname = NULL; |
3754 #ifdef FEAT_BROWSE | |
3755 char_u *browse_file = NULL; | |
3756 #endif | |
3757 int retval = FAIL; | |
3758 long n; | |
6702 | 3759 pos_T orig_pos; |
7 | 3760 linenr_T topline = 0; |
3761 int newcol = -1; | |
3762 int solcol = -1; | |
3763 pos_T *pos; | |
3764 #ifdef FEAT_SUN_WORKSHOP | |
3765 char_u *cp; | |
3766 #endif | |
3767 char_u *command = NULL; | |
1185 | 3768 #ifdef FEAT_SPELL |
3769 int did_get_winopts = FALSE; | |
3770 #endif | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
3771 int readfile_flags = 0; |
7941
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
3772 int did_inc_redrawing_disabled = FALSE; |
7 | 3773 |
3774 if (eap != NULL) | |
3775 command = eap->do_ecmd_cmd; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9481
diff
changeset
|
3776 set_bufref(&old_curbuf, curbuf); |
7 | 3777 |
3778 if (fnum != 0) | |
3779 { | |
3780 if (fnum == curbuf->b_fnum) /* file is already being edited */ | |
3781 return OK; /* nothing to do */ | |
3782 other_file = TRUE; | |
3783 } | |
3784 else | |
3785 { | |
3786 #ifdef FEAT_BROWSE | |
3787 if (cmdmod.browse) | |
3788 { | |
462 | 3789 if ( |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3790 # ifdef FEAT_GUI |
462 | 3791 !gui.in_use && |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3792 # endif |
462 | 3793 au_has_group((char_u *)"FileExplorer")) |
3794 { | |
3795 /* No browsing supported but we do have the file explorer: | |
3796 * Edit the directory. */ | |
3797 if (ffname == NULL || !mch_isdir(ffname)) | |
3798 ffname = (char_u *)"."; | |
3799 } | |
3800 else | |
3801 { | |
3802 browse_file = do_browse(0, (char_u *)_("Edit File"), ffname, | |
7 | 3803 NULL, NULL, NULL, curbuf); |
462 | 3804 if (browse_file == NULL) |
3805 goto theend; | |
3806 ffname = browse_file; | |
3807 } | |
7 | 3808 } |
3809 #endif | |
3810 /* if no short name given, use ffname for short name */ | |
3811 if (sfname == NULL) | |
3812 sfname = ffname; | |
3813 #ifdef USE_FNAME_CASE | |
3814 # ifdef USE_LONG_FNAME | |
3815 if (USE_LONG_FNAME) | |
3816 # endif | |
436 | 3817 if (sfname != NULL) |
3818 fname_case(sfname, 0); /* set correct case for sfname */ | |
7 | 3819 #endif |
3820 | |
3821 if ((flags & ECMD_ADDBUF) && (ffname == NULL || *ffname == NUL)) | |
3822 goto theend; | |
3823 | |
3824 if (ffname == NULL) | |
3825 other_file = TRUE; | |
3826 /* there is no file name */ | |
3827 else if (*ffname == NUL && curbuf->b_ffname == NULL) | |
3828 other_file = FALSE; | |
3829 else | |
3830 { | |
3831 if (*ffname == NUL) /* re-edit with same file name */ | |
3832 { | |
3833 ffname = curbuf->b_ffname; | |
3834 sfname = curbuf->b_fname; | |
3835 } | |
3836 free_fname = fix_fname(ffname); /* may expand to full path name */ | |
3837 if (free_fname != NULL) | |
3838 ffname = free_fname; | |
3839 other_file = otherfile(ffname); | |
3840 #ifdef FEAT_SUN_WORKSHOP | |
3841 if (usingSunWorkShop && p_acd | |
3842 && (cp = vim_strrchr(sfname, '/')) != NULL) | |
3843 sfname = ++cp; | |
3844 #endif | |
3845 } | |
3846 } | |
3847 | |
3848 /* | |
3849 * if the file was changed we may not be allowed to abandon it | |
3850 * - if we are going to re-edit the same file | |
3851 * - or if we are the only window on this file and if ECMD_HIDE is FALSE | |
3852 */ | |
3853 if ( ((!other_file && !(flags & ECMD_OLDBUF)) | |
3854 || (curbuf->b_nwindows == 1 | |
3855 && !(flags & (ECMD_HIDE | ECMD_ADDBUF)))) | |
5464 | 3856 && check_changed(curbuf, (p_awa ? CCGD_AW : 0) |
3857 | (other_file ? 0 : CCGD_MULTWIN) | |
3858 | ((flags & ECMD_FORCEIT) ? CCGD_FORCEIT : 0) | |
3859 | (eap == NULL ? 0 : CCGD_EXCMD))) | |
7 | 3860 { |
3861 if (fnum == 0 && other_file && ffname != NULL) | |
3862 (void)setaltfname(ffname, sfname, newlnum < 0 ? 0 : newlnum); | |
3863 goto theend; | |
3864 } | |
3865 | |
3866 /* | |
3867 * End Visual mode before switching to another buffer, so the text can be | |
3868 * copied into the GUI selection buffer. | |
3869 */ | |
3870 reset_VIsual(); | |
3871 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3872 #if defined(FEAT_EVAL) |
716 | 3873 if ((command != NULL || newlnum > (linenr_T)0) |
3874 && *get_vim_var_str(VV_SWAPCOMMAND) == NUL) | |
3875 { | |
3876 int len; | |
3877 char_u *p; | |
3878 | |
3879 /* Set v:swapcommand for the SwapExists autocommands. */ | |
3880 if (command != NULL) | |
835 | 3881 len = (int)STRLEN(command) + 3; |
716 | 3882 else |
3883 len = 30; | |
3884 p = alloc((unsigned)len); | |
3885 if (p != NULL) | |
3886 { | |
3887 if (command != NULL) | |
3888 vim_snprintf((char *)p, len, ":%s\r", command); | |
3889 else | |
3890 vim_snprintf((char *)p, len, "%ldG", (long)newlnum); | |
3891 set_vim_var_string(VV_SWAPCOMMAND, p, -1); | |
3892 did_set_swapcommand = TRUE; | |
3893 vim_free(p); | |
3894 } | |
3895 } | |
3896 #endif | |
3897 | |
7 | 3898 /* |
3899 * If we are starting to edit another file, open a (new) buffer. | |
3900 * Otherwise we re-use the current buffer. | |
3901 */ | |
3902 if (other_file) | |
3903 { | |
3904 if (!(flags & ECMD_ADDBUF)) | |
3905 { | |
22 | 3906 if (!cmdmod.keepalt) |
3907 curwin->w_alt_fnum = curbuf->b_fnum; | |
1743 | 3908 if (oldwin != NULL) |
3909 buflist_altfpos(oldwin); | |
7 | 3910 } |
3911 | |
3912 if (fnum) | |
3913 buf = buflist_findnr(fnum); | |
3914 else | |
3915 { | |
3916 if (flags & ECMD_ADDBUF) | |
3917 { | |
3918 linenr_T tlnum = 1L; | |
3919 | |
3920 if (command != NULL) | |
3921 { | |
3922 tlnum = atol((char *)command); | |
3923 if (tlnum <= 0) | |
3924 tlnum = 1L; | |
3925 } | |
3926 (void)buflist_new(ffname, sfname, tlnum, BLN_LISTED); | |
3927 goto theend; | |
3928 } | |
3929 buf = buflist_new(ffname, sfname, 0L, | |
3930 BLN_CURBUF | ((flags & ECMD_SET_HELP) ? 0 : BLN_LISTED)); | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3931 |
5816 | 3932 /* autocommands may change curwin and curbuf */ |
3933 if (oldwin != NULL) | |
3934 oldwin = curwin; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9481
diff
changeset
|
3935 set_bufref(&old_curbuf, curbuf); |
7 | 3936 } |
3937 if (buf == NULL) | |
3938 goto theend; | |
3939 if (buf->b_ml.ml_mfp == NULL) /* no memfile yet */ | |
3940 { | |
3941 oldbuf = FALSE; | |
3942 } | |
3943 else /* existing memfile */ | |
3944 { | |
3945 oldbuf = TRUE; | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3946 set_bufref(&bufref, buf); |
7 | 3947 (void)buf_check_timestamp(buf, FALSE); |
10106
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
3948 /* Check if autocommands made the buffer invalid or changed the |
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
3949 * current buffer. */ |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3950 if (!bufref_valid(&bufref) || curbuf != old_curbuf.br_buf) |
7 | 3951 goto theend; |
3952 #ifdef FEAT_EVAL | |
3953 if (aborting()) /* autocmds may abort script processing */ | |
3954 goto theend; | |
3955 #endif | |
3956 } | |
3957 | |
3958 /* May jump to last used line number for a loaded buffer or when asked | |
3959 * for explicitly */ | |
3960 if ((oldbuf && newlnum == ECMD_LASTL) || newlnum == ECMD_LAST) | |
3961 { | |
3962 pos = buflist_findfpos(buf); | |
3963 newlnum = pos->lnum; | |
3964 solcol = pos->col; | |
3965 } | |
3966 | |
3967 /* | |
3968 * Make the (new) buffer the one used by the current window. | |
3969 * If the old buffer becomes unused, free it if ECMD_HIDE is FALSE. | |
3970 * If the current buffer was empty and has no file name, curbuf | |
6639 | 3971 * is returned by buflist_new(), nothing to do here. |
7 | 3972 */ |
3973 if (buf != curbuf) | |
3974 { | |
3975 /* | |
3976 * Be careful: The autocommands may delete any buffer and change | |
3977 * the current buffer. | |
3978 * - If the buffer we are going to edit is deleted, give up. | |
3979 * - If the current buffer is deleted, prefer to load the new | |
3980 * buffer when loading a buffer is required. This avoids | |
3981 * loading another buffer which then must be closed again. | |
3982 * - If we ended up in the new buffer already, need to skip a few | |
3983 * things, set auto_buf. | |
3984 */ | |
3985 if (buf->b_fname != NULL) | |
3986 new_name = vim_strsave(buf->b_fname); | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3987 set_bufref(&au_new_curbuf, buf); |
7 | 3988 apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf); |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3989 if (!bufref_valid(&au_new_curbuf)) |
7 | 3990 { |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3991 /* new buffer has been deleted */ |
7 | 3992 delbuf_msg(new_name); /* frees new_name */ |
3993 goto theend; | |
3994 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3995 #ifdef FEAT_EVAL |
7 | 3996 if (aborting()) /* autocmds may abort script processing */ |
3997 { | |
3998 vim_free(new_name); | |
3999 goto theend; | |
4000 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4001 #endif |
7 | 4002 if (buf == curbuf) /* already in new buffer */ |
4003 auto_buf = TRUE; | |
4004 else | |
4005 { | |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4006 win_T *the_curwin = curwin; |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4007 |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4008 /* Set the w_closing flag to avoid that autocommands close the |
10106
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
4009 * window. And set b_locked for the same reason. */ |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4010 the_curwin->w_closing = TRUE; |
10106
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
4011 ++buf->b_locked; |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4012 |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9481
diff
changeset
|
4013 if (curbuf == old_curbuf.br_buf) |
7 | 4014 buf_copy_options(buf, BCO_ENTER); |
4015 | |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4016 /* Close the link to the current buffer. This will set |
10141
b67088aae933
commit https://github.com/vim/vim/commit/aeac9006d5d14910f214f09df52c026a5936e737
Christian Brabandt <cb@256bit.org>
parents:
10106
diff
changeset
|
4017 * oldwin->w_buffer to NULL. */ |
825 | 4018 u_sync(FALSE); |
1743 | 4019 close_buffer(oldwin, curbuf, |
3365 | 4020 (flags & ECMD_HIDE) ? 0 : DOBUF_UNLOAD, FALSE); |
7 | 4021 |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4022 the_curwin->w_closing = FALSE; |
10106
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
4023 --buf->b_locked; |
3242 | 4024 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4025 #ifdef FEAT_EVAL |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4026 /* autocmds may abort script processing */ |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4027 if (aborting() && curwin->w_buffer != NULL) |
7 | 4028 { |
4029 vim_free(new_name); | |
4030 goto theend; | |
4031 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4032 #endif |
7 | 4033 /* Be careful again, like above. */ |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
4034 if (!bufref_valid(&au_new_curbuf)) |
7 | 4035 { |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
4036 /* new buffer has been deleted */ |
7 | 4037 delbuf_msg(new_name); /* frees new_name */ |
4038 goto theend; | |
4039 } | |
4040 if (buf == curbuf) /* already in new buffer */ | |
4041 auto_buf = TRUE; | |
4042 else | |
4043 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
4044 #ifdef FEAT_SYN_HL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
4045 /* |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
4046 * <VN> We could instead free the synblock |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
4047 * and re-attach to buffer, perhaps. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
4048 */ |
11649
0f7888a5ba68
patch 8.0.0707: freeing wrong memory with certain autocommands
Christian Brabandt <cb@256bit.org>
parents:
11589
diff
changeset
|
4049 if (curwin->w_buffer == NULL |
0f7888a5ba68
patch 8.0.0707: freeing wrong memory with certain autocommands
Christian Brabandt <cb@256bit.org>
parents:
11589
diff
changeset
|
4050 || curwin->w_s == &(curwin->w_buffer->b_s)) |
3480 | 4051 curwin->w_s = &(buf->b_s); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
4052 #endif |
7 | 4053 curwin->w_buffer = buf; |
4054 curbuf = buf; | |
4055 ++curbuf->b_nwindows; | |
5231
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
4056 |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
4057 /* Set 'fileformat', 'binary' and 'fenc' when forced. */ |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
4058 if (!oldbuf && eap != NULL) |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
4059 { |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
4060 set_file_options(TRUE, eap); |
5242
f0361e297d9c
updated for version 7.4a.046
Bram Moolenaar <bram@vim.org>
parents:
5231
diff
changeset
|
4061 #ifdef FEAT_MBYTE |
5231
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
4062 set_forced_fenc(eap); |
5242
f0361e297d9c
updated for version 7.4a.046
Bram Moolenaar <bram@vim.org>
parents:
5231
diff
changeset
|
4063 #endif |
5231
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
4064 } |
7 | 4065 } |
4066 | |
4067 /* May get the window options from the last time this buffer | |
4068 * was in this window (or another window). If not used | |
4069 * before, reset the local window options to the global | |
4070 * values. Also restores old folding stuff. */ | |
1289 | 4071 get_winopts(curbuf); |
1185 | 4072 #ifdef FEAT_SPELL |
4073 did_get_winopts = TRUE; | |
4074 #endif | |
7 | 4075 } |
4076 vim_free(new_name); | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
4077 au_new_curbuf.br_buf = NULL; |
9659
08df6ad72c56
commit https://github.com/vim/vim/commit/ac77aec4daea8d73468fcf4690cb4ccab1d807ed
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
4078 au_new_curbuf.br_buf_free_count = 0; |
7 | 4079 } |
4080 | |
4081 curwin->w_pcmark.lnum = 1; | |
4082 curwin->w_pcmark.col = 0; | |
4083 } | |
4084 else /* !other_file */ | |
4085 { | |
13553
04019fc3de93
patch 8.0.1650: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
4086 if ((flags & ECMD_ADDBUF) || check_fname() == FAIL) |
7 | 4087 goto theend; |
6531 | 4088 |
7 | 4089 oldbuf = (flags & ECMD_OLDBUF); |
4090 } | |
4091 | |
7941
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
4092 /* Don't redraw until the cursor is in the right line, otherwise |
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
4093 * autocommands may cause ml_get errors. */ |
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
4094 ++RedrawingDisabled; |
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
4095 did_inc_redrawing_disabled = TRUE; |
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
4096 |
6365 | 4097 buf = curbuf; |
7 | 4098 if ((flags & ECMD_SET_HELP) || keep_help_flag) |
4099 { | |
6365 | 4100 prepare_help_buffer(); |
7 | 4101 } |
4102 else | |
4103 { | |
4104 /* Don't make a buffer listed if it's a help buffer. Useful when | |
4105 * using CTRL-O to go back to a help file. */ | |
4106 if (!curbuf->b_help) | |
4107 set_buflisted(TRUE); | |
4108 } | |
4109 | |
4110 /* If autocommands change buffers under our fingers, forget about | |
4111 * editing the file. */ | |
4112 if (buf != curbuf) | |
4113 goto theend; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4114 #ifdef FEAT_EVAL |
7 | 4115 if (aborting()) /* autocmds may abort script processing */ |
4116 goto theend; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4117 #endif |
7 | 4118 |
4119 /* Since we are starting to edit a file, consider the filetype to be | |
4120 * unset. Helps for when an autocommand changes files and expects syntax | |
4121 * highlighting to work in the other file. */ | |
4122 did_filetype = FALSE; | |
4123 | |
4124 /* | |
4125 * other_file oldbuf | |
4126 * FALSE FALSE re-edit same file, buffer is re-used | |
4127 * FALSE TRUE re-edit same file, nothing changes | |
4128 * TRUE FALSE start editing new file, new buffer | |
4129 * TRUE TRUE start editing in existing buffer (nothing to do) | |
4130 */ | |
4131 if (!other_file && !oldbuf) /* re-use the buffer */ | |
4132 { | |
4133 set_last_cursor(curwin); /* may set b_last_cursor */ | |
4134 if (newlnum == ECMD_LAST || newlnum == ECMD_LASTL) | |
4135 { | |
4136 newlnum = curwin->w_cursor.lnum; | |
4137 solcol = curwin->w_cursor.col; | |
4138 } | |
4139 buf = curbuf; | |
4140 if (buf->b_fname != NULL) | |
4141 new_name = vim_strsave(buf->b_fname); | |
4142 else | |
4143 new_name = NULL; | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
4144 set_bufref(&bufref, buf); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4145 |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4146 if (p_ur < 0 || curbuf->b_ml.ml_line_count <= p_ur) |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4147 { |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4148 /* Save all the text, so that the reload can be undone. |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4149 * Sync first so that this is a separate undo-able action. */ |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4150 u_sync(FALSE); |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4151 if (u_savecommon(0, curbuf->b_ml.ml_line_count + 1, 0, TRUE) |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4152 == FAIL) |
9705
8c0871098dc9
commit https://github.com/vim/vim/commit/1e2258297bb31720bfbeb234f2dae4d1b3b04fbd
Christian Brabandt <cb@256bit.org>
parents:
9676
diff
changeset
|
4153 { |
8c0871098dc9
commit https://github.com/vim/vim/commit/1e2258297bb31720bfbeb234f2dae4d1b3b04fbd
Christian Brabandt <cb@256bit.org>
parents:
9676
diff
changeset
|
4154 vim_free(new_name); |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4155 goto theend; |
9705
8c0871098dc9
commit https://github.com/vim/vim/commit/1e2258297bb31720bfbeb234f2dae4d1b3b04fbd
Christian Brabandt <cb@256bit.org>
parents:
9676
diff
changeset
|
4156 } |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4157 u_unchanged(curbuf); |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4158 buf_freeall(curbuf, BFA_KEEP_UNDO); |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4159 |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4160 /* tell readfile() not to clear or reload undo info */ |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4161 readfile_flags = READ_KEEP_UNDO; |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4162 } |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4163 else |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4164 buf_freeall(curbuf, 0); /* free all things for buffer */ |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4165 |
7 | 4166 /* If autocommands deleted the buffer we were going to re-edit, give |
4167 * up and jump to the end. */ | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
4168 if (!bufref_valid(&bufref)) |
7 | 4169 { |
4170 delbuf_msg(new_name); /* frees new_name */ | |
4171 goto theend; | |
4172 } | |
4173 vim_free(new_name); | |
4174 | |
4175 /* If autocommands change buffers under our fingers, forget about | |
4176 * re-editing the file. Should do the buf_clear_file(), but perhaps | |
4177 * the autocommands changed the buffer... */ | |
4178 if (buf != curbuf) | |
4179 goto theend; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4180 #ifdef FEAT_EVAL |
7 | 4181 if (aborting()) /* autocmds may abort script processing */ |
4182 goto theend; | |
4183 #endif | |
4184 buf_clear_file(curbuf); | |
4185 curbuf->b_op_start.lnum = 0; /* clear '[ and '] marks */ | |
4186 curbuf->b_op_end.lnum = 0; | |
4187 } | |
4188 | |
4189 /* | |
4190 * If we get here we are sure to start editing | |
4191 */ | |
4192 /* Assume success now */ | |
4193 retval = OK; | |
4194 | |
4195 /* | |
4196 * Check if we are editing the w_arg_idx file in the argument list. | |
4197 */ | |
4198 check_arg_idx(curwin); | |
4199 | |
4200 if (!auto_buf) | |
4201 { | |
4202 /* | |
4203 * Set cursor and init window before reading the file and executing | |
4204 * autocommands. This allows for the autocommands to position the | |
4205 * cursor. | |
4206 */ | |
677 | 4207 curwin_init(); |
7 | 4208 |
4209 #ifdef FEAT_FOLDING | |
1370 | 4210 /* It's possible that all lines in the buffer changed. Need to update |
4211 * automatic folding for all windows where it's used. */ | |
4212 { | |
4213 win_T *win; | |
4214 tabpage_T *tp; | |
4215 | |
4216 FOR_ALL_TAB_WINDOWS(tp, win) | |
4217 if (win->w_buffer == curbuf) | |
4218 foldUpdateAll(win); | |
4219 } | |
7 | 4220 #endif |
4221 | |
961 | 4222 /* Change directories when the 'acd' option is set. */ |
13632
cec5137d5332
patch 8.0.1688: some macros are used without a semicolon
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
4223 DO_AUTOCHDIR; |
961 | 4224 |
7 | 4225 /* |
4226 * Careful: open_buffer() and apply_autocmds() may change the current | |
4227 * buffer and window. | |
4228 */ | |
6702 | 4229 orig_pos = curwin->w_cursor; |
7 | 4230 topline = curwin->w_topline; |
4231 if (!oldbuf) /* need to read the file */ | |
4232 { | |
580 | 4233 #if defined(HAS_SWAP_EXISTS_ACTION) |
7 | 4234 swap_exists_action = SEA_DIALOG; |
4235 #endif | |
4236 curbuf->b_flags |= BF_CHECK_RO; /* set/reset 'ro' flag */ | |
4237 | |
4238 /* | |
4239 * Open the buffer and read the file. | |
4240 */ | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4241 #if defined(FEAT_EVAL) |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4242 if (should_abort(open_buffer(FALSE, eap, readfile_flags))) |
7 | 4243 retval = FAIL; |
4244 #else | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4245 (void)open_buffer(FALSE, eap, readfile_flags); |
7 | 4246 #endif |
4247 | |
580 | 4248 #if defined(HAS_SWAP_EXISTS_ACTION) |
7 | 4249 if (swap_exists_action == SEA_QUIT) |
4250 retval = FAIL; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9481
diff
changeset
|
4251 handle_swap_exists(&old_curbuf); |
7 | 4252 #endif |
4253 } | |
4254 else | |
4255 { | |
23 | 4256 /* Read the modelines, but only to set window-local options. Any |
4257 * buffer-local options have already been set and may have been | |
4258 * changed by the user. */ | |
717 | 4259 do_modelines(OPT_WINONLY); |
23 | 4260 |
7 | 4261 apply_autocmds_retval(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf, |
4262 &retval); | |
4263 apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf, | |
4264 &retval); | |
4265 } | |
4266 check_arg_idx(curwin); | |
4267 | |
6702 | 4268 /* If autocommands change the cursor position or topline, we should |
14033
bcda3b864c31
patch 8.1.0034: cursor not restored with ":edit #"
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
4269 * keep it. Also when it moves within a line. But not when it moves |
bcda3b864c31
patch 8.1.0034: cursor not restored with ":edit #"
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
4270 * to the first non-blank. */ |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
4271 if (!EQUAL_POS(curwin->w_cursor, orig_pos)) |
7 | 4272 { |
14033
bcda3b864c31
patch 8.1.0034: cursor not restored with ":edit #"
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
4273 char_u *text = ml_get_curline(); |
bcda3b864c31
patch 8.1.0034: cursor not restored with ":edit #"
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
4274 |
bcda3b864c31
patch 8.1.0034: cursor not restored with ":edit #"
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
4275 if (curwin->w_cursor.lnum != orig_pos.lnum |
bcda3b864c31
patch 8.1.0034: cursor not restored with ":edit #"
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
4276 || curwin->w_cursor.col != (int)(skipwhite(text) - text)) |
bcda3b864c31
patch 8.1.0034: cursor not restored with ":edit #"
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
4277 { |
bcda3b864c31
patch 8.1.0034: cursor not restored with ":edit #"
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
4278 newlnum = curwin->w_cursor.lnum; |
bcda3b864c31
patch 8.1.0034: cursor not restored with ":edit #"
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
4279 newcol = curwin->w_cursor.col; |
bcda3b864c31
patch 8.1.0034: cursor not restored with ":edit #"
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
4280 } |
7 | 4281 } |
4282 if (curwin->w_topline == topline) | |
4283 topline = 0; | |
4284 | |
4285 /* Even when cursor didn't move we need to recompute topline. */ | |
4286 changed_line_abv_curs(); | |
4287 | |
4288 #ifdef FEAT_TITLE | |
4289 maketitle(); | |
4290 #endif | |
4291 } | |
4292 | |
4293 #ifdef FEAT_DIFF | |
4294 /* Tell the diff stuff that this buffer is new and/or needs updating. | |
4295 * Also needed when re-editing the same buffer, because unloading will | |
4296 * have removed it as a diff buffer. */ | |
673 | 4297 if (curwin->w_p_diff) |
4298 { | |
4299 diff_buf_add(curbuf); | |
4300 diff_invalidate(curbuf); | |
4301 } | |
7 | 4302 #endif |
4303 | |
1185 | 4304 #ifdef FEAT_SPELL |
4305 /* If the window options were changed may need to set the spell language. | |
4306 * Can only do this after the buffer has been properly setup. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
4307 if (did_get_winopts && curwin->w_p_spell && *curwin->w_s->b_p_spl != NUL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
4308 (void)did_set_spelllang(curwin); |
1185 | 4309 #endif |
4310 | |
7 | 4311 if (command == NULL) |
4312 { | |
4313 if (newcol >= 0) /* position set by autocommands */ | |
4314 { | |
4315 curwin->w_cursor.lnum = newlnum; | |
4316 curwin->w_cursor.col = newcol; | |
4317 check_cursor(); | |
4318 } | |
4319 else if (newlnum > 0) /* line number from caller or old position */ | |
4320 { | |
4321 curwin->w_cursor.lnum = newlnum; | |
4322 check_cursor_lnum(); | |
4323 if (solcol >= 0 && !p_sol) | |
4324 { | |
4325 /* 'sol' is off: Use last known column. */ | |
4326 curwin->w_cursor.col = solcol; | |
4327 check_cursor_col(); | |
4328 #ifdef FEAT_VIRTUALEDIT | |
4329 curwin->w_cursor.coladd = 0; | |
4330 #endif | |
4331 curwin->w_set_curswant = TRUE; | |
4332 } | |
4333 else | |
4334 beginline(BL_SOL | BL_FIX); | |
4335 } | |
4336 else /* no line number, go to last line in Ex mode */ | |
4337 { | |
4338 if (exmode_active) | |
4339 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4340 beginline(BL_WHITE | BL_FIX); | |
4341 } | |
4342 } | |
4343 | |
4344 /* Check if cursors in other windows on the same buffer are still valid */ | |
4345 check_lnums(FALSE); | |
4346 | |
4347 /* | |
4348 * Did not read the file, need to show some info about the file. | |
4349 * Do this after setting the cursor. | |
4350 */ | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4351 if (oldbuf && !auto_buf) |
7 | 4352 { |
4353 int msg_scroll_save = msg_scroll; | |
4354 | |
4355 /* Obey the 'O' flag in 'cpoptions': overwrite any previous file | |
4356 * message. */ | |
4357 if (shortmess(SHM_OVERALL) && !exiting && p_verbose == 0) | |
4358 msg_scroll = FALSE; | |
4359 if (!msg_scroll) /* wait a bit when overwriting an error msg */ | |
4360 check_for_delay(FALSE); | |
4361 msg_start(); | |
4362 msg_scroll = msg_scroll_save; | |
4363 msg_scrolled_ign = TRUE; | |
4364 | |
8560
f3c636c673f7
commit https://github.com/vim/vim/commit/426dd0219512af5f4abeb0901b533159253ffba3
Christian Brabandt <cb@256bit.org>
parents:
8556
diff
changeset
|
4365 if (!shortmess(SHM_FILEINFO)) |
f3c636c673f7
commit https://github.com/vim/vim/commit/426dd0219512af5f4abeb0901b533159253ffba3
Christian Brabandt <cb@256bit.org>
parents:
8556
diff
changeset
|
4366 fileinfo(FALSE, TRUE, FALSE); |
7 | 4367 |
4368 msg_scrolled_ign = FALSE; | |
4369 } | |
4370 | |
9414
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
4371 #ifdef FEAT_VIMINFO |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
4372 curbuf->b_last_used = vim_time(); |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
4373 #endif |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
4374 |
7 | 4375 if (command != NULL) |
4376 do_cmdline(command, NULL, NULL, DOCMD_VERBOSE); | |
4377 | |
4378 #ifdef FEAT_KEYMAP | |
4379 if (curbuf->b_kmap_state & KEYMAP_INIT) | |
1869 | 4380 (void)keymap_init(); |
7 | 4381 #endif |
4382 | |
4383 --RedrawingDisabled; | |
7941
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
4384 did_inc_redrawing_disabled = FALSE; |
7 | 4385 if (!skip_redraw) |
4386 { | |
4387 n = p_so; | |
4388 if (topline == 0 && command == NULL) | |
4389 p_so = 999; /* force cursor halfway the window */ | |
4390 update_topline(); | |
4391 curwin->w_scbind_pos = curwin->w_topline; | |
4392 p_so = n; | |
4393 redraw_curbuf_later(NOT_VALID); /* redraw this buffer later */ | |
4394 } | |
4395 | |
4396 if (p_im) | |
4397 need_start_insertmode = TRUE; | |
4398 | |
13174
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4399 #ifdef FEAT_AUTOCHDIR |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4400 /* Change directories when the 'acd' option is set and we aren't already in |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4401 * that directory (should already be done above). Expect getcwd() to be |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4402 * faster than calling shorten_fnames() unnecessarily. */ |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4403 if (p_acd && curbuf->b_ffname != NULL) |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4404 { |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4405 char_u curdir[MAXPATHL]; |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4406 char_u filedir[MAXPATHL]; |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4407 |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4408 vim_strncpy(filedir, curbuf->b_ffname, MAXPATHL - 1); |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4409 *gettail_sep(filedir) = NUL; |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4410 if (mch_dirname(curdir, MAXPATHL) != FAIL |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4411 && vim_fnamecmp(curdir, filedir) != 0) |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4412 do_autochdir(); |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4413 } |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4414 #endif |
821 | 4415 |
4416 #if defined(FEAT_SUN_WORKSHOP) || defined(FEAT_NETBEANS_INTG) | |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2178
diff
changeset
|
4417 if (curbuf->b_ffname != NULL) |
7 | 4418 { |
4419 # ifdef FEAT_SUN_WORKSHOP | |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2178
diff
changeset
|
4420 if (gui.in_use && usingSunWorkShop) |
7 | 4421 workshop_file_opened((char *)curbuf->b_ffname, curbuf->b_p_ro); |
4422 # endif | |
4423 # ifdef FEAT_NETBEANS_INTG | |
2210 | 4424 if ((flags & ECMD_SET_HELP) != ECMD_SET_HELP) |
34 | 4425 netbeans_file_opened(curbuf); |
7 | 4426 # endif |
4427 } | |
4428 #endif | |
4429 | |
4430 theend: | |
7941
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
4431 if (did_inc_redrawing_disabled) |
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
4432 --RedrawingDisabled; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4433 #if defined(FEAT_EVAL) |
716 | 4434 if (did_set_swapcommand) |
4435 set_vim_var_string(VV_SWAPCOMMAND, NULL, -1); | |
4436 #endif | |
7 | 4437 #ifdef FEAT_BROWSE |
4438 vim_free(browse_file); | |
4439 #endif | |
4440 vim_free(free_fname); | |
4441 return retval; | |
4442 } | |
4443 | |
4444 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4445 delbuf_msg(char_u *name) |
7 | 4446 { |
4447 EMSG2(_("E143: Autocommands unexpectedly deleted new buffer %s"), | |
4448 name == NULL ? (char_u *)"" : name); | |
4449 vim_free(name); | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
4450 au_new_curbuf.br_buf = NULL; |
9659
08df6ad72c56
commit https://github.com/vim/vim/commit/ac77aec4daea8d73468fcf4690cb4ccab1d807ed
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
4451 au_new_curbuf.br_buf_free_count = 0; |
7 | 4452 } |
4453 | |
169 | 4454 static int append_indent = 0; /* autoindent for first line */ |
4455 | |
7 | 4456 /* |
4457 * ":insert" and ":append", also used by ":change" | |
4458 */ | |
4459 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4460 ex_append(exarg_T *eap) |
7 | 4461 { |
4462 char_u *theline; | |
4463 int did_undo = FALSE; | |
4464 linenr_T lnum = eap->line2; | |
165 | 4465 int indent = 0; |
4466 char_u *p; | |
4467 int vcol; | |
4468 int empty = (curbuf->b_ml.ml_flags & ML_EMPTY); | |
7 | 4469 |
169 | 4470 /* the ! flag toggles autoindent */ |
4471 if (eap->forceit) | |
4472 curbuf->b_p_ai = !curbuf->b_p_ai; | |
4473 | |
4474 /* First autoindent comes from the line we start on */ | |
4475 if (eap->cmdidx != CMD_change && curbuf->b_p_ai && lnum > 0) | |
4476 append_indent = get_indent_lnum(lnum); | |
4477 | |
7 | 4478 if (eap->cmdidx != CMD_append) |
4479 --lnum; | |
4480 | |
9377
5ec4fbfe38c5
commit https://github.com/vim/vim/commit/70e136e1d86ea1d795774824c7b712245912946d
Christian Brabandt <cb@256bit.org>
parents:
9347
diff
changeset
|
4481 /* when the buffer is empty need to delete the dummy line */ |
165 | 4482 if (empty && lnum == 1) |
4483 lnum = 0; | |
4484 | |
7 | 4485 State = INSERT; /* behave like in Insert mode */ |
4486 if (curbuf->b_p_iminsert == B_IMODE_LMAP) | |
4487 State |= LANGMAP; | |
165 | 4488 |
408 | 4489 for (;;) |
7 | 4490 { |
4491 msg_scroll = TRUE; | |
4492 need_wait_return = FALSE; | |
169 | 4493 if (curbuf->b_p_ai) |
4494 { | |
4495 if (append_indent >= 0) | |
4496 { | |
4497 indent = append_indent; | |
4498 append_indent = -1; | |
4499 } | |
4500 else if (lnum > 0) | |
4501 indent = get_indent_lnum(lnum); | |
4502 } | |
4503 ex_keep_indent = FALSE; | |
7 | 4504 if (eap->getline == NULL) |
169 | 4505 { |
4506 /* No getline() function, use the lines that follow. This ends | |
4507 * when there is no more. */ | |
4508 if (eap->nextcmd == NULL || *eap->nextcmd == NUL) | |
4509 break; | |
4510 p = vim_strchr(eap->nextcmd, NL); | |
4511 if (p == NULL) | |
4512 p = eap->nextcmd + STRLEN(eap->nextcmd); | |
4513 theline = vim_strnsave(eap->nextcmd, (int)(p - eap->nextcmd)); | |
4514 if (*p != NUL) | |
4515 ++p; | |
4516 eap->nextcmd = p; | |
4517 } | |
7 | 4518 else |
6164 | 4519 { |
4520 int save_State = State; | |
4521 | |
4522 /* Set State to avoid the cursor shape to be set to INSERT mode | |
4523 * when getline() returns. */ | |
4524 State = CMDLINE; | |
7 | 4525 theline = eap->getline( |
4526 #ifdef FEAT_EVAL | |
76 | 4527 eap->cstack->cs_looplevel > 0 ? -1 : |
7 | 4528 #endif |
165 | 4529 NUL, eap->cookie, indent); |
6164 | 4530 State = save_State; |
4531 } | |
7 | 4532 lines_left = Rows - 1; |
165 | 4533 if (theline == NULL) |
4534 break; | |
4535 | |
169 | 4536 /* Using ^ CTRL-D in getexmodeline() makes us repeat the indent. */ |
4537 if (ex_keep_indent) | |
4538 append_indent = indent; | |
4539 | |
165 | 4540 /* Look for the "." after automatic indent. */ |
4541 vcol = 0; | |
4542 for (p = theline; indent > vcol; ++p) | |
4543 { | |
4544 if (*p == ' ') | |
4545 ++vcol; | |
4546 else if (*p == TAB) | |
4547 vcol += 8 - vcol % 8; | |
4548 else | |
4549 break; | |
4550 } | |
4551 if ((p[0] == '.' && p[1] == NUL) | |
321 | 4552 || (!did_undo && u_save(lnum, lnum + 1 + (empty ? 1 : 0)) |
4553 == FAIL)) | |
7 | 4554 { |
4555 vim_free(theline); | |
4556 break; | |
4557 } | |
4558 | |
169 | 4559 /* don't use autoindent if nothing was typed. */ |
4560 if (p[0] == NUL) | |
4561 theline[0] = NUL; | |
4562 | |
7 | 4563 did_undo = TRUE; |
4564 ml_append(lnum, theline, (colnr_T)0, FALSE); | |
9377
5ec4fbfe38c5
commit https://github.com/vim/vim/commit/70e136e1d86ea1d795774824c7b712245912946d
Christian Brabandt <cb@256bit.org>
parents:
9347
diff
changeset
|
4565 appended_lines_mark(lnum + (empty ? 1 : 0), 1L); |
7 | 4566 |
4567 vim_free(theline); | |
4568 ++lnum; | |
165 | 4569 |
4570 if (empty) | |
4571 { | |
4572 ml_delete(2L, FALSE); | |
4573 empty = FALSE; | |
4574 } | |
7 | 4575 } |
4576 State = NORMAL; | |
4577 | |
169 | 4578 if (eap->forceit) |
4579 curbuf->b_p_ai = !curbuf->b_p_ai; | |
4580 | |
7 | 4581 /* "start" is set to eap->line2+1 unless that position is invalid (when |
1227 | 4582 * eap->line2 pointed to the end of the buffer and nothing was appended) |
7 | 4583 * "end" is set to lnum when something has been appended, otherwise |
4584 * it is the same than "start" -- Acevedo */ | |
4585 curbuf->b_op_start.lnum = (eap->line2 < curbuf->b_ml.ml_line_count) ? | |
4586 eap->line2 + 1 : curbuf->b_ml.ml_line_count; | |
4587 if (eap->cmdidx != CMD_append) | |
4588 --curbuf->b_op_start.lnum; | |
4589 curbuf->b_op_end.lnum = (eap->line2 < lnum) | |
4590 ? lnum : curbuf->b_op_start.lnum; | |
4591 curbuf->b_op_start.col = curbuf->b_op_end.col = 0; | |
4592 curwin->w_cursor.lnum = lnum; | |
4593 check_cursor_lnum(); | |
4594 beginline(BL_SOL | BL_FIX); | |
4595 | |
4596 need_wait_return = FALSE; /* don't use wait_return() now */ | |
4597 ex_no_reprint = TRUE; | |
4598 } | |
4599 | |
4600 /* | |
4601 * ":change" | |
4602 */ | |
4603 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4604 ex_change(exarg_T *eap) |
7 | 4605 { |
4606 linenr_T lnum; | |
4607 | |
4608 if (eap->line2 >= eap->line1 | |
4609 && u_save(eap->line1 - 1, eap->line2 + 1) == FAIL) | |
4610 return; | |
4611 | |
169 | 4612 /* the ! flag toggles autoindent */ |
4613 if (eap->forceit ? !curbuf->b_p_ai : curbuf->b_p_ai) | |
4614 append_indent = get_indent_lnum(eap->line1); | |
4615 | |
7 | 4616 for (lnum = eap->line2; lnum >= eap->line1; --lnum) |
4617 { | |
4618 if (curbuf->b_ml.ml_flags & ML_EMPTY) /* nothing to delete */ | |
4619 break; | |
4620 ml_delete(eap->line1, FALSE); | |
4621 } | |
1929 | 4622 |
4623 /* make sure the cursor is not beyond the end of the file now */ | |
4624 check_cursor_lnum(); | |
7 | 4625 deleted_lines_mark(eap->line1, (long)(eap->line2 - lnum)); |
4626 | |
4627 /* ":append" on the line above the deleted lines. */ | |
4628 eap->line2 = eap->line1; | |
4629 ex_append(eap); | |
4630 } | |
4631 | |
4632 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4633 ex_z(exarg_T *eap) |
7 | 4634 { |
4635 char_u *x; | |
11303
ef32a5c74515
patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
11254
diff
changeset
|
4636 long bigness; |
165 | 4637 char_u *kind; |
7 | 4638 int minus = 0; |
4639 linenr_T start, end, curs, i; | |
4640 int j; | |
4641 linenr_T lnum = eap->line2; | |
4642 | |
165 | 4643 /* Vi compatible: ":z!" uses display height, without a count uses |
4644 * 'scroll' */ | |
4645 if (eap->forceit) | |
4646 bigness = curwin->w_height; | |
10357
59d01e335858
commit https://github.com/vim/vim/commit/459ca563128f2edb7e3bb190090bbb755a56dd55
Christian Brabandt <cb@256bit.org>
parents:
10299
diff
changeset
|
4647 else if (!ONE_WINDOW) |
5678 | 4648 bigness = curwin->w_height - 3; |
4649 else | |
165 | 4650 bigness = curwin->w_p_scr * 2; |
7 | 4651 if (bigness < 1) |
4652 bigness = 1; | |
4653 | |
4654 x = eap->arg; | |
165 | 4655 kind = x; |
4656 if (*kind == '-' || *kind == '+' || *kind == '=' | |
4657 || *kind == '^' || *kind == '.') | |
4658 ++x; | |
4659 while (*x == '-' || *x == '+') | |
7 | 4660 ++x; |
4661 | |
4662 if (*x != 0) | |
4663 { | |
4664 if (!VIM_ISDIGIT(*x)) | |
4665 { | |
4666 EMSG(_("E144: non-numeric argument to :z")); | |
4667 return; | |
4668 } | |
4669 else | |
165 | 4670 { |
11303
ef32a5c74515
patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
11254
diff
changeset
|
4671 bigness = atol((char *)x); |
ef32a5c74515
patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
11254
diff
changeset
|
4672 |
ef32a5c74515
patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
11254
diff
changeset
|
4673 /* bigness could be < 0 if atol(x) overflows. */ |
ef32a5c74515
patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
11254
diff
changeset
|
4674 if (bigness > 2 * curbuf->b_ml.ml_line_count || bigness < 0) |
ef32a5c74515
patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
11254
diff
changeset
|
4675 bigness = 2 * curbuf->b_ml.ml_line_count; |
ef32a5c74515
patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
11254
diff
changeset
|
4676 |
165 | 4677 p_window = bigness; |
169 | 4678 if (*kind == '=') |
4679 bigness += 2; | |
165 | 4680 } |
7 | 4681 } |
4682 | |
165 | 4683 /* the number of '-' and '+' multiplies the distance */ |
4684 if (*kind == '-' || *kind == '+') | |
4685 for (x = kind + 1; *x == *kind; ++x) | |
4686 ; | |
4687 | |
4688 switch (*kind) | |
7 | 4689 { |
4690 case '-': | |
2881 | 4691 start = lnum - bigness * (linenr_T)(x - kind) + 1; |
4692 end = start + bigness - 1; | |
165 | 4693 curs = end; |
7 | 4694 break; |
4695 | |
4696 case '=': | |
159 | 4697 start = lnum - (bigness + 1) / 2 + 1; |
4698 end = lnum + (bigness + 1) / 2 - 1; | |
7 | 4699 curs = lnum; |
4700 minus = 1; | |
4701 break; | |
4702 | |
4703 case '^': | |
4704 start = lnum - bigness * 2; | |
4705 end = lnum - bigness; | |
4706 curs = lnum - bigness; | |
4707 break; | |
4708 | |
4709 case '.': | |
159 | 4710 start = lnum - (bigness + 1) / 2 + 1; |
4711 end = lnum + (bigness + 1) / 2 - 1; | |
7 | 4712 curs = end; |
4713 break; | |
4714 | |
4715 default: /* '+' */ | |
4716 start = lnum; | |
165 | 4717 if (*kind == '+') |
835 | 4718 start += bigness * (linenr_T)(x - kind - 1) + 1; |
169 | 4719 else if (eap->addr_count == 0) |
4720 ++start; | |
4721 end = start + bigness - 1; | |
7 | 4722 curs = end; |
4723 break; | |
4724 } | |
4725 | |
4726 if (start < 1) | |
4727 start = 1; | |
4728 | |
4729 if (end > curbuf->b_ml.ml_line_count) | |
4730 end = curbuf->b_ml.ml_line_count; | |
4731 | |
4732 if (curs > curbuf->b_ml.ml_line_count) | |
4733 curs = curbuf->b_ml.ml_line_count; | |
11372
1074f58e1673
patch 8.0.0571: negative line number when using :z^ in an empty buffer
Christian Brabandt <cb@256bit.org>
parents:
11303
diff
changeset
|
4734 else if (curs < 1) |
1074f58e1673
patch 8.0.0571: negative line number when using :z^ in an empty buffer
Christian Brabandt <cb@256bit.org>
parents:
11303
diff
changeset
|
4735 curs = 1; |
7 | 4736 |
4737 for (i = start; i <= end; i++) | |
4738 { | |
4739 if (minus && i == lnum) | |
4740 { | |
4741 msg_putchar('\n'); | |
4742 | |
4743 for (j = 1; j < Columns; j++) | |
4744 msg_putchar('-'); | |
4745 } | |
4746 | |
169 | 4747 print_line(i, eap->flags & EXFLAG_NR, eap->flags & EXFLAG_LIST); |
7 | 4748 |
4749 if (minus && i == lnum) | |
4750 { | |
4751 msg_putchar('\n'); | |
4752 | |
4753 for (j = 1; j < Columns; j++) | |
4754 msg_putchar('-'); | |
4755 } | |
4756 } | |
4757 | |
11372
1074f58e1673
patch 8.0.0571: negative line number when using :z^ in an empty buffer
Christian Brabandt <cb@256bit.org>
parents:
11303
diff
changeset
|
4758 if (curwin->w_cursor.lnum != curs) |
1074f58e1673
patch 8.0.0571: negative line number when using :z^ in an empty buffer
Christian Brabandt <cb@256bit.org>
parents:
11303
diff
changeset
|
4759 { |
1074f58e1673
patch 8.0.0571: negative line number when using :z^ in an empty buffer
Christian Brabandt <cb@256bit.org>
parents:
11303
diff
changeset
|
4760 curwin->w_cursor.lnum = curs; |
1074f58e1673
patch 8.0.0571: negative line number when using :z^ in an empty buffer
Christian Brabandt <cb@256bit.org>
parents:
11303
diff
changeset
|
4761 curwin->w_cursor.col = 0; |
1074f58e1673
patch 8.0.0571: negative line number when using :z^ in an empty buffer
Christian Brabandt <cb@256bit.org>
parents:
11303
diff
changeset
|
4762 } |
7 | 4763 ex_no_reprint = TRUE; |
4764 } | |
4765 | |
4766 /* | |
4767 * Check if the restricted flag is set. | |
4768 * If so, give an error message and return TRUE. | |
4769 * Otherwise, return FALSE. | |
4770 */ | |
4771 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4772 check_restricted(void) |
7 | 4773 { |
4774 if (restricted) | |
4775 { | |
4776 EMSG(_("E145: Shell commands not allowed in rvim")); | |
4777 return TRUE; | |
4778 } | |
4779 return FALSE; | |
4780 } | |
4781 | |
4782 /* | |
4783 * Check if the secure flag is set (.exrc or .vimrc in current directory). | |
4784 * If so, give an error message and return TRUE. | |
4785 * Otherwise, return FALSE. | |
4786 */ | |
4787 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4788 check_secure(void) |
7 | 4789 { |
4790 if (secure) | |
4791 { | |
4792 secure = 2; | |
4793 EMSG(_(e_curdir)); | |
4794 return TRUE; | |
4795 } | |
4796 #ifdef HAVE_SANDBOX | |
4797 /* | |
4798 * In the sandbox more things are not allowed, including the things | |
4799 * disallowed in secure mode. | |
4800 */ | |
4801 if (sandbox != 0) | |
4802 { | |
4803 EMSG(_(e_sandbox)); | |
4804 return TRUE; | |
4805 } | |
4806 #endif | |
4807 return FALSE; | |
4808 } | |
4809 | |
4810 static char_u *old_sub = NULL; /* previous substitute pattern */ | |
4811 static int global_need_beginline; /* call beginline() after ":g" */ | |
4812 | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4813 /* |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4814 * Flags that are kept between calls to :substitute. |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4815 */ |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4816 typedef struct { |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4817 int do_all; /* do multiple substitutions per line */ |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4818 int do_ask; /* ask for confirmation */ |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4819 int do_count; /* count only */ |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4820 int do_error; /* if false, ignore errors */ |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4821 int do_print; /* print last line with subs. */ |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4822 int do_list; /* list last line with subs. */ |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4823 int do_number; /* list last line with line nr*/ |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4824 int do_ic; /* ignore case flag */ |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4825 } subflags_T; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4826 |
7 | 4827 /* do_sub() |
4828 * | |
4829 * Perform a substitution from line eap->line1 to line eap->line2 using the | |
4830 * command pointed to by eap->arg which should be of the form: | |
4831 * | |
4832 * /pattern/substitution/{flags} | |
4833 * | |
4834 * The usual escapes are supported as described in the regexp docs. | |
4835 */ | |
4836 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4837 do_sub(exarg_T *eap) |
7 | 4838 { |
4839 linenr_T lnum; | |
4840 long i = 0; | |
4841 regmmatch_T regmatch; | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4842 static subflags_T subflags = {FALSE, FALSE, FALSE, TRUE, FALSE, |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4843 FALSE, FALSE, 0}; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4844 #ifdef FEAT_EVAL |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4845 subflags_T subflags_save; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4846 #endif |
6789 | 4847 int save_do_all; /* remember user specified 'g' flag */ |
4848 int save_do_ask; /* remember user specified 'c' flag */ | |
7 | 4849 char_u *pat = NULL, *sub = NULL; /* init for GCC */ |
4850 int delimiter; | |
4851 int sublen; | |
4852 int got_quit = FALSE; | |
4853 int got_match = FALSE; | |
4854 int temp; | |
4855 int which_pat; | |
4856 char_u *cmd; | |
4857 int save_State; | |
165 | 4858 linenr_T first_line = 0; /* first changed line */ |
4859 linenr_T last_line= 0; /* below last changed line AFTER the | |
7 | 4860 * change */ |
4861 linenr_T old_line_count = curbuf->b_ml.ml_line_count; | |
4862 linenr_T line2; | |
165 | 4863 long nmatch; /* number of lines in match */ |
4864 char_u *sub_firstline; /* allocated copy of first sub line */ | |
4865 int endcolumn = FALSE; /* cursor in last column when done */ | |
170 | 4866 pos_T old_cursor = curwin->w_cursor; |
2126
e038754d419a
updated for version 7.2.408
Bram Moolenaar <bram@zimbu.org>
parents:
1929
diff
changeset
|
4867 int start_nsubs; |
3736 | 4868 #ifdef FEAT_EVAL |
5867 | 4869 int save_ma = 0; |
3736 | 4870 #endif |
7 | 4871 |
4872 cmd = eap->arg; | |
4873 if (!global_busy) | |
4874 { | |
4875 sub_nsubs = 0; | |
4876 sub_nlines = 0; | |
4877 } | |
2126
e038754d419a
updated for version 7.2.408
Bram Moolenaar <bram@zimbu.org>
parents:
1929
diff
changeset
|
4878 start_nsubs = sub_nsubs; |
7 | 4879 |
4880 if (eap->cmdidx == CMD_tilde) | |
4881 which_pat = RE_LAST; /* use last used regexp */ | |
4882 else | |
4883 which_pat = RE_SUBST; /* use last substitute regexp */ | |
4884 | |
4885 /* new pattern and substitution */ | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4886 if (eap->cmd[0] == 's' && *cmd != NUL && !VIM_ISWHITE(*cmd) |
7 | 4887 && vim_strchr((char_u *)"0123456789cegriIp|\"", *cmd) == NULL) |
4888 { | |
4889 /* don't accept alphanumeric for separator */ | |
4890 if (isalpha(*cmd)) | |
4891 { | |
4892 EMSG(_("E146: Regular expressions can't be delimited by letters")); | |
4893 return; | |
4894 } | |
4895 /* | |
4896 * undocumented vi feature: | |
4897 * "\/sub/" and "\?sub?" use last used search pattern (almost like | |
4898 * //sub/r). "\&sub&" use last substitute pattern (like //sub/). | |
4899 */ | |
4900 if (*cmd == '\\') | |
4901 { | |
4902 ++cmd; | |
4903 if (vim_strchr((char_u *)"/?&", *cmd) == NULL) | |
4904 { | |
4905 EMSG(_(e_backslash)); | |
4906 return; | |
4907 } | |
4908 if (*cmd != '&') | |
4909 which_pat = RE_SEARCH; /* use last '/' pattern */ | |
4910 pat = (char_u *)""; /* empty search pattern */ | |
4911 delimiter = *cmd++; /* remember delimiter character */ | |
4912 } | |
4913 else /* find the end of the regexp */ | |
4914 { | |
1466 | 4915 #ifdef FEAT_FKMAP /* reverse the flow of the Farsi characters */ |
4916 if (p_altkeymap && curwin->w_p_rl) | |
4917 lrF_sub(cmd); | |
4918 #endif | |
7 | 4919 which_pat = RE_LAST; /* use last used regexp */ |
4920 delimiter = *cmd++; /* remember delimiter character */ | |
4921 pat = cmd; /* remember start of search pat */ | |
4922 cmd = skip_regexp(cmd, delimiter, p_magic, &eap->arg); | |
4923 if (cmd[0] == delimiter) /* end delimiter found */ | |
4924 *cmd++ = NUL; /* replace it with a NUL */ | |
4925 } | |
4926 | |
4927 /* | |
4928 * Small incompatibility: vi sees '\n' as end of the command, but in | |
4929 * Vim we want to use '\n' to find/substitute a NUL. | |
4930 */ | |
4931 sub = cmd; /* remember the start of the substitution */ | |
4932 | |
4933 while (cmd[0]) | |
4934 { | |
4935 if (cmd[0] == delimiter) /* end delimiter found */ | |
4936 { | |
4937 *cmd++ = NUL; /* replace it with a NUL */ | |
4938 break; | |
4939 } | |
4940 if (cmd[0] == '\\' && cmd[1] != 0) /* skip escaped characters */ | |
4941 ++cmd; | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11123
diff
changeset
|
4942 MB_PTR_ADV(cmd); |
7 | 4943 } |
4944 | |
4945 if (!eap->skip) | |
4946 { | |
169 | 4947 /* In POSIX vi ":s/pat/%/" uses the previous subst. string. */ |
4948 if (STRCMP(sub, "%") == 0 | |
4949 && vim_strchr(p_cpo, CPO_SUBPERCENT) != NULL) | |
4950 { | |
4951 if (old_sub == NULL) /* there is no previous command */ | |
4952 { | |
4953 EMSG(_(e_nopresub)); | |
4954 return; | |
4955 } | |
4956 sub = old_sub; | |
4957 } | |
4958 else | |
4959 { | |
4960 vim_free(old_sub); | |
4961 old_sub = vim_strsave(sub); | |
4962 } | |
7 | 4963 } |
4964 } | |
4965 else if (!eap->skip) /* use previous pattern and substitution */ | |
4966 { | |
4967 if (old_sub == NULL) /* there is no previous command */ | |
4968 { | |
4969 EMSG(_(e_nopresub)); | |
4970 return; | |
4971 } | |
4972 pat = NULL; /* search_regcomp() will use previous pattern */ | |
4973 sub = old_sub; | |
163 | 4974 |
4975 /* Vi compatibility quirk: repeating with ":s" keeps the cursor in the | |
4976 * last column after using "$". */ | |
4977 endcolumn = (curwin->w_curswant == MAXCOL); | |
7 | 4978 } |
4979 | |
5776 | 4980 /* Recognize ":%s/\n//" and turn it into a join command, which is much |
4981 * more efficient. | |
4982 * TODO: find a generic solution to make line-joining operations more | |
4983 * efficient, avoid allocating a string that grows in size. | |
4984 */ | |
5802 | 4985 if (pat != NULL && STRCMP(pat, "\\n") == 0 |
5776 | 4986 && *sub == NUL |
4987 && (*cmd == NUL || (cmd[1] == NUL && (*cmd == 'g' || *cmd == 'l' | |
4988 || *cmd == 'p' || *cmd == '#')))) | |
4989 { | |
6426 | 4990 linenr_T joined_lines_count; |
4991 | |
5776 | 4992 curwin->w_cursor.lnum = eap->line1; |
4993 if (*cmd == 'l') | |
4994 eap->flags = EXFLAG_LIST; | |
4995 else if (*cmd == '#') | |
4996 eap->flags = EXFLAG_NR; | |
4997 else if (*cmd == 'p') | |
4998 eap->flags = EXFLAG_PRINT; | |
4999 | |
6426 | 5000 /* The number of lines joined is the number of lines in the range plus |
5001 * one. One less when the last line is included. */ | |
5002 joined_lines_count = eap->line2 - eap->line1 + 1; | |
5003 if (eap->line2 < curbuf->b_ml.ml_line_count) | |
5004 ++joined_lines_count; | |
5005 if (joined_lines_count > 1) | |
5006 { | |
5007 (void)do_join(joined_lines_count, FALSE, TRUE, FALSE, TRUE); | |
5008 sub_nsubs = joined_lines_count - 1; | |
5009 sub_nlines = 1; | |
5010 (void)do_sub_msg(FALSE); | |
5011 ex_may_print(eap); | |
5012 } | |
5013 | |
5014 if (!cmdmod.keeppatterns) | |
5015 save_re_pat(RE_SUBST, pat, p_magic); | |
5016 #ifdef FEAT_CMDHIST | |
5017 /* put pattern in history */ | |
5018 add_to_history(HIST_SEARCH, pat, TRUE, NUL); | |
5019 #endif | |
5020 | |
5776 | 5021 return; |
5022 } | |
5023 | |
7 | 5024 /* |
5025 * Find trailing options. When '&' is used, keep old options. | |
5026 */ | |
5027 if (*cmd == '&') | |
5028 ++cmd; | |
5029 else | |
5030 { | |
5031 if (!p_ed) | |
5032 { | |
5033 if (p_gd) /* default is global on */ | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5034 subflags.do_all = TRUE; |
7 | 5035 else |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5036 subflags.do_all = FALSE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5037 subflags.do_ask = FALSE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5038 } |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5039 subflags.do_error = TRUE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5040 subflags.do_print = FALSE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5041 subflags.do_count = FALSE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5042 subflags.do_number = FALSE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5043 subflags.do_ic = 0; |
7 | 5044 } |
5045 while (*cmd) | |
5046 { | |
5047 /* | |
5048 * Note that 'g' and 'c' are always inverted, also when p_ed is off. | |
5049 * 'r' is never inverted. | |
5050 */ | |
5051 if (*cmd == 'g') | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5052 subflags.do_all = !subflags.do_all; |
7 | 5053 else if (*cmd == 'c') |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5054 subflags.do_ask = !subflags.do_ask; |
170 | 5055 else if (*cmd == 'n') |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5056 subflags.do_count = TRUE; |
7 | 5057 else if (*cmd == 'e') |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5058 subflags.do_error = !subflags.do_error; |
7 | 5059 else if (*cmd == 'r') /* use last used regexp */ |
5060 which_pat = RE_LAST; | |
5061 else if (*cmd == 'p') | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5062 subflags.do_print = TRUE; |
169 | 5063 else if (*cmd == '#') |
5064 { | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5065 subflags.do_print = TRUE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5066 subflags.do_number = TRUE; |
169 | 5067 } |
5068 else if (*cmd == 'l') | |
5069 { | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5070 subflags.do_print = TRUE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5071 subflags.do_list = TRUE; |
169 | 5072 } |
7 | 5073 else if (*cmd == 'i') /* ignore case */ |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5074 subflags.do_ic = 'i'; |
7 | 5075 else if (*cmd == 'I') /* don't ignore case */ |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5076 subflags.do_ic = 'I'; |
7 | 5077 else |
5078 break; | |
5079 ++cmd; | |
5080 } | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5081 if (subflags.do_count) |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5082 subflags.do_ask = FALSE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5083 |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5084 save_do_all = subflags.do_all; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5085 save_do_ask = subflags.do_ask; |
6789 | 5086 |
7 | 5087 /* |
5088 * check for a trailing count | |
5089 */ | |
5090 cmd = skipwhite(cmd); | |
5091 if (VIM_ISDIGIT(*cmd)) | |
5092 { | |
5093 i = getdigits(&cmd); | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5094 if (i <= 0 && !eap->skip && subflags.do_error) |
7 | 5095 { |
5096 EMSG(_(e_zerocount)); | |
5097 return; | |
5098 } | |
5099 eap->line1 = eap->line2; | |
5100 eap->line2 += i - 1; | |
5101 if (eap->line2 > curbuf->b_ml.ml_line_count) | |
5102 eap->line2 = curbuf->b_ml.ml_line_count; | |
5103 } | |
5104 | |
5105 /* | |
5106 * check for trailing command or garbage | |
5107 */ | |
5108 cmd = skipwhite(cmd); | |
5109 if (*cmd && *cmd != '"') /* if not end-of-line or comment */ | |
5110 { | |
5111 eap->nextcmd = check_nextcmd(cmd); | |
5112 if (eap->nextcmd == NULL) | |
5113 { | |
5114 EMSG(_(e_trailing)); | |
5115 return; | |
5116 } | |
5117 } | |
5118 | |
5119 if (eap->skip) /* not executing commands, only parsing */ | |
5120 return; | |
5121 | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5122 if (!subflags.do_count && !curbuf->b_p_ma) |
823 | 5123 { |
825 | 5124 /* Substitution is not allowed in non-'modifiable' buffer */ |
823 | 5125 EMSG(_(e_modifiable)); |
5126 return; | |
5127 } | |
5128 | |
7 | 5129 if (search_regcomp(pat, RE_SUBST, which_pat, SEARCH_HIS, ®match) == FAIL) |
5130 { | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5131 if (subflags.do_error) |
7 | 5132 EMSG(_(e_invcmd)); |
5133 return; | |
5134 } | |
5135 | |
5136 /* the 'i' or 'I' flag overrules 'ignorecase' and 'smartcase' */ | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5137 if (subflags.do_ic == 'i') |
7 | 5138 regmatch.rmm_ic = TRUE; |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5139 else if (subflags.do_ic == 'I') |
7 | 5140 regmatch.rmm_ic = FALSE; |
5141 | |
5142 sub_firstline = NULL; | |
5143 | |
5144 /* | |
5145 * ~ in the substitute pattern is replaced with the old pattern. | |
5146 * We do it here once to avoid it to be replaced over and over again. | |
5147 * But don't do it when it starts with "\=", then it's an expression. | |
5148 */ | |
5149 if (!(sub[0] == '\\' && sub[1] == '=')) | |
5150 sub = regtilde(sub, p_magic); | |
5151 | |
5152 /* | |
5153 * Check for a match on each line. | |
5154 */ | |
5155 line2 = eap->line2; | |
5156 for (lnum = eap->line1; lnum <= line2 && !(got_quit | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
5157 #if defined(FEAT_EVAL) |
7 | 5158 || aborting() |
5159 #endif | |
5160 ); ++lnum) | |
5161 { | |
1521 | 5162 nmatch = vim_regexec_multi(®match, curwin, curbuf, lnum, |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11494
diff
changeset
|
5163 (colnr_T)0, NULL, NULL); |
7 | 5164 if (nmatch) |
5165 { | |
5166 colnr_T copycol; | |
5167 colnr_T matchcol; | |
5168 colnr_T prev_matchcol = MAXCOL; | |
5169 char_u *new_end, *new_start = NULL; | |
5170 unsigned new_start_len = 0; | |
5171 char_u *p1; | |
5172 int did_sub = FALSE; | |
5173 int lastone; | |
1872 | 5174 int len, copy_len, needed_len; |
7 | 5175 long nmatch_tl = 0; /* nr of lines matched below lnum */ |
5176 int do_again; /* do it again after joining lines */ | |
15 | 5177 int skip_match = FALSE; |
1499 | 5178 linenr_T sub_firstlnum; /* nr of first sub line */ |
7 | 5179 |
5180 /* | |
5181 * The new text is build up step by step, to avoid too much | |
5182 * copying. There are these pieces: | |
1581 | 5183 * sub_firstline The old text, unmodified. |
7 | 5184 * copycol Column in the old text where we started |
5185 * looking for a match; from here old text still | |
5186 * needs to be copied to the new text. | |
5187 * matchcol Column number of the old text where to look | |
5188 * for the next match. It's just after the | |
5189 * previous match or one further. | |
5190 * prev_matchcol Column just after the previous match (if any). | |
5191 * Mostly equal to matchcol, except for the first | |
5192 * match and after skipping an empty match. | |
5193 * regmatch.*pos Where the pattern matched in the old text. | |
5194 * new_start The new text, all that has been produced so | |
5195 * far. | |
5196 * new_end The new text, where to append new text. | |
5197 * | |
1499 | 5198 * lnum The line number where we found the start of |
5199 * the match. Can be below the line we searched | |
5200 * when there is a \n before a \zs in the | |
5201 * pattern. | |
7 | 5202 * sub_firstlnum The line number in the buffer where to look |
5203 * for a match. Can be different from "lnum" | |
5204 * when the pattern or substitute string contains | |
5205 * line breaks. | |
5206 * | |
5207 * Special situations: | |
5208 * - When the substitute string contains a line break, the part up | |
5209 * to the line break is inserted in the text, but the copy of | |
5210 * the original line is kept. "sub_firstlnum" is adjusted for | |
5211 * the inserted lines. | |
5212 * - When the matched pattern contains a line break, the old line | |
5213 * is taken from the line at the end of the pattern. The lines | |
5214 * in the match are deleted later, "sub_firstlnum" is adjusted | |
5215 * accordingly. | |
5216 * | |
5217 * The new text is built up in new_start[]. It has some extra | |
5218 * room to avoid using alloc()/free() too often. new_start_len is | |
1389 | 5219 * the length of the allocated memory at new_start. |
7 | 5220 * |
5221 * Make a copy of the old line, so it won't be taken away when | |
5222 * updating the screen or handling a multi-line match. The "old_" | |
5223 * pointers point into this copy. | |
5224 */ | |
1499 | 5225 sub_firstlnum = lnum; |
7 | 5226 copycol = 0; |
5227 matchcol = 0; | |
5228 | |
5229 /* At first match, remember current cursor position. */ | |
5230 if (!got_match) | |
5231 { | |
5232 setpcmark(); | |
5233 got_match = TRUE; | |
5234 } | |
5235 | |
5236 /* | |
5237 * Loop until nothing more to replace in this line. | |
5238 * 1. Handle match with empty string. | |
5239 * 2. If do_ask is set, ask for confirmation. | |
5240 * 3. substitute the string. | |
5241 * 4. if do_all is set, find next match | |
5242 * 5. break if there isn't another match in this line | |
5243 */ | |
5244 for (;;) | |
5245 { | |
1499 | 5246 /* Advance "lnum" to the line where the match starts. The |
5247 * match does not start in the first line when there is a line | |
5248 * break before \zs. */ | |
5249 if (regmatch.startpos[0].lnum > 0) | |
5250 { | |
5251 lnum += regmatch.startpos[0].lnum; | |
5252 sub_firstlnum += regmatch.startpos[0].lnum; | |
5253 nmatch -= regmatch.startpos[0].lnum; | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13174
diff
changeset
|
5254 VIM_CLEAR(sub_firstline); |
1499 | 5255 } |
5256 | |
5257 if (sub_firstline == NULL) | |
5258 { | |
5259 sub_firstline = vim_strsave(ml_get(sub_firstlnum)); | |
5260 if (sub_firstline == NULL) | |
5261 { | |
5262 vim_free(new_start); | |
5263 goto outofmem; | |
5264 } | |
5265 } | |
5266 | |
7 | 5267 /* Save the line number of the last change for the final |
5268 * cursor position (just like Vi). */ | |
5269 curwin->w_cursor.lnum = lnum; | |
5270 do_again = FALSE; | |
5271 | |
5272 /* | |
5273 * 1. Match empty string does not count, except for first | |
5274 * match. This reproduces the strange vi behaviour. | |
5275 * This also catches endless loops. | |
5276 */ | |
5277 if (matchcol == prev_matchcol | |
5278 && regmatch.endpos[0].lnum == 0 | |
5279 && matchcol == regmatch.endpos[0].col) | |
5280 { | |
15 | 5281 if (sub_firstline[matchcol] == NUL) |
5282 /* We already were at the end of the line. Don't look | |
5283 * for a match in this line again. */ | |
5284 skip_match = TRUE; | |
5285 else | |
2837 | 5286 { |
5287 /* search for a match at next column */ | |
5288 #ifdef FEAT_MBYTE | |
5289 if (has_mbyte) | |
5290 matchcol += mb_ptr2len(sub_firstline + matchcol); | |
5291 else | |
5292 #endif | |
5293 ++matchcol; | |
5294 } | |
7 | 5295 goto skip; |
5296 } | |
5297 | |
5298 /* Normally we continue searching for a match just after the | |
5299 * previous match. */ | |
5300 matchcol = regmatch.endpos[0].col; | |
5301 prev_matchcol = matchcol; | |
5302 | |
5303 /* | |
170 | 5304 * 2. If do_count is set only increase the counter. |
5305 * If do_ask is set, ask for confirmation. | |
7 | 5306 */ |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5307 if (subflags.do_count) |
170 | 5308 { |
5309 /* For a multi-line match, put matchcol at the NUL at | |
5310 * the end of the line and set nmatch to one, so that | |
5311 * we continue looking for a match on the next line. | |
5312 * Avoids that ":s/\nB\@=//gc" get stuck. */ | |
5313 if (nmatch > 1) | |
5314 { | |
835 | 5315 matchcol = (colnr_T)STRLEN(sub_firstline); |
170 | 5316 nmatch = 1; |
1483 | 5317 skip_match = TRUE; |
170 | 5318 } |
5319 sub_nsubs++; | |
5320 did_sub = TRUE; | |
3736 | 5321 #ifdef FEAT_EVAL |
5322 /* Skip the substitution, unless an expression is used, | |
5323 * then it is evaluated in the sandbox. */ | |
5324 if (!(sub[0] == '\\' && sub[1] == '=')) | |
5325 #endif | |
5326 goto skip; | |
170 | 5327 } |
5328 | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5329 if (subflags.do_ask) |
7 | 5330 { |
1874 | 5331 int typed = 0; |
1872 | 5332 |
7 | 5333 /* change State to CONFIRM, so that the mouse works |
5334 * properly */ | |
5335 save_State = State; | |
5336 State = CONFIRM; | |
5337 #ifdef FEAT_MOUSE | |
5338 setmouse(); /* disable mouse in xterm */ | |
5339 #endif | |
5340 curwin->w_cursor.col = regmatch.startpos[0].col; | |
10638
21f983648487
patch 8.0.0209: cursor binding does not work with :substitute
Christian Brabandt <cb@256bit.org>
parents:
10575
diff
changeset
|
5341 if (curwin->w_p_crb) |
21f983648487
patch 8.0.0209: cursor binding does not work with :substitute
Christian Brabandt <cb@256bit.org>
parents:
10575
diff
changeset
|
5342 do_check_cursorbind(); |
7 | 5343 |
5344 /* When 'cpoptions' contains "u" don't sync undo when | |
5345 * asking for confirmation. */ | |
5346 if (vim_strchr(p_cpo, CPO_UNDO) != NULL) | |
5347 ++no_u_sync; | |
5348 | |
5349 /* | |
5350 * Loop until 'y', 'n', 'q', CTRL-E or CTRL-Y typed. | |
5351 */ | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5352 while (subflags.do_ask) |
7 | 5353 { |
169 | 5354 if (exmode_active) |
5355 { | |
5356 char_u *resp; | |
5357 colnr_T sc, ec; | |
5358 | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5359 print_line_no_prefix(lnum, |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5360 subflags.do_number, subflags.do_list); |
169 | 5361 |
5362 getvcol(curwin, &curwin->w_cursor, &sc, NULL, NULL); | |
5363 curwin->w_cursor.col = regmatch.endpos[0].col - 1; | |
10970
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10853
diff
changeset
|
5364 if (curwin->w_cursor.col < 0) |
ab9f7bbe4439
patch 8.0.0374: invalid memory access when using :sc in Ex mode
Christian Brabandt <cb@256bit.org>
parents:
10853
diff
changeset
|
5365 curwin->w_cursor.col = 0; |
169 | 5366 getvcol(curwin, &curwin->w_cursor, NULL, NULL, &ec); |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5367 if (subflags.do_number || curwin->w_p_nu) |
5396 | 5368 { |
5369 int numw = number_width(curwin) + 1; | |
5370 sc += numw; | |
5371 ec += numw; | |
5372 } | |
169 | 5373 msg_start(); |
170 | 5374 for (i = 0; i < (long)sc; ++i) |
169 | 5375 msg_putchar(' '); |
170 | 5376 for ( ; i <= (long)ec; ++i) |
169 | 5377 msg_putchar('^'); |
5378 | |
5379 resp = getexmodeline('?', NULL, 0); | |
5380 if (resp != NULL) | |
5381 { | |
1872 | 5382 typed = *resp; |
169 | 5383 vim_free(resp); |
5384 } | |
5385 } | |
5386 else | |
5387 { | |
4076 | 5388 char_u *orig_line = NULL; |
5389 int len_change = 0; | |
7 | 5390 #ifdef FEAT_FOLDING |
169 | 5391 int save_p_fen = curwin->w_p_fen; |
5392 | |
5393 curwin->w_p_fen = FALSE; | |
5394 #endif | |
5395 /* Invert the matched string. | |
5396 * Remove the inversion afterwards. */ | |
5397 temp = RedrawingDisabled; | |
5398 RedrawingDisabled = 0; | |
5399 | |
4076 | 5400 if (new_start != NULL) |
5401 { | |
5402 /* There already was a substitution, we would | |
5403 * like to show this to the user. We cannot | |
5404 * really update the line, it would change | |
5405 * what matches. Temporarily replace the line | |
5406 * and change it back afterwards. */ | |
5407 orig_line = vim_strsave(ml_get(lnum)); | |
5408 if (orig_line != NULL) | |
5409 { | |
5410 char_u *new_line = concat_str(new_start, | |
5411 sub_firstline + copycol); | |
5412 | |
5413 if (new_line == NULL) | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13174
diff
changeset
|
5414 VIM_CLEAR(orig_line); |
4076 | 5415 else |
5416 { | |
5417 /* Position the cursor relative to the | |
5418 * end of the line, the previous | |
5419 * substitute may have inserted or | |
5420 * deleted characters before the | |
5421 * cursor. */ | |
4086 | 5422 len_change = (int)STRLEN(new_line) |
5423 - (int)STRLEN(orig_line); | |
4076 | 5424 curwin->w_cursor.col += len_change; |
5425 ml_replace(lnum, new_line, FALSE); | |
5426 } | |
5427 } | |
5428 } | |
5429 | |
1499 | 5430 search_match_lines = regmatch.endpos[0].lnum |
5431 - regmatch.startpos[0].lnum; | |
4076 | 5432 search_match_endcol = regmatch.endpos[0].col |
5433 + len_change; | |
169 | 5434 highlight_match = TRUE; |
5435 | |
5436 update_topline(); | |
5437 validate_cursor(); | |
748 | 5438 update_screen(SOME_VALID); |
169 | 5439 highlight_match = FALSE; |
748 | 5440 redraw_later(SOME_VALID); |
7 | 5441 |
5442 #ifdef FEAT_FOLDING | |
169 | 5443 curwin->w_p_fen = save_p_fen; |
5444 #endif | |
5445 if (msg_row == Rows - 1) | |
5446 msg_didout = FALSE; /* avoid a scroll-up */ | |
5447 msg_starthere(); | |
5448 i = msg_scroll; | |
5449 msg_scroll = 0; /* truncate msg when | |
5450 needed */ | |
5451 msg_no_more = TRUE; | |
5452 /* write message same highlighting as for | |
5453 * wait_return */ | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11144
diff
changeset
|
5454 smsg_attr(HL_ATTR(HLF_R), |
169 | 5455 (char_u *)_("replace with %s (y/n/a/q/l/^E/^Y)?"), sub); |
5456 msg_no_more = FALSE; | |
5457 msg_scroll = i; | |
5458 showruler(TRUE); | |
5459 windgoto(msg_row, msg_col); | |
5460 RedrawingDisabled = temp; | |
7 | 5461 |
5462 #ifdef USE_ON_FLY_SCROLL | |
169 | 5463 dont_scroll = FALSE; /* allow scrolling here */ |
5464 #endif | |
5465 ++no_mapping; /* don't map this key */ | |
5466 ++allow_keys; /* allow special keys */ | |
1872 | 5467 typed = plain_vgetc(); |
169 | 5468 --allow_keys; |
5469 --no_mapping; | |
5470 | |
5471 /* clear the question */ | |
5472 msg_didout = FALSE; /* don't scroll up */ | |
5473 msg_col = 0; | |
5474 gotocmdline(TRUE); | |
4076 | 5475 |
5476 /* restore the line */ | |
5477 if (orig_line != NULL) | |
5478 ml_replace(lnum, orig_line, FALSE); | |
169 | 5479 } |
5480 | |
7 | 5481 need_wait_return = FALSE; /* no hit-return prompt */ |
1872 | 5482 if (typed == 'q' || typed == ESC || typed == Ctrl_C |
7 | 5483 #ifdef UNIX |
1872 | 5484 || typed == intr_char |
7 | 5485 #endif |
5486 ) | |
5487 { | |
5488 got_quit = TRUE; | |
5489 break; | |
5490 } | |
1872 | 5491 if (typed == 'n') |
7 | 5492 break; |
1872 | 5493 if (typed == 'y') |
7 | 5494 break; |
1872 | 5495 if (typed == 'l') |
7 | 5496 { |
5497 /* last: replace and then stop */ | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5498 subflags.do_all = FALSE; |
7 | 5499 line2 = lnum; |
5500 break; | |
5501 } | |
1872 | 5502 if (typed == 'a') |
7 | 5503 { |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5504 subflags.do_ask = FALSE; |
7 | 5505 break; |
5506 } | |
5507 #ifdef FEAT_INS_EXPAND | |
1872 | 5508 if (typed == Ctrl_E) |
7 | 5509 scrollup_clamp(); |
1872 | 5510 else if (typed == Ctrl_Y) |
7 | 5511 scrolldown_clamp(); |
5512 #endif | |
5513 } | |
5514 State = save_State; | |
5515 #ifdef FEAT_MOUSE | |
5516 setmouse(); | |
5517 #endif | |
5518 if (vim_strchr(p_cpo, CPO_UNDO) != NULL) | |
5519 --no_u_sync; | |
5520 | |
1872 | 5521 if (typed == 'n') |
7 | 5522 { |
5523 /* For a multi-line match, put matchcol at the NUL at | |
5524 * the end of the line and set nmatch to one, so that | |
5525 * we continue looking for a match on the next line. | |
1091 | 5526 * Avoids that ":%s/\nB\@=//gc" and ":%s/\n/,\r/gc" |
5527 * get stuck when pressing 'n'. */ | |
7 | 5528 if (nmatch > 1) |
5529 { | |
835 | 5530 matchcol = (colnr_T)STRLEN(sub_firstline); |
1091 | 5531 skip_match = TRUE; |
7 | 5532 } |
5533 goto skip; | |
5534 } | |
5535 if (got_quit) | |
4099 | 5536 goto skip; |
7 | 5537 } |
5538 | |
5539 /* Move the cursor to the start of the match, so that we can | |
5540 * use "\=col("."). */ | |
5541 curwin->w_cursor.col = regmatch.startpos[0].col; | |
5542 | |
5543 /* | |
5544 * 3. substitute the string. | |
5545 */ | |
3736 | 5546 #ifdef FEAT_EVAL |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5547 if (subflags.do_count) |
3736 | 5548 { |
3786 | 5549 /* prevent accidentally changing the buffer by a function */ |
3736 | 5550 save_ma = curbuf->b_p_ma; |
5551 curbuf->b_p_ma = FALSE; | |
5552 sandbox++; | |
5553 } | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5554 /* Save flags for recursion. They can change for e.g. |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5555 * :s/^/\=execute("s#^##gn") */ |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5556 subflags_save = subflags; |
3736 | 5557 #endif |
7 | 5558 /* get length of substitution part */ |
1499 | 5559 sublen = vim_regsub_multi(®match, |
5560 sub_firstlnum - regmatch.startpos[0].lnum, | |
7 | 5561 sub, sub_firstline, FALSE, p_magic, TRUE); |
3736 | 5562 #ifdef FEAT_EVAL |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5563 /* Don't keep flags set by a recursive call. */ |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5564 subflags = subflags_save; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5565 if (subflags.do_count) |
3736 | 5566 { |
5567 curbuf->b_p_ma = save_ma; | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5568 if (sandbox > 0) |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5569 sandbox--; |
3736 | 5570 goto skip; |
5571 } | |
5572 #endif | |
7 | 5573 |
533 | 5574 /* When the match included the "$" of the last line it may |
819 | 5575 * go beyond the last line of the buffer. */ |
533 | 5576 if (nmatch > curbuf->b_ml.ml_line_count - sub_firstlnum + 1) |
5577 { | |
5578 nmatch = curbuf->b_ml.ml_line_count - sub_firstlnum + 1; | |
5579 skip_match = TRUE; | |
5580 } | |
5581 | |
7 | 5582 /* Need room for: |
5583 * - result so far in new_start (not for first sub in line) | |
5584 * - original text up to match | |
5585 * - length of substituted part | |
5586 * - original text after match | |
5587 */ | |
5588 if (nmatch == 1) | |
5589 p1 = sub_firstline; | |
5590 else | |
5591 { | |
5592 p1 = ml_get(sub_firstlnum + nmatch - 1); | |
5593 nmatch_tl += nmatch - 1; | |
5594 } | |
1872 | 5595 copy_len = regmatch.startpos[0].col - copycol; |
5596 needed_len = copy_len + ((unsigned)STRLEN(p1) | |
5597 - regmatch.endpos[0].col) + sublen + 1; | |
7 | 5598 if (new_start == NULL) |
5599 { | |
5600 /* | |
5601 * Get some space for a temporary buffer to do the | |
5602 * substitution into (and some extra space to avoid | |
5603 * too many calls to alloc()/free()). | |
5604 */ | |
5605 new_start_len = needed_len + 50; | |
5606 if ((new_start = alloc_check(new_start_len)) == NULL) | |
5607 goto outofmem; | |
5608 *new_start = NUL; | |
5609 new_end = new_start; | |
5610 } | |
5611 else | |
5612 { | |
5613 /* | |
5614 * Check if the temporary buffer is long enough to do the | |
5615 * substitution into. If not, make it larger (with a bit | |
5616 * extra to avoid too many calls to alloc()/free()). | |
5617 */ | |
5618 len = (unsigned)STRLEN(new_start); | |
5619 needed_len += len; | |
1872 | 5620 if (needed_len > (int)new_start_len) |
7 | 5621 { |
5622 new_start_len = needed_len + 50; | |
5623 if ((p1 = alloc_check(new_start_len)) == NULL) | |
5624 { | |
5625 vim_free(new_start); | |
5626 goto outofmem; | |
5627 } | |
5628 mch_memmove(p1, new_start, (size_t)(len + 1)); | |
5629 vim_free(new_start); | |
5630 new_start = p1; | |
5631 } | |
5632 new_end = new_start + len; | |
5633 } | |
5634 | |
5635 /* | |
5636 * copy the text up to the part that matched | |
5637 */ | |
1872 | 5638 mch_memmove(new_end, sub_firstline + copycol, (size_t)copy_len); |
5639 new_end += copy_len; | |
7 | 5640 |
1499 | 5641 (void)vim_regsub_multi(®match, |
5642 sub_firstlnum - regmatch.startpos[0].lnum, | |
7 | 5643 sub, new_end, TRUE, p_magic, TRUE); |
5644 sub_nsubs++; | |
5645 did_sub = TRUE; | |
5646 | |
5647 /* Move the cursor to the start of the line, to avoid that it | |
5648 * is beyond the end of the line after the substitution. */ | |
5649 curwin->w_cursor.col = 0; | |
5650 | |
5651 /* For a multi-line match, make a copy of the last matched | |
5652 * line and continue in that one. */ | |
5653 if (nmatch > 1) | |
5654 { | |
5655 sub_firstlnum += nmatch - 1; | |
5656 vim_free(sub_firstline); | |
5657 sub_firstline = vim_strsave(ml_get(sub_firstlnum)); | |
5658 /* When going beyond the last line, stop substituting. */ | |
5659 if (sub_firstlnum <= line2) | |
5660 do_again = TRUE; | |
5661 else | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5662 subflags.do_all = FALSE; |
7 | 5663 } |
5664 | |
5665 /* Remember next character to be copied. */ | |
5666 copycol = regmatch.endpos[0].col; | |
5667 | |
819 | 5668 if (skip_match) |
5669 { | |
5670 /* Already hit end of the buffer, sub_firstlnum is one | |
5671 * less than what it ought to be. */ | |
5672 vim_free(sub_firstline); | |
5673 sub_firstline = vim_strsave((char_u *)""); | |
5674 copycol = 0; | |
5675 } | |
5676 | |
7 | 5677 /* |
5678 * Now the trick is to replace CTRL-M chars with a real line | |
5679 * break. This would make it impossible to insert a CTRL-M in | |
5680 * the text. The line break can be avoided by preceding the | |
5681 * CTRL-M with a backslash. To be able to insert a backslash, | |
5682 * they must be doubled in the string and are halved here. | |
5683 * That is Vi compatible. | |
5684 */ | |
5685 for (p1 = new_end; *p1; ++p1) | |
5686 { | |
5687 if (p1[0] == '\\' && p1[1] != NUL) /* remove backslash */ | |
1624 | 5688 STRMOVE(p1, p1 + 1); |
7 | 5689 else if (*p1 == CAR) |
5690 { | |
5691 if (u_inssub(lnum) == OK) /* prepare for undo */ | |
5692 { | |
5693 *p1 = NUL; /* truncate up to the CR */ | |
5694 ml_append(lnum - 1, new_start, | |
5695 (colnr_T)(p1 - new_start + 1), FALSE); | |
5696 mark_adjust(lnum + 1, (linenr_T)MAXLNUM, 1L, 0L); | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5697 if (subflags.do_ask) |
7 | 5698 appended_lines(lnum - 1, 1L); |
5699 else | |
5700 { | |
5701 if (first_line == 0) | |
5702 first_line = lnum; | |
5703 last_line = lnum + 1; | |
5704 } | |
5705 /* All line numbers increase. */ | |
5706 ++sub_firstlnum; | |
5707 ++lnum; | |
5708 ++line2; | |
5709 /* move the cursor to the new line, like Vi */ | |
5710 ++curwin->w_cursor.lnum; | |
1444 | 5711 /* copy the rest */ |
1624 | 5712 STRMOVE(new_start, p1 + 1); |
7 | 5713 p1 = new_start - 1; |
5714 } | |
5715 } | |
5716 #ifdef FEAT_MBYTE | |
5717 else if (has_mbyte) | |
474 | 5718 p1 += (*mb_ptr2len)(p1) - 1; |
7 | 5719 #endif |
5720 } | |
5721 | |
5722 /* | |
5723 * 4. If do_all is set, find next match. | |
5724 * Prevent endless loop with patterns that match empty | |
5725 * strings, e.g. :s/$/pat/g or :s/[a-z]* /(&)/g. | |
5726 * But ":s/\n/#/" is OK. | |
5727 */ | |
5728 skip: | |
5729 /* We already know that we did the last subst when we are at | |
5730 * the end of the line, except that a pattern like | |
1499 | 5731 * "bar\|\nfoo" may match at the NUL. "lnum" can be below |
5732 * "line2" when there is a \zs in the pattern after a line | |
5733 * break. */ | |
15 | 5734 lastone = (skip_match |
5735 || got_int | |
5736 || got_quit | |
1499 | 5737 || lnum > line2 |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5738 || !(subflags.do_all || do_again) |
15 | 5739 || (sub_firstline[matchcol] == NUL && nmatch <= 1 |
5740 && !re_multiline(regmatch.regprog))); | |
7 | 5741 nmatch = -1; |
5742 | |
5743 /* | |
5744 * Replace the line in the buffer when needed. This is | |
5745 * skipped when there are more matches. | |
5746 * The check for nmatch_tl is needed for when multi-line | |
5747 * matching must replace the lines before trying to do another | |
5748 * match, otherwise "\@<=" won't work. | |
1499 | 5749 * When the match starts below where we start searching also |
5750 * need to replace the line first (using \zs after \n). | |
7 | 5751 */ |
5752 if (lastone | |
5753 || nmatch_tl > 0 | |
5754 || (nmatch = vim_regexec_multi(®match, curwin, | |
1521 | 5755 curbuf, sub_firstlnum, |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11494
diff
changeset
|
5756 matchcol, NULL, NULL)) == 0 |
1499 | 5757 || regmatch.startpos[0].lnum > 0) |
7 | 5758 { |
5759 if (new_start != NULL) | |
5760 { | |
5761 /* | |
5762 * Copy the rest of the line, that didn't match. | |
5763 * "matchcol" has to be adjusted, we use the end of | |
5764 * the line as reference, because the substitute may | |
5765 * have changed the number of characters. Same for | |
5766 * "prev_matchcol". | |
5767 */ | |
5768 STRCAT(new_start, sub_firstline + copycol); | |
5769 matchcol = (colnr_T)STRLEN(sub_firstline) - matchcol; | |
5770 prev_matchcol = (colnr_T)STRLEN(sub_firstline) | |
5771 - prev_matchcol; | |
5772 | |
5773 if (u_savesub(lnum) != OK) | |
5774 break; | |
5775 ml_replace(lnum, new_start, TRUE); | |
5776 | |
5777 if (nmatch_tl > 0) | |
5778 { | |
5779 /* | |
5780 * Matched lines have now been substituted and are | |
5781 * useless, delete them. The part after the match | |
5782 * has been appended to new_start, we don't need | |
5783 * it in the buffer. | |
5784 */ | |
5785 ++lnum; | |
5786 if (u_savedel(lnum, nmatch_tl) != OK) | |
5787 break; | |
5788 for (i = 0; i < nmatch_tl; ++i) | |
5789 ml_delete(lnum, (int)FALSE); | |
5790 mark_adjust(lnum, lnum + nmatch_tl - 1, | |
5791 (long)MAXLNUM, -nmatch_tl); | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5792 if (subflags.do_ask) |
7 | 5793 deleted_lines(lnum, nmatch_tl); |
5794 --lnum; | |
5795 line2 -= nmatch_tl; /* nr of lines decreases */ | |
5796 nmatch_tl = 0; | |
5797 } | |
5798 | |
5799 /* When asking, undo is saved each time, must also set | |
5800 * changed flag each time. */ | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5801 if (subflags.do_ask) |
7 | 5802 changed_bytes(lnum, 0); |
5803 else | |
5804 { | |
5805 if (first_line == 0) | |
5806 first_line = lnum; | |
5807 last_line = lnum + 1; | |
5808 } | |
5809 | |
5810 sub_firstlnum = lnum; | |
5811 vim_free(sub_firstline); /* free the temp buffer */ | |
5812 sub_firstline = new_start; | |
5813 new_start = NULL; | |
5814 matchcol = (colnr_T)STRLEN(sub_firstline) - matchcol; | |
5815 prev_matchcol = (colnr_T)STRLEN(sub_firstline) | |
5816 - prev_matchcol; | |
5817 copycol = 0; | |
5818 } | |
5819 if (nmatch == -1 && !lastone) | |
5820 nmatch = vim_regexec_multi(®match, curwin, curbuf, | |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11494
diff
changeset
|
5821 sub_firstlnum, matchcol, NULL, NULL); |
7 | 5822 |
5823 /* | |
5824 * 5. break if there isn't another match in this line | |
5825 */ | |
5826 if (nmatch <= 0) | |
1499 | 5827 { |
5828 /* If the match found didn't start where we were | |
5829 * searching, do the next search in the line where we | |
5830 * found the match. */ | |
5831 if (nmatch == -1) | |
5832 lnum -= regmatch.startpos[0].lnum; | |
7 | 5833 break; |
1499 | 5834 } |
7 | 5835 } |
5836 | |
5837 line_breakcheck(); | |
5838 } | |
5839 | |
5840 if (did_sub) | |
5841 ++sub_nlines; | |
1720 | 5842 vim_free(new_start); /* for when substitute was cancelled */ |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13174
diff
changeset
|
5843 VIM_CLEAR(sub_firstline); /* free the copy of the original line */ |
7 | 5844 } |
5845 | |
5846 line_breakcheck(); | |
5847 } | |
5848 | |
5849 if (first_line != 0) | |
5850 { | |
5851 /* Need to subtract the number of added lines from "last_line" to get | |
5852 * the line number before the change (same as adding the number of | |
5853 * deleted lines). */ | |
5854 i = curbuf->b_ml.ml_line_count - old_line_count; | |
5855 changed_lines(first_line, 0, last_line - i, i); | |
5856 } | |
5857 | |
5858 outofmem: | |
5859 vim_free(sub_firstline); /* may have to free allocated copy of the line */ | |
170 | 5860 |
5861 /* ":s/pat//n" doesn't move the cursor */ | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5862 if (subflags.do_count) |
170 | 5863 curwin->w_cursor = old_cursor; |
5864 | |
2126
e038754d419a
updated for version 7.2.408
Bram Moolenaar <bram@zimbu.org>
parents:
1929
diff
changeset
|
5865 if (sub_nsubs > start_nsubs) |
7 | 5866 { |
5867 /* Set the '[ and '] marks. */ | |
5868 curbuf->b_op_start.lnum = eap->line1; | |
5869 curbuf->b_op_end.lnum = line2; | |
5870 curbuf->b_op_start.col = curbuf->b_op_end.col = 0; | |
5871 | |
5872 if (!global_busy) | |
5873 { | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5874 /* when interactive leave cursor on the match */ |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5875 if (!subflags.do_ask) |
3394 | 5876 { |
5877 if (endcolumn) | |
5878 coladvance((colnr_T)MAXCOL); | |
5879 else | |
5880 beginline(BL_WHITE | BL_FIX); | |
5881 } | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5882 if (!do_sub_msg(subflags.do_count) && subflags.do_ask) |
7 | 5883 MSG(""); |
5884 } | |
5885 else | |
5886 global_need_beginline = TRUE; | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5887 if (subflags.do_print) |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5888 print_line(curwin->w_cursor.lnum, |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5889 subflags.do_number, subflags.do_list); |
7 | 5890 } |
5891 else if (!global_busy) | |
5892 { | |
5893 if (got_int) /* interrupted */ | |
5894 EMSG(_(e_interr)); | |
5895 else if (got_match) /* did find something but nothing substituted */ | |
5896 MSG(""); | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5897 else if (subflags.do_error) /* nothing found */ |
7 | 5898 EMSG2(_(e_patnotf2), get_search_pat()); |
5899 } | |
5900 | |
4035 | 5901 #ifdef FEAT_FOLDING |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5902 if (subflags.do_ask && hasAnyFolding(curwin)) |
4035 | 5903 /* Cursor position may require updating */ |
5904 changed_window_setting(); | |
5905 #endif | |
5906 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4613
diff
changeset
|
5907 vim_regfree(regmatch.regprog); |
6789 | 5908 |
5909 /* Restore the flag values, they can be used for ":&&". */ | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5910 subflags.do_all = save_do_all; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5911 subflags.do_ask = save_do_ask; |
7 | 5912 } |
5913 | |
5914 /* | |
5915 * Give message for number of substitutions. | |
5916 * Can also be used after a ":global" command. | |
5917 * Return TRUE if a message was given. | |
5918 */ | |
484 | 5919 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5920 do_sub_msg( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5921 int count_only) /* used 'n' flag for ":s" */ |
7 | 5922 { |
5923 /* | |
5924 * Only report substitutions when: | |
5925 * - more than 'report' substitutions | |
5926 * - command was typed by user, or number of changed lines > 'report' | |
5927 * - giving messages is not disabled by 'lazyredraw' | |
5928 */ | |
170 | 5929 if (((sub_nsubs > p_report && (KeyTyped || sub_nlines > 1 || p_report < 1)) |
5930 || count_only) | |
7 | 5931 && messaging()) |
5932 { | |
5933 if (got_int) | |
5934 STRCPY(msg_buf, _("(Interrupted) ")); | |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
5935 else |
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
5936 *msg_buf = NUL; |
7 | 5937 if (sub_nsubs == 1) |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2254
diff
changeset
|
5938 vim_snprintf_add((char *)msg_buf, sizeof(msg_buf), |
274 | 5939 "%s", count_only ? _("1 match") : _("1 substitution")); |
7 | 5940 else |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2254
diff
changeset
|
5941 vim_snprintf_add((char *)msg_buf, sizeof(msg_buf), |
170 | 5942 count_only ? _("%ld matches") : _("%ld substitutions"), |
7 | 5943 sub_nsubs); |
5944 if (sub_nlines == 1) | |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2254
diff
changeset
|
5945 vim_snprintf_add((char *)msg_buf, sizeof(msg_buf), |
274 | 5946 "%s", _(" on 1 line")); |
7 | 5947 else |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2254
diff
changeset
|
5948 vim_snprintf_add((char *)msg_buf, sizeof(msg_buf), |
274 | 5949 _(" on %ld lines"), (long)sub_nlines); |
7 | 5950 if (msg(msg_buf)) |
5951 /* save message to display it after redraw */ | |
680 | 5952 set_keep_msg(msg_buf, 0); |
7 | 5953 return TRUE; |
5954 } | |
5955 if (got_int) | |
5956 { | |
5957 EMSG(_(e_interr)); | |
5958 return TRUE; | |
5959 } | |
5960 return FALSE; | |
5961 } | |
5962 | |
11494
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
5963 static void |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
5964 global_exe_one(char_u *cmd, linenr_T lnum) |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
5965 { |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
5966 curwin->w_cursor.lnum = lnum; |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
5967 curwin->w_cursor.col = 0; |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
5968 if (*cmd == NUL || *cmd == '\n') |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
5969 do_cmdline((char_u *)"p", NULL, NULL, DOCMD_NOWAIT); |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
5970 else |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
5971 do_cmdline(cmd, NULL, NULL, DOCMD_NOWAIT); |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
5972 } |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
5973 |
7 | 5974 /* |
5975 * Execute a global command of the form: | |
5976 * | |
5977 * g/pattern/X : execute X on all lines where pattern matches | |
5978 * v/pattern/X : execute X on all lines where pattern does not match | |
5979 * | |
5980 * where 'X' is an EX command | |
5981 * | |
5982 * The command character (as well as the trailing slash) is optional, and | |
5983 * is assumed to be 'p' if missing. | |
5984 * | |
5985 * This is implemented in two passes: first we scan the file for the pattern and | |
3786 | 5986 * set a mark for each line that (not) matches. Secondly we execute the command |
7 | 5987 * for each line that has a mark. This is required because after deleting |
5988 * lines we do not know where to search for the next match. | |
5989 */ | |
5990 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5991 ex_global(exarg_T *eap) |
7 | 5992 { |
5993 linenr_T lnum; /* line number according to old situation */ | |
170 | 5994 int ndone = 0; |
7 | 5995 int type; /* first char of cmd: 'v' or 'g' */ |
5996 char_u *cmd; /* command argument */ | |
5997 | |
5998 char_u delim; /* delimiter, normally '/' */ | |
5999 char_u *pat; | |
6000 regmmatch_T regmatch; | |
6001 int match; | |
6002 int which_pat; | |
6003 | |
11494
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6004 /* When nesting the command works on one line. This allows for |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6005 * ":g/found/v/notfound/command". */ |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6006 if (global_busy && (eap->line1 != 1 |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6007 || eap->line2 != curbuf->b_ml.ml_line_count)) |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6008 { |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6009 /* will increment global_busy to break out of the loop */ |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6010 EMSG(_("E147: Cannot do :global recursive with a range")); |
7 | 6011 return; |
6012 } | |
6013 | |
6014 if (eap->forceit) /* ":global!" is like ":vglobal" */ | |
6015 type = 'v'; | |
6016 else | |
6017 type = *eap->cmd; | |
6018 cmd = eap->arg; | |
6019 which_pat = RE_LAST; /* default: use last used regexp */ | |
6020 | |
6021 /* | |
6022 * undocumented vi feature: | |
6023 * "\/" and "\?": use previous search pattern. | |
6024 * "\&": use previous substitute pattern. | |
6025 */ | |
6026 if (*cmd == '\\') | |
6027 { | |
6028 ++cmd; | |
6029 if (vim_strchr((char_u *)"/?&", *cmd) == NULL) | |
6030 { | |
6031 EMSG(_(e_backslash)); | |
6032 return; | |
6033 } | |
6034 if (*cmd == '&') | |
6035 which_pat = RE_SUBST; /* use previous substitute pattern */ | |
6036 else | |
6037 which_pat = RE_SEARCH; /* use previous search pattern */ | |
6038 ++cmd; | |
6039 pat = (char_u *)""; | |
6040 } | |
6041 else if (*cmd == NUL) | |
6042 { | |
6043 EMSG(_("E148: Regular expression missing from global")); | |
6044 return; | |
6045 } | |
6046 else | |
6047 { | |
6048 delim = *cmd; /* get the delimiter */ | |
6049 if (delim) | |
6050 ++cmd; /* skip delimiter if there is one */ | |
6051 pat = cmd; /* remember start of pattern */ | |
6052 cmd = skip_regexp(cmd, delim, p_magic, &eap->arg); | |
6053 if (cmd[0] == delim) /* end delimiter found */ | |
6054 *cmd++ = NUL; /* replace it with a NUL */ | |
6055 } | |
6056 | |
6057 #ifdef FEAT_FKMAP /* when in Farsi mode, reverse the character flow */ | |
6058 if (p_altkeymap && curwin->w_p_rl) | |
6059 lrFswap(pat,0); | |
6060 #endif | |
6061 | |
6062 if (search_regcomp(pat, RE_BOTH, which_pat, SEARCH_HIS, ®match) == FAIL) | |
6063 { | |
6064 EMSG(_(e_invcmd)); | |
6065 return; | |
6066 } | |
6067 | |
11494
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6068 if (global_busy) |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6069 { |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6070 lnum = curwin->w_cursor.lnum; |
1521 | 6071 match = vim_regexec_multi(®match, curwin, curbuf, lnum, |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11494
diff
changeset
|
6072 (colnr_T)0, NULL, NULL); |
7 | 6073 if ((type == 'g' && match) || (type == 'v' && !match)) |
11494
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6074 global_exe_one(cmd, lnum); |
7 | 6075 } |
6076 else | |
6116 | 6077 { |
11494
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6078 /* |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6079 * pass 1: set marks for each (not) matching line |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6080 */ |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6081 for (lnum = eap->line1; lnum <= eap->line2 && !got_int; ++lnum) |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6082 { |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6083 /* a match on this line? */ |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6084 match = vim_regexec_multi(®match, curwin, curbuf, lnum, |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11494
diff
changeset
|
6085 (colnr_T)0, NULL, NULL); |
11494
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6086 if ((type == 'g' && match) || (type == 'v' && !match)) |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6087 { |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6088 ml_setmarked(lnum); |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6089 ndone++; |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6090 } |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6091 line_breakcheck(); |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6092 } |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6093 |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6094 /* |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6095 * pass 2: execute the command for each line that has been marked |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6096 */ |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6097 if (got_int) |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6098 MSG(_(e_interr)); |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6099 else if (ndone == 0) |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6100 { |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6101 if (type == 'v') |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6102 smsg((char_u *)_("Pattern found in every line: %s"), pat); |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6103 else |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6104 smsg((char_u *)_("Pattern not found: %s"), pat); |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6105 } |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6106 else |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6107 { |
6116 | 6108 #ifdef FEAT_CLIPBOARD |
11494
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6109 start_global_changes(); |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6110 #endif |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6111 global_exe(cmd); |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6112 #ifdef FEAT_CLIPBOARD |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6113 end_global_changes(); |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6114 #endif |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6115 } |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6116 |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6117 ml_clearmarked(); /* clear rest of the marks */ |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6118 } |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6119 |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4613
diff
changeset
|
6120 vim_regfree(regmatch.regprog); |
7 | 6121 } |
6122 | |
6123 /* | |
6124 * Execute "cmd" on lines marked with ml_setmarked(). | |
6125 */ | |
6126 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6127 global_exe(char_u *cmd) |
7 | 6128 { |
2819 | 6129 linenr_T old_lcount; /* b_ml.ml_line_count before the command */ |
6130 buf_T *old_buf = curbuf; /* remember what buffer we started in */ | |
6131 linenr_T lnum; /* line number according to old situation */ | |
7 | 6132 |
6133 /* | |
6134 * Set current position only once for a global command. | |
6135 * If global_busy is set, setpcmark() will not do anything. | |
6136 * If there is an error, global_busy will be incremented. | |
6137 */ | |
6138 setpcmark(); | |
6139 | |
6140 /* When the command writes a message, don't overwrite the command. */ | |
6141 msg_didout = TRUE; | |
6142 | |
2127
4e22214f8464
updated for version 7.2.409
Bram Moolenaar <bram@zimbu.org>
parents:
2126
diff
changeset
|
6143 sub_nsubs = 0; |
4e22214f8464
updated for version 7.2.409
Bram Moolenaar <bram@zimbu.org>
parents:
2126
diff
changeset
|
6144 sub_nlines = 0; |
7 | 6145 global_need_beginline = FALSE; |
6146 global_busy = 1; | |
6147 old_lcount = curbuf->b_ml.ml_line_count; | |
6148 while (!got_int && (lnum = ml_firstmarked()) != 0 && global_busy == 1) | |
6149 { | |
11494
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6150 global_exe_one(cmd, lnum); |
7 | 6151 ui_breakcheck(); |
6152 } | |
6153 | |
6154 global_busy = 0; | |
6155 if (global_need_beginline) | |
6156 beginline(BL_WHITE | BL_FIX); | |
6157 else | |
6158 check_cursor(); /* cursor may be beyond the end of the line */ | |
6159 | |
39 | 6160 /* the cursor may not have moved in the text but a change in a previous |
6161 * line may move it on the screen */ | |
6162 changed_line_abv_curs(); | |
6163 | |
7 | 6164 /* If it looks like no message was written, allow overwriting the |
6165 * command with the report for number of changes. */ | |
6166 if (msg_col == 0 && msg_scrolled == 0) | |
6167 msg_didout = FALSE; | |
6168 | |
1227 | 6169 /* If substitutes done, report number of substitutes, otherwise report |
2819 | 6170 * number of extra or deleted lines. |
6171 * Don't report extra or deleted lines in the edge case where the buffer | |
6172 * we are in after execution is different from the buffer we started in. */ | |
6173 if (!do_sub_msg(FALSE) && curbuf == old_buf) | |
7 | 6174 msgmore(curbuf->b_ml.ml_line_count - old_lcount); |
6175 } | |
6176 | |
6177 #ifdef FEAT_VIMINFO | |
6178 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6179 read_viminfo_sub_string(vir_T *virp, int force) |
7 | 6180 { |
2690 | 6181 if (force) |
7 | 6182 vim_free(old_sub); |
6183 if (force || old_sub == NULL) | |
6184 old_sub = viminfo_readstring(virp, 1, TRUE); | |
6185 return viminfo_readline(virp); | |
6186 } | |
6187 | |
6188 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6189 write_viminfo_sub_string(FILE *fp) |
7 | 6190 { |
6191 if (get_viminfo_parameter('/') != 0 && old_sub != NULL) | |
6192 { | |
2545
298d8d6e69be
Avoid warnings from the clang compiler. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2394
diff
changeset
|
6193 fputs(_("\n# Last Substitute String:\n$"), fp); |
7 | 6194 viminfo_writestring(fp, old_sub); |
6195 } | |
6196 } | |
6197 #endif /* FEAT_VIMINFO */ | |
6198 | |
359 | 6199 #if defined(EXITFREE) || defined(PROTO) |
6200 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6201 free_old_sub(void) |
359 | 6202 { |
6203 vim_free(old_sub); | |
6204 } | |
6205 #endif | |
6206 | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12297
diff
changeset
|
6207 #if defined(FEAT_QUICKFIX) || defined(PROTO) |
7 | 6208 /* |
6209 * Set up for a tagpreview. | |
735 | 6210 * Return TRUE when it was created. |
7 | 6211 */ |
735 | 6212 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6213 prepare_tagpreview( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6214 int undo_sync) /* sync undo when leaving the window */ |
7 | 6215 { |
6216 win_T *wp; | |
6217 | |
6218 # ifdef FEAT_GUI | |
6219 need_mouse_correct = TRUE; | |
6220 # endif | |
6221 | |
6222 /* | |
6223 * If there is already a preview window open, use that one. | |
6224 */ | |
6225 if (!curwin->w_p_pvw) | |
6226 { | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
6227 FOR_ALL_WINDOWS(wp) |
7 | 6228 if (wp->w_p_pvw) |
6229 break; | |
6230 if (wp != NULL) | |
816 | 6231 win_enter(wp, undo_sync); |
7 | 6232 else |
6233 { | |
6234 /* | |
6235 * There is no preview window open yet. Create one. | |
6236 */ | |
6237 if (win_split(g_do_tagpreview > 0 ? g_do_tagpreview : 0, 0) | |
6238 == FAIL) | |
735 | 6239 return FALSE; |
7 | 6240 curwin->w_p_pvw = TRUE; |
6241 curwin->w_p_wfh = TRUE; | |
2583 | 6242 RESET_BINDING(curwin); /* don't take over 'scrollbind' |
6243 and 'cursorbind' */ | |
7 | 6244 # ifdef FEAT_DIFF |
6245 curwin->w_p_diff = FALSE; /* no 'diff' */ | |
6246 # endif | |
6247 # ifdef FEAT_FOLDING | |
6248 curwin->w_p_fdc = 0; /* no 'foldcolumn' */ | |
6249 # endif | |
735 | 6250 return TRUE; |
7 | 6251 } |
6252 } | |
735 | 6253 return FALSE; |
7 | 6254 } |
6255 | |
6256 #endif | |
6257 | |
6258 | |
6259 /* | |
6260 * ":help": open a read-only window on a help file | |
6261 */ | |
6262 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6263 ex_help(exarg_T *eap) |
7 | 6264 { |
6265 char_u *arg; | |
6266 char_u *tag; | |
6267 FILE *helpfd; /* file descriptor of help file */ | |
6268 int n; | |
6269 int i; | |
6270 win_T *wp; | |
6271 int num_matches; | |
6272 char_u **matches; | |
6273 char_u *p; | |
6274 int empty_fnum = 0; | |
6275 int alt_fnum = 0; | |
6276 buf_T *buf; | |
6277 #ifdef FEAT_MULTI_LANG | |
6278 int len; | |
9 | 6279 char_u *lang; |
7 | 6280 #endif |
3112 | 6281 #ifdef FEAT_FOLDING |
6282 int old_KeyTyped = KeyTyped; | |
6283 #endif | |
7 | 6284 |
6285 if (eap != NULL) | |
6286 { | |
6287 /* | |
6288 * A ":help" command ends at the first LF, or at a '|' that is | |
6289 * followed by some text. Set nextcmd to the following command. | |
6290 */ | |
6291 for (arg = eap->arg; *arg; ++arg) | |
6292 { | |
6293 if (*arg == '\n' || *arg == '\r' | |
6294 || (*arg == '|' && arg[1] != NUL && arg[1] != '|')) | |
6295 { | |
6296 *arg++ = NUL; | |
6297 eap->nextcmd = arg; | |
6298 break; | |
6299 } | |
6300 } | |
6301 arg = eap->arg; | |
6302 | |
3446 | 6303 if (eap->forceit && *arg == NUL && !curbuf->b_help) |
7 | 6304 { |
6305 EMSG(_("E478: Don't panic!")); | |
6306 return; | |
6307 } | |
6308 | |
6309 if (eap->skip) /* not executing commands */ | |
6310 return; | |
6311 } | |
6312 else | |
6313 arg = (char_u *)""; | |
6314 | |
6315 /* remove trailing blanks */ | |
6316 p = arg + STRLEN(arg) - 1; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
6317 while (p > arg && VIM_ISWHITE(*p) && p[-1] != '\\') |
7 | 6318 *p-- = NUL; |
6319 | |
6320 #ifdef FEAT_MULTI_LANG | |
6321 /* Check for a specified language */ | |
9 | 6322 lang = check_help_lang(arg); |
7 | 6323 #endif |
6324 | |
6325 /* When no argument given go to the index. */ | |
6326 if (*arg == NUL) | |
6327 arg = (char_u *)"help.txt"; | |
6328 | |
6329 /* | |
6330 * Check if there is a match for the argument. | |
6331 */ | |
6332 n = find_help_tags(arg, &num_matches, &matches, | |
6333 eap != NULL && eap->forceit); | |
6334 | |
6335 i = 0; | |
6336 #ifdef FEAT_MULTI_LANG | |
6337 if (n != FAIL && lang != NULL) | |
6338 /* Find first item with the requested language. */ | |
6339 for (i = 0; i < num_matches; ++i) | |
6340 { | |
835 | 6341 len = (int)STRLEN(matches[i]); |
7 | 6342 if (len > 3 && matches[i][len - 3] == '@' |
6343 && STRICMP(matches[i] + len - 2, lang) == 0) | |
6344 break; | |
6345 } | |
6346 #endif | |
6347 if (i >= num_matches || n == FAIL) | |
6348 { | |
6349 #ifdef FEAT_MULTI_LANG | |
6350 if (lang != NULL) | |
6351 EMSG3(_("E661: Sorry, no '%s' help for %s"), lang, arg); | |
6352 else | |
6353 #endif | |
6354 EMSG2(_("E149: Sorry, no help for %s"), arg); | |
6355 if (n != FAIL) | |
6356 FreeWild(num_matches, matches); | |
6357 return; | |
6358 } | |
6359 | |
6360 /* The first match (in the requested language) is the best match. */ | |
6361 tag = vim_strsave(matches[i]); | |
6362 FreeWild(num_matches, matches); | |
6363 | |
6364 #ifdef FEAT_GUI | |
6365 need_mouse_correct = TRUE; | |
6366 #endif | |
6367 | |
6368 /* | |
6369 * Re-use an existing help window or open a new one. | |
684 | 6370 * Always open a new one for ":tab help". |
7 | 6371 */ |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12297
diff
changeset
|
6372 if (!bt_help(curwin->w_buffer) || cmdmod.tab != 0) |
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12297
diff
changeset
|
6373 { |
684 | 6374 if (cmdmod.tab != 0) |
6375 wp = NULL; | |
6376 else | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
6377 FOR_ALL_WINDOWS(wp) |
11800
5ceaecedbad2
patch 8.0.0782: using freed memory in quickfix code
Christian Brabandt <cb@256bit.org>
parents:
11666
diff
changeset
|
6378 if (bt_help(wp->w_buffer)) |
684 | 6379 break; |
7 | 6380 if (wp != NULL && wp->w_buffer->b_nwindows > 0) |
6381 win_enter(wp, TRUE); | |
6382 else | |
6383 { | |
6384 /* | |
6385 * There is no help window yet. | |
6386 * Try to open the file specified by the "helpfile" option. | |
6387 */ | |
6388 if ((helpfd = mch_fopen((char *)p_hf, READBIN)) == NULL) | |
6389 { | |
274 | 6390 smsg((char_u *)_("Sorry, help file \"%s\" not found"), p_hf); |
7 | 6391 goto erret; |
6392 } | |
6393 fclose(helpfd); | |
6394 | |
6395 /* Split off help window; put it at far top if no position | |
684 | 6396 * specified, the current window is vertically split and |
6397 * narrow. */ | |
7 | 6398 n = WSP_HELP; |
6399 if (cmdmod.split == 0 && curwin->w_width != Columns | |
684 | 6400 && curwin->w_width < 80) |
7 | 6401 n |= WSP_TOP; |
6402 if (win_split(0, n) == FAIL) | |
684 | 6403 goto erret; |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12297
diff
changeset
|
6404 |
7 | 6405 if (curwin->w_height < p_hh) |
6406 win_setheight((int)p_hh); | |
6407 | |
6408 /* | |
6409 * Open help file (do_ecmd() will set b_help flag, readfile() will | |
6410 * set b_p_ro flag). | |
6411 * Set the alternate file to the previously edited file. | |
6412 */ | |
6413 alt_fnum = curbuf->b_fnum; | |
6414 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_LASTL, | |
1743 | 6415 ECMD_HIDE + ECMD_SET_HELP, |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12297
diff
changeset
|
6416 NULL); /* buffer is still open, don't store info */ |
22 | 6417 if (!cmdmod.keepalt) |
6418 curwin->w_alt_fnum = alt_fnum; | |
7 | 6419 empty_fnum = curbuf->b_fnum; |
6420 } | |
6421 } | |
6422 | |
6423 if (!p_im) | |
6424 restart_edit = 0; /* don't want insert mode in help file */ | |
6425 | |
3112 | 6426 #ifdef FEAT_FOLDING |
6427 /* Restore KeyTyped, setting 'filetype=help' may reset it. | |
6428 * It is needed for do_tag top open folds under the cursor. */ | |
6429 KeyTyped = old_KeyTyped; | |
6430 #endif | |
6431 | |
7 | 6432 if (tag != NULL) |
6433 do_tag(tag, DT_HELP, 1, FALSE, TRUE); | |
6434 | |
819 | 6435 /* Delete the empty buffer if we're not using it. Careful: autocommands |
6436 * may have jumped to another window, check that the buffer is not in a | |
6437 * window. */ | |
7 | 6438 if (empty_fnum != 0 && curbuf->b_fnum != empty_fnum) |
6439 { | |
6440 buf = buflist_findnr(empty_fnum); | |
819 | 6441 if (buf != NULL && buf->b_nwindows == 0) |
7 | 6442 wipe_buffer(buf, TRUE); |
6443 } | |
6444 | |
6445 /* keep the previous alternate file */ | |
22 | 6446 if (alt_fnum != 0 && curwin->w_alt_fnum == empty_fnum && !cmdmod.keepalt) |
7 | 6447 curwin->w_alt_fnum = alt_fnum; |
6448 | |
6449 erret: | |
6450 vim_free(tag); | |
6451 } | |
6452 | |
6228 | 6453 /* |
6234 | 6454 * ":helpclose": Close one help window |
6228 | 6455 */ |
6456 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6457 ex_helpclose(exarg_T *eap UNUSED) |
6228 | 6458 { |
6459 win_T *win; | |
6460 | |
6461 FOR_ALL_WINDOWS(win) | |
6462 { | |
11800
5ceaecedbad2
patch 8.0.0782: using freed memory in quickfix code
Christian Brabandt <cb@256bit.org>
parents:
11666
diff
changeset
|
6463 if (bt_help(win->w_buffer)) |
6228 | 6464 { |
6465 win_close(win, FALSE); | |
6234 | 6466 return; |
6228 | 6467 } |
6468 } | |
6469 } | |
7 | 6470 |
9 | 6471 #if defined(FEAT_MULTI_LANG) || defined(PROTO) |
6472 /* | |
6473 * In an argument search for a language specifiers in the form "@xx". | |
6474 * Changes the "@" to NUL if found, and returns a pointer to "xx". | |
6475 * Returns NULL if not found. | |
6476 */ | |
6477 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6478 check_help_lang(char_u *arg) |
9 | 6479 { |
835 | 6480 int len = (int)STRLEN(arg); |
9 | 6481 |
6482 if (len >= 3 && arg[len - 3] == '@' && ASCII_ISALPHA(arg[len - 2]) | |
6483 && ASCII_ISALPHA(arg[len - 1])) | |
6484 { | |
6485 arg[len - 3] = NUL; /* remove the '@' */ | |
6486 return arg + len - 2; | |
6487 } | |
6488 return NULL; | |
6489 } | |
6490 #endif | |
6491 | |
7 | 6492 /* |
6493 * Return a heuristic indicating how well the given string matches. The | |
6494 * smaller the number, the better the match. This is the order of priorities, | |
6495 * from best match to worst match: | |
6496 * - Match with least alpha-numeric characters is better. | |
6497 * - Match with least total characters is better. | |
6498 * - Match towards the start is better. | |
6499 * - Match starting with "+" is worse (feature instead of command) | |
6500 * Assumption is made that the matched_string passed has already been found to | |
6501 * match some string for which help is requested. webb. | |
6502 */ | |
6503 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6504 help_heuristic( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6505 char_u *matched_string, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6506 int offset, /* offset for match */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6507 int wrong_case) /* no matching case */ |
7 | 6508 { |
6509 int num_letters; | |
6510 char_u *p; | |
6511 | |
6512 num_letters = 0; | |
6513 for (p = matched_string; *p; p++) | |
6514 if (ASCII_ISALNUM(*p)) | |
6515 num_letters++; | |
6516 | |
6517 /* | |
6518 * Multiply the number of letters by 100 to give it a much bigger | |
6519 * weighting than the number of characters. | |
6520 * If there only is a match while ignoring case, add 5000. | |
6521 * If the match starts in the middle of a word, add 10000 to put it | |
6522 * somewhere in the last half. | |
6523 * If the match is more than 2 chars from the start, multiply by 200 to | |
6524 * put it after matches at the start. | |
6525 */ | |
6526 if (ASCII_ISALNUM(matched_string[offset]) && offset > 0 | |
6527 && ASCII_ISALNUM(matched_string[offset - 1])) | |
6528 offset += 10000; | |
6529 else if (offset > 2) | |
6530 offset *= 200; | |
6531 if (wrong_case) | |
6532 offset += 5000; | |
6533 /* Features are less interesting than the subjects themselves, but "+" | |
6534 * alone is not a feature. */ | |
6535 if (matched_string[0] == '+' && matched_string[1] != NUL) | |
6536 offset += 100; | |
6537 return (int)(100 * num_letters + STRLEN(matched_string) + offset); | |
6538 } | |
6539 | |
6540 /* | |
6541 * Compare functions for qsort() below, that checks the help heuristics number | |
6542 * that has been put after the tagname by find_tags(). | |
6543 */ | |
6544 static int | |
6545 #ifdef __BORLANDC__ | |
6546 _RTLENTRYF | |
6547 #endif | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6548 help_compare(const void *s1, const void *s2) |
7 | 6549 { |
6550 char *p1; | |
6551 char *p2; | |
6552 | |
6553 p1 = *(char **)s1 + strlen(*(char **)s1) + 1; | |
6554 p2 = *(char **)s2 + strlen(*(char **)s2) + 1; | |
6555 return strcmp(p1, p2); | |
6556 } | |
6557 | |
6558 /* | |
6559 * Find all help tags matching "arg", sort them and return in matches[], with | |
6560 * the number of matches in num_matches. | |
6561 * The matches will be sorted with a "best" match algorithm. | |
6562 * When "keep_lang" is TRUE try keeping the language of the current buffer. | |
6563 */ | |
6564 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6565 find_help_tags( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6566 char_u *arg, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6567 int *num_matches, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6568 char_u ***matches, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6569 int keep_lang) |
7 | 6570 { |
6571 char_u *s, *d; | |
6572 int i; | |
6573 static char *(mtable[]) = {"*", "g*", "[*", "]*", ":*", | |
445 | 6574 "/*", "/\\*", "\"*", "**", |
5269
7d1f89b27103
updated for version 7.4b.011
Bram Moolenaar <bram@vim.org>
parents:
5257
diff
changeset
|
6575 "cpo-*", "/\\(\\)", "/\\%(\\)", |
10853
b760fa91f8b3
patch 8.0.0316: :help z? does not work
Christian Brabandt <cb@256bit.org>
parents:
10851
diff
changeset
|
6576 "?", ":?", "?<CR>", "g?", "g?g?", "g??", |
279 | 6577 "/\\?", "/\\z(\\)", "\\=", ":s\\=", |
10851
256b1b96c2ad
patch 8.0.0315: :help :[range] does not work
Christian Brabandt <cb@256bit.org>
parents:
10638
diff
changeset
|
6578 "[count]", "[quotex]", |
256b1b96c2ad
patch 8.0.0315: :help :[range] does not work
Christian Brabandt <cb@256bit.org>
parents:
10638
diff
changeset
|
6579 "[range]", ":[range]", |
5647 | 6580 "[pattern]", "\\|", "\\%$", |
6581 "s/\\~", "s/\\U", "s/\\L", | |
6582 "s/\\1", "s/\\2", "s/\\3", "s/\\9"}; | |
7 | 6583 static char *(rtable[]) = {"star", "gstar", "[star", "]star", ":star", |
445 | 6584 "/star", "/\\\\star", "quotestar", "starstar", |
5269
7d1f89b27103
updated for version 7.4b.011
Bram Moolenaar <bram@vim.org>
parents:
5257
diff
changeset
|
6585 "cpo-star", "/\\\\(\\\\)", "/\\\\%(\\\\)", |
10853
b760fa91f8b3
patch 8.0.0316: :help z? does not work
Christian Brabandt <cb@256bit.org>
parents:
10851
diff
changeset
|
6586 "?", ":?", "?<CR>", "g?", "g?g?", "g??", |
279 | 6587 "/\\\\?", "/\\\\z(\\\\)", "\\\\=", ":s\\\\=", |
10851
256b1b96c2ad
patch 8.0.0315: :help :[range] does not work
Christian Brabandt <cb@256bit.org>
parents:
10638
diff
changeset
|
6588 "\\[count]", "\\[quotex]", |
256b1b96c2ad
patch 8.0.0315: :help :[range] does not work
Christian Brabandt <cb@256bit.org>
parents:
10638
diff
changeset
|
6589 "\\[range]", ":\\[range]", |
5647 | 6590 "\\[pattern]", "\\\\bar", "/\\\\%\\$", |
5867 | 6591 "s/\\\\\\~", "s/\\\\U", "s/\\\\L", |
5647 | 6592 "s/\\\\1", "s/\\\\2", "s/\\\\3", "s/\\\\9"}; |
7 | 6593 int flags; |
6594 | |
6595 d = IObuff; /* assume IObuff is long enough! */ | |
6596 | |
6597 /* | |
6598 * Recognize a few exceptions to the rule. Some strings that contain '*' | |
6599 * with "star". Otherwise '*' is recognized as a wildcard. | |
6600 */ | |
1872 | 6601 for (i = (int)(sizeof(mtable) / sizeof(char *)); --i >= 0; ) |
7 | 6602 if (STRCMP(arg, mtable[i]) == 0) |
6603 { | |
6604 STRCPY(d, rtable[i]); | |
6605 break; | |
6606 } | |
6607 | |
6608 if (i < 0) /* no match in table */ | |
6609 { | |
6610 /* Replace "\S" with "/\\S", etc. Otherwise every tag is matched. | |
6611 * Also replace "\%^" and "\%(", they match every tag too. | |
6612 * Also "\zs", "\z1", etc. | |
6613 * Also "\@<", "\@=", "\@<=", etc. | |
6614 * And also "\_$" and "\_^". */ | |
6615 if (arg[0] == '\\' | |
6616 && ((arg[1] != NUL && arg[2] == NUL) | |
6617 || (vim_strchr((char_u *)"%_z@", arg[1]) != NULL | |
6618 && arg[2] != NUL))) | |
6619 { | |
6620 STRCPY(d, "/\\\\"); | |
6621 STRCPY(d + 3, arg + 1); | |
6622 /* Check for "/\\_$", should be "/\\_\$" */ | |
6623 if (d[3] == '_' && d[4] == '$') | |
6624 STRCPY(d + 4, "\\$"); | |
6625 } | |
6626 else | |
6627 { | |
3786 | 6628 /* Replace: |
6629 * "[:...:]" with "\[:...:]" | |
6630 * "[++...]" with "\[++...]" | |
5867 | 6631 * "\{" with "\\{" -- matching "} \}" |
3786 | 6632 */ |
6633 if ((arg[0] == '[' && (arg[1] == ':' | |
6634 || (arg[1] == '+' && arg[2] == '+'))) | |
6635 || (arg[0] == '\\' && arg[1] == '{')) | |
7 | 6636 *d++ = '\\'; |
6637 | |
8556
f4dca5239317
commit https://github.com/vim/vim/commit/00f9e0dbbd3472db217d56639fad9346b9eb3b82
Christian Brabandt <cb@256bit.org>
parents:
8544
diff
changeset
|
6638 /* |
f4dca5239317
commit https://github.com/vim/vim/commit/00f9e0dbbd3472db217d56639fad9346b9eb3b82
Christian Brabandt <cb@256bit.org>
parents:
8544
diff
changeset
|
6639 * If tag starts with "('", skip the "(". Fixes CTRL-] on ('option'. |
f4dca5239317
commit https://github.com/vim/vim/commit/00f9e0dbbd3472db217d56639fad9346b9eb3b82
Christian Brabandt <cb@256bit.org>
parents:
8544
diff
changeset
|
6640 */ |
f4dca5239317
commit https://github.com/vim/vim/commit/00f9e0dbbd3472db217d56639fad9346b9eb3b82
Christian Brabandt <cb@256bit.org>
parents:
8544
diff
changeset
|
6641 if (*arg == '(' && arg[1] == '\'') |
f4dca5239317
commit https://github.com/vim/vim/commit/00f9e0dbbd3472db217d56639fad9346b9eb3b82
Christian Brabandt <cb@256bit.org>
parents:
8544
diff
changeset
|
6642 arg++; |
7 | 6643 for (s = arg; *s; ++s) |
6644 { | |
6645 /* | |
6646 * Replace "|" with "bar" and '"' with "quote" to match the name of | |
6647 * the tags for these commands. | |
6648 * Replace "*" with ".*" and "?" with "." to match command line | |
6649 * completion. | |
6650 * Insert a backslash before '~', '$' and '.' to avoid their | |
6651 * special meaning. | |
6652 */ | |
6653 if (d - IObuff > IOSIZE - 10) /* getting too long!? */ | |
6654 break; | |
6655 switch (*s) | |
6656 { | |
6657 case '|': STRCPY(d, "bar"); | |
6658 d += 3; | |
6659 continue; | |
6660 case '"': STRCPY(d, "quote"); | |
6661 d += 5; | |
6662 continue; | |
6663 case '*': *d++ = '.'; | |
6664 break; | |
6665 case '?': *d++ = '.'; | |
6666 continue; | |
6667 case '$': | |
6668 case '.': | |
6669 case '~': *d++ = '\\'; | |
6670 break; | |
6671 } | |
6672 | |
6673 /* | |
6674 * Replace "^x" by "CTRL-X". Don't do this for "^_" to make | |
6675 * ":help i_^_CTRL-D" work. | |
6676 * Insert '-' before and after "CTRL-X" when applicable. | |
6677 */ | |
6678 if (*s < ' ' || (*s == '^' && s[1] && (ASCII_ISALPHA(s[1]) | |
6679 || vim_strchr((char_u *)"?@[\\]^", s[1]) != NULL))) | |
6680 { | |
5282
8c42772f0543
updated for version 7.4b.017
Bram Moolenaar <bram@vim.org>
parents:
5269
diff
changeset
|
6681 if (d > IObuff && d[-1] != '_' && d[-1] != '\\') |
8c42772f0543
updated for version 7.4b.017
Bram Moolenaar <bram@vim.org>
parents:
5269
diff
changeset
|
6682 *d++ = '_'; /* prepend a '_' to make x_CTRL-x */ |
7 | 6683 STRCPY(d, "CTRL-"); |
6684 d += 5; | |
6685 if (*s < ' ') | |
6686 { | |
6687 #ifdef EBCDIC | |
6688 *d++ = CtrlChar(*s); | |
6689 #else | |
6690 *d++ = *s + '@'; | |
6691 #endif | |
6692 if (d[-1] == '\\') | |
6693 *d++ = '\\'; /* double a backslash */ | |
6694 } | |
6695 else | |
6696 *d++ = *++s; | |
6697 if (s[1] != NUL && s[1] != '_') | |
6698 *d++ = '_'; /* append a '_' */ | |
6699 continue; | |
6700 } | |
6701 else if (*s == '^') /* "^" or "CTRL-^" or "^_" */ | |
6702 *d++ = '\\'; | |
6703 | |
6704 /* | |
6705 * Insert a backslash before a backslash after a slash, for search | |
6706 * pattern tags: "/\|" --> "/\\|". | |
6707 */ | |
6708 else if (s[0] == '\\' && s[1] != '\\' | |
6709 && *arg == '/' && s == arg + 1) | |
6710 *d++ = '\\'; | |
6711 | |
6712 /* "CTRL-\_" -> "CTRL-\\_" to avoid the special meaning of "\_" in | |
6713 * "CTRL-\_CTRL-N" */ | |
6714 if (STRNICMP(s, "CTRL-\\_", 7) == 0) | |
6715 { | |
6716 STRCPY(d, "CTRL-\\\\"); | |
6717 d += 7; | |
6718 s += 6; | |
6719 } | |
6720 | |
6721 *d++ = *s; | |
6722 | |
6723 /* | |
8883
b7de875169e6
commit https://github.com/vim/vim/commit/81edd171a9465cf99cede4fa4a7b7bca3d538b0f
Christian Brabandt <cb@256bit.org>
parents:
8879
diff
changeset
|
6724 * If tag contains "({" or "([", tag terminates at the "(". |
b7de875169e6
commit https://github.com/vim/vim/commit/81edd171a9465cf99cede4fa4a7b7bca3d538b0f
Christian Brabandt <cb@256bit.org>
parents:
8879
diff
changeset
|
6725 * This is for help on functions, e.g.: abs({expr}). |
b7de875169e6
commit https://github.com/vim/vim/commit/81edd171a9465cf99cede4fa4a7b7bca3d538b0f
Christian Brabandt <cb@256bit.org>
parents:
8879
diff
changeset
|
6726 */ |
b7de875169e6
commit https://github.com/vim/vim/commit/81edd171a9465cf99cede4fa4a7b7bca3d538b0f
Christian Brabandt <cb@256bit.org>
parents:
8879
diff
changeset
|
6727 if (*s == '(' && (s[1] == '{' || s[1] =='[')) |
b7de875169e6
commit https://github.com/vim/vim/commit/81edd171a9465cf99cede4fa4a7b7bca3d538b0f
Christian Brabandt <cb@256bit.org>
parents:
8879
diff
changeset
|
6728 break; |
b7de875169e6
commit https://github.com/vim/vim/commit/81edd171a9465cf99cede4fa4a7b7bca3d538b0f
Christian Brabandt <cb@256bit.org>
parents:
8879
diff
changeset
|
6729 |
b7de875169e6
commit https://github.com/vim/vim/commit/81edd171a9465cf99cede4fa4a7b7bca3d538b0f
Christian Brabandt <cb@256bit.org>
parents:
8879
diff
changeset
|
6730 /* |
7 | 6731 * If tag starts with ', toss everything after a second '. Fixes |
6732 * CTRL-] on 'option'. (would include the trailing '.'). | |
6733 */ | |
6734 if (*s == '\'' && s > arg && *arg == '\'') | |
6735 break; | |
9234
6e80397a592c
commit https://github.com/vim/vim/commit/28b942a064dd486cc241894b625ab72f5a5c6d1b
Christian Brabandt <cb@256bit.org>
parents:
8883
diff
changeset
|
6736 /* Also '{' and '}'. */ |
6e80397a592c
commit https://github.com/vim/vim/commit/28b942a064dd486cc241894b625ab72f5a5c6d1b
Christian Brabandt <cb@256bit.org>
parents:
8883
diff
changeset
|
6737 if (*s == '}' && s > arg && *arg == '{') |
6e80397a592c
commit https://github.com/vim/vim/commit/28b942a064dd486cc241894b625ab72f5a5c6d1b
Christian Brabandt <cb@256bit.org>
parents:
8883
diff
changeset
|
6738 break; |
7 | 6739 } |
6740 *d = NUL; | |
3480 | 6741 |
6742 if (*IObuff == '`') | |
6743 { | |
6744 if (d > IObuff + 2 && d[-1] == '`') | |
6745 { | |
6746 /* remove the backticks from `command` */ | |
6747 mch_memmove(IObuff, IObuff + 1, STRLEN(IObuff)); | |
6748 d[-2] = NUL; | |
6749 } | |
6750 else if (d > IObuff + 3 && d[-2] == '`' && d[-1] == ',') | |
6751 { | |
6752 /* remove the backticks and comma from `command`, */ | |
6753 mch_memmove(IObuff, IObuff + 1, STRLEN(IObuff)); | |
6754 d[-3] = NUL; | |
6755 } | |
6756 else if (d > IObuff + 4 && d[-3] == '`' | |
6757 && d[-2] == '\\' && d[-1] == '.') | |
6758 { | |
6759 /* remove the backticks and dot from `command`\. */ | |
6760 mch_memmove(IObuff, IObuff + 1, STRLEN(IObuff)); | |
6761 d[-4] = NUL; | |
6762 } | |
6763 } | |
7 | 6764 } |
6765 } | |
6766 | |
6767 *matches = (char_u **)""; | |
6768 *num_matches = 0; | |
6769 flags = TAG_HELP | TAG_REGEXP | TAG_NAMES | TAG_VERBOSE; | |
6770 if (keep_lang) | |
6771 flags |= TAG_KEEP_LANG; | |
1696 | 6772 if (find_tags(IObuff, num_matches, matches, flags, (int)MAXCOL, NULL) == OK |
7 | 6773 && *num_matches > 0) |
1696 | 6774 { |
7 | 6775 /* Sort the matches found on the heuristic number that is after the |
6776 * tag name. */ | |
6777 qsort((void *)*matches, (size_t)*num_matches, | |
6778 sizeof(char_u *), help_compare); | |
1696 | 6779 /* Delete more than TAG_MANY to reduce the size of the listing. */ |
6780 while (*num_matches > TAG_MANY) | |
6781 vim_free((*matches)[--*num_matches]); | |
6782 } | |
7 | 6783 return OK; |
6784 } | |
6785 | |
6786 /* | |
6365 | 6787 * Called when starting to edit a buffer for a help file. |
6788 */ | |
6789 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6790 prepare_help_buffer(void) |
6365 | 6791 { |
6792 char_u *p; | |
6793 | |
6794 curbuf->b_help = TRUE; | |
6795 #ifdef FEAT_QUICKFIX | |
6796 set_string_option_direct((char_u *)"buftype", -1, | |
6797 (char_u *)"help", OPT_FREE|OPT_LOCAL, 0); | |
6798 #endif | |
6799 | |
6800 /* | |
6801 * Always set these options after jumping to a help tag, because the | |
6802 * user may have an autocommand that gets in the way. | |
6803 * Accept all ASCII chars for keywords, except ' ', '*', '"', '|', and | |
6804 * latin1 word characters (for translated help files). | |
6805 * Only set it when needed, buf_init_chartab() is some work. | |
6806 */ | |
6807 p = | |
6808 #ifdef EBCDIC | |
6809 (char_u *)"65-255,^*,^|,^\""; | |
6810 #else | |
6811 (char_u *)"!-~,^*,^|,^\",192-255"; | |
6812 #endif | |
6813 if (STRCMP(curbuf->b_p_isk, p) != 0) | |
6814 { | |
6815 set_string_option_direct((char_u *)"isk", -1, p, OPT_FREE|OPT_LOCAL, 0); | |
6816 check_buf_options(curbuf); | |
6817 (void)buf_init_chartab(curbuf, FALSE); | |
6818 } | |
6819 | |
6415 | 6820 #ifdef FEAT_FOLDING |
6365 | 6821 /* Don't use the global foldmethod.*/ |
6822 set_string_option_direct((char_u *)"fdm", -1, (char_u *)"manual", | |
6823 OPT_FREE|OPT_LOCAL, 0); | |
6415 | 6824 #endif |
6365 | 6825 |
6826 curbuf->b_p_ts = 8; /* 'tabstop' is 8 */ | |
6827 curwin->w_p_list = FALSE; /* no list mode */ | |
6828 | |
6829 curbuf->b_p_ma = FALSE; /* not modifiable */ | |
6830 curbuf->b_p_bin = FALSE; /* reset 'bin' before reading file */ | |
6831 curwin->w_p_nu = 0; /* no line numbers */ | |
6832 curwin->w_p_rnu = 0; /* no relative line numbers */ | |
6833 RESET_BINDING(curwin); /* no scroll or cursor binding */ | |
6834 #ifdef FEAT_ARABIC | |
6835 curwin->w_p_arab = FALSE; /* no arabic mode */ | |
6836 #endif | |
6837 #ifdef FEAT_RIGHTLEFT | |
6838 curwin->w_p_rl = FALSE; /* help window is left-to-right */ | |
6839 #endif | |
6840 #ifdef FEAT_FOLDING | |
6841 curwin->w_p_fen = FALSE; /* No folding in the help window */ | |
6842 #endif | |
6843 #ifdef FEAT_DIFF | |
6844 curwin->w_p_diff = FALSE; /* No 'diff' */ | |
6845 #endif | |
6846 #ifdef FEAT_SPELL | |
6847 curwin->w_p_spell = FALSE; /* No spell checking */ | |
6848 #endif | |
6849 | |
6850 set_buflisted(FALSE); | |
6851 } | |
6852 | |
6853 /* | |
7 | 6854 * After reading a help file: May cleanup a help buffer when syntax |
6855 * highlighting is not used. | |
6856 */ | |
6857 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6858 fix_help_buffer(void) |
7 | 6859 { |
6860 linenr_T lnum; | |
6861 char_u *line; | |
6862 int in_example = FALSE; | |
6863 int len; | |
3141 | 6864 char_u *fname; |
7 | 6865 char_u *p; |
6866 char_u *rt; | |
6867 int mustfree; | |
6868 | |
11533
c83dd5fa40d8
patch 8.0.0649: when opening a help file the filetype is set several times
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
6869 /* Set filetype to "help" if still needed. */ |
c83dd5fa40d8
patch 8.0.0649: when opening a help file the filetype is set several times
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
6870 if (STRCMP(curbuf->b_p_ft, "help") != 0) |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11537
diff
changeset
|
6871 { |
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11537
diff
changeset
|
6872 ++curbuf_lock; |
11533
c83dd5fa40d8
patch 8.0.0649: when opening a help file the filetype is set several times
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
6873 set_option_value((char_u *)"ft", 0L, (char_u *)"help", OPT_LOCAL); |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11537
diff
changeset
|
6874 --curbuf_lock; |
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11537
diff
changeset
|
6875 } |
7 | 6876 |
6877 #ifdef FEAT_SYN_HL | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
6878 if (!syntax_present(curwin)) |
7 | 6879 #endif |
6880 { | |
6881 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) | |
6882 { | |
6883 line = ml_get_buf(curbuf, lnum, FALSE); | |
6884 len = (int)STRLEN(line); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
6885 if (in_example && len > 0 && !VIM_ISWHITE(line[0])) |
7 | 6886 { |
6887 /* End of example: non-white or '<' in first column. */ | |
6888 if (line[0] == '<') | |
6889 { | |
6890 /* blank-out a '<' in the first column */ | |
6891 line = ml_get_buf(curbuf, lnum, TRUE); | |
6892 line[0] = ' '; | |
6893 } | |
6894 in_example = FALSE; | |
6895 } | |
6896 if (!in_example && len > 0) | |
6897 { | |
6898 if (line[len - 1] == '>' && (len == 1 || line[len - 2] == ' ')) | |
6899 { | |
6900 /* blank-out a '>' in the last column (start of example) */ | |
6901 line = ml_get_buf(curbuf, lnum, TRUE); | |
6902 line[len - 1] = ' '; | |
6903 in_example = TRUE; | |
6904 } | |
6905 else if (line[len - 1] == '~') | |
6906 { | |
6907 /* blank-out a '~' at the end of line (header marker) */ | |
6908 line = ml_get_buf(curbuf, lnum, TRUE); | |
6909 line[len - 1] = ' '; | |
6910 } | |
6911 } | |
6912 } | |
6913 } | |
6914 | |
6915 /* | |
3141 | 6916 * In the "help.txt" and "help.abx" file, add the locally added help |
6917 * files. This uses the very first line in the help file. | |
7 | 6918 */ |
3141 | 6919 fname = gettail(curbuf->b_fname); |
6920 if (fnamecmp(fname, "help.txt") == 0 | |
6921 #ifdef FEAT_MULTI_LANG | |
6922 || (fnamencmp(fname, "help.", 5) == 0 | |
6923 && ASCII_ISALPHA(fname[5]) | |
6924 && ASCII_ISALPHA(fname[6]) | |
6925 && TOLOWER_ASC(fname[7]) == 'x' | |
6926 && fname[8] == NUL) | |
6927 #endif | |
6928 ) | |
7 | 6929 { |
6930 for (lnum = 1; lnum < curbuf->b_ml.ml_line_count; ++lnum) | |
6931 { | |
6932 line = ml_get_buf(curbuf, lnum, FALSE); | |
3141 | 6933 if (strstr((char *)line, "*local-additions*") == NULL) |
6934 continue; | |
6935 | |
6936 /* Go through all directories in 'runtimepath', skipping | |
6937 * $VIMRUNTIME. */ | |
6938 p = p_rtp; | |
6939 while (*p != NUL) | |
7 | 6940 { |
3141 | 6941 copy_option_part(&p, NameBuff, MAXPATHL, ","); |
6942 mustfree = FALSE; | |
6943 rt = vim_getenv((char_u *)"VIMRUNTIME", &mustfree); | |
13276
6958e700a458
patch 8.0.1512: warning for possibly using NULL pointer
Christian Brabandt <cb@256bit.org>
parents:
13268
diff
changeset
|
6944 if (rt != NULL && fullpathcmp(rt, NameBuff, FALSE) != FPC_SAME) |
7 | 6945 { |
3141 | 6946 int fcount; |
6947 char_u **fnames; | |
6948 FILE *fd; | |
6949 char_u *s; | |
6950 int fi; | |
7 | 6951 #ifdef FEAT_MBYTE |
3141 | 6952 vimconv_T vc; |
6953 char_u *cp; | |
6954 #endif | |
6955 | |
6956 /* Find all "doc/ *.txt" files in this directory. */ | |
6957 add_pathsep(NameBuff); | |
6958 #ifdef FEAT_MULTI_LANG | |
6959 STRCAT(NameBuff, "doc/*.??[tx]"); | |
7 | 6960 #else |
3141 | 6961 STRCAT(NameBuff, "doc/*.txt"); |
6962 #endif | |
6963 if (gen_expand_wildcards(1, &NameBuff, &fcount, | |
6964 &fnames, EW_FILE|EW_SILENT) == OK | |
6965 && fcount > 0) | |
6966 { | |
6967 #ifdef FEAT_MULTI_LANG | |
13014
e1deb00ffc27
patch 8.0.1383: local additions in help skips some files
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
6968 int i1, i2; |
e1deb00ffc27
patch 8.0.1383: local additions in help skips some files
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
6969 char_u *f1, *f2; |
e1deb00ffc27
patch 8.0.1383: local additions in help skips some files
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
6970 char_u *t1, *t2; |
e1deb00ffc27
patch 8.0.1383: local additions in help skips some files
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
6971 char_u *e1, *e2; |
3141 | 6972 |
6973 /* If foo.abx is found use it instead of foo.txt in | |
6974 * the same directory. */ | |
6975 for (i1 = 0; i1 < fcount; ++i1) | |
6976 { | |
6977 for (i2 = 0; i2 < fcount; ++i2) | |
6978 { | |
6979 if (i1 == i2) | |
6980 continue; | |
6981 if (fnames[i1] == NULL || fnames[i2] == NULL) | |
6982 continue; | |
6983 f1 = fnames[i1]; | |
6984 f2 = fnames[i2]; | |
6985 t1 = gettail(f1); | |
13014
e1deb00ffc27
patch 8.0.1383: local additions in help skips some files
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
6986 t2 = gettail(f2); |
3141 | 6987 e1 = vim_strrchr(t1, '.'); |
13014
e1deb00ffc27
patch 8.0.1383: local additions in help skips some files
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
6988 e2 = vim_strrchr(t2, '.'); |
10299
7b2f95633e28
commit https://github.com/vim/vim/commit/7756e7465d627ff9cd01e59625484a8c302ef853
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
6989 if (e1 == NULL || e2 == NULL) |
3141 | 6990 continue; |
6991 if (fnamecmp(e1, ".txt") != 0 | |
6992 && fnamecmp(e1, fname + 4) != 0) | |
6993 { | |
6994 /* Not .txt and not .abx, remove it. */ | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13174
diff
changeset
|
6995 VIM_CLEAR(fnames[i1]); |
3141 | 6996 continue; |
6997 } | |
13014
e1deb00ffc27
patch 8.0.1383: local additions in help skips some files
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
6998 if (e1 - f1 != e2 - f2 |
e1deb00ffc27
patch 8.0.1383: local additions in help skips some files
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
6999 || fnamencmp(f1, f2, e1 - f1) != 0) |
3141 | 7000 continue; |
7001 if (fnamecmp(e1, ".txt") == 0 | |
7002 && fnamecmp(e2, fname + 4) == 0) | |
7003 /* use .abx instead of .txt */ | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13174
diff
changeset
|
7004 VIM_CLEAR(fnames[i1]); |
7 | 7005 } |
7006 } | |
3141 | 7007 #endif |
7008 for (fi = 0; fi < fcount; ++fi) | |
7009 { | |
7010 if (fnames[fi] == NULL) | |
7011 continue; | |
7012 fd = mch_fopen((char *)fnames[fi], "r"); | |
7013 if (fd != NULL) | |
7014 { | |
7015 vim_fgets(IObuff, IOSIZE, fd); | |
7016 if (IObuff[0] == '*' | |
7017 && (s = vim_strchr(IObuff + 1, '*')) | |
7018 != NULL) | |
7019 { | |
7020 #ifdef FEAT_MBYTE | |
7021 int this_utf = MAYBE; | |
7022 #endif | |
7023 /* Change tag definition to a | |
7024 * reference and remove <CR>/<NL>. */ | |
7025 IObuff[0] = '|'; | |
7026 *s = '|'; | |
7027 while (*s != NUL) | |
7028 { | |
7029 if (*s == '\r' || *s == '\n') | |
7030 *s = NUL; | |
7031 #ifdef FEAT_MBYTE | |
7032 /* The text is utf-8 when a byte | |
7033 * above 127 is found and no | |
7034 * illegal byte sequence is found. | |
7035 */ | |
7036 if (*s >= 0x80 && this_utf != FALSE) | |
7037 { | |
7038 int l; | |
7039 | |
7040 this_utf = TRUE; | |
7041 l = utf_ptr2len(s); | |
7042 if (l == 1) | |
7043 this_utf = FALSE; | |
7044 s += l - 1; | |
7045 } | |
7046 #endif | |
7047 ++s; | |
7048 } | |
7049 #ifdef FEAT_MBYTE | |
7050 /* The help file is latin1 or utf-8; | |
7051 * conversion to the current | |
7052 * 'encoding' may be required. */ | |
7053 vc.vc_type = CONV_NONE; | |
7054 convert_setup(&vc, (char_u *)( | |
7055 this_utf == TRUE ? "utf-8" | |
7056 : "latin1"), p_enc); | |
7057 if (vc.vc_type == CONV_NONE) | |
7058 /* No conversion needed. */ | |
7059 cp = IObuff; | |
7060 else | |
7061 { | |
7062 /* Do the conversion. If it fails | |
7063 * use the unconverted text. */ | |
7064 cp = string_convert(&vc, IObuff, | |
7065 NULL); | |
7066 if (cp == NULL) | |
7067 cp = IObuff; | |
7068 } | |
7069 convert_setup(&vc, NULL, NULL); | |
7070 | |
7071 ml_append(lnum, cp, (colnr_T)0, FALSE); | |
7072 if (cp != IObuff) | |
7073 vim_free(cp); | |
7074 #else | |
7075 ml_append(lnum, IObuff, (colnr_T)0, | |
7076 FALSE); | |
7077 #endif | |
7078 ++lnum; | |
7079 } | |
7080 fclose(fd); | |
7081 } | |
7082 } | |
7083 FreeWild(fcount, fnames); | |
7 | 7084 } |
7085 } | |
3141 | 7086 if (mustfree) |
7087 vim_free(rt); | |
7 | 7088 } |
3141 | 7089 break; |
7 | 7090 } |
7091 } | |
7092 } | |
7093 | |
40 | 7094 /* |
7095 * ":exusage" | |
7096 */ | |
7097 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7098 ex_exusage(exarg_T *eap UNUSED) |
40 | 7099 { |
7100 do_cmdline_cmd((char_u *)"help ex-cmd-index"); | |
7101 } | |
7102 | |
7103 /* | |
7104 * ":viusage" | |
7105 */ | |
7106 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7107 ex_viusage(exarg_T *eap UNUSED) |
40 | 7108 { |
7109 do_cmdline_cmd((char_u *)"help normal-index"); | |
7110 } | |
7111 | |
7 | 7112 /* |
8522
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7113 * Generate tags in one help directory. |
7 | 7114 */ |
7115 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7116 helptags_one( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7117 char_u *dir, /* doc directory */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7118 char_u *ext, /* suffix, ".txt", ".itx", ".frx", etc. */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7119 char_u *tagfname, /* "tags" for English, "tags-fr" for French. */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7120 int add_help_tags) /* add "help-tags" tag */ |
7 | 7121 { |
7122 FILE *fd_tags; | |
7123 FILE *fd; | |
7124 garray_T ga; | |
7125 int filecount; | |
7126 char_u **files; | |
7127 char_u *p1, *p2; | |
7128 int fi; | |
7129 char_u *s; | |
7130 int i; | |
7131 char_u *fname; | |
3957 | 7132 int dirlen; |
7 | 7133 # ifdef FEAT_MBYTE |
7134 int utf8 = MAYBE; | |
7135 int this_utf8; | |
7136 int firstline; | |
7137 int mix = FALSE; /* detected mixed encodings */ | |
7138 # endif | |
7139 | |
7140 /* | |
7141 * Find all *.txt files. | |
7142 */ | |
3978 | 7143 dirlen = (int)STRLEN(dir); |
7 | 7144 STRCPY(NameBuff, dir); |
3957 | 7145 STRCAT(NameBuff, "/**/*"); |
7 | 7146 STRCAT(NameBuff, ext); |
7147 if (gen_expand_wildcards(1, &NameBuff, &filecount, &files, | |
7148 EW_FILE|EW_SILENT) == FAIL | |
7149 || filecount == 0) | |
7150 { | |
7151 if (!got_int) | |
9953
9560a2eb7968
commit https://github.com/vim/vim/commit/5b30291785e6b9be1a607504c14bd03c601b59a6
Christian Brabandt <cb@256bit.org>
parents:
9947
diff
changeset
|
7152 EMSG2(_("E151: No match: %s"), NameBuff); |
7 | 7153 return; |
7154 } | |
7155 | |
7156 /* | |
7157 * Open the tags file for writing. | |
7158 * Do this before scanning through all the files. | |
7159 */ | |
7160 STRCPY(NameBuff, dir); | |
7161 add_pathsep(NameBuff); | |
7162 STRCAT(NameBuff, tagfname); | |
531 | 7163 fd_tags = mch_fopen((char *)NameBuff, "w"); |
7 | 7164 if (fd_tags == NULL) |
7165 { | |
7166 EMSG2(_("E152: Cannot open %s for writing"), NameBuff); | |
7167 FreeWild(filecount, files); | |
7168 return; | |
7169 } | |
7170 | |
7171 /* | |
1502 | 7172 * If using the "++t" argument or generating tags for "$VIMRUNTIME/doc" |
7173 * add the "help-tags" tag. | |
7 | 7174 */ |
7175 ga_init2(&ga, (int)sizeof(char_u *), 100); | |
1502 | 7176 if (add_help_tags || fullpathcmp((char_u *)"$VIMRUNTIME/doc", |
7177 dir, FALSE) == FPC_SAME) | |
7 | 7178 { |
7179 if (ga_grow(&ga, 1) == FAIL) | |
7180 got_int = TRUE; | |
7181 else | |
7182 { | |
835 | 7183 s = alloc(18 + (unsigned)STRLEN(tagfname)); |
7 | 7184 if (s == NULL) |
7185 got_int = TRUE; | |
7186 else | |
7187 { | |
7188 sprintf((char *)s, "help-tags\t%s\t1\n", tagfname); | |
7189 ((char_u **)ga.ga_data)[ga.ga_len] = s; | |
7190 ++ga.ga_len; | |
7191 } | |
7192 } | |
7193 } | |
7194 | |
7195 /* | |
7196 * Go over all the files and extract the tags. | |
7197 */ | |
7198 for (fi = 0; fi < filecount && !got_int; ++fi) | |
7199 { | |
531 | 7200 fd = mch_fopen((char *)files[fi], "r"); |
7 | 7201 if (fd == NULL) |
7202 { | |
7203 EMSG2(_("E153: Unable to open %s for reading"), files[fi]); | |
7204 continue; | |
7205 } | |
3957 | 7206 fname = files[fi] + dirlen + 1; |
7 | 7207 |
7208 # ifdef FEAT_MBYTE | |
7209 firstline = TRUE; | |
7210 # endif | |
7211 while (!vim_fgets(IObuff, IOSIZE, fd) && !got_int) | |
7212 { | |
7213 # ifdef FEAT_MBYTE | |
7214 if (firstline) | |
7215 { | |
7216 /* Detect utf-8 file by a non-ASCII char in the first line. */ | |
7217 this_utf8 = MAYBE; | |
7218 for (s = IObuff; *s != NUL; ++s) | |
7219 if (*s >= 0x80) | |
7220 { | |
7221 int l; | |
7222 | |
7223 this_utf8 = TRUE; | |
474 | 7224 l = utf_ptr2len(s); |
7 | 7225 if (l == 1) |
7226 { | |
7227 /* Illegal UTF-8 byte sequence. */ | |
7228 this_utf8 = FALSE; | |
7229 break; | |
7230 } | |
7231 s += l - 1; | |
7232 } | |
7233 if (this_utf8 == MAYBE) /* only ASCII characters found */ | |
7234 this_utf8 = FALSE; | |
7235 if (utf8 == MAYBE) /* first file */ | |
7236 utf8 = this_utf8; | |
7237 else if (utf8 != this_utf8) | |
7238 { | |
7239 EMSG2(_("E670: Mix of help file encodings within a language: %s"), files[fi]); | |
7240 mix = !got_int; | |
7241 got_int = TRUE; | |
7242 } | |
7243 firstline = FALSE; | |
7244 } | |
7245 # endif | |
7246 p1 = vim_strchr(IObuff, '*'); /* find first '*' */ | |
7247 while (p1 != NULL) | |
7248 { | |
3514 | 7249 /* Use vim_strbyte() instead of vim_strchr() so that when |
7250 * 'encoding' is dbcs it still works, don't find '*' in the | |
7251 * second byte. */ | |
7252 p2 = vim_strbyte(p1 + 1, '*'); /* find second '*' */ | |
7 | 7253 if (p2 != NULL && p2 > p1 + 1) /* skip "*" and "**" */ |
7254 { | |
7255 for (s = p1 + 1; s < p2; ++s) | |
7256 if (*s == ' ' || *s == '\t' || *s == '|') | |
7257 break; | |
7258 | |
7259 /* | |
7260 * Only accept a *tag* when it consists of valid | |
7261 * characters, there is white space before it and is | |
7262 * followed by a white character or end-of-line. | |
7263 */ | |
7264 if (s == p2 | |
7265 && (p1 == IObuff || p1[-1] == ' ' || p1[-1] == '\t') | |
7266 && (vim_strchr((char_u *)" \t\n\r", s[1]) != NULL | |
7267 || s[1] == '\0')) | |
7268 { | |
7269 *p2 = '\0'; | |
7270 ++p1; | |
7271 if (ga_grow(&ga, 1) == FAIL) | |
7272 { | |
7273 got_int = TRUE; | |
7274 break; | |
7275 } | |
7276 s = alloc((unsigned)(p2 - p1 + STRLEN(fname) + 2)); | |
7277 if (s == NULL) | |
7278 { | |
7279 got_int = TRUE; | |
7280 break; | |
7281 } | |
7282 ((char_u **)ga.ga_data)[ga.ga_len] = s; | |
7283 ++ga.ga_len; | |
7284 sprintf((char *)s, "%s\t%s", p1, fname); | |
7285 | |
7286 /* find next '*' */ | |
7287 p2 = vim_strchr(p2 + 1, '*'); | |
7288 } | |
7289 } | |
7290 p1 = p2; | |
7291 } | |
7292 line_breakcheck(); | |
7293 } | |
7294 | |
7295 fclose(fd); | |
7296 } | |
7297 | |
7298 FreeWild(filecount, files); | |
7299 | |
7300 if (!got_int) | |
7301 { | |
7302 /* | |
7303 * Sort the tags. | |
7304 */ | |
7009 | 7305 if (ga.ga_data != NULL) |
7306 sort_strings((char_u **)ga.ga_data, ga.ga_len); | |
7 | 7307 |
7308 /* | |
7309 * Check for duplicates. | |
7310 */ | |
7311 for (i = 1; i < ga.ga_len; ++i) | |
7312 { | |
7313 p1 = ((char_u **)ga.ga_data)[i - 1]; | |
7314 p2 = ((char_u **)ga.ga_data)[i]; | |
7315 while (*p1 == *p2) | |
7316 { | |
7317 if (*p2 == '\t') | |
7318 { | |
7319 *p2 = NUL; | |
274 | 7320 vim_snprintf((char *)NameBuff, MAXPATHL, |
7 | 7321 _("E154: Duplicate tag \"%s\" in file %s/%s"), |
7322 ((char_u **)ga.ga_data)[i], dir, p2 + 1); | |
7323 EMSG(NameBuff); | |
7324 *p2 = '\t'; | |
7325 break; | |
7326 } | |
7327 ++p1; | |
7328 ++p2; | |
7329 } | |
7330 } | |
7331 | |
7332 # ifdef FEAT_MBYTE | |
7333 if (utf8 == TRUE) | |
7334 fprintf(fd_tags, "!_TAG_FILE_ENCODING\tutf-8\t//\n"); | |
7335 # endif | |
7336 | |
7337 /* | |
7338 * Write the tags into the file. | |
7339 */ | |
7340 for (i = 0; i < ga.ga_len; ++i) | |
7341 { | |
7342 s = ((char_u **)ga.ga_data)[i]; | |
1325 | 7343 if (STRNCMP(s, "help-tags\t", 10) == 0) |
7 | 7344 /* help-tags entry was added in formatted form */ |
1325 | 7345 fputs((char *)s, fd_tags); |
7 | 7346 else |
7347 { | |
7348 fprintf(fd_tags, "%s\t/*", s); | |
7349 for (p1 = s; *p1 != '\t'; ++p1) | |
7350 { | |
7351 /* insert backslash before '\\' and '/' */ | |
7352 if (*p1 == '\\' || *p1 == '/') | |
7353 putc('\\', fd_tags); | |
7354 putc(*p1, fd_tags); | |
7355 } | |
7356 fprintf(fd_tags, "*\n"); | |
7357 } | |
7358 } | |
7359 } | |
7360 #ifdef FEAT_MBYTE | |
7361 if (mix) | |
7362 got_int = FALSE; /* continue with other languages */ | |
7363 #endif | |
7364 | |
7365 for (i = 0; i < ga.ga_len; ++i) | |
7366 vim_free(((char_u **)ga.ga_data)[i]); | |
7367 ga_clear(&ga); | |
7368 fclose(fd_tags); /* there is no check for an error... */ | |
7369 } | |
7370 | |
8522
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7371 /* |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7372 * Generate tags in one help directory, taking care of translations. |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7373 */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7374 static void |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7375 do_helptags(char_u *dirname, int add_help_tags) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7376 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7377 #ifdef FEAT_MULTI_LANG |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7378 int len; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7379 int i, j; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7380 garray_T ga; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7381 char_u lang[2]; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7382 char_u ext[5]; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7383 char_u fname[8]; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7384 int filecount; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7385 char_u **files; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7386 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7387 /* Get a list of all files in the help directory and in subdirectories. */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7388 STRCPY(NameBuff, dirname); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7389 add_pathsep(NameBuff); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7390 STRCAT(NameBuff, "**"); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7391 if (gen_expand_wildcards(1, &NameBuff, &filecount, &files, |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7392 EW_FILE|EW_SILENT) == FAIL |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7393 || filecount == 0) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7394 { |
9953
9560a2eb7968
commit https://github.com/vim/vim/commit/5b30291785e6b9be1a607504c14bd03c601b59a6
Christian Brabandt <cb@256bit.org>
parents:
9947
diff
changeset
|
7395 EMSG2(_("E151: No match: %s"), NameBuff); |
8522
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7396 return; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7397 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7398 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7399 /* Go over all files in the directory to find out what languages are |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7400 * present. */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7401 ga_init2(&ga, 1, 10); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7402 for (i = 0; i < filecount; ++i) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7403 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7404 len = (int)STRLEN(files[i]); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7405 if (len > 4) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7406 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7407 if (STRICMP(files[i] + len - 4, ".txt") == 0) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7408 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7409 /* ".txt" -> language "en" */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7410 lang[0] = 'e'; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7411 lang[1] = 'n'; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7412 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7413 else if (files[i][len - 4] == '.' |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7414 && ASCII_ISALPHA(files[i][len - 3]) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7415 && ASCII_ISALPHA(files[i][len - 2]) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7416 && TOLOWER_ASC(files[i][len - 1]) == 'x') |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7417 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7418 /* ".abx" -> language "ab" */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7419 lang[0] = TOLOWER_ASC(files[i][len - 3]); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7420 lang[1] = TOLOWER_ASC(files[i][len - 2]); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7421 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7422 else |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7423 continue; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7424 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7425 /* Did we find this language already? */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7426 for (j = 0; j < ga.ga_len; j += 2) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7427 if (STRNCMP(lang, ((char_u *)ga.ga_data) + j, 2) == 0) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7428 break; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7429 if (j == ga.ga_len) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7430 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7431 /* New language, add it. */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7432 if (ga_grow(&ga, 2) == FAIL) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7433 break; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7434 ((char_u *)ga.ga_data)[ga.ga_len++] = lang[0]; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7435 ((char_u *)ga.ga_data)[ga.ga_len++] = lang[1]; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7436 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7437 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7438 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7439 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7440 /* |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7441 * Loop over the found languages to generate a tags file for each one. |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7442 */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7443 for (j = 0; j < ga.ga_len; j += 2) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7444 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7445 STRCPY(fname, "tags-xx"); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7446 fname[5] = ((char_u *)ga.ga_data)[j]; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7447 fname[6] = ((char_u *)ga.ga_data)[j + 1]; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7448 if (fname[5] == 'e' && fname[6] == 'n') |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7449 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7450 /* English is an exception: use ".txt" and "tags". */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7451 fname[4] = NUL; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7452 STRCPY(ext, ".txt"); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7453 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7454 else |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7455 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7456 /* Language "ab" uses ".abx" and "tags-ab". */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7457 STRCPY(ext, ".xxx"); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7458 ext[1] = fname[5]; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7459 ext[2] = fname[6]; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7460 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7461 helptags_one(dirname, ext, fname, add_help_tags); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7462 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7463 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7464 ga_clear(&ga); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7465 FreeWild(filecount, files); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7466 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7467 #else |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7468 /* No language support, just use "*.txt" and "tags". */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7469 helptags_one(dirname, (char_u *)".txt", (char_u *)"tags", add_help_tags); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7470 #endif |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7471 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7472 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7473 static void |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7474 helptags_cb(char_u *fname, void *cookie) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7475 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7476 do_helptags(fname, *(int *)cookie); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7477 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7478 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7479 /* |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7480 * ":helptags" |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7481 */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7482 void |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7483 ex_helptags(exarg_T *eap) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7484 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7485 expand_T xpc; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7486 char_u *dirname; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7487 int add_help_tags = FALSE; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7488 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7489 /* Check for ":helptags ++t {dir}". */ |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
7490 if (STRNCMP(eap->arg, "++t", 3) == 0 && VIM_ISWHITE(eap->arg[3])) |
8522
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7491 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7492 add_help_tags = TRUE; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7493 eap->arg = skipwhite(eap->arg + 3); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7494 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7495 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7496 if (STRCMP(eap->arg, "ALL") == 0) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7497 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7498 do_in_path(p_rtp, (char_u *)"doc", DIP_ALL + DIP_DIR, |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7499 helptags_cb, &add_help_tags); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7500 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7501 else |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7502 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7503 ExpandInit(&xpc); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7504 xpc.xp_context = EXPAND_DIRECTORIES; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7505 dirname = ExpandOne(&xpc, eap->arg, NULL, |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7506 WILD_LIST_NOTFOUND|WILD_SILENT, WILD_EXPAND_FREE); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7507 if (dirname == NULL || !mch_isdir(dirname)) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7508 EMSG2(_("E150: Not a directory: %s"), eap->arg); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7509 else |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7510 do_helptags(dirname, add_help_tags); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7511 vim_free(dirname); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7512 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7513 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7514 |
7 | 7515 #if defined(FEAT_SIGNS) || defined(PROTO) |
7516 | |
7517 /* | |
7518 * Struct to hold the sign properties. | |
7519 */ | |
7520 typedef struct sign sign_T; | |
7521 | |
7522 struct sign | |
7523 { | |
7524 sign_T *sn_next; /* next sign in list */ | |
2606 | 7525 int sn_typenr; /* type number of sign */ |
7 | 7526 char_u *sn_name; /* name of sign */ |
7527 char_u *sn_icon; /* name of pixmap */ | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7528 # ifdef FEAT_SIGN_ICONS |
7 | 7529 void *sn_image; /* icon image */ |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7530 # endif |
7 | 7531 char_u *sn_text; /* text used instead of pixmap */ |
7532 int sn_line_hl; /* highlight ID for line */ | |
7533 int sn_text_hl; /* highlight ID for text */ | |
7534 }; | |
7535 | |
7536 static sign_T *first_sign = NULL; | |
2605 | 7537 static int next_sign_typenr = 1; |
7 | 7538 |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
7539 static int sign_cmd_idx(char_u *begin_cmd, char_u *end_cmd); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
7540 static void sign_list_defined(sign_T *sp); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
7541 static void sign_undefine(sign_T *sp, sign_T *sp_prev); |
7 | 7542 |
1868 | 7543 static char *cmds[] = { |
7544 "define", | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7545 # define SIGNCMD_DEFINE 0 |
1868 | 7546 "undefine", |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7547 # define SIGNCMD_UNDEFINE 1 |
1868 | 7548 "list", |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7549 # define SIGNCMD_LIST 2 |
1868 | 7550 "place", |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7551 # define SIGNCMD_PLACE 3 |
1868 | 7552 "unplace", |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7553 # define SIGNCMD_UNPLACE 4 |
1868 | 7554 "jump", |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7555 # define SIGNCMD_JUMP 5 |
1868 | 7556 NULL |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7557 # define SIGNCMD_LAST 6 |
1868 | 7558 }; |
7559 | |
7560 /* | |
7561 * Find index of a ":sign" subcmd from its name. | |
7562 * "*end_cmd" must be writable. | |
7563 */ | |
7564 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7565 sign_cmd_idx( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7566 char_u *begin_cmd, /* begin of sign subcmd */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7567 char_u *end_cmd) /* just after sign subcmd */ |
1868 | 7568 { |
7569 int idx; | |
7570 char save = *end_cmd; | |
7571 | |
7572 *end_cmd = NUL; | |
7573 for (idx = 0; ; ++idx) | |
7574 if (cmds[idx] == NULL || STRCMP(begin_cmd, cmds[idx]) == 0) | |
7575 break; | |
7576 *end_cmd = save; | |
7577 return idx; | |
7578 } | |
7579 | |
7 | 7580 /* |
7581 * ":sign" command | |
7582 */ | |
7583 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7584 ex_sign(exarg_T *eap) |
7 | 7585 { |
7586 char_u *arg = eap->arg; | |
7587 char_u *p; | |
7588 int idx; | |
7589 sign_T *sp; | |
7590 sign_T *sp_prev; | |
12820
63d87ba12c34
patch 8.0.1287: temp file used for viminfo may have wrong permissions
Christian Brabandt <cb@256bit.org>
parents:
12676
diff
changeset
|
7591 buf_T *buf = NULL; |
7 | 7592 |
7593 /* Parse the subcommand. */ | |
7594 p = skiptowhite(arg); | |
1868 | 7595 idx = sign_cmd_idx(arg, p); |
7596 if (idx == SIGNCMD_LAST) | |
7597 { | |
7598 EMSG2(_("E160: Unknown sign command: %s"), arg); | |
7599 return; | |
7 | 7600 } |
7601 arg = skipwhite(p); | |
7602 | |
7603 if (idx <= SIGNCMD_LIST) | |
7604 { | |
7605 /* | |
7606 * Define, undefine or list signs. | |
7607 */ | |
7608 if (idx == SIGNCMD_LIST && *arg == NUL) | |
7609 { | |
7610 /* ":sign list": list all defined signs */ | |
3411 | 7611 for (sp = first_sign; sp != NULL && !got_int; sp = sp->sn_next) |
7 | 7612 sign_list_defined(sp); |
7613 } | |
7614 else if (*arg == NUL) | |
7615 EMSG(_("E156: Missing sign name")); | |
7616 else | |
7617 { | |
2605 | 7618 /* Isolate the sign name. If it's a number skip leading zeroes, |
7619 * so that "099" and "99" are the same sign. But keep "0". */ | |
7 | 7620 p = skiptowhite(arg); |
7621 if (*p != NUL) | |
7622 *p++ = NUL; | |
2605 | 7623 while (arg[0] == '0' && arg[1] != NUL) |
7624 ++arg; | |
7625 | |
7 | 7626 sp_prev = NULL; |
7627 for (sp = first_sign; sp != NULL; sp = sp->sn_next) | |
7628 { | |
7629 if (STRCMP(sp->sn_name, arg) == 0) | |
7630 break; | |
7631 sp_prev = sp; | |
7632 } | |
7633 if (idx == SIGNCMD_DEFINE) | |
7634 { | |
7635 /* ":sign define {name} ...": define a sign */ | |
7636 if (sp == NULL) | |
7637 { | |
2605 | 7638 sign_T *lp; |
7639 int start = next_sign_typenr; | |
7640 | |
7 | 7641 /* Allocate a new sign. */ |
7642 sp = (sign_T *)alloc_clear((unsigned)sizeof(sign_T)); | |
7643 if (sp == NULL) | |
7644 return; | |
7645 | |
2605 | 7646 /* Check that next_sign_typenr is not already being used. |
7647 * This only happens after wrapping around. Hopefully | |
7648 * another one got deleted and we can use its number. */ | |
7649 for (lp = first_sign; lp != NULL; ) | |
7 | 7650 { |
2605 | 7651 if (lp->sn_typenr == next_sign_typenr) |
7 | 7652 { |
2605 | 7653 ++next_sign_typenr; |
7654 if (next_sign_typenr == MAX_TYPENR) | |
7655 next_sign_typenr = 1; | |
7656 if (next_sign_typenr == start) | |
7 | 7657 { |
2605 | 7658 vim_free(sp); |
7659 EMSG(_("E612: Too many signs defined")); | |
7660 return; | |
7 | 7661 } |
2605 | 7662 lp = first_sign; /* start all over */ |
7663 continue; | |
7 | 7664 } |
2605 | 7665 lp = lp->sn_next; |
7666 } | |
7667 | |
7668 sp->sn_typenr = next_sign_typenr; | |
7669 if (++next_sign_typenr == MAX_TYPENR) | |
7670 next_sign_typenr = 1; /* wrap around */ | |
7671 | |
7672 sp->sn_name = vim_strsave(arg); | |
7673 if (sp->sn_name == NULL) /* out of memory */ | |
7674 { | |
7675 vim_free(sp); | |
7676 return; | |
7 | 7677 } |
2601 | 7678 |
7679 /* add the new sign to the list of signs */ | |
7680 if (sp_prev == NULL) | |
7681 first_sign = sp; | |
7682 else | |
7683 sp_prev->sn_next = sp; | |
7 | 7684 } |
7685 | |
7686 /* set values for a defined sign. */ | |
7687 for (;;) | |
7688 { | |
7689 arg = skipwhite(p); | |
7690 if (*arg == NUL) | |
7691 break; | |
7692 p = skiptowhite_esc(arg); | |
7693 if (STRNCMP(arg, "icon=", 5) == 0) | |
7694 { | |
7695 arg += 5; | |
7696 vim_free(sp->sn_icon); | |
7697 sp->sn_icon = vim_strnsave(arg, (int)(p - arg)); | |
7698 backslash_halve(sp->sn_icon); | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7699 # ifdef FEAT_SIGN_ICONS |
7 | 7700 if (gui.in_use) |
7701 { | |
7702 out_flush(); | |
7703 if (sp->sn_image != NULL) | |
7704 gui_mch_destroy_sign(sp->sn_image); | |
7705 sp->sn_image = gui_mch_register_sign(sp->sn_icon); | |
7706 } | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7707 # endif |
7 | 7708 } |
7709 else if (STRNCMP(arg, "text=", 5) == 0) | |
7710 { | |
7711 char_u *s; | |
7712 int cells; | |
7713 int len; | |
7714 | |
7715 arg += 5; | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7716 # ifdef FEAT_MBYTE |
7 | 7717 /* Count cells and check for non-printable chars */ |
7718 if (has_mbyte) | |
7719 { | |
7720 cells = 0; | |
474 | 7721 for (s = arg; s < p; s += (*mb_ptr2len)(s)) |
7 | 7722 { |
7723 if (!vim_isprintc((*mb_ptr2char)(s))) | |
7724 break; | |
7725 cells += (*mb_ptr2cells)(s); | |
7726 } | |
7727 } | |
7728 else | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7729 # endif |
7 | 7730 { |
7731 for (s = arg; s < p; ++s) | |
7732 if (!vim_isprintc(*s)) | |
7733 break; | |
835 | 7734 cells = (int)(s - arg); |
7 | 7735 } |
7736 /* Currently must be one or two display cells */ | |
7737 if (s != p || cells < 1 || cells > 2) | |
7738 { | |
7739 *p = NUL; | |
7740 EMSG2(_("E239: Invalid sign text: %s"), arg); | |
7741 return; | |
7742 } | |
7743 | |
7744 vim_free(sp->sn_text); | |
7745 /* Allocate one byte more if we need to pad up | |
7746 * with a space. */ | |
835 | 7747 len = (int)(p - arg + ((cells == 1) ? 1 : 0)); |
7 | 7748 sp->sn_text = vim_strnsave(arg, len); |
7749 | |
7750 if (sp->sn_text != NULL && cells == 1) | |
7751 STRCPY(sp->sn_text + len - 1, " "); | |
7752 } | |
7753 else if (STRNCMP(arg, "linehl=", 7) == 0) | |
7754 { | |
7755 arg += 7; | |
7756 sp->sn_line_hl = syn_check_group(arg, (int)(p - arg)); | |
7757 } | |
7758 else if (STRNCMP(arg, "texthl=", 7) == 0) | |
7759 { | |
7760 arg += 7; | |
7761 sp->sn_text_hl = syn_check_group(arg, (int)(p - arg)); | |
7762 } | |
7763 else | |
7764 { | |
7765 EMSG2(_(e_invarg2), arg); | |
7766 return; | |
7767 } | |
7768 } | |
7769 } | |
7770 else if (sp == NULL) | |
7771 EMSG2(_("E155: Unknown sign: %s"), arg); | |
7772 else if (idx == SIGNCMD_LIST) | |
7773 /* ":sign list {name}" */ | |
7774 sign_list_defined(sp); | |
7775 else | |
7776 /* ":sign undefine {name}" */ | |
1828 | 7777 sign_undefine(sp, sp_prev); |
7 | 7778 } |
7779 } | |
7780 else | |
7781 { | |
7782 int id = -1; | |
7783 linenr_T lnum = -1; | |
7784 char_u *sign_name = NULL; | |
7785 char_u *arg1; | |
7786 | |
7787 if (*arg == NUL) | |
7788 { | |
7789 if (idx == SIGNCMD_PLACE) | |
7790 { | |
7791 /* ":sign place": list placed signs in all buffers */ | |
7792 sign_list_placed(NULL); | |
7793 } | |
7794 else if (idx == SIGNCMD_UNPLACE) | |
7795 { | |
7796 /* ":sign unplace": remove placed sign at cursor */ | |
7797 id = buf_findsign_id(curwin->w_buffer, curwin->w_cursor.lnum); | |
7798 if (id > 0) | |
7799 { | |
7800 buf_delsign(curwin->w_buffer, id); | |
7801 update_debug_sign(curwin->w_buffer, curwin->w_cursor.lnum); | |
7802 } | |
7803 else | |
7804 EMSG(_("E159: Missing sign number")); | |
7805 } | |
7806 else | |
7807 EMSG(_(e_argreq)); | |
7808 return; | |
7809 } | |
7810 | |
7811 if (idx == SIGNCMD_UNPLACE && arg[0] == '*' && arg[1] == NUL) | |
7812 { | |
7813 /* ":sign unplace *": remove all placed signs */ | |
7814 buf_delete_all_signs(); | |
7815 return; | |
7816 } | |
7817 | |
7818 /* first arg could be placed sign id */ | |
7819 arg1 = arg; | |
7820 if (VIM_ISDIGIT(*arg)) | |
7821 { | |
7822 id = getdigits(&arg); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
7823 if (!VIM_ISWHITE(*arg) && *arg != NUL) |
7 | 7824 { |
7825 id = -1; | |
7826 arg = arg1; | |
7827 } | |
7828 else | |
7829 { | |
7830 arg = skipwhite(arg); | |
7831 if (idx == SIGNCMD_UNPLACE && *arg == NUL) | |
7832 { | |
7833 /* ":sign unplace {id}": remove placed sign by number */ | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
7834 FOR_ALL_BUFFERS(buf) |
7 | 7835 if ((lnum = buf_delsign(buf, id)) != 0) |
7836 update_debug_sign(buf, lnum); | |
7837 return; | |
7838 } | |
7839 } | |
7840 } | |
7841 | |
7842 /* | |
7843 * Check for line={lnum} name={name} and file={fname} or buffer={nr}. | |
7844 * Leave "arg" pointing to {fname}. | |
7845 */ | |
7846 for (;;) | |
7847 { | |
7848 if (STRNCMP(arg, "line=", 5) == 0) | |
7849 { | |
7850 arg += 5; | |
7851 lnum = atoi((char *)arg); | |
7852 arg = skiptowhite(arg); | |
7853 } | |
3672 | 7854 else if (STRNCMP(arg, "*", 1) == 0 && idx == SIGNCMD_UNPLACE) |
7855 { | |
7856 if (id != -1) | |
7857 { | |
7858 EMSG(_(e_invarg)); | |
7859 return; | |
7860 } | |
7861 id = -2; | |
7862 arg = skiptowhite(arg + 1); | |
7863 } | |
7 | 7864 else if (STRNCMP(arg, "name=", 5) == 0) |
7865 { | |
7866 arg += 5; | |
7867 sign_name = arg; | |
7868 arg = skiptowhite(arg); | |
7869 if (*arg != NUL) | |
7870 *arg++ = NUL; | |
2605 | 7871 while (sign_name[0] == '0' && sign_name[1] != NUL) |
7872 ++sign_name; | |
7 | 7873 } |
7874 else if (STRNCMP(arg, "file=", 5) == 0) | |
7875 { | |
7876 arg += 5; | |
7877 buf = buflist_findname(arg); | |
7878 break; | |
7879 } | |
7880 else if (STRNCMP(arg, "buffer=", 7) == 0) | |
7881 { | |
7882 arg += 7; | |
7883 buf = buflist_findnr((int)getdigits(&arg)); | |
7884 if (*skipwhite(arg) != NUL) | |
7885 EMSG(_(e_trailing)); | |
7886 break; | |
7887 } | |
7888 else | |
7889 { | |
7890 EMSG(_(e_invarg)); | |
7891 return; | |
7892 } | |
7893 arg = skipwhite(arg); | |
7894 } | |
7895 | |
7896 if (buf == NULL) | |
7897 { | |
7898 EMSG2(_("E158: Invalid buffer name: %s"), arg); | |
7899 } | |
3672 | 7900 else if (id <= 0 && !(idx == SIGNCMD_UNPLACE && id == -2)) |
7 | 7901 { |
7902 if (lnum >= 0 || sign_name != NULL) | |
7903 EMSG(_(e_invarg)); | |
7904 else | |
7905 /* ":sign place file={fname}": list placed signs in one file */ | |
7906 sign_list_placed(buf); | |
7907 } | |
7908 else if (idx == SIGNCMD_JUMP) | |
7909 { | |
7910 /* ":sign jump {id} file={fname}" */ | |
7911 if (lnum >= 0 || sign_name != NULL) | |
7912 EMSG(_(e_invarg)); | |
7913 else if ((lnum = buf_findsign(buf, id)) > 0) | |
7914 { /* goto a sign ... */ | |
7915 if (buf_jump_open_win(buf) != NULL) | |
7916 { /* ... in a current window */ | |
7917 curwin->w_cursor.lnum = lnum; | |
7918 check_cursor_lnum(); | |
7919 beginline(BL_WHITE); | |
7920 } | |
7921 else | |
7922 { /* ... not currently in a window */ | |
7923 char_u *cmd; | |
7924 | |
9902
5a667a3a3743
commit https://github.com/vim/vim/commit/bfd096d02087a10e8e2f4bdfb74e0435506fa8bb
Christian Brabandt <cb@256bit.org>
parents:
9890
diff
changeset
|
7925 if (buf->b_fname == NULL) |
5a667a3a3743
commit https://github.com/vim/vim/commit/bfd096d02087a10e8e2f4bdfb74e0435506fa8bb
Christian Brabandt <cb@256bit.org>
parents:
9890
diff
changeset
|
7926 { |
5a667a3a3743
commit https://github.com/vim/vim/commit/bfd096d02087a10e8e2f4bdfb74e0435506fa8bb
Christian Brabandt <cb@256bit.org>
parents:
9890
diff
changeset
|
7927 EMSG(_("E934: Cannot jump to a buffer that does not have a name")); |
5a667a3a3743
commit https://github.com/vim/vim/commit/bfd096d02087a10e8e2f4bdfb74e0435506fa8bb
Christian Brabandt <cb@256bit.org>
parents:
9890
diff
changeset
|
7928 return; |
5a667a3a3743
commit https://github.com/vim/vim/commit/bfd096d02087a10e8e2f4bdfb74e0435506fa8bb
Christian Brabandt <cb@256bit.org>
parents:
9890
diff
changeset
|
7929 } |
7 | 7930 cmd = alloc((unsigned)STRLEN(buf->b_fname) + 25); |
7931 if (cmd == NULL) | |
7932 return; | |
7933 sprintf((char *)cmd, "e +%ld %s", (long)lnum, buf->b_fname); | |
7934 do_cmdline_cmd(cmd); | |
7935 vim_free(cmd); | |
7936 } | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7937 # ifdef FEAT_FOLDING |
7 | 7938 foldOpenCursor(); |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7939 # endif |
7 | 7940 } |
7941 else | |
7942 EMSGN(_("E157: Invalid sign ID: %ld"), id); | |
7943 } | |
7944 else if (idx == SIGNCMD_UNPLACE) | |
7945 { | |
7946 if (lnum >= 0 || sign_name != NULL) | |
7947 EMSG(_(e_invarg)); | |
3672 | 7948 else if (id == -2) |
7949 { | |
7950 /* ":sign unplace * file={fname}" */ | |
7951 redraw_buf_later(buf, NOT_VALID); | |
7952 buf_delete_signs(buf); | |
7953 } | |
7 | 7954 else |
7955 { | |
3672 | 7956 /* ":sign unplace {id} file={fname}" */ |
7 | 7957 lnum = buf_delsign(buf, id); |
7958 update_debug_sign(buf, lnum); | |
7959 } | |
7960 } | |
7961 /* idx == SIGNCMD_PLACE */ | |
7962 else if (sign_name != NULL) | |
7963 { | |
7964 for (sp = first_sign; sp != NULL; sp = sp->sn_next) | |
7965 if (STRCMP(sp->sn_name, sign_name) == 0) | |
7966 break; | |
7967 if (sp == NULL) | |
7968 { | |
7969 EMSG2(_("E155: Unknown sign: %s"), sign_name); | |
7970 return; | |
7971 } | |
7972 if (lnum > 0) | |
7973 /* ":sign place {id} line={lnum} name={name} file={fname}": | |
7974 * place a sign */ | |
7975 buf_addsign(buf, id, lnum, sp->sn_typenr); | |
7976 else | |
7977 /* ":sign place {id} file={fname}": change sign type */ | |
7978 lnum = buf_change_sign_type(buf, id, sp->sn_typenr); | |
5865 | 7979 if (lnum > 0) |
7980 update_debug_sign(buf, lnum); | |
7981 else | |
7982 EMSG2(_("E885: Not possible to change sign %s"), sign_name); | |
7 | 7983 } |
7984 else | |
7985 EMSG(_(e_invarg)); | |
7986 } | |
7987 } | |
7988 | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7989 # if defined(FEAT_SIGN_ICONS) || defined(PROTO) |
7 | 7990 /* |
7991 * Allocate the icons. Called when the GUI has started. Allows defining | |
7992 * signs before it starts. | |
7993 */ | |
7994 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7995 sign_gui_started(void) |
7 | 7996 { |
7997 sign_T *sp; | |
7998 | |
7999 for (sp = first_sign; sp != NULL; sp = sp->sn_next) | |
8000 if (sp->sn_icon != NULL) | |
8001 sp->sn_image = gui_mch_register_sign(sp->sn_icon); | |
8002 } | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8003 # endif |
7 | 8004 |
8005 /* | |
8006 * List one sign. | |
8007 */ | |
8008 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8009 sign_list_defined(sign_T *sp) |
7 | 8010 { |
8011 char_u *p; | |
8012 | |
274 | 8013 smsg((char_u *)"sign %s", sp->sn_name); |
7 | 8014 if (sp->sn_icon != NULL) |
8015 { | |
8016 MSG_PUTS(" icon="); | |
8017 msg_outtrans(sp->sn_icon); | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8018 # ifdef FEAT_SIGN_ICONS |
7 | 8019 if (sp->sn_image == NULL) |
8020 MSG_PUTS(_(" (NOT FOUND)")); | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8021 # else |
7 | 8022 MSG_PUTS(_(" (not supported)")); |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8023 # endif |
7 | 8024 } |
8025 if (sp->sn_text != NULL) | |
8026 { | |
8027 MSG_PUTS(" text="); | |
8028 msg_outtrans(sp->sn_text); | |
8029 } | |
8030 if (sp->sn_line_hl > 0) | |
8031 { | |
8032 MSG_PUTS(" linehl="); | |
11254
918942a3b0ef
patch 8.0.0513: getting name of cleared highlight group is wrong
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
8033 p = get_highlight_name_ext(NULL, sp->sn_line_hl - 1, FALSE); |
7 | 8034 if (p == NULL) |
8035 MSG_PUTS("NONE"); | |
8036 else | |
8037 msg_puts(p); | |
8038 } | |
8039 if (sp->sn_text_hl > 0) | |
8040 { | |
8041 MSG_PUTS(" texthl="); | |
11254
918942a3b0ef
patch 8.0.0513: getting name of cleared highlight group is wrong
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
8042 p = get_highlight_name_ext(NULL, sp->sn_text_hl - 1, FALSE); |
7 | 8043 if (p == NULL) |
8044 MSG_PUTS("NONE"); | |
8045 else | |
8046 msg_puts(p); | |
8047 } | |
8048 } | |
8049 | |
8050 /* | |
1828 | 8051 * Undefine a sign and free its memory. |
8052 */ | |
8053 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8054 sign_undefine(sign_T *sp, sign_T *sp_prev) |
1828 | 8055 { |
8056 vim_free(sp->sn_name); | |
8057 vim_free(sp->sn_icon); | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8058 # ifdef FEAT_SIGN_ICONS |
1828 | 8059 if (sp->sn_image != NULL) |
8060 { | |
8061 out_flush(); | |
8062 gui_mch_destroy_sign(sp->sn_image); | |
8063 } | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8064 # endif |
1828 | 8065 vim_free(sp->sn_text); |
8066 if (sp_prev == NULL) | |
8067 first_sign = sp->sn_next; | |
8068 else | |
8069 sp_prev->sn_next = sp->sn_next; | |
8070 vim_free(sp); | |
8071 } | |
8072 | |
8073 /* | |
7 | 8074 * Get highlighting attribute for sign "typenr". |
8075 * If "line" is TRUE: line highl, if FALSE: text highl. | |
8076 */ | |
8077 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8078 sign_get_attr(int typenr, int line) |
7 | 8079 { |
8080 sign_T *sp; | |
8081 | |
8082 for (sp = first_sign; sp != NULL; sp = sp->sn_next) | |
8083 if (sp->sn_typenr == typenr) | |
8084 { | |
8085 if (line) | |
8086 { | |
8087 if (sp->sn_line_hl > 0) | |
8088 return syn_id2attr(sp->sn_line_hl); | |
8089 } | |
8090 else | |
8091 { | |
8092 if (sp->sn_text_hl > 0) | |
8093 return syn_id2attr(sp->sn_text_hl); | |
8094 } | |
8095 break; | |
8096 } | |
8097 return 0; | |
8098 } | |
8099 | |
8100 /* | |
8101 * Get text mark for sign "typenr". | |
8102 * Returns NULL if there isn't one. | |
8103 */ | |
8104 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8105 sign_get_text(int typenr) |
7 | 8106 { |
8107 sign_T *sp; | |
8108 | |
8109 for (sp = first_sign; sp != NULL; sp = sp->sn_next) | |
8110 if (sp->sn_typenr == typenr) | |
8111 return sp->sn_text; | |
8112 return NULL; | |
8113 } | |
8114 | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8115 # if defined(FEAT_SIGN_ICONS) || defined(PROTO) |
7 | 8116 void * |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8117 sign_get_image( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8118 int typenr) /* the attribute which may have a sign */ |
7 | 8119 { |
8120 sign_T *sp; | |
8121 | |
8122 for (sp = first_sign; sp != NULL; sp = sp->sn_next) | |
8123 if (sp->sn_typenr == typenr) | |
8124 return sp->sn_image; | |
8125 return NULL; | |
8126 } | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8127 # endif |
7 | 8128 |
8129 /* | |
8130 * Get the name of a sign by its typenr. | |
8131 */ | |
8132 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8133 sign_typenr2name(int typenr) |
7 | 8134 { |
8135 sign_T *sp; | |
8136 | |
8137 for (sp = first_sign; sp != NULL; sp = sp->sn_next) | |
8138 if (sp->sn_typenr == typenr) | |
8139 return sp->sn_name; | |
8140 return (char_u *)_("[Deleted]"); | |
8141 } | |
8142 | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8143 # if defined(EXITFREE) || defined(PROTO) |
1828 | 8144 /* |
8145 * Undefine/free all signs. | |
8146 */ | |
8147 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8148 free_signs(void) |
1828 | 8149 { |
8150 while (first_sign != NULL) | |
8151 sign_undefine(first_sign, NULL); | |
8152 } | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8153 # endif |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8154 |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8155 # if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
1868 | 8156 static enum |
8157 { | |
8158 EXP_SUBCMD, /* expand :sign sub-commands */ | |
8159 EXP_DEFINE, /* expand :sign define {name} args */ | |
8160 EXP_PLACE, /* expand :sign place {id} args */ | |
8161 EXP_UNPLACE, /* expand :sign unplace" */ | |
8162 EXP_SIGN_NAMES /* expand with name of placed signs */ | |
8163 } expand_what; | |
8164 | |
8165 /* | |
8166 * Function given to ExpandGeneric() to obtain the sign command | |
8167 * expansion. | |
8168 */ | |
8169 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8170 get_sign_name(expand_T *xp UNUSED, int idx) |
1868 | 8171 { |
8172 sign_T *sp; | |
8173 int current_idx; | |
8174 | |
8175 switch (expand_what) | |
8176 { | |
8177 case EXP_SUBCMD: | |
8178 return (char_u *)cmds[idx]; | |
8179 case EXP_DEFINE: | |
8180 { | |
8181 char *define_arg[] = | |
8182 { | |
8183 "icon=", "linehl=", "text=", "texthl=", NULL | |
8184 }; | |
8185 return (char_u *)define_arg[idx]; | |
8186 } | |
8187 case EXP_PLACE: | |
8188 { | |
8189 char *place_arg[] = | |
8190 { | |
8191 "line=", "name=", "file=", "buffer=", NULL | |
8192 }; | |
8193 return (char_u *)place_arg[idx]; | |
8194 } | |
8195 case EXP_UNPLACE: | |
8196 { | |
8197 char *unplace_arg[] = { "file=", "buffer=", NULL }; | |
8198 return (char_u *)unplace_arg[idx]; | |
8199 } | |
8200 case EXP_SIGN_NAMES: | |
8201 /* Complete with name of signs already defined */ | |
8202 current_idx = 0; | |
8203 for (sp = first_sign; sp != NULL; sp = sp->sn_next) | |
8204 if (current_idx++ == idx) | |
8205 return sp->sn_name; | |
8206 return NULL; | |
8207 default: | |
8208 return NULL; | |
8209 } | |
8210 } | |
8211 | |
8212 /* | |
8213 * Handle command line completion for :sign command. | |
8214 */ | |
8215 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8216 set_context_in_sign_cmd(expand_T *xp, char_u *arg) |
1868 | 8217 { |
8218 char_u *p; | |
8219 char_u *end_subcmd; | |
8220 char_u *last; | |
8221 int cmd_idx; | |
8222 char_u *begin_subcmd_args; | |
8223 | |
8224 /* Default: expand subcommands. */ | |
8225 xp->xp_context = EXPAND_SIGN; | |
8226 expand_what = EXP_SUBCMD; | |
8227 xp->xp_pattern = arg; | |
8228 | |
8229 end_subcmd = skiptowhite(arg); | |
8230 if (*end_subcmd == NUL) | |
8231 /* expand subcmd name | |
8232 * :sign {subcmd}<CTRL-D>*/ | |
8233 return; | |
8234 | |
8235 cmd_idx = sign_cmd_idx(arg, end_subcmd); | |
8236 | |
8237 /* :sign {subcmd} {subcmd_args} | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2290
diff
changeset
|
8238 * | |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2290
diff
changeset
|
8239 * begin_subcmd_args */ |
1868 | 8240 begin_subcmd_args = skipwhite(end_subcmd); |
8241 p = skiptowhite(begin_subcmd_args); | |
8242 if (*p == NUL) | |
8243 { | |
8244 /* | |
8245 * Expand first argument of subcmd when possible. | |
8246 * For ":jump {id}" and ":unplace {id}", we could | |
8247 * possibly expand the ids of all signs already placed. | |
8248 */ | |
8249 xp->xp_pattern = begin_subcmd_args; | |
8250 switch (cmd_idx) | |
8251 { | |
8252 case SIGNCMD_LIST: | |
8253 case SIGNCMD_UNDEFINE: | |
8254 /* :sign list <CTRL-D> | |
8255 * :sign undefine <CTRL-D> */ | |
8256 expand_what = EXP_SIGN_NAMES; | |
8257 break; | |
8258 default: | |
8259 xp->xp_context = EXPAND_NOTHING; | |
8260 } | |
8261 return; | |
8262 } | |
8263 | |
8264 /* expand last argument of subcmd */ | |
8265 | |
8266 /* :sign define {name} {args}... | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2290
diff
changeset
|
8267 * | |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2290
diff
changeset
|
8268 * p */ |
1868 | 8269 |
8270 /* Loop until reaching last argument. */ | |
8271 do | |
8272 { | |
8273 p = skipwhite(p); | |
8274 last = p; | |
8275 p = skiptowhite(p); | |
8276 } while (*p != NUL); | |
8277 | |
8278 p = vim_strchr(last, '='); | |
8279 | |
8280 /* :sign define {name} {args}... {last}= | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2290
diff
changeset
|
8281 * | | |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2290
diff
changeset
|
8282 * last p */ |
10299
7b2f95633e28
commit https://github.com/vim/vim/commit/7756e7465d627ff9cd01e59625484a8c302ef853
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
8283 if (p == NULL) |
1868 | 8284 { |
8285 /* Expand last argument name (before equal sign). */ | |
8286 xp->xp_pattern = last; | |
8287 switch (cmd_idx) | |
8288 { | |
8289 case SIGNCMD_DEFINE: | |
8290 expand_what = EXP_DEFINE; | |
8291 break; | |
8292 case SIGNCMD_PLACE: | |
8293 expand_what = EXP_PLACE; | |
8294 break; | |
8295 case SIGNCMD_JUMP: | |
8296 case SIGNCMD_UNPLACE: | |
8297 expand_what = EXP_UNPLACE; | |
8298 break; | |
8299 default: | |
8300 xp->xp_context = EXPAND_NOTHING; | |
8301 } | |
8302 } | |
8303 else | |
8304 { | |
8305 /* Expand last argument value (after equal sign). */ | |
8306 xp->xp_pattern = p + 1; | |
8307 switch (cmd_idx) | |
8308 { | |
8309 case SIGNCMD_DEFINE: | |
8310 if (STRNCMP(last, "texthl", p - last) == 0 || | |
8311 STRNCMP(last, "linehl", p - last) == 0) | |
8312 xp->xp_context = EXPAND_HIGHLIGHT; | |
8313 else if (STRNCMP(last, "icon", p - last) == 0) | |
8314 xp->xp_context = EXPAND_FILES; | |
8315 else | |
8316 xp->xp_context = EXPAND_NOTHING; | |
8317 break; | |
8318 case SIGNCMD_PLACE: | |
8319 if (STRNCMP(last, "name", p - last) == 0) | |
8320 expand_what = EXP_SIGN_NAMES; | |
8321 else | |
8322 xp->xp_context = EXPAND_NOTHING; | |
8323 break; | |
8324 default: | |
8325 xp->xp_context = EXPAND_NOTHING; | |
8326 } | |
8327 } | |
8328 } | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8329 # endif |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8330 #endif |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8331 |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8332 /* |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8333 * Make the user happy. |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8334 */ |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8335 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8336 ex_smile(exarg_T *eap UNUSED) |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8337 { |
8879
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8338 static char *code[] = { |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8339 "\34 \4o\14$\4ox\30 \2o\30$\1ox\25 \2o\36$\1o\11 \1o\1$\3 \2$\1 \1o\1$x\5 \1o\1 \1$\1 \2o\10 \1o\44$\1o\7 \2$\1 \2$\1 \2$\1o\1$x\2 \2o\1 \1$\1 \1$\1 \1\"\1$\6 \1o\11$\4 \15$\4 \11$\1o\7 \3$\1o\2$\1o\1$x\2 \1\"\6$\1o\1$\5 \1o\11$\6 \13$\6 \12$\1o\4 \10$x\4 \7$\4 \13$\6 \13$\6 \27$x\4 \27$\4 \15$\4 \16$\2 \3\"\3$x\5 \1\"\3$\4\"\61$\5 \1\"\3$x\6 \3$\3 \1o\62$\5 \1\"\3$\1ox\5 \1o\2$\1\"\3 \63$\7 \3$\1ox\5 \3$\4 \55$\1\"\1 \1\"\6$", |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8340 "\5o\4$\1ox\4 \1o\3$\4o\5$\2 \45$\3 \1o\21$x\4 \10$\1\"\4$\3 \42$\5 \4$\10\"x\3 \4\"\7 \4$\4 \1\"\34$\1\"\6 \1o\3$x\16 \1\"\3$\1o\5 \3\"\22$\1\"\2$\1\"\11 \3$x\20 \3$\1o\12 \1\"\2$\2\"\6$\4\"\13 \1o\3$x\21 \4$\1o\40 \1o\3$\1\"x\22 \1\"\4$\1o\6 \1o\6$\1o\1\"\4$\1o\10 \1o\4$x\24 \1\"\5$\2o\5 \2\"\4$\1o\5$\1o\3 \1o\4$\2\"x\27 \2\"\5$\4o\2 \1\"\3$\1o\11$\3\"x\32 \2\"\7$\2o\1 \12$x\42 \4\"\13$x\46 \14$x\47 \12$\1\"x\50 \1\"\3$\4\"x" |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8341 }; |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8342 char *p; |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8343 int n; |
8879
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8344 int i; |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8345 |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8346 msg_start(); |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8347 msg_putchar('\n'); |
8879
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8348 for (i = 0; i < 2; ++i) |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8349 for (p = code[i]; *p != NUL; ++p) |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8350 if (*p == 'x') |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8351 msg_putchar('\n'); |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8352 else |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8353 for (n = *p++; n > 0; --n) |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8354 if (*p == 'o' || *p == '$') |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11144
diff
changeset
|
8355 msg_putchar_attr(*p, HL_ATTR(HLF_L)); |
8879
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8356 else |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8357 msg_putchar(*p); |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8358 msg_clr_eos(); |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8359 } |
7 | 8360 |
8361 /* | |
8362 * ":drop" | |
8363 * Opens the first argument in a window. When there are two or more arguments | |
8364 * the argument list is redefined. | |
8365 */ | |
8366 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8367 ex_drop(exarg_T *eap) |
7 | 8368 { |
8369 int split = FALSE; | |
8370 win_T *wp; | |
8371 buf_T *buf; | |
735 | 8372 tabpage_T *tp; |
7 | 8373 |
8374 /* | |
8375 * Check if the first argument is already being edited in a window. If | |
8376 * so, jump to that window. | |
8377 * We would actually need to check all arguments, but that's complicated | |
8378 * and mostly only one file is dropped. | |
8379 * This also ignores wildcards, since it is very unlikely the user is | |
8380 * editing a file name with a wildcard character. | |
8381 */ | |
735 | 8382 set_arglist(eap->arg); |
8383 | |
1067 | 8384 /* |
8385 * Expanding wildcards may result in an empty argument list. E.g. when | |
8386 * editing "foo.pyc" and ".pyc" is in 'wildignore'. Assume that we | |
8387 * already did an error message for this. | |
8388 */ | |
8389 if (ARGCOUNT == 0) | |
8390 return; | |
8391 | |
735 | 8392 if (cmdmod.tab) |
8393 { | |
8394 /* ":tab drop file ...": open a tab for each argument that isn't | |
8395 * edited in a window yet. It's like ":tab all" but without closing | |
8396 * windows or tabs. */ | |
8397 ex_all(eap); | |
8398 } | |
8399 else | |
8400 { | |
8401 /* ":drop file ...": Edit the first argument. Jump to an existing | |
8402 * window if possible, edit in current window if the current buffer | |
8403 * can be abandoned, otherwise open a new window. */ | |
8404 buf = buflist_findnr(ARGLIST[0].ae_fnum); | |
8405 | |
8406 FOR_ALL_TAB_WINDOWS(tp, wp) | |
8407 { | |
8408 if (wp->w_buffer == buf) | |
7 | 8409 { |
825 | 8410 goto_tabpage_win(tp, wp); |
7 | 8411 curwin->w_arg_idx = 0; |
8412 return; | |
8413 } | |
8414 } | |
735 | 8415 |
8416 /* | |
8417 * Check whether the current buffer is changed. If so, we will need | |
8418 * to split the current window or data could be lost. | |
8419 * Skip the check if the 'hidden' option is set, as in this case the | |
8420 * buffer won't be lost. | |
8421 */ | |
11957
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11800
diff
changeset
|
8422 if (!buf_hide(curbuf)) |
735 | 8423 { |
8424 ++emsg_off; | |
5464 | 8425 split = check_changed(curbuf, CCGD_AW | CCGD_EXCMD); |
735 | 8426 --emsg_off; |
8427 } | |
8428 | |
8429 /* Fake a ":sfirst" or ":first" command edit the first argument. */ | |
8430 if (split) | |
8431 { | |
8432 eap->cmdidx = CMD_sfirst; | |
8433 eap->cmd[0] = 's'; | |
8434 } | |
8435 else | |
8436 eap->cmdidx = CMD_first; | |
8437 ex_rewind(eap); | |
8438 } | |
7 | 8439 } |
9915
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8440 |
9931
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8441 /* |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8442 * Skip over the pattern argument of ":vimgrep /pat/[g][j]". |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8443 * Put the start of the pattern in "*s", unless "s" is NULL. |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8444 * If "flags" is not NULL put the flags in it: VGR_GLOBAL, VGR_NOJUMP. |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8445 * If "s" is not NULL terminate the pattern with a NUL. |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8446 * Return a pointer to the char just past the pattern plus flags. |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8447 */ |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8448 char_u * |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8449 skip_vimgrep_pat(char_u *p, char_u **s, int *flags) |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8450 { |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8451 int c; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8452 |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8453 if (vim_isIDc(*p)) |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8454 { |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8455 /* ":vimgrep pattern fname" */ |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8456 if (s != NULL) |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8457 *s = p; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8458 p = skiptowhite(p); |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8459 if (s != NULL && *p != NUL) |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8460 *p++ = NUL; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8461 } |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8462 else |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8463 { |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8464 /* ":vimgrep /pattern/[g][j] fname" */ |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8465 if (s != NULL) |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8466 *s = p + 1; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8467 c = *p; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8468 p = skip_regexp(p + 1, c, TRUE, NULL); |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8469 if (*p != c) |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8470 return NULL; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8471 |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8472 /* Truncate the pattern. */ |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8473 if (s != NULL) |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8474 *p = NUL; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8475 ++p; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8476 |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8477 /* Find the flags */ |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8478 while (*p == 'g' || *p == 'j') |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8479 { |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8480 if (flags != NULL) |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8481 { |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8482 if (*p == 'g') |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8483 *flags |= VGR_GLOBAL; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8484 else |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8485 *flags |= VGR_NOJUMP; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8486 } |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8487 ++p; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8488 } |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8489 } |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8490 return p; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8491 } |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8492 |
9915
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8493 #if defined(FEAT_EVAL) || defined(PROTO) |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8494 /* |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8495 * List v:oldfiles in a nice way. |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8496 */ |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8497 void |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8498 ex_oldfiles(exarg_T *eap UNUSED) |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8499 { |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8500 list_T *l = get_vim_var_list(VV_OLDFILES); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8501 listitem_T *li; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8502 int nr = 0; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8503 char_u *fname; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8504 |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8505 if (l == NULL) |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8506 msg((char_u *)_("No old files")); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8507 else |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8508 { |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8509 msg_start(); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8510 msg_scroll = TRUE; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8511 for (li = l->lv_first; li != NULL && !got_int; li = li->li_next) |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8512 { |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8513 ++nr; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8514 fname = get_tv_string(&li->li_tv); |
9945
d63a89b526ea
commit https://github.com/vim/vim/commit/d6f2ee32dcfa18c781ef157918b524318a2215a2
Christian Brabandt <cb@256bit.org>
parents:
9931
diff
changeset
|
8515 if (!message_filtered(fname)) |
9915
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8516 { |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8517 msg_outnum((long)nr); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8518 MSG_PUTS(": "); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8519 msg_outtrans(fname); |
10021
5fc4bec66c33
commit https://github.com/vim/vim/commit/885c00eabe6d1fd757d4f0eb531ad3a15a35ec04
Christian Brabandt <cb@256bit.org>
parents:
9980
diff
changeset
|
8520 msg_clr_eos(); |
9915
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8521 msg_putchar('\n'); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8522 out_flush(); /* output one line at a time */ |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8523 ui_breakcheck(); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8524 } |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8525 } |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8526 |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8527 /* Assume "got_int" was set to truncate the listing. */ |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8528 got_int = FALSE; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8529 |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8530 # ifdef FEAT_BROWSE_CMD |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8531 if (cmdmod.browse) |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8532 { |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8533 quit_more = FALSE; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8534 nr = prompt_for_number(FALSE); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8535 msg_starthere(); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8536 if (nr > 0) |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8537 { |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8538 char_u *p = list_find_str(get_vim_var_list(VV_OLDFILES), |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8539 (long)nr); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8540 |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8541 if (p != NULL) |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8542 { |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8543 p = expand_env_save(p); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8544 eap->arg = p; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8545 eap->cmdidx = CMD_edit; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8546 cmdmod.browse = FALSE; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8547 do_exedit(eap, NULL); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8548 vim_free(p); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8549 } |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8550 } |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8551 } |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8552 # endif |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8553 } |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8554 } |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8555 #endif |