Mercurial > vim
annotate src/ex_cmds.c @ 16812:55ca009f1493
Added tag v8.1.1407 for changeset 0457d49eb2d9c5a74bb3010f6e1216699ddba69d
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 26 May 2019 23:45:05 +0200 |
parents | fc58fee685e2 |
children | ce04ebdf26b8 |
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); |
16606
7e733046db1d
patch 8.1.1306: Borland support is outdated and doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
16475
diff
changeset
|
32 static int help_compare(const void *s1, const void *s2); |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
33 static void prepare_help_buffer(void); |
7 | 34 |
35 /* | |
36 * ":ascii" and "ga". | |
37 */ | |
38 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
39 do_ascii(exarg_T *eap UNUSED) |
7 | 40 { |
41 int c; | |
1784 | 42 int cval; |
7 | 43 char buf1[20]; |
44 char buf2[20]; | |
45 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
|
46 #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
|
47 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
|
48 #endif |
714 | 49 int cc[MAX_MCO]; |
50 int ci = 0; | |
7 | 51 int len; |
52 | |
53 if (enc_utf8) | |
714 | 54 c = utfc_ptr2char(ml_get_cursor(), cc); |
7 | 55 else |
56 c = gchar_cursor(); | |
57 if (c == NUL) | |
58 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
59 msg("NUL"); |
7 | 60 return; |
61 } | |
62 | |
63 IObuff[0] = NUL; | |
64 if (!has_mbyte || (enc_dbcs != 0 && c < 0x100) || c < 0x80) | |
65 { | |
66 if (c == NL) /* NUL is stored as NL */ | |
67 c = NUL; | |
1784 | 68 if (c == CAR && get_fileformat(curbuf) == EOL_MAC) |
69 cval = NL; /* NL is stored as CR */ | |
70 else | |
71 cval = c; | |
7 | 72 if (vim_isprintc_strict(c) && (c < ' ' |
73 #ifndef EBCDIC | |
74 || c > '~' | |
75 #endif | |
76 )) | |
77 { | |
78 transchar_nonprint(buf3, c); | |
1872 | 79 vim_snprintf(buf1, sizeof(buf1), " <%s>", (char *)buf3); |
7 | 80 } |
81 else | |
82 buf1[0] = NUL; | |
83 #ifndef EBCDIC | |
84 if (c >= 0x80) | |
1872 | 85 vim_snprintf(buf2, sizeof(buf2), " <M-%s>", |
86 (char *)transchar(c & 0x7f)); | |
7 | 87 else |
88 #endif | |
89 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
|
90 #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
|
91 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
|
92 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
|
93 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
|
94 _("<%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
|
95 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
|
96 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
|
97 #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
|
98 vim_snprintf((char *)IObuff, IOSIZE, |
274 | 99 _("<%s>%s%s %d, Hex %02x, Octal %03o"), |
1784 | 100 transchar(c), buf1, buf2, cval, cval, cval); |
963 | 101 if (enc_utf8) |
102 c = cc[ci++]; | |
103 else | |
104 c = 0; | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
105 } |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
106 |
7 | 107 /* Repeat for combining characters. */ |
108 while (has_mbyte && (c >= 0x100 || (enc_utf8 && c >= 0x80))) | |
109 { | |
110 len = (int)STRLEN(IObuff); | |
111 /* This assumes every multi-byte char is printable... */ | |
112 if (len > 0) | |
113 IObuff[len++] = ' '; | |
114 IObuff[len++] = '<'; | |
963 | 115 if (enc_utf8 && utf_iscomposing(c) |
625 | 116 # ifdef USE_GUI |
7 | 117 && !gui.in_use |
625 | 118 # endif |
7 | 119 ) |
120 IObuff[len++] = ' '; /* draw composing char on top of a space */ | |
274 | 121 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
|
122 #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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 : _("> %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
|
128 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
|
129 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
|
130 #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
|
131 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
|
132 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
|
133 : _("> %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
|
134 c, c, c); |
714 | 135 if (ci == MAX_MCO) |
136 break; | |
963 | 137 if (enc_utf8) |
138 c = cc[ci++]; | |
139 else | |
140 c = 0; | |
7 | 141 } |
142 | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
143 msg((char *)IObuff); |
7 | 144 } |
145 | |
146 /* | |
147 * ":left", ":center" and ":right": align text. | |
148 */ | |
149 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
150 ex_align(exarg_T *eap) |
7 | 151 { |
152 pos_T save_curpos; | |
153 int len; | |
154 int indent = 0; | |
155 int new_indent; | |
156 int has_tab; | |
157 int width; | |
158 | |
159 #ifdef FEAT_RIGHTLEFT | |
160 if (curwin->w_p_rl) | |
161 { | |
162 /* switch left and right aligning */ | |
163 if (eap->cmdidx == CMD_right) | |
164 eap->cmdidx = CMD_left; | |
165 else if (eap->cmdidx == CMD_left) | |
166 eap->cmdidx = CMD_right; | |
167 } | |
168 #endif | |
169 | |
170 width = atoi((char *)eap->arg); | |
171 save_curpos = curwin->w_cursor; | |
172 if (eap->cmdidx == CMD_left) /* width is used for new indent */ | |
173 { | |
174 if (width >= 0) | |
175 indent = width; | |
176 } | |
177 else | |
178 { | |
179 /* | |
180 * if 'textwidth' set, use it | |
181 * else if 'wrapmargin' set, use it | |
182 * if invalid value, use 80 | |
183 */ | |
184 if (width <= 0) | |
185 width = curbuf->b_p_tw; | |
186 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
|
187 width = curwin->w_width - curbuf->b_p_wm; |
7 | 188 if (width <= 0) |
189 width = 80; | |
190 } | |
191 | |
192 if (u_save((linenr_T)(eap->line1 - 1), (linenr_T)(eap->line2 + 1)) == FAIL) | |
193 return; | |
194 | |
195 for (curwin->w_cursor.lnum = eap->line1; | |
196 curwin->w_cursor.lnum <= eap->line2; ++curwin->w_cursor.lnum) | |
197 { | |
198 if (eap->cmdidx == CMD_left) /* left align */ | |
199 new_indent = indent; | |
200 else | |
201 { | |
944 | 202 has_tab = FALSE; /* avoid uninit warnings */ |
7 | 203 len = linelen(eap->cmdidx == CMD_right ? &has_tab |
204 : NULL) - get_indent(); | |
205 | |
206 if (len <= 0) /* skip blank lines */ | |
207 continue; | |
208 | |
209 if (eap->cmdidx == CMD_center) | |
210 new_indent = (width - len) / 2; | |
211 else | |
212 { | |
213 new_indent = width - len; /* right align */ | |
214 | |
215 /* | |
216 * Make sure that embedded TABs don't make the text go too far | |
217 * to the right. | |
218 */ | |
219 if (has_tab) | |
220 while (new_indent > 0) | |
221 { | |
222 (void)set_indent(new_indent, 0); | |
223 if (linelen(NULL) <= width) | |
224 { | |
225 /* | |
226 * Now try to move the line as much as possible to | |
227 * the right. Stop when it moves too far. | |
228 */ | |
229 do | |
230 (void)set_indent(++new_indent, 0); | |
231 while (linelen(NULL) <= width); | |
232 --new_indent; | |
233 break; | |
234 } | |
235 --new_indent; | |
236 } | |
237 } | |
238 } | |
239 if (new_indent < 0) | |
240 new_indent = 0; | |
241 (void)set_indent(new_indent, 0); /* set indent */ | |
242 } | |
243 changed_lines(eap->line1, 0, eap->line2 + 1, 0L); | |
244 curwin->w_cursor = save_curpos; | |
245 beginline(BL_WHITE | BL_FIX); | |
246 } | |
247 | |
248 /* | |
249 * Get the length of the current line, excluding trailing white space. | |
250 */ | |
251 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
252 linelen(int *has_tab) |
7 | 253 { |
254 char_u *line; | |
255 char_u *first; | |
256 char_u *last; | |
257 int save; | |
258 int len; | |
259 | |
260 /* find the first non-blank character */ | |
261 line = ml_get_curline(); | |
262 first = skipwhite(line); | |
263 | |
264 /* find the character after the last non-blank character */ | |
265 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
|
266 last > first && VIM_ISWHITE(last[-1]); --last) |
7 | 267 ; |
268 save = *last; | |
269 *last = NUL; | |
270 len = linetabsize(line); /* get line length */ | |
271 if (has_tab != NULL) /* check for embedded TAB */ | |
14513
076b9632bda4
patch 8.1.0270: checking for a Tab in a line could be faster
Christian Brabandt <cb@256bit.org>
parents:
14443
diff
changeset
|
272 *has_tab = (vim_strchr(first, TAB) != NULL); |
7 | 273 *last = save; |
274 | |
275 return len; | |
276 } | |
277 | |
826 | 278 /* Buffer for two lines used during sorting. They are allocated to |
279 * contain the longest line being sorted. */ | |
280 static char_u *sortbuf1; | |
281 static char_u *sortbuf2; | |
284 | 282 |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
283 static int sort_ic; /* ignore case */ |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
284 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
|
285 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
|
286 #ifdef FEAT_FLOAT |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
287 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
|
288 #endif |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
289 |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
290 static int sort_abort; /* flag to indicate if sorting has been interrupted */ |
294 | 291 |
292 /* Struct to store info to be sorted. */ | |
293 typedef struct | |
294 { | |
15906
f581167d59bf
patch 8.1.0959: sorting large numbers is not tested
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
295 linenr_T lnum; // line number |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
296 union { |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
297 struct |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
298 { |
15906
f581167d59bf
patch 8.1.0959: sorting large numbers is not tested
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
299 varnumber_T start_col_nr; // starting column number |
f581167d59bf
patch 8.1.0959: sorting large numbers is not tested
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
300 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
|
301 } line; |
15906
f581167d59bf
patch 8.1.0959: sorting large numbers is not tested
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
302 struct |
f581167d59bf
patch 8.1.0959: sorting large numbers is not tested
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
303 { |
f581167d59bf
patch 8.1.0959: sorting large numbers is not tested
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
304 varnumber_T value; // value if sorting by integer |
f581167d59bf
patch 8.1.0959: sorting large numbers is not tested
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
305 int is_number; // TRUE when line contains a number |
f581167d59bf
patch 8.1.0959: sorting large numbers is not tested
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
306 } num; |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
307 #ifdef FEAT_FLOAT |
15906
f581167d59bf
patch 8.1.0959: sorting large numbers is not tested
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
308 float_T value_flt; // value if sorting by float |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
309 #endif |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
310 } st_u; |
294 | 311 } sorti_T; |
284 | 312 |
16606
7e733046db1d
patch 8.1.1306: Borland support is outdated and doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
16475
diff
changeset
|
313 static int sort_compare(const void *s1, const void *s2); |
284 | 314 |
315 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
316 sort_compare(const void *s1, const void *s2) |
284 | 317 { |
294 | 318 sorti_T l1 = *(sorti_T *)s1; |
319 sorti_T l2 = *(sorti_T *)s2; | |
826 | 320 int result = 0; |
321 | |
322 /* If the user interrupts, there's no way to stop qsort() immediately, but | |
834 | 323 * if we return 0 every time, qsort will assume it's done sorting and |
324 * exit. */ | |
826 | 325 if (sort_abort) |
326 return 0; | |
327 fast_breakcheck(); | |
328 if (got_int) | |
329 sort_abort = TRUE; | |
330 | |
294 | 331 if (sort_nr) |
15906
f581167d59bf
patch 8.1.0959: sorting large numbers is not tested
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
332 { |
f581167d59bf
patch 8.1.0959: sorting large numbers is not tested
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
333 if (l1.st_u.num.is_number != l2.st_u.num.is_number) |
f581167d59bf
patch 8.1.0959: sorting large numbers is not tested
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
334 result = l1.st_u.num.is_number - l2.st_u.num.is_number; |
f581167d59bf
patch 8.1.0959: sorting large numbers is not tested
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
335 else |
f581167d59bf
patch 8.1.0959: sorting large numbers is not tested
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
336 result = l1.st_u.num.value == l2.st_u.num.value ? 0 |
f581167d59bf
patch 8.1.0959: sorting large numbers is not tested
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
337 : l1.st_u.num.value > l2.st_u.num.value ? 1 : -1; |
f581167d59bf
patch 8.1.0959: sorting large numbers is not tested
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
338 } |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
339 #ifdef FEAT_FLOAT |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
340 else if (sort_flt) |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
341 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
|
342 : 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
|
343 #endif |
826 | 344 else |
345 { | |
834 | 346 /* We need to copy one line into "sortbuf1", because there is no |
347 * guarantee that the first pointer becomes invalid when obtaining the | |
348 * second one. */ | |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
349 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
|
350 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
|
351 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
|
352 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
|
353 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
|
354 sortbuf2[l2.st_u.line.end_col_nr - l2.st_u.line.start_col_nr] = 0; |
826 | 355 |
834 | 356 result = sort_ic ? STRICMP(sortbuf1, sortbuf2) |
357 : STRCMP(sortbuf1, sortbuf2); | |
358 } | |
359 | |
360 /* If two lines have the same value, preserve the original line order. */ | |
826 | 361 if (result == 0) |
834 | 362 return (int)(l1.lnum - l2.lnum); |
363 return result; | |
284 | 364 } |
365 | |
366 /* | |
367 * ":sort". | |
368 */ | |
369 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
370 ex_sort(exarg_T *eap) |
284 | 371 { |
372 regmatch_T regmatch; | |
373 int len; | |
374 linenr_T lnum; | |
375 long maxlen = 0; | |
294 | 376 sorti_T *nrs; |
1872 | 377 size_t count = (size_t)(eap->line2 - eap->line1 + 1); |
294 | 378 size_t i; |
284 | 379 char_u *p; |
380 char_u *s; | |
826 | 381 char_u *s2; |
382 char_u c; /* temporary character storage */ | |
284 | 383 int unique = FALSE; |
384 long deleted; | |
826 | 385 colnr_T start_col; |
386 colnr_T end_col; | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
387 int sort_what = 0; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
388 int format_found = 0; |
14206
f2ab259ef88a
patch 8.1.0120: buffer 'modified' set even when :sort has no changes
Christian Brabandt <cb@256bit.org>
parents:
14194
diff
changeset
|
389 int change_occurred = FALSE; // Buffer contents changed. |
284 | 390 |
1538 | 391 /* Sorting one line is really quick! */ |
392 if (count <= 1) | |
393 return; | |
394 | |
284 | 395 if (u_save((linenr_T)(eap->line1 - 1), (linenr_T)(eap->line2 + 1)) == FAIL) |
396 return; | |
826 | 397 sortbuf1 = NULL; |
398 sortbuf2 = NULL; | |
284 | 399 regmatch.regprog = NULL; |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
400 nrs = (sorti_T *)alloc(count * sizeof(sorti_T)); |
284 | 401 if (nrs == NULL) |
826 | 402 goto sortend; |
403 | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
404 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
|
405 #ifdef FEAT_FLOAT |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
406 sort_flt = 0; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
407 #endif |
294 | 408 |
284 | 409 for (p = eap->arg; *p != NUL; ++p) |
410 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
411 if (VIM_ISWHITE(*p)) |
284 | 412 ; |
413 else if (*p == 'i') | |
414 sort_ic = TRUE; | |
826 | 415 else if (*p == 'r') |
416 sort_rx = TRUE; | |
294 | 417 else if (*p == 'n') |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
418 { |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
419 sort_nr = 1; |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
420 ++format_found; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
421 } |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
422 #ifdef FEAT_FLOAT |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
423 else if (*p == 'f') |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
424 { |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
425 sort_flt = 1; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
426 ++format_found; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
427 } |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
428 #endif |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
429 else if (*p == 'b') |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
430 { |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
431 sort_what = STR2NR_BIN + STR2NR_FORCE; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
432 ++format_found; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
433 } |
294 | 434 else if (*p == 'o') |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
435 { |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
436 sort_what = STR2NR_OCT + STR2NR_FORCE; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
437 ++format_found; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
438 } |
294 | 439 else if (*p == 'x') |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
440 { |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
441 sort_what = STR2NR_HEX + STR2NR_FORCE; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
442 ++format_found; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
443 } |
284 | 444 else if (*p == 'u') |
445 unique = TRUE; | |
289 | 446 else if (*p == '"') /* comment start */ |
447 break; | |
448 else if (check_nextcmd(p) != NULL) | |
449 { | |
450 eap->nextcmd = check_nextcmd(p); | |
451 break; | |
452 } | |
453 else if (!ASCII_ISALPHA(*p) && regmatch.regprog == NULL) | |
284 | 454 { |
455 s = skip_regexp(p + 1, *p, TRUE, NULL); | |
456 if (*s != *p) | |
457 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
458 emsg(_(e_invalpat)); |
826 | 459 goto sortend; |
284 | 460 } |
461 *s = NUL; | |
1314 | 462 /* Use last search pattern if sort pattern is empty. */ |
4199 | 463 if (s == p + 1) |
464 { | |
465 if (last_search_pat() == NULL) | |
466 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
467 emsg(_(e_noprevre)); |
4199 | 468 goto sortend; |
469 } | |
1314 | 470 regmatch.regprog = vim_regcomp(last_search_pat(), RE_MAGIC); |
4199 | 471 } |
1314 | 472 else |
473 regmatch.regprog = vim_regcomp(p + 1, RE_MAGIC); | |
284 | 474 if (regmatch.regprog == NULL) |
826 | 475 goto sortend; |
289 | 476 p = s; /* continue after the regexp */ |
284 | 477 regmatch.rm_ic = p_ic; |
478 } | |
479 else | |
480 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
481 semsg(_(e_invarg2), p); |
826 | 482 goto sortend; |
284 | 483 } |
484 } | |
485 | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
486 /* 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
|
487 if (format_found > 1) |
294 | 488 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
489 emsg(_(e_invarg)); |
826 | 490 goto sortend; |
294 | 491 } |
492 | |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
493 /* 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
|
494 * sorting. */ |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
495 sort_nr += sort_what; |
294 | 496 |
284 | 497 /* |
294 | 498 * Make an array with all line numbers. This avoids having to copy all |
284 | 499 * the lines into allocated memory. |
826 | 500 * When sorting on strings "start_col_nr" is the offset in the line, for |
501 * numbers sorting it's the number to sort on. This means the pattern | |
502 * matching and number conversion only has to be done once per line. | |
294 | 503 * Also get the longest line length for allocating "sortbuf". |
284 | 504 */ |
505 for (lnum = eap->line1; lnum <= eap->line2; ++lnum) | |
506 { | |
507 s = ml_get(lnum); | |
835 | 508 len = (int)STRLEN(s); |
284 | 509 if (maxlen < len) |
510 maxlen = len; | |
294 | 511 |
826 | 512 start_col = 0; |
513 end_col = len; | |
294 | 514 if (regmatch.regprog != NULL && vim_regexec(®match, s, 0)) |
826 | 515 { |
516 if (sort_rx) | |
517 { | |
835 | 518 start_col = (colnr_T)(regmatch.startp[0] - s); |
519 end_col = (colnr_T)(regmatch.endp[0] - s); | |
826 | 520 } |
521 else | |
835 | 522 start_col = (colnr_T)(regmatch.endp[0] - s); |
826 | 523 } |
294 | 524 else |
826 | 525 if (regmatch.regprog != NULL) |
526 end_col = 0; | |
294 | 527 |
7844
6669966db9e9
commit https://github.com/vim/vim/commit/937204a9175d0fe2f13c8bc4ebeb043003d7e7d7
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
528 if (sort_nr |
6669966db9e9
commit https://github.com/vim/vim/commit/937204a9175d0fe2f13c8bc4ebeb043003d7e7d7
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
529 #ifdef FEAT_FLOAT |
6669966db9e9
commit https://github.com/vim/vim/commit/937204a9175d0fe2f13c8bc4ebeb043003d7e7d7
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
530 || sort_flt |
6669966db9e9
commit https://github.com/vim/vim/commit/937204a9175d0fe2f13c8bc4ebeb043003d7e7d7
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
531 #endif |
6669966db9e9
commit https://github.com/vim/vim/commit/937204a9175d0fe2f13c8bc4ebeb043003d7e7d7
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
532 ) |
294 | 533 { |
826 | 534 /* Make sure vim_str2nr doesn't read any digits past the end |
535 * of the match, by temporarily terminating the string there */ | |
536 s2 = s + end_col; | |
537 c = *s2; | |
2606 | 538 *s2 = NUL; |
294 | 539 /* Sorting on number: Store the number itself. */ |
1687 | 540 p = s + start_col; |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
541 if (sort_nr) |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
542 { |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
543 if (sort_what & STR2NR_HEX) |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
544 s = skiptohex(p); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
545 else if (sort_what & STR2NR_BIN) |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
546 s = skiptobin(p); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
547 else |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
548 s = skiptodigit(p); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
549 if (s > p && s[-1] == '-') |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
550 --s; /* include preceding negative sign */ |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
551 if (*s == NUL) |
15906
f581167d59bf
patch 8.1.0959: sorting large numbers is not tested
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
552 { |
f581167d59bf
patch 8.1.0959: sorting large numbers is not tested
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
553 /* line without number should sort before any number */ |
f581167d59bf
patch 8.1.0959: sorting large numbers is not tested
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
554 nrs[lnum - eap->line1].st_u.num.is_number = FALSE; |
f581167d59bf
patch 8.1.0959: sorting large numbers is not tested
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
555 nrs[lnum - eap->line1].st_u.num.value = 0; |
f581167d59bf
patch 8.1.0959: sorting large numbers is not tested
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
556 } |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
557 else |
15906
f581167d59bf
patch 8.1.0959: sorting large numbers is not tested
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
558 { |
f581167d59bf
patch 8.1.0959: sorting large numbers is not tested
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
559 nrs[lnum - eap->line1].st_u.num.is_number = TRUE; |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
560 vim_str2nr(s, NULL, NULL, sort_what, |
16706
77bcb5055fec
patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents:
16698
diff
changeset
|
561 &nrs[lnum - eap->line1].st_u.num.value, |
77bcb5055fec
patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents:
16698
diff
changeset
|
562 NULL, 0, FALSE); |
15906
f581167d59bf
patch 8.1.0959: sorting large numbers is not tested
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
563 } |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
564 } |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
565 #ifdef FEAT_FLOAT |
294 | 566 else |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
567 { |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
568 s = skipwhite(p); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
569 if (*s == '+') |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
570 s = skipwhite(s + 1); |
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 if (*s == NUL) |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
573 /* 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
|
574 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
|
575 else |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
576 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
|
577 strtod((char *)s, NULL); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
578 } |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
579 #endif |
2606 | 580 *s2 = c; |
294 | 581 } |
582 else | |
826 | 583 { |
294 | 584 /* 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
|
585 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
|
586 nrs[lnum - eap->line1].st_u.line.end_col_nr = end_col; |
826 | 587 } |
294 | 588 |
589 nrs[lnum - eap->line1].lnum = lnum; | |
481 | 590 |
591 if (regmatch.regprog != NULL) | |
592 fast_breakcheck(); | |
593 if (got_int) | |
826 | 594 goto sortend; |
284 | 595 } |
596 | |
294 | 597 /* Allocate a buffer that can hold the longest line. */ |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
598 sortbuf1 = alloc(maxlen + 1); |
826 | 599 if (sortbuf1 == NULL) |
600 goto sortend; | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
601 sortbuf2 = alloc(maxlen + 1); |
826 | 602 if (sortbuf2 == NULL) |
603 goto sortend; | |
284 | 604 |
481 | 605 /* Sort the array of line numbers. Note: can't be interrupted! */ |
294 | 606 qsort((void *)nrs, count, sizeof(sorti_T), sort_compare); |
284 | 607 |
826 | 608 if (sort_abort) |
609 goto sortend; | |
610 | |
284 | 611 /* Insert the lines in the sorted order below the last one. */ |
612 lnum = eap->line2; | |
613 for (i = 0; i < count; ++i) | |
614 { | |
14206
f2ab259ef88a
patch 8.1.0120: buffer 'modified' set even when :sort has no changes
Christian Brabandt <cb@256bit.org>
parents:
14194
diff
changeset
|
615 linenr_T get_lnum = nrs[eap->forceit ? count - i - 1 : i].lnum; |
f2ab259ef88a
patch 8.1.0120: buffer 'modified' set even when :sort has no changes
Christian Brabandt <cb@256bit.org>
parents:
14194
diff
changeset
|
616 |
f2ab259ef88a
patch 8.1.0120: buffer 'modified' set even when :sort has no changes
Christian Brabandt <cb@256bit.org>
parents:
14194
diff
changeset
|
617 // If the original line number of the line being placed is not the same |
f2ab259ef88a
patch 8.1.0120: buffer 'modified' set even when :sort has no changes
Christian Brabandt <cb@256bit.org>
parents:
14194
diff
changeset
|
618 // as "lnum" (accounting for offset), we know that the buffer changed. |
f2ab259ef88a
patch 8.1.0120: buffer 'modified' set even when :sort has no changes
Christian Brabandt <cb@256bit.org>
parents:
14194
diff
changeset
|
619 if (get_lnum + ((linenr_T)count - 1) != lnum) |
f2ab259ef88a
patch 8.1.0120: buffer 'modified' set even when :sort has no changes
Christian Brabandt <cb@256bit.org>
parents:
14194
diff
changeset
|
620 change_occurred = TRUE; |
f2ab259ef88a
patch 8.1.0120: buffer 'modified' set even when :sort has no changes
Christian Brabandt <cb@256bit.org>
parents:
14194
diff
changeset
|
621 |
f2ab259ef88a
patch 8.1.0120: buffer 'modified' set even when :sort has no changes
Christian Brabandt <cb@256bit.org>
parents:
14194
diff
changeset
|
622 s = ml_get(get_lnum); |
284 | 623 if (!unique || i == 0 |
826 | 624 || (sort_ic ? STRICMP(s, sortbuf1) : STRCMP(s, sortbuf1)) != 0) |
284 | 625 { |
14206
f2ab259ef88a
patch 8.1.0120: buffer 'modified' set even when :sort has no changes
Christian Brabandt <cb@256bit.org>
parents:
14194
diff
changeset
|
626 // Copy the line into a buffer, it may become invalid in |
f2ab259ef88a
patch 8.1.0120: buffer 'modified' set even when :sort has no changes
Christian Brabandt <cb@256bit.org>
parents:
14194
diff
changeset
|
627 // ml_append(). And it's needed for "unique". |
7340
645abb8d8daf
commit https://github.com/vim/vim/commit/75e3ad019933f4879137775549261bf51985ab7d
Christian Brabandt <cb@256bit.org>
parents:
7226
diff
changeset
|
628 STRCPY(sortbuf1, s); |
645abb8d8daf
commit https://github.com/vim/vim/commit/75e3ad019933f4879137775549261bf51985ab7d
Christian Brabandt <cb@256bit.org>
parents:
7226
diff
changeset
|
629 if (ml_append(lnum++, sortbuf1, (colnr_T)0, FALSE) == FAIL) |
284 | 630 break; |
631 } | |
481 | 632 fast_breakcheck(); |
633 if (got_int) | |
826 | 634 goto sortend; |
284 | 635 } |
636 | |
637 /* delete the original lines if appending worked */ | |
638 if (i == count) | |
639 for (i = 0; i < count; ++i) | |
640 ml_delete(eap->line1, FALSE); | |
641 else | |
642 count = 0; | |
643 | |
294 | 644 /* Adjust marks for deleted (or added) lines and prepare for displaying. */ |
835 | 645 deleted = (long)(count - (lnum - eap->line2)); |
284 | 646 if (deleted > 0) |
14808
3d0b6e2a3a01
patch 8.1.0416: sort doesn't report deleted lines
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
647 { |
284 | 648 mark_adjust(eap->line2 - deleted, eap->line2, (long)MAXLNUM, -deleted); |
14808
3d0b6e2a3a01
patch 8.1.0416: sort doesn't report deleted lines
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
649 msgmore(-deleted); |
3d0b6e2a3a01
patch 8.1.0416: sort doesn't report deleted lines
Christian Brabandt <cb@256bit.org>
parents:
14730
diff
changeset
|
650 } |
284 | 651 else if (deleted < 0) |
652 mark_adjust(eap->line2, MAXLNUM, -deleted, 0L); | |
14206
f2ab259ef88a
patch 8.1.0120: buffer 'modified' set even when :sort has no changes
Christian Brabandt <cb@256bit.org>
parents:
14194
diff
changeset
|
653 |
f2ab259ef88a
patch 8.1.0120: buffer 'modified' set even when :sort has no changes
Christian Brabandt <cb@256bit.org>
parents:
14194
diff
changeset
|
654 if (change_occurred || deleted != 0) |
f2ab259ef88a
patch 8.1.0120: buffer 'modified' set even when :sort has no changes
Christian Brabandt <cb@256bit.org>
parents:
14194
diff
changeset
|
655 changed_lines(eap->line1, 0, eap->line2 + 1, -deleted); |
294 | 656 |
284 | 657 curwin->w_cursor.lnum = eap->line1; |
658 beginline(BL_WHITE | BL_FIX); | |
659 | |
826 | 660 sortend: |
284 | 661 vim_free(nrs); |
826 | 662 vim_free(sortbuf1); |
663 vim_free(sortbuf2); | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4613
diff
changeset
|
664 vim_regfree(regmatch.regprog); |
481 | 665 if (got_int) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
666 emsg(_(e_interr)); |
284 | 667 } |
668 | |
7 | 669 /* |
670 * ":retab". | |
671 */ | |
672 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
673 ex_retab(exarg_T *eap) |
7 | 674 { |
675 linenr_T lnum; | |
676 int got_tab = FALSE; | |
677 long num_spaces = 0; | |
678 long num_tabs; | |
679 long len; | |
680 long col; | |
681 long vcol; | |
682 long start_col = 0; /* For start of white-space string */ | |
683 long start_vcol = 0; /* For start of white-space string */ | |
684 long old_len; | |
685 char_u *ptr; | |
686 char_u *new_line = (char_u *)1; /* init to non-NULL */ | |
687 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
|
688 #ifdef FEAT_VARTABS |
14194
6fbb8dfb3389
patch 8.1.0114: confusing variable name
Christian Brabandt <cb@256bit.org>
parents:
14185
diff
changeset
|
689 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
|
690 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
|
691 #else |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
692 int temp; |
7 | 693 int new_ts; |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
694 #endif |
7 | 695 int save_list; |
696 linenr_T first_line = 0; /* first changed line */ | |
697 linenr_T last_line = 0; /* last changed line */ | |
698 | |
699 save_list = curwin->w_p_list; | |
700 curwin->w_p_list = 0; /* don't want list mode here */ | |
701 | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
702 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
703 new_ts_str = eap->arg; |
14194
6fbb8dfb3389
patch 8.1.0114: confusing variable name
Christian Brabandt <cb@256bit.org>
parents:
14185
diff
changeset
|
704 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
|
705 return; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
706 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
|
707 ++(eap->arg); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
708 |
14194
6fbb8dfb3389
patch 8.1.0114: confusing variable name
Christian Brabandt <cb@256bit.org>
parents:
14185
diff
changeset
|
709 // 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
|
710 // 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
|
711 // is null. |
6fbb8dfb3389
patch 8.1.0114: confusing variable name
Christian Brabandt <cb@256bit.org>
parents:
14185
diff
changeset
|
712 if (new_vts_array == NULL) |
6fbb8dfb3389
patch 8.1.0114: confusing variable name
Christian Brabandt <cb@256bit.org>
parents:
14185
diff
changeset
|
713 { |
6fbb8dfb3389
patch 8.1.0114: confusing variable name
Christian Brabandt <cb@256bit.org>
parents:
14185
diff
changeset
|
714 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
|
715 new_ts_str = NULL; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
716 } |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
717 else |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
718 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
|
719 #else |
7 | 720 new_ts = getdigits(&(eap->arg)); |
721 if (new_ts < 0) | |
722 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
723 emsg(_(e_positive)); |
7 | 724 return; |
725 } | |
726 if (new_ts == 0) | |
727 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
|
728 #endif |
7 | 729 for (lnum = eap->line1; !got_int && lnum <= eap->line2; ++lnum) |
730 { | |
731 ptr = ml_get(lnum); | |
732 col = 0; | |
733 vcol = 0; | |
734 did_undo = FALSE; | |
735 for (;;) | |
736 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
737 if (VIM_ISWHITE(ptr[col])) |
7 | 738 { |
739 if (!got_tab && num_spaces == 0) | |
740 { | |
741 /* First consecutive white-space */ | |
742 start_vcol = vcol; | |
743 start_col = col; | |
744 } | |
745 if (ptr[col] == ' ') | |
746 num_spaces++; | |
747 else | |
748 got_tab = TRUE; | |
749 } | |
750 else | |
751 { | |
752 if (got_tab || (eap->forceit && num_spaces > 1)) | |
753 { | |
754 /* Retabulate this string of white-space */ | |
755 | |
756 /* len is virtual length of white string */ | |
757 len = num_spaces = vcol - start_vcol; | |
758 num_tabs = 0; | |
759 if (!curbuf->b_p_et) | |
760 { | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
761 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
762 int t, s; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
763 |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
764 tabstop_fromto(start_vcol, vcol, |
14194
6fbb8dfb3389
patch 8.1.0114: confusing variable name
Christian Brabandt <cb@256bit.org>
parents:
14185
diff
changeset
|
765 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
|
766 num_tabs = t; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
767 num_spaces = s; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
768 #else |
7 | 769 temp = new_ts - (start_vcol % new_ts); |
770 if (num_spaces >= temp) | |
771 { | |
772 num_spaces -= temp; | |
773 num_tabs++; | |
774 } | |
775 num_tabs += num_spaces / new_ts; | |
776 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
|
777 #endif |
7 | 778 } |
779 if (curbuf->b_p_et || got_tab || | |
780 (num_spaces + num_tabs < len)) | |
781 { | |
782 if (did_undo == FALSE) | |
783 { | |
784 did_undo = TRUE; | |
785 if (u_save((linenr_T)(lnum - 1), | |
786 (linenr_T)(lnum + 1)) == FAIL) | |
787 { | |
788 new_line = NULL; /* flag out-of-memory */ | |
789 break; | |
790 } | |
791 } | |
792 | |
793 /* len is actual number of white characters used */ | |
794 len = num_spaces + num_tabs; | |
795 old_len = (long)STRLEN(ptr); | |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
796 new_line = alloc(old_len - col + start_col + len + 1); |
7 | 797 if (new_line == NULL) |
798 break; | |
799 if (start_col > 0) | |
800 mch_memmove(new_line, ptr, (size_t)start_col); | |
801 mch_memmove(new_line + start_col + len, | |
802 ptr + col, (size_t)(old_len - col + 1)); | |
803 ptr = new_line + start_col; | |
804 for (col = 0; col < len; col++) | |
805 ptr[col] = (col < num_tabs) ? '\t' : ' '; | |
806 ml_replace(lnum, new_line, FALSE); | |
807 if (first_line == 0) | |
808 first_line = lnum; | |
809 last_line = lnum; | |
810 ptr = new_line; | |
811 col = start_col + len; | |
812 } | |
813 } | |
814 got_tab = FALSE; | |
815 num_spaces = 0; | |
816 } | |
817 if (ptr[col] == NUL) | |
818 break; | |
819 vcol += chartabsize(ptr + col, (colnr_T)vcol); | |
820 if (has_mbyte) | |
474 | 821 col += (*mb_ptr2len)(ptr + col); |
7 | 822 else |
823 ++col; | |
824 } | |
825 if (new_line == NULL) /* out of memory */ | |
826 break; | |
827 line_breakcheck(); | |
828 } | |
829 if (got_int) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
830 emsg(_(e_interr)); |
7 | 831 |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
832 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
833 // 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
|
834 // 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
|
835 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
|
836 && tabstop_count(new_vts_array) == 1 |
6fbb8dfb3389
patch 8.1.0114: confusing variable name
Christian Brabandt <cb@256bit.org>
parents:
14185
diff
changeset
|
837 && 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
|
838 ; /* not changed */ |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
839 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
|
840 && 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
|
841 ; /* not changed */ |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
842 else |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
843 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
|
844 #else |
7 | 845 if (curbuf->b_p_ts != new_ts) |
846 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
|
847 #endif |
7 | 848 if (first_line != 0) |
849 changed_lines(first_line, 0, last_line + 1, 0L); | |
850 | |
851 curwin->w_p_list = save_list; /* restore 'list' */ | |
852 | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
853 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
854 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
|
855 { |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
856 // 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
|
857 // 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
|
858 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
|
859 |
14194
6fbb8dfb3389
patch 8.1.0114: confusing variable name
Christian Brabandt <cb@256bit.org>
parents:
14185
diff
changeset
|
860 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
|
861 { |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
862 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
|
863 OPT_FREE|OPT_LOCAL, 0); |
14194
6fbb8dfb3389
patch 8.1.0114: confusing variable name
Christian Brabandt <cb@256bit.org>
parents:
14185
diff
changeset
|
864 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
|
865 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
|
866 } |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
867 else |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
868 { |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
869 // '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
|
870 // retab then update 'tabstop'. |
14194
6fbb8dfb3389
patch 8.1.0114: confusing variable name
Christian Brabandt <cb@256bit.org>
parents:
14185
diff
changeset
|
871 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
|
872 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
|
873 } |
14218
539b070778b0
patch 8.1.0126: various problems with 'vartabstop'
Christian Brabandt <cb@256bit.org>
parents:
14206
diff
changeset
|
874 vim_free(new_ts_str); |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
875 } |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
876 #else |
7 | 877 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
|
878 #endif |
7 | 879 coladvance(curwin->w_curswant); |
880 | |
881 u_clearline(); | |
882 } | |
883 | |
884 /* | |
885 * :move command - move lines line1-line2 to line dest | |
886 * | |
887 * return FAIL for failure, OK otherwise | |
888 */ | |
889 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
890 do_move(linenr_T line1, linenr_T line2, linenr_T dest) |
7 | 891 { |
892 char_u *str; | |
893 linenr_T l; | |
15010
e3910b9827d0
patch 8.1.0516: :move command marks buffer modified when nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
14917
diff
changeset
|
894 linenr_T extra; // Num lines added before line1 |
e3910b9827d0
patch 8.1.0516: :move command marks buffer modified when nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
14917
diff
changeset
|
895 linenr_T num_lines; // Num lines moved |
e3910b9827d0
patch 8.1.0516: :move command marks buffer modified when nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
14917
diff
changeset
|
896 linenr_T last_line; // Last line in file after adding new text |
6755 | 897 #ifdef FEAT_FOLDING |
11140
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
898 win_T *win; |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
899 tabpage_T *tp; |
6755 | 900 #endif |
7 | 901 |
902 if (dest >= line1 && dest < line2) | |
903 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
904 emsg(_("E134: Cannot move a range of lines into itself")); |
7 | 905 return FAIL; |
906 } | |
907 | |
15010
e3910b9827d0
patch 8.1.0516: :move command marks buffer modified when nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
14917
diff
changeset
|
908 // Do nothing if we are not actually moving any lines. This will prevent |
e3910b9827d0
patch 8.1.0516: :move command marks buffer modified when nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
14917
diff
changeset
|
909 // the 'modified' flag from being set without cause. |
e3910b9827d0
patch 8.1.0516: :move command marks buffer modified when nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
14917
diff
changeset
|
910 if (dest == line1 - 1 || dest == line2) |
e3910b9827d0
patch 8.1.0516: :move command marks buffer modified when nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
14917
diff
changeset
|
911 { |
e3910b9827d0
patch 8.1.0516: :move command marks buffer modified when nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
14917
diff
changeset
|
912 // Move the cursor as if lines were moved (see below) to be backwards |
e3910b9827d0
patch 8.1.0516: :move command marks buffer modified when nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
14917
diff
changeset
|
913 // compatible. |
e3910b9827d0
patch 8.1.0516: :move command marks buffer modified when nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
14917
diff
changeset
|
914 if (dest >= line1) |
e3910b9827d0
patch 8.1.0516: :move command marks buffer modified when nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
14917
diff
changeset
|
915 curwin->w_cursor.lnum = dest; |
e3910b9827d0
patch 8.1.0516: :move command marks buffer modified when nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
14917
diff
changeset
|
916 else |
e3910b9827d0
patch 8.1.0516: :move command marks buffer modified when nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
14917
diff
changeset
|
917 curwin->w_cursor.lnum = dest + (line2 - line1) + 1; |
e3910b9827d0
patch 8.1.0516: :move command marks buffer modified when nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
14917
diff
changeset
|
918 |
e3910b9827d0
patch 8.1.0516: :move command marks buffer modified when nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
14917
diff
changeset
|
919 return OK; |
e3910b9827d0
patch 8.1.0516: :move command marks buffer modified when nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
14917
diff
changeset
|
920 } |
e3910b9827d0
patch 8.1.0516: :move command marks buffer modified when nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
14917
diff
changeset
|
921 |
7 | 922 num_lines = line2 - line1 + 1; |
923 | |
924 /* | |
925 * First we copy the old text to its new location -- webb | |
926 * Also copy the flag that ":global" command uses. | |
927 */ | |
928 if (u_save(dest, dest + 1) == FAIL) | |
929 return FAIL; | |
930 for (extra = 0, l = line1; l <= line2; l++) | |
931 { | |
932 str = vim_strsave(ml_get(l + extra)); | |
933 if (str != NULL) | |
934 { | |
935 ml_append(dest + l - line1, str, (colnr_T)0, FALSE); | |
936 vim_free(str); | |
937 if (dest < line1) | |
938 extra++; | |
939 } | |
940 } | |
941 | |
942 /* | |
943 * Now we must be careful adjusting our marks so that we don't overlap our | |
944 * mark_adjust() calls. | |
945 * | |
946 * We adjust the marks within the old text so that they refer to the | |
947 * last lines of the file (temporarily), because we know no other marks | |
948 * will be set there since these line numbers did not exist until we added | |
949 * our new lines. | |
950 * | |
951 * Then we adjust the marks on lines between the old and new text positions | |
952 * (either forwards or backwards). | |
953 * | |
954 * And Finally we adjust the marks we put at the end of the file back to | |
955 * their final destination at the new text position -- webb | |
956 */ | |
957 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
|
958 mark_adjust_nofold(line1, line2, last_line - line2, 0L); |
7 | 959 if (dest >= line2) |
960 { | |
11140
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
961 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
|
962 #ifdef FEAT_FOLDING |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
963 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
|
964 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
|
965 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
|
966 } |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
967 #endif |
7 | 968 curbuf->b_op_start.lnum = dest - num_lines + 1; |
969 curbuf->b_op_end.lnum = dest; | |
970 } | |
971 else | |
972 { | |
11140
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
973 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
|
974 #ifdef FEAT_FOLDING |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
975 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
|
976 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
|
977 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
|
978 } |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
979 #endif |
7 | 980 curbuf->b_op_start.lnum = dest + 1; |
981 curbuf->b_op_end.lnum = dest + num_lines; | |
982 } | |
983 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
|
984 mark_adjust_nofold(last_line - num_lines + 1, last_line, |
7 | 985 -(last_line - dest - extra), 0L); |
986 | |
987 /* | |
988 * Now we delete the original text -- webb | |
989 */ | |
990 if (u_save(line1 + extra - 1, line2 + extra + 1) == FAIL) | |
991 return FAIL; | |
992 | |
993 for (l = line1; l <= line2; l++) | |
994 ml_delete(line1 + extra, TRUE); | |
995 | |
996 if (!global_busy && num_lines > p_report) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
997 smsg(NGETTEXT("%ld line moved", "%ld lines moved", num_lines), |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14513
diff
changeset
|
998 (long)num_lines); |
7 | 999 |
1000 /* | |
1001 * Leave the cursor on the last of the moved lines. | |
1002 */ | |
1003 if (dest >= line1) | |
1004 curwin->w_cursor.lnum = dest; | |
1005 else | |
1006 curwin->w_cursor.lnum = dest + (line2 - line1) + 1; | |
1007 | |
1008 if (line1 < dest) | |
3184 | 1009 { |
1010 dest += num_lines + 1; | |
1011 last_line = curbuf->b_ml.ml_line_count; | |
1012 if (dest > last_line + 1) | |
1013 dest = last_line + 1; | |
1014 changed_lines(line1, 0, dest, 0L); | |
1015 } | |
7 | 1016 else |
1017 changed_lines(dest + 1, 0, line1 + num_lines, 0L); | |
1018 | |
1019 return OK; | |
1020 } | |
1021 | |
1022 /* | |
1023 * ":copy" | |
1024 */ | |
1025 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1026 ex_copy(linenr_T line1, linenr_T line2, linenr_T n) |
7 | 1027 { |
1028 linenr_T count; | |
1029 char_u *p; | |
1030 | |
1031 count = line2 - line1 + 1; | |
1032 curbuf->b_op_start.lnum = n + 1; | |
1033 curbuf->b_op_end.lnum = n + count; | |
1034 curbuf->b_op_start.col = curbuf->b_op_end.col = 0; | |
1035 | |
1036 /* | |
1037 * there are three situations: | |
1038 * 1. destination is above line1 | |
1039 * 2. destination is between line1 and line2 | |
1040 * 3. destination is below line2 | |
1041 * | |
1042 * n = destination (when starting) | |
1043 * curwin->w_cursor.lnum = destination (while copying) | |
1044 * line1 = start of source (while copying) | |
1045 * line2 = end of source (while copying) | |
1046 */ | |
1047 if (u_save(n, n + 1) == FAIL) | |
1048 return; | |
1049 | |
1050 curwin->w_cursor.lnum = n; | |
1051 while (line1 <= line2) | |
1052 { | |
1053 /* need to use vim_strsave() because the line will be unlocked within | |
1054 * ml_append() */ | |
1055 p = vim_strsave(ml_get(line1)); | |
1056 if (p != NULL) | |
1057 { | |
1058 ml_append(curwin->w_cursor.lnum, p, (colnr_T)0, FALSE); | |
1059 vim_free(p); | |
1060 } | |
1061 /* situation 2: skip already copied lines */ | |
1062 if (line1 == n) | |
1063 line1 = curwin->w_cursor.lnum; | |
1064 ++line1; | |
1065 if (curwin->w_cursor.lnum < line1) | |
1066 ++line1; | |
1067 if (curwin->w_cursor.lnum < line2) | |
1068 ++line2; | |
1069 ++curwin->w_cursor.lnum; | |
1070 } | |
1071 | |
1072 appended_lines_mark(n, count); | |
1073 | |
1074 msgmore((long)count); | |
1075 } | |
1076 | |
359 | 1077 static char_u *prevcmd = NULL; /* the previous command */ |
1078 | |
1079 #if defined(EXITFREE) || defined(PROTO) | |
1080 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1081 free_prev_shellcmd(void) |
359 | 1082 { |
1083 vim_free(prevcmd); | |
1084 } | |
1085 #endif | |
1086 | |
7 | 1087 /* |
1088 * Handle the ":!cmd" command. Also for ":r !cmd" and ":w !cmd" | |
1089 * Bangs in the argument are replaced with the previously entered command. | |
1090 * Remember the argument. | |
1091 */ | |
1092 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1093 do_bang( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1094 int addr_count, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1095 exarg_T *eap, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1096 int forceit, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1097 int do_in, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1098 int do_out) |
7 | 1099 { |
1100 char_u *arg = eap->arg; /* command */ | |
1101 linenr_T line1 = eap->line1; /* start of range */ | |
1102 linenr_T line2 = eap->line2; /* end of range */ | |
1103 char_u *newcmd = NULL; /* the new command */ | |
1104 int free_newcmd = FALSE; /* need to free() newcmd */ | |
1105 int ins_prevcmd; | |
1106 char_u *t; | |
1107 char_u *p; | |
1108 char_u *trailarg; | |
1109 int len; | |
1110 int scroll_save = msg_scroll; | |
1111 | |
1112 /* | |
1113 * Disallow shell commands for "rvim". | |
1114 * Disallow shell commands from .exrc and .vimrc in current directory for | |
1115 * security reasons. | |
1116 */ | |
1117 if (check_restricted() || check_secure()) | |
1118 return; | |
1119 | |
1120 if (addr_count == 0) /* :! */ | |
1121 { | |
1122 msg_scroll = FALSE; /* don't scroll here */ | |
1123 autowrite_all(); | |
1124 msg_scroll = scroll_save; | |
1125 } | |
1126 | |
1127 /* | |
1128 * Try to find an embedded bang, like in :!<cmd> ! [args] | |
1129 * (:!! is indicated by the 'forceit' variable) | |
1130 */ | |
1131 ins_prevcmd = forceit; | |
1132 trailarg = arg; | |
1133 do | |
1134 { | |
1135 len = (int)STRLEN(trailarg) + 1; | |
1136 if (newcmd != NULL) | |
1137 len += (int)STRLEN(newcmd); | |
1138 if (ins_prevcmd) | |
1139 { | |
1140 if (prevcmd == NULL) | |
1141 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
1142 emsg(_(e_noprev)); |
7 | 1143 vim_free(newcmd); |
1144 return; | |
1145 } | |
1146 len += (int)STRLEN(prevcmd); | |
1147 } | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
1148 if ((t = alloc(len)) == NULL) |
7 | 1149 { |
1150 vim_free(newcmd); | |
1151 return; | |
1152 } | |
1153 *t = NUL; | |
1154 if (newcmd != NULL) | |
1155 STRCAT(t, newcmd); | |
1156 if (ins_prevcmd) | |
1157 STRCAT(t, prevcmd); | |
1158 p = t + STRLEN(t); | |
1159 STRCAT(t, trailarg); | |
1160 vim_free(newcmd); | |
1161 newcmd = t; | |
1162 | |
1163 /* | |
1164 * Scan the rest of the argument for '!', which is replaced by the | |
1165 * previous command. "\!" is replaced by "!" (this is vi compatible). | |
1166 */ | |
1167 trailarg = NULL; | |
1168 while (*p) | |
1169 { | |
2823 | 1170 if (*p == '!') |
7 | 1171 { |
1172 if (p > newcmd && p[-1] == '\\') | |
1624 | 1173 STRMOVE(p - 1, p); |
7 | 1174 else |
1175 { | |
1176 trailarg = p; | |
1177 *trailarg++ = NUL; | |
1178 ins_prevcmd = TRUE; | |
1179 break; | |
1180 } | |
1181 } | |
1182 ++p; | |
1183 } | |
1184 } while (trailarg != NULL); | |
1185 | |
1186 vim_free(prevcmd); | |
1187 prevcmd = newcmd; | |
1188 | |
1189 if (bangredo) /* put cmd in redo buffer for ! command */ | |
1190 { | |
5728 | 1191 /* If % or # appears in the command, it must have been escaped. |
1192 * Reescape them, so that redoing them does not substitute them by the | |
1193 * buffername. */ | |
1194 char_u *cmd = vim_strsave_escaped(prevcmd, (char_u *)"%#"); | |
1195 | |
1196 if (cmd != NULL) | |
1197 { | |
1198 AppendToRedobuffLit(cmd, -1); | |
1199 vim_free(cmd); | |
1200 } | |
1201 else | |
1202 AppendToRedobuffLit(prevcmd, -1); | |
7 | 1203 AppendToRedobuff((char_u *)"\n"); |
1204 bangredo = FALSE; | |
1205 } | |
1206 /* | |
1207 * Add quotes around the command, for shells that need them. | |
1208 */ | |
1209 if (*p_shq != NUL) | |
1210 { | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
1211 newcmd = alloc(STRLEN(prevcmd) + 2 * STRLEN(p_shq) + 1); |
7 | 1212 if (newcmd == NULL) |
1213 return; | |
1214 STRCPY(newcmd, p_shq); | |
1215 STRCAT(newcmd, prevcmd); | |
1216 STRCAT(newcmd, p_shq); | |
1217 free_newcmd = TRUE; | |
1218 } | |
1219 if (addr_count == 0) /* :! */ | |
1220 { | |
1221 /* echo the command */ | |
1222 msg_start(); | |
1223 msg_putchar(':'); | |
1224 msg_putchar('!'); | |
1225 msg_outtrans(newcmd); | |
1226 msg_clr_eos(); | |
1227 windgoto(msg_row, msg_col); | |
1228 | |
1229 do_shell(newcmd, 0); | |
1230 } | |
1231 else /* :range! */ | |
725 | 1232 { |
7 | 1233 /* Careful: This may recursively call do_bang() again! (because of |
1234 * autocommands) */ | |
1235 do_filter(line1, line2, eap, newcmd, do_in, do_out); | |
725 | 1236 apply_autocmds(EVENT_SHELLFILTERPOST, NULL, NULL, FALSE, curbuf); |
1237 } | |
7 | 1238 if (free_newcmd) |
1239 vim_free(newcmd); | |
1240 } | |
1241 | |
1242 /* | |
1243 * do_filter: filter lines through a command given by the user | |
1244 * | |
169 | 1245 * We mostly use temp files and the call_shell() routine here. This would |
1246 * normally be done using pipes on a UNIX machine, but this is more portable | |
1247 * to non-unix machines. The call_shell() routine needs to be able | |
7 | 1248 * to deal with redirection somehow, and should handle things like looking |
1249 * at the PATH env. variable, and adding reasonable extensions to the | |
1250 * command name given by the user. All reasonable versions of call_shell() | |
1251 * do this. | |
169 | 1252 * Alternatively, if on Unix and redirecting input or output, but not both, |
1253 * and the 'shelltemp' option isn't set, use pipes. | |
7 | 1254 * We use input redirection if do_in is TRUE. |
1255 * We use output redirection if do_out is TRUE. | |
1256 */ | |
1257 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1258 do_filter( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1259 linenr_T line1, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1260 linenr_T line2, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1261 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
|
1262 char_u *cmd, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1263 int do_in, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1264 int do_out) |
7 | 1265 { |
1266 char_u *itmp = NULL; | |
1267 char_u *otmp = NULL; | |
1268 linenr_T linecount; | |
1269 linenr_T read_linecount; | |
1270 pos_T cursor_save; | |
1271 char_u *cmd_buf; | |
1272 buf_T *old_curbuf = curbuf; | |
169 | 1273 int shell_flags = 0; |
7 | 1274 |
1275 if (*cmd == NUL) /* no filter command */ | |
1276 return; | |
1277 | |
1278 cursor_save = curwin->w_cursor; | |
1279 linecount = line2 - line1 + 1; | |
1280 curwin->w_cursor.lnum = line1; | |
1281 curwin->w_cursor.col = 0; | |
1282 changed_line_abv_curs(); | |
1283 invalidate_botline(); | |
1284 | |
1285 /* | |
169 | 1286 * When using temp files: |
1287 * 1. * Form temp file names | |
1288 * 2. * Write the lines to a temp file | |
1289 * 3. Run the filter command on the temp file | |
1290 * 4. * Read the output of the command into the buffer | |
1291 * 5. * Delete the original lines to be filtered | |
1292 * 6. * Remove the temp files | |
1293 * | |
1294 * When writing the input with a pipe or when catching the output with a | |
1295 * pipe only need to do 3. | |
7 | 1296 */ |
1297 | |
169 | 1298 if (do_out) |
1299 shell_flags |= SHELL_DOOUT; | |
1300 | |
3482 | 1301 #ifdef FEAT_FILTERPIPE |
169 | 1302 if (!do_in && do_out && !p_stmp) |
1303 { | |
1304 /* Use a pipe to fetch stdout of the command, do not use a temp file. */ | |
1305 shell_flags |= SHELL_READ; | |
1306 curwin->w_cursor.lnum = line2; | |
1307 } | |
1308 else if (do_in && !do_out && !p_stmp) | |
7 | 1309 { |
169 | 1310 /* Use a pipe to write stdin of the command, do not use a temp file. */ |
1311 shell_flags |= SHELL_WRITE; | |
1312 curbuf->b_op_start.lnum = line1; | |
1313 curbuf->b_op_end.lnum = line2; | |
7 | 1314 } |
169 | 1315 else if (do_in && do_out && !p_stmp) |
1316 { | |
1317 /* Use a pipe to write stdin and fetch stdout of the command, do not | |
1318 * use a temp file. */ | |
1319 shell_flags |= SHELL_READ|SHELL_WRITE; | |
1320 curbuf->b_op_start.lnum = line1; | |
1321 curbuf->b_op_end.lnum = line2; | |
1322 curwin->w_cursor.lnum = line2; | |
1323 } | |
1324 else | |
1325 #endif | |
6721 | 1326 if ((do_in && (itmp = vim_tempname('i', FALSE)) == NULL) |
1327 || (do_out && (otmp = vim_tempname('o', FALSE)) == NULL)) | |
169 | 1328 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
1329 emsg(_(e_notmp)); |
169 | 1330 goto filterend; |
1331 } | |
7 | 1332 |
1333 /* | |
1334 * The writing and reading of temp files will not be shown. | |
1335 * Vi also doesn't do this and the messages are not very informative. | |
1336 */ | |
1337 ++no_wait_return; /* don't call wait_return() while busy */ | |
169 | 1338 if (itmp != NULL && buf_write(curbuf, itmp, NULL, line1, line2, eap, |
7 | 1339 FALSE, FALSE, FALSE, TRUE) == FAIL) |
1340 { | |
1341 msg_putchar('\n'); /* keep message from buf_write() */ | |
1342 --no_wait_return; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
1343 #if defined(FEAT_EVAL) |
7 | 1344 if (!aborting()) |
1345 #endif | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
1346 (void)semsg(_(e_notcreate), itmp); /* will call wait_return */ |
7 | 1347 goto filterend; |
1348 } | |
1349 if (curbuf != old_curbuf) | |
1350 goto filterend; | |
1351 | |
1352 if (!do_out) | |
1353 msg_putchar('\n'); | |
1354 | |
1581 | 1355 /* Create the shell command in allocated memory. */ |
7 | 1356 cmd_buf = make_filter_cmd(cmd, itmp, otmp); |
1357 if (cmd_buf == NULL) | |
1358 goto filterend; | |
1359 | |
1360 windgoto((int)Rows - 1, 0); | |
1361 cursor_on(); | |
1362 | |
1363 /* | |
1364 * When not redirecting the output the command can write anything to the | |
1365 * screen. If 'shellredir' is equal to ">", screen may be messed up by | |
1366 * stderr output of external command. Clear the screen later. | |
1367 * If do_in is FALSE, this could be something like ":r !cat", which may | |
1368 * also mess up the screen, clear it later. | |
1369 */ | |
1370 if (!do_out || STRCMP(p_srr, ">") == 0 || !do_in) | |
1371 redraw_later_clear(); | |
1372 | |
169 | 1373 if (do_out) |
1374 { | |
1375 if (u_save((linenr_T)(line2), (linenr_T)(line2 + 1)) == FAIL) | |
1581 | 1376 { |
1377 vim_free(cmd_buf); | |
169 | 1378 goto error; |
1581 | 1379 } |
169 | 1380 redraw_curbuf_later(VALID); |
1381 } | |
1382 read_linecount = curbuf->b_ml.ml_line_count; | |
1383 | |
7 | 1384 /* |
1385 * When call_shell() fails wait_return() is called to give the user a | |
1386 * chance to read the error messages. Otherwise errors are ignored, so you | |
1387 * can see the error messages from the command that appear on stdout; use | |
1388 * 'u' to fix the text | |
1389 * Switch to cooked mode when not redirecting stdin, avoids that something | |
1390 * like ":r !cat" hangs. | |
1391 * Pass on the SHELL_DOOUT flag when the output is being redirected. | |
1392 */ | |
169 | 1393 if (call_shell(cmd_buf, SHELL_FILTER | SHELL_COOKED | shell_flags)) |
7 | 1394 { |
1395 redraw_later_clear(); | |
1396 wait_return(FALSE); | |
1397 } | |
1398 vim_free(cmd_buf); | |
1399 | |
1400 did_check_timestamps = FALSE; | |
1401 need_check_timestamps = TRUE; | |
1402 | |
1403 /* When interrupting the shell command, it may still have produced some | |
1404 * useful output. Reset got_int here, so that readfile() won't cancel | |
1405 * reading. */ | |
1406 ui_breakcheck(); | |
1407 got_int = FALSE; | |
1408 | |
1409 if (do_out) | |
1410 { | |
169 | 1411 if (otmp != NULL) |
7 | 1412 { |
169 | 1413 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
|
1414 eap, READ_FILTER) != OK) |
169 | 1415 { |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
1416 #if defined(FEAT_EVAL) |
169 | 1417 if (!aborting()) |
1418 #endif | |
1419 { | |
1420 msg_putchar('\n'); | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
1421 semsg(_(e_notread), otmp); |
169 | 1422 } |
1423 goto error; | |
7 | 1424 } |
169 | 1425 if (curbuf != old_curbuf) |
1426 goto filterend; | |
7 | 1427 } |
169 | 1428 |
1429 read_linecount = curbuf->b_ml.ml_line_count - read_linecount; | |
1430 | |
1431 if (shell_flags & SHELL_READ) | |
1432 { | |
1433 curbuf->b_op_start.lnum = line2 + 1; | |
1434 curbuf->b_op_end.lnum = curwin->w_cursor.lnum; | |
1435 appended_lines_mark(line2, read_linecount); | |
1436 } | |
7 | 1437 |
1438 if (do_in) | |
1439 { | |
1440 if (cmdmod.keepmarks || vim_strchr(p_cpo, CPO_REMMARK) == NULL) | |
1441 { | |
1442 if (read_linecount >= linecount) | |
1443 /* move all marks from old lines to new lines */ | |
1444 mark_adjust(line1, line2, linecount, 0L); | |
1445 else | |
1446 { | |
1447 /* move marks from old lines to new lines, delete marks | |
1448 * that are in deleted lines */ | |
1449 mark_adjust(line1, line1 + read_linecount - 1, | |
1450 linecount, 0L); | |
1451 mark_adjust(line1 + read_linecount, line2, MAXLNUM, 0L); | |
1452 } | |
1453 } | |
1454 | |
1455 /* | |
1456 * Put cursor on first filtered line for ":range!cmd". | |
1457 * Adjust '[ and '] (set by buf_write()). | |
1458 */ | |
1459 curwin->w_cursor.lnum = line1; | |
1460 del_lines(linecount, TRUE); | |
1461 curbuf->b_op_start.lnum -= linecount; /* adjust '[ */ | |
1462 curbuf->b_op_end.lnum -= linecount; /* adjust '] */ | |
1463 write_lnum_adjust(-linecount); /* adjust last line | |
1464 for next write */ | |
100 | 1465 #ifdef FEAT_FOLDING |
1466 foldUpdate(curwin, curbuf->b_op_start.lnum, curbuf->b_op_end.lnum); | |
1467 #endif | |
7 | 1468 } |
1469 else | |
1470 { | |
1471 /* | |
1472 * Put cursor on last new line for ":r !cmd". | |
1473 */ | |
169 | 1474 linecount = curbuf->b_op_end.lnum - curbuf->b_op_start.lnum + 1; |
7 | 1475 curwin->w_cursor.lnum = curbuf->b_op_end.lnum; |
1476 } | |
100 | 1477 |
7 | 1478 beginline(BL_WHITE | BL_FIX); /* cursor on first non-blank */ |
1479 --no_wait_return; | |
1480 | |
1481 if (linecount > p_report) | |
1482 { | |
1483 if (do_in) | |
1484 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
1485 vim_snprintf(msg_buf, sizeof(msg_buf), |
274 | 1486 _("%ld lines filtered"), (long)linecount); |
7 | 1487 if (msg(msg_buf) && !msg_scroll) |
1488 /* save message to display it after redraw */ | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
1489 set_keep_msg((char_u *)msg_buf, 0); |
7 | 1490 } |
1491 else | |
1492 msgmore((long)linecount); | |
1493 } | |
1494 } | |
1495 else | |
1496 { | |
1497 error: | |
1498 /* put cursor back in same position for ":w !cmd" */ | |
1499 curwin->w_cursor = cursor_save; | |
1500 --no_wait_return; | |
1501 wait_return(FALSE); | |
1502 } | |
1503 | |
1504 filterend: | |
1505 | |
1506 if (curbuf != old_curbuf) | |
1507 { | |
1508 --no_wait_return; | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
1509 emsg(_("E135: *Filter* Autocommands must not change current buffer")); |
7 | 1510 } |
1511 if (itmp != NULL) | |
1512 mch_remove(itmp); | |
1513 if (otmp != NULL) | |
1514 mch_remove(otmp); | |
1515 vim_free(itmp); | |
1516 vim_free(otmp); | |
1517 } | |
1518 | |
1519 /* | |
1520 * Call a shell to execute a command. | |
1521 * When "cmd" is NULL start an interactive shell. | |
1522 */ | |
1523 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1524 do_shell( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1525 char_u *cmd, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1526 int flags) /* may be SHELL_DOOUT when output is redirected */ |
7 | 1527 { |
1528 buf_T *buf; | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1529 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7 | 1530 int save_nwr; |
1531 #endif | |
1532 #ifdef MSWIN | |
1533 int winstart = FALSE; | |
16021
5417a7f802ff
patch 8.1.1016: MS-Windows: No color in shell when using "!" in 'guioptions
Bram Moolenaar <Bram@vim.org>
parents:
15906
diff
changeset
|
1534 int keep_termcap = FALSE; |
7 | 1535 #endif |
1536 | |
1537 /* | |
1538 * Disallow shell commands for "rvim". | |
1539 * Disallow shell commands from .exrc and .vimrc in current directory for | |
1540 * security reasons. | |
1541 */ | |
1542 if (check_restricted() || check_secure()) | |
1543 { | |
1544 msg_end(); | |
1545 return; | |
1546 } | |
1547 | |
1548 #ifdef MSWIN | |
1549 /* | |
16021
5417a7f802ff
patch 8.1.1016: MS-Windows: No color in shell when using "!" in 'guioptions
Bram Moolenaar <Bram@vim.org>
parents:
15906
diff
changeset
|
1550 * Check if ":!start" is used. This implies not stopping termcap mode. |
7 | 1551 */ |
1552 if (cmd != NULL) | |
16021
5417a7f802ff
patch 8.1.1016: MS-Windows: No color in shell when using "!" in 'guioptions
Bram Moolenaar <Bram@vim.org>
parents:
15906
diff
changeset
|
1553 keep_termcap = winstart = (STRNICMP(cmd, "start ", 6) == 0); |
5417a7f802ff
patch 8.1.1016: MS-Windows: No color in shell when using "!" in 'guioptions
Bram Moolenaar <Bram@vim.org>
parents:
15906
diff
changeset
|
1554 |
5417a7f802ff
patch 8.1.1016: MS-Windows: No color in shell when using "!" in 'guioptions
Bram Moolenaar <Bram@vim.org>
parents:
15906
diff
changeset
|
1555 # if defined(FEAT_GUI) && defined(FEAT_TERMINAL) |
5417a7f802ff
patch 8.1.1016: MS-Windows: No color in shell when using "!" in 'guioptions
Bram Moolenaar <Bram@vim.org>
parents:
15906
diff
changeset
|
1556 // Don't stop termcap mode when using a terminal window for the shell. |
5417a7f802ff
patch 8.1.1016: MS-Windows: No color in shell when using "!" in 'guioptions
Bram Moolenaar <Bram@vim.org>
parents:
15906
diff
changeset
|
1557 if (gui.in_use && vim_strchr(p_go, GO_TERMINAL) != NULL) |
5417a7f802ff
patch 8.1.1016: MS-Windows: No color in shell when using "!" in 'guioptions
Bram Moolenaar <Bram@vim.org>
parents:
15906
diff
changeset
|
1558 keep_termcap = TRUE; |
5417a7f802ff
patch 8.1.1016: MS-Windows: No color in shell when using "!" in 'guioptions
Bram Moolenaar <Bram@vim.org>
parents:
15906
diff
changeset
|
1559 # endif |
7 | 1560 #endif |
1561 | |
1562 /* | |
1563 * For autocommands we want to get the output on the current screen, to | |
1564 * avoid having to type return below. | |
1565 */ | |
16021
5417a7f802ff
patch 8.1.1016: MS-Windows: No color in shell when using "!" in 'guioptions
Bram Moolenaar <Bram@vim.org>
parents:
15906
diff
changeset
|
1566 msg_putchar('\r'); // put cursor at start of line |
7 | 1567 if (!autocmd_busy) |
1568 { | |
1569 #ifdef MSWIN | |
16021
5417a7f802ff
patch 8.1.1016: MS-Windows: No color in shell when using "!" in 'guioptions
Bram Moolenaar <Bram@vim.org>
parents:
15906
diff
changeset
|
1570 if (!keep_termcap) |
7 | 1571 #endif |
1572 stoptermcap(); | |
1573 } | |
1574 #ifdef MSWIN | |
1575 if (!winstart) | |
1576 #endif | |
16021
5417a7f802ff
patch 8.1.1016: MS-Windows: No color in shell when using "!" in 'guioptions
Bram Moolenaar <Bram@vim.org>
parents:
15906
diff
changeset
|
1577 msg_putchar('\n'); // may shift screen one line up |
5417a7f802ff
patch 8.1.1016: MS-Windows: No color in shell when using "!" in 'guioptions
Bram Moolenaar <Bram@vim.org>
parents:
15906
diff
changeset
|
1578 |
5417a7f802ff
patch 8.1.1016: MS-Windows: No color in shell when using "!" in 'guioptions
Bram Moolenaar <Bram@vim.org>
parents:
15906
diff
changeset
|
1579 // warning message before calling the shell |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
1580 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
|
1581 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
|
1582 if (bufIsChangedNotTerm(buf)) |
7 | 1583 { |
1584 #ifdef FEAT_GUI_MSWIN | |
16021
5417a7f802ff
patch 8.1.1016: MS-Windows: No color in shell when using "!" in 'guioptions
Bram Moolenaar <Bram@vim.org>
parents:
15906
diff
changeset
|
1585 if (!keep_termcap) |
5417a7f802ff
patch 8.1.1016: MS-Windows: No color in shell when using "!" in 'guioptions
Bram Moolenaar <Bram@vim.org>
parents:
15906
diff
changeset
|
1586 starttermcap(); // don't want a message box here |
7 | 1587 #endif |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
1588 msg_puts(_("[No write since last change]\n")); |
7 | 1589 #ifdef FEAT_GUI_MSWIN |
16021
5417a7f802ff
patch 8.1.1016: MS-Windows: No color in shell when using "!" in 'guioptions
Bram Moolenaar <Bram@vim.org>
parents:
15906
diff
changeset
|
1590 if (!keep_termcap) |
7 | 1591 stoptermcap(); |
1592 #endif | |
1593 break; | |
1594 } | |
1595 | |
16021
5417a7f802ff
patch 8.1.1016: MS-Windows: No color in shell when using "!" in 'guioptions
Bram Moolenaar <Bram@vim.org>
parents:
15906
diff
changeset
|
1596 // This windgoto is required for when the '\n' resulted in a "delete line |
5417a7f802ff
patch 8.1.1016: MS-Windows: No color in shell when using "!" in 'guioptions
Bram Moolenaar <Bram@vim.org>
parents:
15906
diff
changeset
|
1597 // 1" command to the terminal. |
7 | 1598 if (!swapping_screen()) |
1599 windgoto(msg_row, msg_col); | |
1600 cursor_on(); | |
1601 (void)call_shell(cmd, SHELL_COOKED | flags); | |
1602 did_check_timestamps = FALSE; | |
1603 need_check_timestamps = TRUE; | |
1604 | |
1605 /* | |
1606 * put the message cursor at the end of the screen, avoids wait_return() | |
1607 * to overwrite the text that the external command showed | |
1608 */ | |
1609 if (!swapping_screen()) | |
1610 { | |
1611 msg_row = Rows - 1; | |
1612 msg_col = 0; | |
1613 } | |
1614 | |
1615 if (autocmd_busy) | |
1616 { | |
1617 if (msg_silent == 0) | |
1618 redraw_later_clear(); | |
1619 } | |
1620 else | |
1621 { | |
1622 /* | |
1623 * For ":sh" there is no need to call wait_return(), just redraw. | |
1624 * Also for the Win32 GUI (the output is in a console window). | |
1625 * Otherwise there is probably text on the screen that the user wants | |
1626 * to read before redrawing, so call wait_return(). | |
1627 */ | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1628 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1629 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1630 if (!gui.in_use) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1631 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1632 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1633 if (cmd == NULL |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15850
diff
changeset
|
1634 # ifdef MSWIN |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1635 || (keep_termcap && !need_wait_return) |
7 | 1636 # endif |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1637 ) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1638 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1639 if (msg_silent == 0) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1640 redraw_later_clear(); |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1641 need_wait_return = FALSE; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1642 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1643 else |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1644 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1645 /* |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1646 * If we switch screens when starttermcap() is called, we |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1647 * really want to wait for "hit return to continue". |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1648 */ |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1649 save_nwr = no_wait_return; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1650 if (swapping_screen()) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1651 no_wait_return = FALSE; |
7 | 1652 # ifdef AMIGA |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1653 wait_return(term_console ? -1 : msg_silent == 0); // see below |
7 | 1654 # else |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1655 wait_return(msg_silent == 0); |
7 | 1656 # endif |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1657 no_wait_return = save_nwr; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1658 } |
7 | 1659 } |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15850
diff
changeset
|
1660 #endif /* FEAT_GUI_MSWIN */ |
7 | 1661 |
1662 #ifdef MSWIN | |
16021
5417a7f802ff
patch 8.1.1016: MS-Windows: No color in shell when using "!" in 'guioptions
Bram Moolenaar <Bram@vim.org>
parents:
15906
diff
changeset
|
1663 if (!keep_termcap) // if keep_termcap is TRUE didn't stop termcap |
5417a7f802ff
patch 8.1.1016: MS-Windows: No color in shell when using "!" in 'guioptions
Bram Moolenaar <Bram@vim.org>
parents:
15906
diff
changeset
|
1664 #endif |
5417a7f802ff
patch 8.1.1016: MS-Windows: No color in shell when using "!" in 'guioptions
Bram Moolenaar <Bram@vim.org>
parents:
15906
diff
changeset
|
1665 starttermcap(); // start termcap if not done by wait_return() |
7 | 1666 |
1667 /* | |
1668 * In an Amiga window redrawing is caused by asking the window size. | |
1669 * If we got an interrupt this will not work. The chance that the | |
1670 * window size is wrong is very small, but we need to redraw the | |
1671 * screen. Don't do this if ':' hit in wait_return(). THIS IS UGLY | |
1672 * but it saves an extra redraw. | |
1673 */ | |
1674 #ifdef AMIGA | |
1675 if (skip_redraw) /* ':' hit in wait_return() */ | |
1676 { | |
1677 if (msg_silent == 0) | |
1678 redraw_later_clear(); | |
1679 } | |
1680 else if (term_console) | |
1681 { | |
1682 OUT_STR(IF_EB("\033[0 q", ESC_STR "[0 q")); /* get window size */ | |
1683 if (got_int && msg_silent == 0) | |
1684 redraw_later_clear(); /* if got_int is TRUE, redraw needed */ | |
1685 else | |
1686 must_redraw = 0; /* no extra redraw needed */ | |
1687 } | |
1688 #endif | |
1689 } | |
1690 | |
1691 /* display any error messages now */ | |
1692 display_errors(); | |
725 | 1693 |
1694 apply_autocmds(EVENT_SHELLCMDPOST, NULL, NULL, FALSE, curbuf); | |
7 | 1695 } |
1696 | |
14913
d4777be849d0
patch 8.1.0468: MS-Windows: filter command with pipe character fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1697 #if !defined(UNIX) |
d4777be849d0
patch 8.1.0468: MS-Windows: filter command with pipe character fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1698 static char_u * |
d4777be849d0
patch 8.1.0468: MS-Windows: filter command with pipe character fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1699 find_pipe(char_u *cmd) |
d4777be849d0
patch 8.1.0468: MS-Windows: filter command with pipe character fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1700 { |
d4777be849d0
patch 8.1.0468: MS-Windows: filter command with pipe character fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1701 char_u *p; |
d4777be849d0
patch 8.1.0468: MS-Windows: filter command with pipe character fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1702 int inquote = FALSE; |
d4777be849d0
patch 8.1.0468: MS-Windows: filter command with pipe character fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1703 |
d4777be849d0
patch 8.1.0468: MS-Windows: filter command with pipe character fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1704 for (p = cmd; *p != NUL; ++p) |
d4777be849d0
patch 8.1.0468: MS-Windows: filter command with pipe character fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1705 { |
d4777be849d0
patch 8.1.0468: MS-Windows: filter command with pipe character fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1706 if (!inquote && *p == '|') |
d4777be849d0
patch 8.1.0468: MS-Windows: filter command with pipe character fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1707 return p; |
d4777be849d0
patch 8.1.0468: MS-Windows: filter command with pipe character fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1708 if (*p == '"') |
d4777be849d0
patch 8.1.0468: MS-Windows: filter command with pipe character fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1709 inquote = !inquote; |
d4777be849d0
patch 8.1.0468: MS-Windows: filter command with pipe character fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1710 else if (rem_backslash(p)) |
d4777be849d0
patch 8.1.0468: MS-Windows: filter command with pipe character fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1711 ++p; |
d4777be849d0
patch 8.1.0468: MS-Windows: filter command with pipe character fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1712 } |
d4777be849d0
patch 8.1.0468: MS-Windows: filter command with pipe character fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1713 return NULL; |
d4777be849d0
patch 8.1.0468: MS-Windows: filter command with pipe character fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1714 } |
d4777be849d0
patch 8.1.0468: MS-Windows: filter command with pipe character fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1715 #endif |
d4777be849d0
patch 8.1.0468: MS-Windows: filter command with pipe character fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1716 |
7 | 1717 /* |
1718 * Create a shell command from a command string, input redirection file and | |
1719 * output redirection file. | |
1720 * Returns an allocated string with the shell command, or NULL for failure. | |
1721 */ | |
1722 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1723 make_filter_cmd( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1724 char_u *cmd, /* command */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1725 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
|
1726 char_u *otmp) /* NULL or name of output file */ |
7 | 1727 { |
1728 char_u *buf; | |
1729 long_u len; | |
5867 | 1730 |
7410
08e62c4fc17d
commit https://github.com/vim/vim/commit/53076830fea6df737455523f7e235bfe4f79864d
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
1731 #if defined(UNIX) |
5881 | 1732 int is_fish_shell; |
5911 | 1733 char_u *shell_name = get_isolated_shell_name(); |
5881 | 1734 |
5867 | 1735 /* Account for fish's different syntax for subshells */ |
5911 | 1736 is_fish_shell = (fnamecmp(shell_name, "fish") == 0); |
1737 vim_free(shell_name); | |
5867 | 1738 if (is_fish_shell) |
1739 len = (long_u)STRLEN(cmd) + 13; /* "begin; " + "; end" + NUL */ | |
1740 else | |
1741 #endif | |
1742 len = (long_u)STRLEN(cmd) + 3; /* "()" + NUL */ | |
7 | 1743 if (itmp != NULL) |
1744 len += (long_u)STRLEN(itmp) + 9; /* " { < " + " } " */ | |
1745 if (otmp != NULL) | |
1746 len += (long_u)STRLEN(otmp) + (long_u)STRLEN(p_srr) + 2; /* " " */ | |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
1747 buf = alloc(len); |
7 | 1748 if (buf == NULL) |
1749 return NULL; | |
1750 | |
7410
08e62c4fc17d
commit https://github.com/vim/vim/commit/53076830fea6df737455523f7e235bfe4f79864d
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
1751 #if defined(UNIX) |
7 | 1752 /* |
169 | 1753 * Put braces around the command (for concatenated commands) when |
1754 * redirecting input and/or output. | |
7 | 1755 */ |
169 | 1756 if (itmp != NULL || otmp != NULL) |
5867 | 1757 { |
1758 if (is_fish_shell) | |
1759 vim_snprintf((char *)buf, len, "begin; %s; end", (char *)cmd); | |
1760 else | |
1761 vim_snprintf((char *)buf, len, "(%s)", (char *)cmd); | |
1762 } | |
169 | 1763 else |
1764 STRCPY(buf, cmd); | |
7 | 1765 if (itmp != NULL) |
1766 { | |
1767 STRCAT(buf, " < "); | |
1768 STRCAT(buf, itmp); | |
1769 } | |
1770 #else | |
1771 /* | |
5867 | 1772 * For shells that don't understand braces around commands, at least allow |
7 | 1773 * the use of commands in a pipe. |
1774 */ | |
1775 STRCPY(buf, cmd); | |
1776 if (itmp != NULL) | |
1777 { | |
1778 char_u *p; | |
1779 | |
1780 /* | |
1781 * If there is a pipe, we have to put the '<' in front of it. | |
1782 * Don't do this when 'shellquote' is not empty, otherwise the | |
1783 * redirection would be inside the quotes. | |
1784 */ | |
1785 if (*p_shq == NUL) | |
1786 { | |
14913
d4777be849d0
patch 8.1.0468: MS-Windows: filter command with pipe character fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1787 p = find_pipe(buf); |
7 | 1788 if (p != NULL) |
1789 *p = NUL; | |
1790 } | |
1791 STRCAT(buf, " <"); /* " < " causes problems on Amiga */ | |
1792 STRCAT(buf, itmp); | |
1793 if (*p_shq == NUL) | |
1794 { | |
14913
d4777be849d0
patch 8.1.0468: MS-Windows: filter command with pipe character fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1795 p = find_pipe(cmd); |
7 | 1796 if (p != NULL) |
1797 { | |
1798 STRCAT(buf, " "); /* insert a space before the '|' for DOS */ | |
1799 STRCAT(buf, p); | |
1800 } | |
1801 } | |
1802 } | |
1803 #endif | |
1804 if (otmp != NULL) | |
1872 | 1805 append_redir(buf, (int)len, p_srr, otmp); |
7 | 1806 |
1807 return buf; | |
1808 } | |
1809 | |
1810 /* | |
1872 | 1811 * Append output redirection for file "fname" to the end of string buffer |
1812 * "buf[buflen]" | |
7 | 1813 * Works with the 'shellredir' and 'shellpipe' options. |
1814 * The caller should make sure that there is enough room: | |
1815 * STRLEN(opt) + STRLEN(fname) + 3 | |
1816 */ | |
1817 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1818 append_redir( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1819 char_u *buf, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1820 int buflen, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1821 char_u *opt, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1822 char_u *fname) |
7 | 1823 { |
1824 char_u *p; | |
1872 | 1825 char_u *end; |
1826 | |
1827 end = buf + STRLEN(buf); | |
5257
e63e4b4be923
updated for version 7.4b.005
Bram Moolenaar <bram@vim.org>
parents:
5242
diff
changeset
|
1828 /* find "%s" */ |
7 | 1829 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
|
1830 { |
e63e4b4be923
updated for version 7.4b.005
Bram Moolenaar <bram@vim.org>
parents:
5242
diff
changeset
|
1831 if (p[1] == 's') /* found %s */ |
7 | 1832 break; |
5257
e63e4b4be923
updated for version 7.4b.005
Bram Moolenaar <bram@vim.org>
parents:
5242
diff
changeset
|
1833 if (p[1] == '%') /* skip %% */ |
e63e4b4be923
updated for version 7.4b.005
Bram Moolenaar <bram@vim.org>
parents:
5242
diff
changeset
|
1834 ++p; |
e63e4b4be923
updated for version 7.4b.005
Bram Moolenaar <bram@vim.org>
parents:
5242
diff
changeset
|
1835 } |
7 | 1836 if (p != NULL) |
1837 { | |
1872 | 1838 *end = ' '; /* not really needed? Not with sh, ksh or bash */ |
1839 vim_snprintf((char *)end + 1, (size_t)(buflen - (end + 1 - buf)), | |
1840 (char *)opt, (char *)fname); | |
7 | 1841 } |
1842 else | |
1872 | 1843 vim_snprintf((char *)end, (size_t)(buflen - (end - buf)), |
7 | 1844 #ifdef FEAT_QUICKFIX |
1845 " %s %s", | |
1846 #else | |
1847 " %s%s", /* " > %s" causes problems on Amiga */ | |
1848 #endif | |
1849 (char *)opt, (char *)fname); | |
1850 } | |
1851 | |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
1852 #if defined(FEAT_VIMINFO) || defined(PROTO) |
7 | 1853 |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
1854 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
|
1855 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
|
1856 static void write_viminfo_barlines(vir_T *virp, FILE *fp_out); |
7 | 1857 static int viminfo_errcnt; |
1858 | |
1859 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1860 no_viminfo(void) |
7 | 1861 { |
1862 /* "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
|
1863 return STRCMP(p_viminfofile, "NONE") == 0; |
7 | 1864 } |
1865 | |
1866 /* | |
1867 * Report an error for reading a viminfo file. | |
1868 * Count the number of errors. When there are more than 10, return TRUE. | |
1869 */ | |
1870 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1871 viminfo_error(char *errnum, char *message, char_u *line) |
7 | 1872 { |
274 | 1873 vim_snprintf((char *)IObuff, IOSIZE, _("%sviminfo: %s in line: "), |
1874 errnum, message); | |
1459 | 1875 STRNCAT(IObuff, line, IOSIZE - STRLEN(IObuff) - 1); |
156 | 1876 if (IObuff[STRLEN(IObuff) - 1] == '\n') |
1877 IObuff[STRLEN(IObuff) - 1] = NUL; | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
1878 emsg((char *)IObuff); |
7 | 1879 if (++viminfo_errcnt >= 10) |
1880 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
1881 emsg(_("E136: viminfo: Too many errors, skipping rest of file")); |
7 | 1882 return TRUE; |
1883 } | |
1884 return FALSE; | |
1885 } | |
1886 | |
1887 /* | |
1888 * read_viminfo() -- Read the viminfo file. Registers etc. which are already | |
1733 | 1889 * set are not over-written unless "flags" includes VIF_FORCEIT. -- webb |
7 | 1890 */ |
1891 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1892 read_viminfo( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1893 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
|
1894 int flags) /* VIF_WANT_INFO et al. */ |
7 | 1895 { |
1896 FILE *fp; | |
1897 char_u *fname; | |
1898 | |
1899 if (no_viminfo()) | |
1900 return FAIL; | |
1901 | |
1733 | 1902 fname = viminfo_filename(file); /* get file name in allocated buffer */ |
7 | 1903 if (fname == NULL) |
1904 return FAIL; | |
1905 fp = mch_fopen((char *)fname, READBIN); | |
1906 | |
1907 if (p_verbose > 0) | |
294 | 1908 { |
1909 verbose_enter(); | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
1910 smsg(_("Reading viminfo file \"%s\"%s%s%s"), |
274 | 1911 fname, |
1733 | 1912 (flags & VIF_WANT_INFO) ? _(" info") : "", |
1913 (flags & VIF_WANT_MARKS) ? _(" marks") : "", | |
1914 (flags & VIF_GET_OLDFILES) ? _(" oldfiles") : "", | |
274 | 1915 fp == NULL ? _(" FAILED") : ""); |
294 | 1916 verbose_leave(); |
1917 } | |
7 | 1918 |
1919 vim_free(fname); | |
1920 if (fp == NULL) | |
1921 return FAIL; | |
1922 | |
1923 viminfo_errcnt = 0; | |
1733 | 1924 do_viminfo(fp, NULL, flags); |
7 | 1925 |
1926 fclose(fp); | |
1927 return OK; | |
1928 } | |
1929 | |
1930 /* | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1931 * 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
|
1932 * 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
|
1933 * run simultaneously, without losing any marks etc. |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1934 * 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
|
1935 * info is written to the file. |
7 | 1936 */ |
1937 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1938 write_viminfo(char_u *file, int forceit) |
7 | 1939 { |
1940 char_u *fname; | |
1941 FILE *fp_in = NULL; /* input viminfo file, if any */ | |
1942 FILE *fp_out = NULL; /* output viminfo file */ | |
1943 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
|
1944 stat_T st_new; /* mch_stat() of potential new file */ |
7 | 1945 #if defined(UNIX) || defined(VMS) |
1946 mode_t umask_save; | |
1947 #endif | |
1948 #ifdef UNIX | |
1949 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
|
1950 stat_T st_old; /* mch_stat() of existing viminfo file */ |
7 | 1951 #endif |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15850
diff
changeset
|
1952 #ifdef MSWIN |
7194
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1953 int hidden = FALSE; |
601 | 1954 #endif |
7 | 1955 |
1956 if (no_viminfo()) | |
1957 return; | |
1958 | |
1959 fname = viminfo_filename(file); /* may set to default if NULL */ | |
1960 if (fname == NULL) | |
1961 return; | |
1962 | |
1963 fp_in = mch_fopen((char *)fname, READBIN); | |
1964 if (fp_in == NULL) | |
1965 { | |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1966 int fd; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1967 |
7 | 1968 /* if it does exist, but we can't read it, don't try writing */ |
1969 if (mch_stat((char *)fname, &st_new) == 0) | |
1970 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
|
1971 |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1972 /* 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
|
1973 * 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
|
1974 * 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
|
1975 * 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
|
1976 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
|
1977 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
|
1978 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
|
1979 goto end; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1980 fp_out = fdopen(fd, WRITEBIN); |
7 | 1981 } |
1982 else | |
1983 { | |
1984 /* | |
1985 * There is an existing viminfo file. Create a temporary file to | |
1986 * 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
|
1987 * 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
|
1988 * successful. |
7 | 1989 */ |
1990 #ifdef UNIX | |
1991 /* | |
1992 * For Unix we check the owner of the file. It's not very nice to | |
1993 * overwrite a user's viminfo file after a "su root", with a | |
1994 * viminfo file that the user can't read. | |
1995 */ | |
1869 | 1996 st_old.st_dev = (dev_t)0; |
1438 | 1997 st_old.st_ino = 0; |
7 | 1998 st_old.st_mode = 0600; |
1076 | 1999 if (mch_stat((char *)fname, &st_old) == 0 |
2000 && getuid() != ROOT_UID | |
560 | 2001 && !(st_old.st_uid == getuid() |
7 | 2002 ? (st_old.st_mode & 0200) |
2003 : (st_old.st_gid == getgid() | |
2004 ? (st_old.st_mode & 0020) | |
2005 : (st_old.st_mode & 0002)))) | |
2006 { | |
944 | 2007 int tt = msg_didany; |
7 | 2008 |
2009 /* avoid a wait_return for this message, it's annoying */ | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
2010 semsg(_("E137: Viminfo file is not writable: %s"), fname); |
7 | 2011 msg_didany = tt; |
840 | 2012 fclose(fp_in); |
7 | 2013 goto end; |
2014 } | |
2015 #endif | |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15850
diff
changeset
|
2016 #ifdef MSWIN |
601 | 2017 /* 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
|
2018 hidden = mch_ishidden(fname); |
601 | 2019 #endif |
7 | 2020 |
2021 /* | |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2022 * 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
|
2023 * 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
|
2024 * 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
|
2025 * stat() and open(). Use mch_open() with O_EXCL to avoid that. |
7 | 2026 * May try twice: Once normal and once with shortname set, just in |
2027 * case somebody puts his viminfo file in an 8.3 filesystem. | |
2028 */ | |
2029 for (;;) | |
2030 { | |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2031 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
|
2032 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
|
2033 |
7 | 2034 tempname = buf_modname( |
2035 #ifdef UNIX | |
2036 shortname, | |
2037 #else | |
2038 FALSE, | |
2039 #endif | |
2040 fname, | |
2041 #ifdef VMS | |
2042 (char_u *)"-tmp", | |
2043 #else | |
2044 (char_u *)".tmp", | |
2045 #endif | |
2046 FALSE); | |
2047 if (tempname == NULL) /* out of memory */ | |
2048 break; | |
2049 | |
2050 /* | |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2051 * 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
|
2052 * 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
|
2053 * 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
|
2054 * the same file as the original. |
7 | 2055 */ |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2056 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
|
2057 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
|
2058 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
|
2059 for (;;) |
7 | 2060 { |
2061 /* | |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2062 * 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
|
2063 * existing file! |
7 | 2064 */ |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2065 if (mch_stat((char *)tempname, &st_new) == 0) |
7 | 2066 { |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2067 #ifdef UNIX |
7 | 2068 /* |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2069 * 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
|
2070 * 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
|
2071 * 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
|
2072 * shortname set. |
7 | 2073 */ |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2074 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
|
2075 && st_new.st_ino == st_old.st_ino) |
7 | 2076 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13174
diff
changeset
|
2077 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
|
2078 shortname = TRUE; |
7 | 2079 break; |
2080 } | |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2081 #endif |
7 | 2082 } |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2083 else |
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 /* 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
|
2086 * another Vim tries to do it at the same time. */ |
762 | 2087 #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
|
2088 /* 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
|
2089 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
|
2090 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
|
2091 (void)umask(umask_save); |
762 | 2092 #else |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2093 int fd; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2094 |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2095 /* 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
|
2096 * protection: |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2097 * 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
|
2098 * 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
|
2099 * Others: r&w for user only. */ |
762 | 2100 # 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
|
2101 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
|
2102 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
|
2103 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
|
2104 (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
|
2105 (void)umask(umask_save); |
762 | 2106 # else |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2107 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
|
2108 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
|
2109 # endif |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2110 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
|
2111 { |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2112 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
|
2113 # ifdef EEXIST |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2114 /* Avoid trying lots of names while the problem is lack |
15760
aa80c63f34bb
patch 8.1.0887: the 'l' flag in :subsitute is sticky
Bram Moolenaar <Bram@vim.org>
parents:
15748
diff
changeset
|
2115 * of permission, only retry if the file already |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2116 * exists. */ |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2117 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
|
2118 break; |
762 | 2119 # endif |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2120 } |
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 fp_out = fdopen(fd, WRITEBIN); |
762 | 2123 #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
|
2124 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
|
2125 break; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2126 } |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2127 |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2128 /* 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
|
2129 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
|
2130 { |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2131 /* 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
|
2132 * the viminfo file then. */ |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
2133 semsg(_("E929: Too many viminfo temp files, like %s!"), |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2134 tempname); |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2135 break; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2136 } |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2137 *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
|
2138 --next_char; |
7 | 2139 } |
557 | 2140 |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2141 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
|
2142 break; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2143 /* 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
|
2144 } |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2145 |
557 | 2146 #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
|
2147 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
|
2148 { |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2149 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
|
2150 |
7 | 2151 /* |
12820
63d87ba12c34
patch 8.0.1287: temp file used for viminfo may have wrong permissions
Christian Brabandt <cb@256bit.org>
parents:
12676
diff
changeset
|
2152 * 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
|
2153 * otherwise preserve permissions, making sure the group matches. |
7 | 2154 */ |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2155 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
|
2156 { |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2157 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
|
2158 /* 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
|
2159 * file will now owned by the current user, oh well. */ |
14730
193471015e1a
patch 8.1.0377: xdiff doesn't use the Vim memory allocation functions
Christian Brabandt <cb@256bit.org>
parents:
14585
diff
changeset
|
2160 vim_ignored = fchown(fileno(fp_out), st_old.st_uid, -1); |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2161 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
|
2162 && 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
|
2163 /* 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
|
2164 * 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
|
2165 (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
|
2166 } |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2167 else |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2168 /* 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
|
2169 (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
|
2170 } |
12942
914fbd1d269f
patch 8.0.1347: MS-Windows: build broken by misplaced curly
Christian Brabandt <cb@256bit.org>
parents:
12938
diff
changeset
|
2171 #endif |
914fbd1d269f
patch 8.0.1347: MS-Windows: build broken by misplaced curly
Christian Brabandt <cb@256bit.org>
parents:
12938
diff
changeset
|
2172 } |
7 | 2173 |
2174 /* | |
2175 * Check if the new viminfo file can be written to. | |
2176 */ | |
2177 if (fp_out == NULL) | |
2178 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
2179 semsg(_("E138: Can't write viminfo file %s!"), |
301 | 2180 (fp_in == NULL || tempname == NULL) ? fname : tempname); |
7 | 2181 if (fp_in != NULL) |
2182 fclose(fp_in); | |
2183 goto end; | |
2184 } | |
2185 | |
2186 if (p_verbose > 0) | |
294 | 2187 { |
2188 verbose_enter(); | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
2189 smsg(_("Writing viminfo file \"%s\""), fname); |
294 | 2190 verbose_leave(); |
2191 } | |
7 | 2192 |
2193 viminfo_errcnt = 0; | |
1733 | 2194 do_viminfo(fp_in, fp_out, forceit ? 0 : (VIF_WANT_INFO | VIF_WANT_MARKS)); |
7 | 2195 |
8573
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2196 if (fclose(fp_out) == EOF) |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2197 ++viminfo_errcnt; |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2198 |
7 | 2199 if (fp_in != NULL) |
2200 { | |
2201 fclose(fp_in); | |
601 | 2202 |
6049 | 2203 /* In case of an error keep the original viminfo file. Otherwise |
2204 * 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
|
2205 if (viminfo_errcnt == 0) |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2206 { |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2207 if (vim_rename(tempname, fname) == -1) |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2208 { |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2209 ++viminfo_errcnt; |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
2210 semsg(_("E886: Can't rename viminfo file to %s!"), fname); |
8573
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2211 } |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15850
diff
changeset
|
2212 # ifdef MSWIN |
8573
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2213 /* 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
|
2214 else if (hidden) |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2215 mch_hide(fname); |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2216 # endif |
6049 | 2217 } |
2218 if (viminfo_errcnt > 0) | |
7 | 2219 mch_remove(tempname); |
601 | 2220 } |
2221 | |
7 | 2222 end: |
2223 vim_free(fname); | |
2224 vim_free(tempname); | |
2225 } | |
2226 | |
2227 /* | |
2228 * Get the viminfo file name to use. | |
2229 * If "file" is given and not empty, use it (has already been expanded by | |
2230 * cmdline functions). | |
2231 * Otherwise use "-i file_name", value from 'viminfo' or the default, and | |
2232 * expand environment variables. | |
2233 * Returns an allocated string. NULL when out of memory. | |
2234 */ | |
2235 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2236 viminfo_filename(char_u *file) |
7 | 2237 { |
2238 if (file == NULL || *file == NUL) | |
2239 { | |
11666
5cd9ba96561d
patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents:
11649
diff
changeset
|
2240 if (*p_viminfofile != NUL) |
5cd9ba96561d
patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents:
11649
diff
changeset
|
2241 file = p_viminfofile; |
7 | 2242 else if ((file = find_viminfo_parameter('n')) == NULL || *file == NUL) |
2243 { | |
2244 #ifdef VIMINFO_FILE2 | |
2245 # ifdef VMS | |
2246 if (mch_getenv((char_u *)"SYS$LOGIN") == NULL) | |
2247 # 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
|
2248 # 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
|
2249 /* 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
|
2250 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
|
2251 && 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
|
2252 # else |
7 | 2253 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
|
2254 # endif |
7 | 2255 # endif |
2256 { | |
2257 /* don't use $VIM when not available. */ | |
2258 expand_env((char_u *)"$VIM", NameBuff, MAXPATHL); | |
2259 if (STRCMP("$VIM", NameBuff) != 0) /* $VIM was expanded */ | |
2260 file = (char_u *)VIMINFO_FILE2; | |
2261 else | |
2262 file = (char_u *)VIMINFO_FILE; | |
2263 } | |
2264 else | |
2265 #endif | |
2266 file = (char_u *)VIMINFO_FILE; | |
2267 } | |
2268 expand_env(file, NameBuff, MAXPATHL); | |
2269 file = NameBuff; | |
2270 } | |
2271 return vim_strsave(file); | |
2272 } | |
2273 | |
2274 /* | |
2275 * do_viminfo() -- Should only be called from read_viminfo() & write_viminfo(). | |
2276 */ | |
2277 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2278 do_viminfo(FILE *fp_in, FILE *fp_out, int flags) |
7 | 2279 { |
2280 int eof = FALSE; | |
2281 vir_T vir; | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2282 int merge = FALSE; |
9414
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2283 int do_copy_marks = FALSE; |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2284 garray_T buflist; |
7 | 2285 |
2286 if ((vir.vir_line = alloc(LSIZE)) == NULL) | |
2287 return; | |
2288 vir.vir_fd = fp_in; | |
2289 vir.vir_conv.vc_type = CONV_NONE; | |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2290 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
|
2291 vir.vir_version = -1; |
7 | 2292 |
2293 if (fp_in != NULL) | |
2294 { | |
1733 | 2295 if (flags & VIF_WANT_INFO) |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2296 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2297 if (fp_out != NULL) |
9284
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2298 { |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2299 /* 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
|
2300 * 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
|
2301 prepare_viminfo_registers(); |
9284
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2302 prepare_viminfo_marks(); |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2303 } |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2304 |
1733 | 2305 eof = read_viminfo_up_to_marks(&vir, |
2306 flags & VIF_FORCEIT, fp_out != NULL); | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2307 merge = TRUE; |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2308 } |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2309 else if (flags != 0) |
7 | 2310 /* Skip info, find start of marks */ |
2311 while (!(eof = viminfo_readline(&vir)) | |
2312 && vir.vir_line[0] != '>') | |
2313 ; | |
9414
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2314 |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2315 do_copy_marks = (flags & |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2316 (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
|
2317 } |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2318 |
7 | 2319 if (fp_out != NULL) |
2320 { | |
2321 /* Write the info: */ | |
2322 fprintf(fp_out, _("# This viminfo file was generated by Vim %s.\n"), | |
2323 VIM_VERSION_MEDIUM); | |
2545
298d8d6e69be
Avoid warnings from the clang compiler. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2394
diff
changeset
|
2324 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
|
2325 write_viminfo_version(fp_out); |
2545
298d8d6e69be
Avoid warnings from the clang compiler. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2394
diff
changeset
|
2326 fputs(_("# Value of 'encoding' when this file was written\n"), fp_out); |
7 | 2327 fprintf(fp_out, "*encoding=%s\n\n", p_enc); |
2328 write_viminfo_search_pattern(fp_out); | |
2329 write_viminfo_sub_string(fp_out); | |
2330 #ifdef FEAT_CMDHIST | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2331 write_viminfo_history(fp_out, merge); |
7 | 2332 #endif |
2333 write_viminfo_registers(fp_out); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2334 finish_viminfo_registers(); |
7 | 2335 #ifdef FEAT_EVAL |
2336 write_viminfo_varlist(fp_out); | |
2337 #endif | |
2338 write_viminfo_filemarks(fp_out); | |
9284
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2339 finish_viminfo_marks(); |
7 | 2340 write_viminfo_bufferlist(fp_out); |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2341 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
|
2342 |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2343 if (do_copy_marks) |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2344 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
|
2345 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
|
2346 } |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2347 |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2348 if (do_copy_marks) |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2349 { |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2350 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
|
2351 if (fp_out != NULL) |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2352 ga_clear(&buflist); |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2353 } |
7 | 2354 |
2355 vim_free(vir.vir_line); | |
2356 if (vir.vir_conv.vc_type != CONV_NONE) | |
2357 convert_setup(&vir.vir_conv, NULL, NULL); | |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2358 ga_clear_strings(&vir.vir_barlines); |
7 | 2359 } |
2360 | |
2361 /* | |
2362 * read_viminfo_up_to_marks() -- Only called from do_viminfo(). Reads in the | |
2363 * first part of the viminfo file which contains everything but the marks that | |
2364 * are local to a file. Returns TRUE when end-of-file is reached. -- webb | |
2365 */ | |
2366 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2367 read_viminfo_up_to_marks( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2368 vir_T *virp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2369 int forceit, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2370 int writing) |
7 | 2371 { |
2372 int eof; | |
2373 buf_T *buf; | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2374 int got_encoding = FALSE; |
7 | 2375 |
2376 #ifdef FEAT_CMDHIST | |
4285 | 2377 prepare_viminfo_history(forceit ? 9999 : 0, writing); |
7 | 2378 #endif |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2379 |
7 | 2380 eof = viminfo_readline(virp); |
2381 while (!eof && virp->vir_line[0] != '>') | |
2382 { | |
2383 switch (virp->vir_line[0]) | |
2384 { | |
2385 /* Characters reserved for future expansion, ignored now */ | |
2386 case '+': /* "+40 /path/dir file", for running vim without args */ | |
2387 case '^': /* to be defined */ | |
2388 case '<': /* long line - ignored */ | |
2389 /* A comment or empty line. */ | |
2390 case NUL: | |
2391 case '\r': | |
2392 case '\n': | |
2393 case '#': | |
2394 eof = viminfo_readline(virp); | |
2395 break; | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2396 case '|': |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2397 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
|
2398 forceit, writing); |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2399 break; |
7 | 2400 case '*': /* "*encoding=value" */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2401 got_encoding = TRUE; |
7 | 2402 eof = viminfo_encoding(virp); |
2403 break; | |
2404 case '!': /* global variable */ | |
2405 #ifdef FEAT_EVAL | |
2406 eof = read_viminfo_varlist(virp, writing); | |
2407 #else | |
2408 eof = viminfo_readline(virp); | |
2409 #endif | |
2410 break; | |
2411 case '%': /* entry for buffer list */ | |
2412 eof = read_viminfo_bufferlist(virp, writing); | |
2413 break; | |
2414 case '"': | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2415 /* 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
|
2416 * lines. */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2417 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
|
2418 eof = read_viminfo_register(virp, forceit); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2419 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2420 do { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2421 eof = viminfo_readline(virp); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2422 } 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
|
2423 || virp->vir_line[0] == '<')); |
7 | 2424 break; |
2425 case '/': /* Search string */ | |
2426 case '&': /* Substitute search string */ | |
2427 case '~': /* Last search string, followed by '/' or '&' */ | |
2428 eof = read_viminfo_search_pattern(virp, forceit); | |
2429 break; | |
2430 case '$': | |
2431 eof = read_viminfo_sub_string(virp, forceit); | |
2432 break; | |
2433 case ':': | |
2434 case '?': | |
2435 case '=': | |
2436 case '@': | |
2437 #ifdef FEAT_CMDHIST | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2438 /* 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
|
2439 * lines. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2440 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
|
2441 eof = read_viminfo_history(virp, writing); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2442 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2443 #endif |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2444 eof = viminfo_readline(virp); |
7 | 2445 break; |
2446 case '-': | |
2447 case '\'': | |
9297
9c663cda189f
commit https://github.com/vim/vim/commit/a641e1d4da3f9152c489318c06a93fcd1c746637
Christian Brabandt <cb@256bit.org>
parents:
9284
diff
changeset
|
2448 /* 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
|
2449 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
|
2450 eof = read_viminfo_filemark(virp, forceit); |
9c663cda189f
commit https://github.com/vim/vim/commit/a641e1d4da3f9152c489318c06a93fcd1c746637
Christian Brabandt <cb@256bit.org>
parents:
9284
diff
changeset
|
2451 else |
9c663cda189f
commit https://github.com/vim/vim/commit/a641e1d4da3f9152c489318c06a93fcd1c746637
Christian Brabandt <cb@256bit.org>
parents:
9284
diff
changeset
|
2452 eof = viminfo_readline(virp); |
7 | 2453 break; |
2454 default: | |
2455 if (viminfo_error("E575: ", _("Illegal starting char"), | |
2456 virp->vir_line)) | |
2457 eof = TRUE; | |
2458 else | |
2459 eof = viminfo_readline(virp); | |
2460 break; | |
2461 } | |
2462 } | |
2463 | |
2464 #ifdef FEAT_CMDHIST | |
2465 /* Finish reading history items. */ | |
4285 | 2466 if (!writing) |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9248
diff
changeset
|
2467 finish_viminfo_history(virp); |
7 | 2468 #endif |
2469 | |
2470 /* 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
|
2471 FOR_ALL_BUFFERS(buf) |
7 | 2472 fmarks_check_names(buf); |
2473 | |
2474 return eof; | |
2475 } | |
2476 | |
2477 /* | |
2478 * Compare the 'encoding' value in the viminfo file with the current value of | |
2479 * 'encoding'. If different and the 'c' flag is in 'viminfo', setup for | |
2480 * conversion of text with iconv() in viminfo_readstring(). | |
2481 */ | |
2482 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2483 viminfo_encoding(vir_T *virp) |
7 | 2484 { |
2485 char_u *p; | |
2486 int i; | |
2487 | |
2488 if (get_viminfo_parameter('c') != 0) | |
2489 { | |
2490 p = vim_strchr(virp->vir_line, '='); | |
2491 if (p != NULL) | |
2492 { | |
2493 /* remove trailing newline */ | |
2494 ++p; | |
2495 for (i = 0; vim_isprintc(p[i]); ++i) | |
2496 ; | |
2497 p[i] = NUL; | |
2498 | |
2499 convert_setup(&virp->vir_conv, p, p_enc); | |
2500 } | |
2501 } | |
2502 return viminfo_readline(virp); | |
2503 } | |
2504 | |
2505 /* | |
2506 * Read a line from the viminfo file. | |
2507 * Returns TRUE for end-of-file; | |
2508 */ | |
2509 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2510 viminfo_readline(vir_T *virp) |
7 | 2511 { |
2512 return vim_fgets(virp->vir_line, LSIZE, virp->vir_fd); | |
2513 } | |
2514 | |
2515 /* | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2516 * Check string read from viminfo file. |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2517 * Remove '\n' at the end of the line. |
7 | 2518 * - replace CTRL-V CTRL-V with CTRL-V |
2519 * - replace CTRL-V 'n' with '\n' | |
2520 * | |
2521 * Check for a long line as written by viminfo_writestring(). | |
2522 * | |
2523 * Return the string in allocated memory (NULL when out of memory). | |
2524 */ | |
2525 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2526 viminfo_readstring( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2527 vir_T *virp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2528 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
|
2529 int convert UNUSED) /* convert the string */ |
7 | 2530 { |
2531 char_u *retval; | |
2532 char_u *s, *d; | |
2533 long len; | |
2534 | |
2535 if (virp->vir_line[off] == Ctrl_V && vim_isdigit(virp->vir_line[off + 1])) | |
2536 { | |
2537 len = atol((char *)virp->vir_line + off + 1); | |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
2538 retval = alloc(len); |
7 | 2539 if (retval == NULL) |
2540 { | |
2541 /* Line too long? File messed up? Skip next line. */ | |
2542 (void)vim_fgets(virp->vir_line, 10, virp->vir_fd); | |
2543 return NULL; | |
2544 } | |
2545 (void)vim_fgets(retval, (int)len, virp->vir_fd); | |
2546 s = retval + 1; /* Skip the leading '<' */ | |
2547 } | |
2548 else | |
2549 { | |
2550 retval = vim_strsave(virp->vir_line + off); | |
2551 if (retval == NULL) | |
2552 return NULL; | |
2553 s = retval; | |
2554 } | |
2555 | |
2556 /* Change CTRL-V CTRL-V to CTRL-V and CTRL-V n to \n in-place. */ | |
2557 d = retval; | |
2558 while (*s != NUL && *s != '\n') | |
2559 { | |
2560 if (s[0] == Ctrl_V && s[1] != NUL) | |
2561 { | |
2562 if (s[1] == 'n') | |
2563 *d++ = '\n'; | |
2564 else | |
2565 *d++ = Ctrl_V; | |
2566 s += 2; | |
2567 } | |
2568 else | |
2569 *d++ = *s++; | |
2570 } | |
2571 *d = NUL; | |
2572 | |
2573 if (convert && virp->vir_conv.vc_type != CONV_NONE && *retval != NUL) | |
2574 { | |
2575 d = string_convert(&virp->vir_conv, retval, NULL); | |
2576 if (d != NULL) | |
2577 { | |
2578 vim_free(retval); | |
2579 retval = d; | |
2580 } | |
2581 } | |
2582 | |
2583 return retval; | |
2584 } | |
2585 | |
2586 /* | |
2587 * write string to viminfo file | |
2588 * - replace CTRL-V with CTRL-V CTRL-V | |
2589 * - replace '\n' with CTRL-V 'n' | |
2590 * - add a '\n' at the end | |
2591 * | |
2592 * For a long line: | |
2593 * - write " CTRL-V <length> \n " in first line | |
2594 * - write " < <string> \n " in second line | |
2595 */ | |
2596 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2597 viminfo_writestring(FILE *fd, char_u *p) |
7 | 2598 { |
2599 int c; | |
2600 char_u *s; | |
2601 int len = 0; | |
2602 | |
2603 for (s = p; *s != NUL; ++s) | |
2604 { | |
2605 if (*s == Ctrl_V || *s == '\n') | |
2606 ++len; | |
2607 ++len; | |
2608 } | |
2609 | |
2610 /* If the string will be too long, write its length and put it in the next | |
2611 * line. Take into account that some room is needed for what comes before | |
2612 * the string (e.g., variable name). Add something to the length for the | |
2613 * '<', NL and trailing NUL. */ | |
2614 if (len > LSIZE / 2) | |
2615 fprintf(fd, IF_EB("\026%d\n<", CTRL_V_STR "%d\n<"), len + 3); | |
2616 | |
2617 while ((c = *p++) != NUL) | |
2618 { | |
2619 if (c == Ctrl_V || c == '\n') | |
2620 { | |
2621 putc(Ctrl_V, fd); | |
2622 if (c == '\n') | |
2623 c = 'n'; | |
2624 } | |
2625 putc(c, fd); | |
2626 } | |
2627 putc('\n', fd); | |
2628 } | |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2629 |
9240
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 * 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
|
2632 * 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
|
2633 * Returns remaining characters in the line. |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2634 */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2635 int |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2636 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
|
2637 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2638 char_u *p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2639 int remaining = remaining_start; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2640 int len = 2; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2641 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2642 /* 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
|
2643 for (p = s; *p != NUL; ++p) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2644 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2645 if (*p == NL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2646 len += 2; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2647 else if (*p == '"' || *p == '\\') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2648 len += 2; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2649 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2650 ++len; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2651 } |
9978
baad324e9fbc
commit https://github.com/vim/vim/commit/257095760732597983bdd026e791907b7980e295
Christian Brabandt <cb@256bit.org>
parents:
9959
diff
changeset
|
2652 if (len > remaining - 2) |
9240
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 fprintf(fd, ">%d\n|<", len); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2655 remaining = LSIZE - 20; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2656 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2657 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2658 putc('"', fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2659 for (p = s; *p != NUL; ++p) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2660 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2661 if (*p == NL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2662 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2663 putc('\\', fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2664 putc('n', fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2665 --remaining; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2666 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2667 else if (*p == '"' || *p == '\\') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2668 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2669 putc('\\', fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2670 putc(*p, fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2671 --remaining; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2672 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2673 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2674 putc(*p, fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2675 --remaining; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2676 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2677 if (remaining < 3) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2678 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2679 putc('\n', fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2680 putc('|', fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2681 putc('<', fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2682 /* Leave enough space for another continuation. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2683 remaining = LSIZE - 20; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2684 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2685 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2686 putc('"', fd); |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2687 return remaining - 2; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2688 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2689 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2690 /* |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2691 * 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
|
2692 * 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
|
2693 * 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
|
2694 */ |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2695 static int |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2696 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
|
2697 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2698 char_u *p = text; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2699 char_u *nextp = NULL; |
9244
931bbf7b6ee3
commit https://github.com/vim/vim/commit/fdd82fe365d0e287bafc71f98c039cb5af8ed827
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
2700 char_u *buf = NULL; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2701 bval_T *value; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2702 int i; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2703 int allocated = FALSE; |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2704 int eof; |
9268
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2705 char_u *sconv; |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2706 int converted; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2707 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2708 while (*p == ',') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2709 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2710 ++p; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2711 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
|
2712 break; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2713 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
|
2714 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2715 if (*p == '>') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2716 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2717 /* 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
|
2718 * 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
|
2719 if (!allocated) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2720 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2721 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
|
2722 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2723 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
|
2724 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2725 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
|
2726 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2727 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
|
2728 vp->bv_allocated = TRUE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2729 } |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2730 } |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2731 allocated = TRUE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2732 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2733 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2734 if (vim_isdigit(p[1])) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2735 { |
9248
9c751c33dc0f
commit https://github.com/vim/vim/commit/1d5f1d07aedb6f149f5de145b1dfd6528a769c93
Christian Brabandt <cb@256bit.org>
parents:
9244
diff
changeset
|
2736 size_t len; |
9c751c33dc0f
commit https://github.com/vim/vim/commit/1d5f1d07aedb6f149f5de145b1dfd6528a769c93
Christian Brabandt <cb@256bit.org>
parents:
9244
diff
changeset
|
2737 size_t todo; |
9c751c33dc0f
commit https://github.com/vim/vim/commit/1d5f1d07aedb6f149f5de145b1dfd6528a769c93
Christian Brabandt <cb@256bit.org>
parents:
9244
diff
changeset
|
2738 size_t n; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2739 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2740 /* 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
|
2741 * than LSIZE: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2742 * |{bartype},>{length of "{text}{text2}"} |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2743 * |<"{text1} |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2744 * |<{text2}",{value} |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2745 * Length includes the quotes. |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2746 */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2747 ++p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2748 len = getdigits(&p); |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
2749 buf = alloc(len + 1); |
9270
79cb08f0d812
commit https://github.com/vim/vim/commit/62f8b4e18014b259bcde4a2845c602b0a44a3714
Christian Brabandt <cb@256bit.org>
parents:
9268
diff
changeset
|
2750 if (buf == NULL) |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2751 return TRUE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2752 p = buf; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2753 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
|
2754 { |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2755 eof = viminfo_readline(virp); |
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2756 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
|
2757 || virp->vir_line[1] != '<') |
9270
79cb08f0d812
commit https://github.com/vim/vim/commit/62f8b4e18014b259bcde4a2845c602b0a44a3714
Christian Brabandt <cb@256bit.org>
parents:
9268
diff
changeset
|
2758 { |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2759 /* 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
|
2760 * this one starts with '|'. */ |
9270
79cb08f0d812
commit https://github.com/vim/vim/commit/62f8b4e18014b259bcde4a2845c602b0a44a3714
Christian Brabandt <cb@256bit.org>
parents:
9268
diff
changeset
|
2761 vim_free(buf); |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2762 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
|
2763 } |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2764 /* 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
|
2765 n = STRLEN(virp->vir_line); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2766 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
|
2767 || virp->vir_line[n - 1] == CAR)) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2768 --n; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2769 n -= 2; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2770 if (n > todo) |
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 /* more values follow after the string */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2773 nextp = virp->vir_line + 2 + todo; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2774 n = todo; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2775 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2776 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
|
2777 p += n; |
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 *p = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2780 p = buf; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2781 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2782 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2783 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2784 /* 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
|
2785 * |{bartype},{lots of values},> |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2786 * |<{value},{value} |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2787 */ |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2788 eof = viminfo_readline(virp); |
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2789 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
|
2790 || virp->vir_line[1] != '<') |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2791 /* 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
|
2792 * this one starts with '|'. */ |
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2793 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
|
2794 p = virp->vir_line + 2; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2795 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2796 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2797 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2798 if (isdigit(*p)) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2799 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2800 value->bv_type = BVAL_NR; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2801 value->bv_nr = getdigits(&p); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2802 ++values->ga_len; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2803 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2804 else if (*p == '"') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2805 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2806 int len = 0; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2807 char_u *s = p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2808 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2809 /* Unescape special characters in-place. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2810 ++p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2811 while (*p != '"') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2812 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2813 if (*p == NL || *p == NUL) |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2814 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
|
2815 if (*p == '\\') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2816 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2817 ++p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2818 if (*p == 'n') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2819 s[len++] = '\n'; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2820 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2821 s[len++] = *p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2822 ++p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2823 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2824 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2825 s[len++] = *p++; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2826 } |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2827 ++p; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2828 s[len] = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2829 |
9268
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2830 converted = FALSE; |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2831 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
|
2832 { |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2833 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
|
2834 if (sconv != NULL) |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2835 { |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2836 if (s == buf) |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2837 vim_free(s); |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2838 s = sconv; |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2839 buf = s; |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2840 converted = TRUE; |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2841 } |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2842 } |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
2843 |
9268
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2844 /* 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
|
2845 * 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
|
2846 if (s != buf && allocated) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2847 s = vim_strsave(s); |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2848 value->bv_string = s; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2849 value->bv_type = BVAL_STRING; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2850 value->bv_len = len; |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
2851 value->bv_allocated = allocated || converted; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2852 ++values->ga_len; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2853 if (nextp != NULL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2854 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2855 /* values following a long string */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2856 p = nextp; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2857 nextp = NULL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2858 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2859 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2860 else if (*p == ',') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2861 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2862 value->bv_type = BVAL_EMPTY; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2863 ++values->ga_len; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2864 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2865 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2866 break; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2867 } |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2868 return TRUE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2869 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2870 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2871 static int |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2872 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
|
2873 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2874 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
|
2875 int bartype; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2876 garray_T values; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2877 bval_T *vp; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2878 int i; |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2879 int read_next = TRUE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2880 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2881 /* The format is: |{bartype},{value},... |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2882 * For a very long string: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2883 * |{bartype},>{length of "{text}{text2}"} |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2884 * |<{text1} |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2885 * |<{text2},{value} |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2886 * 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
|
2887 * |{bartype},{lots of values},> |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2888 * |<{value},{value} |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2889 */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2890 if (*p == '<') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2891 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2892 /* Continuation line of an unrecognized item. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2893 if (writing) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2894 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
|
2895 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2896 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2897 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2898 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
|
2899 bartype = getdigits(&p); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2900 switch (bartype) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2901 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2902 case BARTYPE_VERSION: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2903 /* 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
|
2904 * 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
|
2905 * doesn't understand the version. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2906 if (!got_encoding) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2907 { |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2908 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
|
2909 vp = (bval_T *)values.ga_data; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2910 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
|
2911 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
|
2912 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2913 break; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2914 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2915 case BARTYPE_HISTORY: |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2916 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
|
2917 handle_viminfo_history(&values, writing); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2918 break; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2919 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2920 case BARTYPE_REGISTER: |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2921 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
|
2922 handle_viminfo_register(&values, force); |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2923 break; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2924 |
9284
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2925 case BARTYPE_MARK: |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2926 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
|
2927 handle_viminfo_mark(&values, force); |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2928 break; |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2929 |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2930 default: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2931 /* copy unrecognized line (for future use) */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2932 if (writing) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2933 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
|
2934 } |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2935 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
|
2936 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2937 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
|
2938 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
|
2939 vim_free(vp->bv_string); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2940 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2941 ga_clear(&values); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2942 } |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2943 |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2944 if (read_next) |
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2945 return viminfo_readline(virp); |
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2946 return FALSE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2947 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2948 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2949 static void |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2950 write_viminfo_version(FILE *fp_out) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2951 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2952 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
|
2953 BARTYPE_VERSION, VIMINFO_VERSION); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2954 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2955 |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2956 static void |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2957 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
|
2958 { |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2959 int i; |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2960 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
|
2961 int seen_useful = FALSE; |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2962 char *line; |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2963 |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2964 if (gap->ga_len > 0) |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2965 { |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2966 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
|
2967 |
9412
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2968 /* 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
|
2969 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
|
2970 { |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2971 line = ((char **)(gap->ga_data))[i]; |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2972 if (seen_useful || line[1] != '<') |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2973 { |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2974 fputs(line, fp_out); |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2975 seen_useful = TRUE; |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2976 } |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2977 } |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2978 } |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2979 } |
7 | 2980 #endif /* FEAT_VIMINFO */ |
2981 | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2982 /* |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2983 * 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
|
2984 * was used. |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2985 */ |
9347
25c562442f8c
commit https://github.com/vim/vim/commit/f4fba6dcd508cb369ffa6916d9cb3fcf3d7ed548
Christian Brabandt <cb@256bit.org>
parents:
9330
diff
changeset
|
2986 time_T |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2987 vim_time(void) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2988 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2989 # ifdef FEAT_EVAL |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2990 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
|
2991 # else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2992 return time(NULL); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2993 # endif |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2994 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2995 |
7 | 2996 /* |
2997 * Implementation of ":fixdel", also used by get_stty(). | |
2998 * <BS> resulting <Del> | |
2999 * ^? ^H | |
3000 * not ^? ^? | |
3001 */ | |
3002 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3003 do_fixdel(exarg_T *eap UNUSED) |
7 | 3004 { |
3005 char_u *p; | |
3006 | |
3007 p = find_termcode((char_u *)"kb"); | |
3008 add_termcode((char_u *)"kD", p != NULL | |
3009 && *p == DEL ? (char_u *)CTRL_H_STR : DEL_STR, FALSE); | |
3010 } | |
3011 | |
3012 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3013 print_line_no_prefix( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3014 linenr_T lnum, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3015 int use_number, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3016 int list) |
7 | 3017 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
3018 char numbuf[30]; |
7 | 3019 |
3020 if (curwin->w_p_nu || use_number) | |
3021 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
3022 vim_snprintf(numbuf, sizeof(numbuf), |
1872 | 3023 "%*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
|
3024 msg_puts_attr(numbuf, HL_ATTR(HLF_N)); /* Highlight line nrs */ |
7 | 3025 } |
169 | 3026 msg_prt_line(ml_get(lnum), list); |
7 | 3027 } |
3028 | |
3029 /* | |
3030 * Print a text line. Also in silent mode ("ex -s"). | |
3031 */ | |
3032 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3033 print_line(linenr_T lnum, int use_number, int list) |
7 | 3034 { |
3035 int save_silent = silent_mode; | |
3036 | |
9980
b222552cf0c4
commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents:
9978
diff
changeset
|
3037 /* apply :filter /pat/ */ |
b222552cf0c4
commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents:
9978
diff
changeset
|
3038 if (message_filtered(ml_get(lnum))) |
b222552cf0c4
commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents:
9978
diff
changeset
|
3039 return; |
b222552cf0c4
commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents:
9978
diff
changeset
|
3040 |
169 | 3041 msg_start(); |
7 | 3042 silent_mode = FALSE; |
169 | 3043 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */ |
3044 print_line_no_prefix(lnum, use_number, list); | |
7 | 3045 if (save_silent) |
3046 { | |
3047 msg_putchar('\n'); | |
3048 cursor_on(); /* msg_start() switches it off */ | |
3049 out_flush(); | |
3050 silent_mode = save_silent; | |
1798 | 3051 } |
3052 info_message = FALSE; | |
7 | 3053 } |
3054 | |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3055 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3056 rename_buffer(char_u *new_fname) |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3057 { |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3058 char_u *fname, *sfname, *xfname; |
4613
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3059 buf_T *buf; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3060 |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3061 buf = curbuf; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3062 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
|
3063 /* buffer changed, don't change name now */ |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3064 if (buf != curbuf) |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3065 return FAIL; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3066 #ifdef FEAT_EVAL |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3067 if (aborting()) /* autocmds may abort script processing */ |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3068 return FAIL; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3069 #endif |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3070 /* |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3071 * 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
|
3072 * 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
|
3073 * name, which will become the alternate file name. |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3074 * 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
|
3075 * name. |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3076 */ |
4613
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3077 fname = curbuf->b_ffname; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3078 sfname = curbuf->b_sfname; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3079 xfname = curbuf->b_fname; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3080 curbuf->b_ffname = NULL; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3081 curbuf->b_sfname = NULL; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3082 if (setfname(curbuf, new_fname, NULL, TRUE) == FAIL) |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3083 { |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3084 curbuf->b_ffname = fname; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3085 curbuf->b_sfname = sfname; |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3086 return FAIL; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3087 } |
4613
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3088 curbuf->b_flags |= BF_NOTEDITED; |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3089 if (xfname != NULL && *xfname != NUL) |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3090 { |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3091 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
|
3092 if (buf != NULL && !cmdmod.keepalt) |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3093 curwin->w_alt_fnum = buf->b_fnum; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3094 } |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3095 vim_free(fname); |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3096 vim_free(sfname); |
4613
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3097 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
|
3098 |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3099 /* 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
|
3100 DO_AUTOCHDIR; |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3101 return OK; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3102 } |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3103 |
7 | 3104 /* |
3105 * ":file[!] [fname]". | |
3106 */ | |
3107 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3108 ex_file(exarg_T *eap) |
7 | 3109 { |
14 | 3110 /* ":0file" removes the file name. Check for illegal uses ":3file", |
3111 * "0file name", etc. */ | |
3112 if (eap->addr_count > 0 | |
3113 && (*eap->arg != NUL | |
3114 || eap->line2 > 0 | |
3115 || eap->addr_count > 1)) | |
3116 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
3117 emsg(_(e_invarg)); |
14 | 3118 return; |
3119 } | |
3120 | |
3121 if (*eap->arg != NUL || eap->addr_count == 1) | |
7 | 3122 { |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3123 if (rename_buffer(eap->arg) == FAIL) |
7 | 3124 return; |
14185
20468fb49f9b
patch 8.1.0110: file name not displayed with ":file"
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
3125 redraw_tabline = TRUE; |
20468fb49f9b
patch 8.1.0110: file name not displayed with ":file"
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
3126 } |
20468fb49f9b
patch 8.1.0110: file name not displayed with ":file"
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
3127 |
20468fb49f9b
patch 8.1.0110: file name not displayed with ":file"
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
3128 // 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
|
3129 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
|
3130 fileinfo(FALSE, FALSE, eap->forceit); |
7 | 3131 } |
3132 | |
3133 /* | |
3134 * ":update". | |
3135 */ | |
3136 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3137 ex_update(exarg_T *eap) |
7 | 3138 { |
3139 if (curbufIsChanged()) | |
3140 (void)do_write(eap); | |
3141 } | |
3142 | |
3143 /* | |
3144 * ":write" and ":saveas". | |
3145 */ | |
3146 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3147 ex_write(exarg_T *eap) |
7 | 3148 { |
16475
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16453
diff
changeset
|
3149 if (eap->cmdidx == CMD_saveas) |
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16453
diff
changeset
|
3150 { |
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16453
diff
changeset
|
3151 // :saveas does not take a range, uses all lines. |
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16453
diff
changeset
|
3152 eap->line1 = 1; |
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16453
diff
changeset
|
3153 eap->line2 = curbuf->b_ml.ml_line_count; |
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16453
diff
changeset
|
3154 } |
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16453
diff
changeset
|
3155 |
7 | 3156 if (eap->usefilter) /* input lines to shell command */ |
3157 do_bang(1, eap, FALSE, TRUE, FALSE); | |
3158 else | |
3159 (void)do_write(eap); | |
3160 } | |
3161 | |
3162 /* | |
3163 * write current buffer to file 'eap->arg' | |
3164 * if 'eap->append' is TRUE, append to the file | |
3165 * | |
3166 * if *eap->arg == NUL write to current file | |
3167 * | |
3168 * return FAIL for failure, OK otherwise | |
3169 */ | |
3170 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3171 do_write(exarg_T *eap) |
7 | 3172 { |
3173 int other; | |
3174 char_u *fname = NULL; /* init to shut up gcc */ | |
3175 char_u *ffname; | |
3176 int retval = FAIL; | |
3177 char_u *free_fname = NULL; | |
3178 #ifdef FEAT_BROWSE | |
3179 char_u *browse_file = NULL; | |
3180 #endif | |
3181 buf_T *alt_buf = NULL; | |
9469
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
3182 int name_was_missing; |
7 | 3183 |
3184 if (not_writing()) /* check 'write' option */ | |
3185 return FAIL; | |
3186 | |
3187 ffname = eap->arg; | |
3188 #ifdef FEAT_BROWSE | |
3189 if (cmdmod.browse) | |
3190 { | |
29 | 3191 browse_file = do_browse(BROWSE_SAVE, (char_u *)_("Save As"), ffname, |
7 | 3192 NULL, NULL, NULL, curbuf); |
3193 if (browse_file == NULL) | |
3194 goto theend; | |
3195 ffname = browse_file; | |
3196 } | |
3197 #endif | |
3198 if (*ffname == NUL) | |
3199 { | |
3200 if (eap->cmdidx == CMD_saveas) | |
3201 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
3202 emsg(_(e_argreq)); |
7 | 3203 goto theend; |
3204 } | |
3205 other = FALSE; | |
3206 } | |
3207 else | |
3208 { | |
3209 fname = ffname; | |
3210 free_fname = fix_fname(ffname); | |
3211 /* | |
3212 * When out-of-memory, keep unexpanded file name, because we MUST be | |
3213 * able to write the file in this situation. | |
3214 */ | |
3215 if (free_fname != NULL) | |
3216 ffname = free_fname; | |
3217 other = otherfile(ffname); | |
3218 } | |
3219 | |
3220 /* | |
3221 * If we have a new file, put its name in the list of alternate file names. | |
3222 */ | |
3223 if (other) | |
3224 { | |
3225 if (vim_strchr(p_cpo, CPO_ALTWRITE) != NULL | |
3226 || eap->cmdidx == CMD_saveas) | |
3227 alt_buf = setaltfname(ffname, fname, (linenr_T)1); | |
3228 else | |
3229 alt_buf = buflist_findname(ffname); | |
3230 if (alt_buf != NULL && alt_buf->b_ml.ml_mfp != NULL) | |
3231 { | |
3232 /* Overwriting a file that is loaded in another buffer is not a | |
3233 * good idea. */ | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
3234 emsg(_(e_bufloaded)); |
7 | 3235 goto theend; |
3236 } | |
3237 } | |
3238 | |
3239 /* | |
3240 * Writing to the current file is not allowed in readonly mode | |
3241 * and a file name is required. | |
3242 * "nofile" and "nowrite" buffers cannot be written implicitly either. | |
3243 */ | |
3244 if (!other && ( | |
3245 #ifdef FEAT_QUICKFIX | |
3246 bt_dontwrite_msg(curbuf) || | |
3247 #endif | |
3248 check_fname() == FAIL || check_readonly(&eap->forceit, curbuf))) | |
3249 goto theend; | |
3250 | |
3251 if (!other) | |
3252 { | |
3253 ffname = curbuf->b_ffname; | |
3254 fname = curbuf->b_fname; | |
3255 /* | |
3256 * Not writing the whole file is only allowed with '!'. | |
3257 */ | |
3258 if ( (eap->line1 != 1 | |
3259 || eap->line2 != curbuf->b_ml.ml_line_count) | |
3260 && !eap->forceit | |
3261 && !eap->append | |
3262 && !p_wa) | |
3263 { | |
3264 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
3265 if (p_confirm || cmdmod.confirm) | |
3266 { | |
3267 if (vim_dialog_yesno(VIM_QUESTION, NULL, | |
3268 (char_u *)_("Write partial file?"), 2) != VIM_YES) | |
3269 goto theend; | |
3270 eap->forceit = TRUE; | |
3271 } | |
3272 else | |
3273 #endif | |
3274 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
3275 emsg(_("E140: Use ! to write partial buffer")); |
7 | 3276 goto theend; |
3277 } | |
3278 } | |
3279 } | |
3280 | |
3281 if (check_overwrite(eap, curbuf, fname, ffname, other) == OK) | |
3282 { | |
3283 if (eap->cmdidx == CMD_saveas && alt_buf != NULL) | |
3284 { | |
3285 buf_T *was_curbuf = curbuf; | |
3286 | |
3287 apply_autocmds(EVENT_BUFFILEPRE, NULL, NULL, FALSE, curbuf); | |
21 | 3288 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
|
3289 #ifdef FEAT_EVAL |
7 | 3290 if (curbuf != was_curbuf || aborting()) |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3291 #else |
7 | 3292 if (curbuf != was_curbuf) |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3293 #endif |
7 | 3294 { |
3295 /* buffer changed, don't change name now */ | |
3296 retval = FAIL; | |
3297 goto theend; | |
3298 } | |
3299 /* Exchange the file names for the current and the alternate | |
3300 * buffer. This makes it look like we are now editing the buffer | |
3301 * under the new name. Must be done before buf_write(), because | |
3302 * if there is no file name and 'cpo' contains 'F', it will set | |
3303 * the file name. */ | |
3304 fname = alt_buf->b_fname; | |
3305 alt_buf->b_fname = curbuf->b_fname; | |
3306 curbuf->b_fname = fname; | |
3307 fname = alt_buf->b_ffname; | |
3308 alt_buf->b_ffname = curbuf->b_ffname; | |
3309 curbuf->b_ffname = fname; | |
3310 fname = alt_buf->b_sfname; | |
3311 alt_buf->b_sfname = curbuf->b_sfname; | |
3312 curbuf->b_sfname = fname; | |
3313 buf_name_changed(curbuf); | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3314 |
7 | 3315 apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, curbuf); |
21 | 3316 apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, alt_buf); |
7 | 3317 if (!alt_buf->b_p_bl) |
3318 { | |
3319 alt_buf->b_p_bl = TRUE; | |
3320 apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, alt_buf); | |
3321 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3322 #ifdef FEAT_EVAL |
7 | 3323 if (curbuf != was_curbuf || aborting()) |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3324 #else |
7 | 3325 if (curbuf != was_curbuf) |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3326 #endif |
7 | 3327 { |
3328 /* buffer changed, don't write the file */ | |
3329 retval = FAIL; | |
3330 goto theend; | |
3331 } | |
634 | 3332 |
3333 /* If 'filetype' was empty try detecting it now. */ | |
3334 if (*curbuf->b_p_ft == NUL) | |
3335 { | |
819 | 3336 if (au_has_group((char_u *)"filetypedetect")) |
3337 (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
|
3338 TRUE, NULL); |
717 | 3339 do_modelines(0); |
634 | 3340 } |
2648 | 3341 |
3342 /* Autocommands may have changed buffer names, esp. when | |
3343 * 'autochdir' is set. */ | |
3344 fname = curbuf->b_sfname; | |
7 | 3345 } |
3346 | |
9469
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
3347 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
|
3348 |
7 | 3349 retval = buf_write(curbuf, ffname, fname, eap->line1, eap->line2, |
3350 eap, eap->append, eap->forceit, TRUE, FALSE); | |
634 | 3351 |
819 | 3352 /* After ":saveas fname" reset 'readonly'. */ |
961 | 3353 if (eap->cmdidx == CMD_saveas) |
3354 { | |
3355 if (retval == OK) | |
1806 | 3356 { |
961 | 3357 curbuf->b_p_ro = FALSE; |
1806 | 3358 redraw_tabline = TRUE; |
3359 } | |
9469
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
3360 } |
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
3361 |
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
3362 /* 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
|
3363 * got changed or set. */ |
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
3364 if (eap->cmdidx == CMD_saveas || name_was_missing) |
13632
cec5137d5332
patch 8.0.1688: some macros are used without a semicolon
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
3365 DO_AUTOCHDIR; |
7 | 3366 } |
3367 | |
3368 theend: | |
3369 #ifdef FEAT_BROWSE | |
3370 vim_free(browse_file); | |
3371 #endif | |
3372 vim_free(free_fname); | |
3373 return retval; | |
3374 } | |
3375 | |
3376 /* | |
3377 * Check if it is allowed to overwrite a file. If b_flags has BF_NOTEDITED, | |
3378 * BF_NEW or BF_READERR, check for overwriting current file. | |
3379 * May set eap->forceit if a dialog says it's OK to overwrite. | |
3380 * Return OK if it's OK, FAIL if it is not. | |
3381 */ | |
3486 | 3382 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3383 check_overwrite( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3384 exarg_T *eap, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3385 buf_T *buf, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3386 char_u *fname, /* file name to be used (can differ from |
7 | 3387 buf->ffname) */ |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3388 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
|
3389 int other) /* writing under other name */ |
7 | 3390 { |
3391 /* | |
3392 * write to other file or b_flags set or not writing the whole file: | |
3393 * overwriting only allowed with '!' | |
3394 */ | |
3395 if ( (other | |
3396 || (buf->b_flags & BF_NOTEDITED) | |
3397 || ((buf->b_flags & BF_NEW) | |
3398 && vim_strchr(p_cpo, CPO_OVERNEW) == NULL) | |
3399 || (buf->b_flags & BF_READERR)) | |
3400 && !p_wa | |
1457 | 3401 #ifdef FEAT_QUICKFIX |
3402 && !bt_nofile(buf) | |
3403 #endif | |
7 | 3404 && vim_fexists(ffname)) |
3405 { | |
460 | 3406 if (!eap->forceit && !eap->append) |
7 | 3407 { |
460 | 3408 #ifdef UNIX |
637 | 3409 /* with UNIX it is possible to open a directory */ |
460 | 3410 if (mch_isdir(ffname)) |
3411 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
3412 semsg(_(e_isadir2), ffname); |
460 | 3413 return FAIL; |
3414 } | |
7 | 3415 #endif |
3416 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
460 | 3417 if (p_confirm || cmdmod.confirm) |
3418 { | |
2770 | 3419 char_u buff[DIALOG_MSG_SIZE]; |
460 | 3420 |
3421 dialog_msg(buff, _("Overwrite existing file \"%s\"?"), fname); | |
3422 if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) != VIM_YES) | |
3423 return FAIL; | |
3424 eap->forceit = TRUE; | |
3425 } | |
3426 else | |
3427 #endif | |
3428 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
3429 emsg(_(e_exists)); |
7 | 3430 return FAIL; |
460 | 3431 } |
7 | 3432 } |
460 | 3433 |
3434 /* For ":w! filename" check that no swap file exists for "filename". */ | |
3435 if (other && !emsg_silent) | |
7 | 3436 { |
2770 | 3437 char_u *dir; |
460 | 3438 char_u *p; |
3439 int r; | |
3440 char_u *swapname; | |
3441 | |
3442 /* We only try the first entry in 'directory', without checking if | |
3443 * it's writable. If the "." directory is not writable the write | |
3444 * will probably fail anyway. | |
3445 * Use 'shortname' of the current buffer, since there is no buffer | |
3446 * for the written file. */ | |
3447 if (*p_dir == NUL) | |
2770 | 3448 { |
3449 dir = alloc(5); | |
3450 if (dir == NULL) | |
3451 return FAIL; | |
460 | 3452 STRCPY(dir, "."); |
2770 | 3453 } |
460 | 3454 else |
3455 { | |
2770 | 3456 dir = alloc(MAXPATHL); |
3457 if (dir == NULL) | |
3458 return FAIL; | |
460 | 3459 p = p_dir; |
3460 copy_option_part(&p, dir, MAXPATHL, ","); | |
3461 } | |
3462 swapname = makeswapname(fname, ffname, curbuf, dir); | |
2770 | 3463 vim_free(dir); |
460 | 3464 r = vim_fexists(swapname); |
3465 if (r) | |
3466 { | |
3467 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
3468 if (p_confirm || cmdmod.confirm) | |
3469 { | |
2770 | 3470 char_u buff[DIALOG_MSG_SIZE]; |
460 | 3471 |
3472 dialog_msg(buff, | |
3473 _("Swap file \"%s\" exists, overwrite anyway?"), | |
3474 swapname); | |
3475 if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) | |
3476 != VIM_YES) | |
819 | 3477 { |
3478 vim_free(swapname); | |
460 | 3479 return FAIL; |
819 | 3480 } |
460 | 3481 eap->forceit = TRUE; |
3482 } | |
3483 else | |
3484 #endif | |
3485 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
3486 semsg(_("E768: Swap file exists: %s (:silent! overrides)"), |
460 | 3487 swapname); |
819 | 3488 vim_free(swapname); |
460 | 3489 return FAIL; |
3490 } | |
3491 } | |
819 | 3492 vim_free(swapname); |
7 | 3493 } |
3494 } | |
3495 return OK; | |
3496 } | |
3497 | |
3498 /* | |
3499 * Handle ":wnext", ":wNext" and ":wprevious" commands. | |
3500 */ | |
3501 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3502 ex_wnext(exarg_T *eap) |
7 | 3503 { |
3504 int i; | |
3505 | |
3506 if (eap->cmd[1] == 'n') | |
3507 i = curwin->w_arg_idx + (int)eap->line2; | |
3508 else | |
3509 i = curwin->w_arg_idx - (int)eap->line2; | |
3510 eap->line1 = 1; | |
3511 eap->line2 = curbuf->b_ml.ml_line_count; | |
3512 if (do_write(eap) != FAIL) | |
3513 do_argfile(eap, i); | |
3514 } | |
3515 | |
3516 /* | |
3517 * ":wall", ":wqall" and ":xall": Write all changed files (and exit). | |
3518 */ | |
3519 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3520 do_wqall(exarg_T *eap) |
7 | 3521 { |
3522 buf_T *buf; | |
3523 int error = 0; | |
3524 int save_forceit = eap->forceit; | |
3525 | |
3526 if (eap->cmdidx == CMD_xall || eap->cmdidx == CMD_wqall) | |
3527 exiting = TRUE; | |
3528 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
3529 FOR_ALL_BUFFERS(buf) |
7 | 3530 { |
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
|
3531 #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
|
3532 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
|
3533 { |
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
|
3534 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
|
3535 ++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
|
3536 } |
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
|
3537 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
|
3538 #endif |
12648
cdfd6eb8bb80
patch 8.0.1202: :wall gives an errof for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
3539 if (bufIsChanged(buf) && !bt_dontwrite(buf)) |
7 | 3540 { |
3541 /* | |
3542 * Check if there is a reason the buffer cannot be written: | |
3543 * 1. if the 'write' option is set | |
3544 * 2. if there is no file name (even after browsing) | |
3545 * 3. if the 'readonly' is set (even after a dialog) | |
3546 * 4. if overwriting is allowed (even after a dialog) | |
3547 */ | |
3548 if (not_writing()) | |
3549 { | |
3550 ++error; | |
3551 break; | |
3552 } | |
3553 #ifdef FEAT_BROWSE | |
3554 /* ":browse wall": ask for file name if there isn't one */ | |
3555 if (buf->b_ffname == NULL && cmdmod.browse) | |
3556 browse_save_fname(buf); | |
3557 #endif | |
3558 if (buf->b_ffname == NULL) | |
3559 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
3560 semsg(_("E141: No file name for buffer %ld"), (long)buf->b_fnum); |
7 | 3561 ++error; |
3562 } | |
3563 else if (check_readonly(&eap->forceit, buf) | |
3564 || check_overwrite(eap, buf, buf->b_fname, buf->b_ffname, | |
3565 FALSE) == FAIL) | |
3566 { | |
3567 ++error; | |
3568 } | |
3569 else | |
3570 { | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3571 bufref_T bufref; |
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3572 |
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3573 set_bufref(&bufref, buf); |
7 | 3574 if (buf_write_all(buf, eap->forceit) == FAIL) |
3575 ++error; | |
3576 /* 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
|
3577 if (!bufref_valid(&bufref)) |
7 | 3578 buf = firstbuf; |
3579 } | |
3580 eap->forceit = save_forceit; /* check_overwrite() may set it */ | |
3581 } | |
3582 } | |
3583 if (exiting) | |
3584 { | |
3585 if (!error) | |
3586 getout(0); /* exit Vim */ | |
3587 not_exiting(); | |
3588 } | |
3589 } | |
3590 | |
3591 /* | |
3592 * Check the 'write' option. | |
3593 * Return TRUE and give a message when it's not st. | |
3594 */ | |
3595 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3596 not_writing(void) |
7 | 3597 { |
3598 if (p_write) | |
3599 return FALSE; | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
3600 emsg(_("E142: File not written: Writing is disabled by 'write' option")); |
7 | 3601 return TRUE; |
3602 } | |
3603 | |
3604 /* | |
1303 | 3605 * Check if a buffer is read-only (either 'readonly' option is set or file is |
3606 * read-only). Ask for overruling in a dialog. Return TRUE and give an error | |
3607 * message when the buffer is readonly. | |
7 | 3608 */ |
3609 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3610 check_readonly(int *forceit, buf_T *buf) |
7 | 3611 { |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9377
diff
changeset
|
3612 stat_T st; |
1303 | 3613 |
3614 /* Handle a file being readonly when the 'readonly' option is set or when | |
3615 * the file exists and permissions are read-only. | |
3616 * We will send 0777 to check_file_readonly(), as the "perm" variable is | |
3617 * important for device checks but not here. */ | |
3618 if (!*forceit && (buf->b_p_ro | |
3619 || (mch_stat((char *)buf->b_ffname, &st) >= 0 | |
3620 && check_file_readonly(buf->b_ffname, 0777)))) | |
7 | 3621 { |
3622 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
3623 if ((p_confirm || cmdmod.confirm) && buf->b_fname != NULL) | |
3624 { | |
2770 | 3625 char_u buff[DIALOG_MSG_SIZE]; |
7 | 3626 |
1303 | 3627 if (buf->b_p_ro) |
3628 dialog_msg(buff, _("'readonly' option is set for \"%s\".\nDo you wish to write anyway?"), | |
3629 buf->b_fname); | |
3630 else | |
3631 dialog_msg(buff, _("File permissions of \"%s\" are read-only.\nIt may still be possible to write it.\nDo you wish to try?"), | |
7 | 3632 buf->b_fname); |
3633 | |
3634 if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) == VIM_YES) | |
3635 { | |
3636 /* Set forceit, to force the writing of a readonly file */ | |
3637 *forceit = TRUE; | |
3638 return FALSE; | |
3639 } | |
3640 else | |
3641 return TRUE; | |
3642 } | |
3643 else | |
3644 #endif | |
1303 | 3645 if (buf->b_p_ro) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
3646 emsg(_(e_readonly)); |
1303 | 3647 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
3648 semsg(_("E505: \"%s\" is read-only (add ! to override)"), |
1303 | 3649 buf->b_fname); |
7 | 3650 return TRUE; |
3651 } | |
1303 | 3652 |
7 | 3653 return FALSE; |
3654 } | |
3655 | |
3656 /* | |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14913
diff
changeset
|
3657 * Try to abandon the current file and edit a new or existing file. |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14913
diff
changeset
|
3658 * "fnum" is the number of the file, if zero use "ffname_arg"/"sfname_arg". |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3659 * "lnum" is the line number for the cursor in the new file (if non-zero). |
7 | 3660 * |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3661 * Return: |
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3662 * GETFILE_ERROR for "normal" error, |
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3663 * 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
|
3664 * GETFILE_SAME_FILE for success |
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3665 * GETFILE_OPEN_OTHER for successfully opening another file. |
7 | 3666 */ |
3667 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3668 getfile( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3669 int fnum, |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14913
diff
changeset
|
3670 char_u *ffname_arg, |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14913
diff
changeset
|
3671 char_u *sfname_arg, |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3672 int setpm, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3673 linenr_T lnum, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3674 int forceit) |
7 | 3675 { |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14913
diff
changeset
|
3676 char_u *ffname = ffname_arg; |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14913
diff
changeset
|
3677 char_u *sfname = sfname_arg; |
7 | 3678 int other; |
3679 int retval; | |
3680 char_u *free_me = NULL; | |
3681 | |
634 | 3682 if (text_locked()) |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3683 return GETFILE_ERROR; |
819 | 3684 if (curbuf_locked()) |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3685 return GETFILE_ERROR; |
7 | 3686 |
3687 if (fnum == 0) | |
3688 { | |
3689 /* make ffname full path, set sfname */ | |
3690 fname_expand(curbuf, &ffname, &sfname); | |
3691 other = otherfile(ffname); | |
3692 free_me = ffname; /* has been allocated, free() later */ | |
3693 } | |
3694 else | |
3695 other = (fnum != curbuf->b_fnum); | |
3696 | |
3697 if (other) | |
3698 ++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
|
3699 if (other && !forceit && curbuf->b_nwindows == 1 && !buf_hide(curbuf) |
7 | 3700 && curbufIsChanged() && autowrite(curbuf, forceit) == FAIL) |
3701 { | |
3702 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
3703 if (p_confirm && p_write) | |
3704 dialog_changed(curbuf, FALSE); | |
3705 if (curbufIsChanged()) | |
3706 #endif | |
3707 { | |
3708 if (other) | |
3709 --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
|
3710 no_write_message(); |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3711 retval = GETFILE_NOT_WRITTEN; /* file has been changed */ |
7 | 3712 goto theend; |
3713 } | |
3714 } | |
3715 if (other) | |
3716 --no_wait_return; | |
3717 if (setpm) | |
3718 setpcmark(); | |
3719 if (!other) | |
3720 { | |
3721 if (lnum != 0) | |
3722 curwin->w_cursor.lnum = lnum; | |
3723 check_cursor_lnum(); | |
3724 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
|
3725 retval = GETFILE_SAME_FILE; /* it's in the same file */ |
7 | 3726 } |
3727 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
|
3728 (buf_hide(curbuf) ? ECMD_HIDE : 0) + (forceit ? ECMD_FORCEIT : 0), |
1743 | 3729 curwin) == OK) |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3730 retval = GETFILE_OPEN_OTHER; /* opened another file */ |
7 | 3731 else |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3732 retval = GETFILE_ERROR; /* error encountered */ |
7 | 3733 |
3734 theend: | |
3735 vim_free(free_me); | |
3736 return retval; | |
3737 } | |
3738 | |
3739 /* | |
3740 * start editing a new file | |
3741 * | |
3742 * fnum: file number; if zero use ffname/sfname | |
3743 * ffname: the file name | |
3744 * - full path if sfname used, | |
3745 * - any file name if sfname is NULL | |
3746 * - empty string to re-edit with the same file name (but may be | |
3747 * in a different directory) | |
3748 * - NULL to start an empty buffer | |
3749 * sfname: the short file name (or NULL) | |
3750 * eap: contains the command to be executed after loading the file and | |
3751 * forced 'ff' and 'fenc' | |
3752 * newlnum: if > 0: put cursor on this line number (if possible) | |
3753 * if ECMD_LASTL: use last position in loaded file | |
3754 * if ECMD_LAST: use last position in all files | |
3755 * if ECMD_ONE: use first line | |
3756 * flags: | |
3757 * ECMD_HIDE: if TRUE don't free the current buffer | |
3758 * ECMD_SET_HELP: set b_help flag of (new) buffer before opening file | |
3759 * ECMD_OLDBUF: use existing buffer if it exists | |
3760 * ECMD_FORCEIT: ! used for Ex command | |
3761 * ECMD_ADDBUF: don't edit, just add to buffer list | |
1743 | 3762 * 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
|
3763 * 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
|
3764 * of the previous buffer for "oldwin" is stored. |
7 | 3765 * |
3766 * return FAIL for failure, OK otherwise | |
3767 */ | |
3768 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3769 do_ecmd( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3770 int fnum, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3771 char_u *ffname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3772 char_u *sfname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3773 exarg_T *eap, /* can be NULL! */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3774 linenr_T newlnum, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3775 int flags, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3776 win_T *oldwin) |
7 | 3777 { |
3778 int other_file; /* TRUE if editing another file */ | |
3779 int oldbuf; /* TRUE if using existing buffer */ | |
3780 int auto_buf = FALSE; /* TRUE if autocommands brought us | |
3781 into the buffer unexpectedly */ | |
3782 char_u *new_name = NULL; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3783 #if defined(FEAT_EVAL) |
716 | 3784 int did_set_swapcommand = FALSE; |
7 | 3785 #endif |
3786 buf_T *buf; | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3787 bufref_T bufref; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9481
diff
changeset
|
3788 bufref_T old_curbuf; |
7 | 3789 char_u *free_fname = NULL; |
3790 #ifdef FEAT_BROWSE | |
3791 char_u *browse_file = NULL; | |
3792 #endif | |
3793 int retval = FAIL; | |
3794 long n; | |
6702 | 3795 pos_T orig_pos; |
7 | 3796 linenr_T topline = 0; |
3797 int newcol = -1; | |
3798 int solcol = -1; | |
3799 pos_T *pos; | |
3800 char_u *command = NULL; | |
1185 | 3801 #ifdef FEAT_SPELL |
3802 int did_get_winopts = FALSE; | |
3803 #endif | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
3804 int readfile_flags = 0; |
7941
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
3805 int did_inc_redrawing_disabled = FALSE; |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
3806 long *so_ptr = curwin->w_p_so >= 0 ? &curwin->w_p_so : &p_so; |
7 | 3807 |
3808 if (eap != NULL) | |
3809 command = eap->do_ecmd_cmd; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9481
diff
changeset
|
3810 set_bufref(&old_curbuf, curbuf); |
7 | 3811 |
3812 if (fnum != 0) | |
3813 { | |
3814 if (fnum == curbuf->b_fnum) /* file is already being edited */ | |
3815 return OK; /* nothing to do */ | |
3816 other_file = TRUE; | |
3817 } | |
3818 else | |
3819 { | |
3820 #ifdef FEAT_BROWSE | |
3821 if (cmdmod.browse) | |
3822 { | |
462 | 3823 if ( |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3824 # ifdef FEAT_GUI |
462 | 3825 !gui.in_use && |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3826 # endif |
462 | 3827 au_has_group((char_u *)"FileExplorer")) |
3828 { | |
3829 /* No browsing supported but we do have the file explorer: | |
3830 * Edit the directory. */ | |
3831 if (ffname == NULL || !mch_isdir(ffname)) | |
3832 ffname = (char_u *)"."; | |
3833 } | |
3834 else | |
3835 { | |
3836 browse_file = do_browse(0, (char_u *)_("Edit File"), ffname, | |
7 | 3837 NULL, NULL, NULL, curbuf); |
462 | 3838 if (browse_file == NULL) |
3839 goto theend; | |
3840 ffname = browse_file; | |
3841 } | |
7 | 3842 } |
3843 #endif | |
3844 /* if no short name given, use ffname for short name */ | |
3845 if (sfname == NULL) | |
3846 sfname = ffname; | |
3847 #ifdef USE_FNAME_CASE | |
15794
0d8291665b59
patch 8.1.0904: USE_LONG_FNAME never defined
Bram Moolenaar <Bram@vim.org>
parents:
15760
diff
changeset
|
3848 if (sfname != NULL) |
0d8291665b59
patch 8.1.0904: USE_LONG_FNAME never defined
Bram Moolenaar <Bram@vim.org>
parents:
15760
diff
changeset
|
3849 fname_case(sfname, 0); /* set correct case for sfname */ |
7 | 3850 #endif |
3851 | |
3852 if ((flags & ECMD_ADDBUF) && (ffname == NULL || *ffname == NUL)) | |
3853 goto theend; | |
3854 | |
3855 if (ffname == NULL) | |
3856 other_file = TRUE; | |
3857 /* there is no file name */ | |
3858 else if (*ffname == NUL && curbuf->b_ffname == NULL) | |
3859 other_file = FALSE; | |
3860 else | |
3861 { | |
3862 if (*ffname == NUL) /* re-edit with same file name */ | |
3863 { | |
3864 ffname = curbuf->b_ffname; | |
3865 sfname = curbuf->b_fname; | |
3866 } | |
3867 free_fname = fix_fname(ffname); /* may expand to full path name */ | |
3868 if (free_fname != NULL) | |
3869 ffname = free_fname; | |
3870 other_file = otherfile(ffname); | |
3871 } | |
3872 } | |
3873 | |
3874 /* | |
3875 * if the file was changed we may not be allowed to abandon it | |
3876 * - if we are going to re-edit the same file | |
3877 * - or if we are the only window on this file and if ECMD_HIDE is FALSE | |
3878 */ | |
3879 if ( ((!other_file && !(flags & ECMD_OLDBUF)) | |
3880 || (curbuf->b_nwindows == 1 | |
3881 && !(flags & (ECMD_HIDE | ECMD_ADDBUF)))) | |
5464 | 3882 && check_changed(curbuf, (p_awa ? CCGD_AW : 0) |
3883 | (other_file ? 0 : CCGD_MULTWIN) | |
3884 | ((flags & ECMD_FORCEIT) ? CCGD_FORCEIT : 0) | |
3885 | (eap == NULL ? 0 : CCGD_EXCMD))) | |
7 | 3886 { |
3887 if (fnum == 0 && other_file && ffname != NULL) | |
3888 (void)setaltfname(ffname, sfname, newlnum < 0 ? 0 : newlnum); | |
3889 goto theend; | |
3890 } | |
3891 | |
3892 /* | |
3893 * End Visual mode before switching to another buffer, so the text can be | |
3894 * copied into the GUI selection buffer. | |
3895 */ | |
3896 reset_VIsual(); | |
3897 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3898 #if defined(FEAT_EVAL) |
716 | 3899 if ((command != NULL || newlnum > (linenr_T)0) |
3900 && *get_vim_var_str(VV_SWAPCOMMAND) == NUL) | |
3901 { | |
3902 int len; | |
3903 char_u *p; | |
3904 | |
3905 /* Set v:swapcommand for the SwapExists autocommands. */ | |
3906 if (command != NULL) | |
835 | 3907 len = (int)STRLEN(command) + 3; |
716 | 3908 else |
3909 len = 30; | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
3910 p = alloc(len); |
716 | 3911 if (p != NULL) |
3912 { | |
3913 if (command != NULL) | |
3914 vim_snprintf((char *)p, len, ":%s\r", command); | |
3915 else | |
3916 vim_snprintf((char *)p, len, "%ldG", (long)newlnum); | |
3917 set_vim_var_string(VV_SWAPCOMMAND, p, -1); | |
3918 did_set_swapcommand = TRUE; | |
3919 vim_free(p); | |
3920 } | |
3921 } | |
3922 #endif | |
3923 | |
7 | 3924 /* |
3925 * If we are starting to edit another file, open a (new) buffer. | |
3926 * Otherwise we re-use the current buffer. | |
3927 */ | |
3928 if (other_file) | |
3929 { | |
3930 if (!(flags & ECMD_ADDBUF)) | |
3931 { | |
22 | 3932 if (!cmdmod.keepalt) |
3933 curwin->w_alt_fnum = curbuf->b_fnum; | |
1743 | 3934 if (oldwin != NULL) |
3935 buflist_altfpos(oldwin); | |
7 | 3936 } |
3937 | |
3938 if (fnum) | |
3939 buf = buflist_findnr(fnum); | |
3940 else | |
3941 { | |
3942 if (flags & ECMD_ADDBUF) | |
3943 { | |
3944 linenr_T tlnum = 1L; | |
3945 | |
3946 if (command != NULL) | |
3947 { | |
3948 tlnum = atol((char *)command); | |
3949 if (tlnum <= 0) | |
3950 tlnum = 1L; | |
3951 } | |
3952 (void)buflist_new(ffname, sfname, tlnum, BLN_LISTED); | |
3953 goto theend; | |
3954 } | |
3955 buf = buflist_new(ffname, sfname, 0L, | |
3956 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
|
3957 |
5816 | 3958 /* autocommands may change curwin and curbuf */ |
3959 if (oldwin != NULL) | |
3960 oldwin = curwin; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9481
diff
changeset
|
3961 set_bufref(&old_curbuf, curbuf); |
7 | 3962 } |
3963 if (buf == NULL) | |
3964 goto theend; | |
3965 if (buf->b_ml.ml_mfp == NULL) /* no memfile yet */ | |
3966 { | |
3967 oldbuf = FALSE; | |
3968 } | |
3969 else /* existing memfile */ | |
3970 { | |
3971 oldbuf = TRUE; | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3972 set_bufref(&bufref, buf); |
7 | 3973 (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
|
3974 /* 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
|
3975 * current buffer. */ |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3976 if (!bufref_valid(&bufref) || curbuf != old_curbuf.br_buf) |
7 | 3977 goto theend; |
3978 #ifdef FEAT_EVAL | |
3979 if (aborting()) /* autocmds may abort script processing */ | |
3980 goto theend; | |
3981 #endif | |
3982 } | |
3983 | |
3984 /* May jump to last used line number for a loaded buffer or when asked | |
3985 * for explicitly */ | |
3986 if ((oldbuf && newlnum == ECMD_LASTL) || newlnum == ECMD_LAST) | |
3987 { | |
3988 pos = buflist_findfpos(buf); | |
3989 newlnum = pos->lnum; | |
3990 solcol = pos->col; | |
3991 } | |
3992 | |
3993 /* | |
3994 * Make the (new) buffer the one used by the current window. | |
3995 * If the old buffer becomes unused, free it if ECMD_HIDE is FALSE. | |
3996 * If the current buffer was empty and has no file name, curbuf | |
6639 | 3997 * is returned by buflist_new(), nothing to do here. |
7 | 3998 */ |
3999 if (buf != curbuf) | |
4000 { | |
4001 /* | |
4002 * Be careful: The autocommands may delete any buffer and change | |
4003 * the current buffer. | |
4004 * - If the buffer we are going to edit is deleted, give up. | |
4005 * - If the current buffer is deleted, prefer to load the new | |
4006 * buffer when loading a buffer is required. This avoids | |
4007 * loading another buffer which then must be closed again. | |
4008 * - If we ended up in the new buffer already, need to skip a few | |
4009 * things, set auto_buf. | |
4010 */ | |
4011 if (buf->b_fname != NULL) | |
4012 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
|
4013 set_bufref(&au_new_curbuf, buf); |
7 | 4014 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
|
4015 if (!bufref_valid(&au_new_curbuf)) |
7 | 4016 { |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
4017 /* new buffer has been deleted */ |
7 | 4018 delbuf_msg(new_name); /* frees new_name */ |
4019 goto theend; | |
4020 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4021 #ifdef FEAT_EVAL |
7 | 4022 if (aborting()) /* autocmds may abort script processing */ |
4023 { | |
4024 vim_free(new_name); | |
4025 goto theend; | |
4026 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4027 #endif |
7 | 4028 if (buf == curbuf) /* already in new buffer */ |
4029 auto_buf = TRUE; | |
4030 else | |
4031 { | |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4032 win_T *the_curwin = curwin; |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4033 |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4034 /* 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
|
4035 * 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
|
4036 the_curwin->w_closing = TRUE; |
10106
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
4037 ++buf->b_locked; |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4038 |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9481
diff
changeset
|
4039 if (curbuf == old_curbuf.br_buf) |
7 | 4040 buf_copy_options(buf, BCO_ENTER); |
4041 | |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4042 /* 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
|
4043 * oldwin->w_buffer to NULL. */ |
825 | 4044 u_sync(FALSE); |
1743 | 4045 close_buffer(oldwin, curbuf, |
3365 | 4046 (flags & ECMD_HIDE) ? 0 : DOBUF_UNLOAD, FALSE); |
7 | 4047 |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4048 the_curwin->w_closing = FALSE; |
10106
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
4049 --buf->b_locked; |
3242 | 4050 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4051 #ifdef FEAT_EVAL |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4052 /* autocmds may abort script processing */ |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4053 if (aborting() && curwin->w_buffer != NULL) |
7 | 4054 { |
4055 vim_free(new_name); | |
4056 goto theend; | |
4057 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4058 #endif |
7 | 4059 /* Be careful again, like above. */ |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
4060 if (!bufref_valid(&au_new_curbuf)) |
7 | 4061 { |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
4062 /* new buffer has been deleted */ |
7 | 4063 delbuf_msg(new_name); /* frees new_name */ |
4064 goto theend; | |
4065 } | |
4066 if (buf == curbuf) /* already in new buffer */ | |
4067 auto_buf = TRUE; | |
4068 else | |
4069 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
4070 #ifdef FEAT_SYN_HL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
4071 /* |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
4072 * <VN> We could instead free the synblock |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
4073 * and re-attach to buffer, perhaps. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
4074 */ |
11649
0f7888a5ba68
patch 8.0.0707: freeing wrong memory with certain autocommands
Christian Brabandt <cb@256bit.org>
parents:
11589
diff
changeset
|
4075 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
|
4076 || curwin->w_s == &(curwin->w_buffer->b_s)) |
3480 | 4077 curwin->w_s = &(buf->b_s); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
4078 #endif |
7 | 4079 curwin->w_buffer = buf; |
4080 curbuf = buf; | |
4081 ++curbuf->b_nwindows; | |
5231
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
4082 |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
4083 /* Set 'fileformat', 'binary' and 'fenc' when forced. */ |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
4084 if (!oldbuf && eap != NULL) |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
4085 { |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
4086 set_file_options(TRUE, eap); |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
4087 set_forced_fenc(eap); |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
4088 } |
7 | 4089 } |
4090 | |
4091 /* May get the window options from the last time this buffer | |
4092 * was in this window (or another window). If not used | |
4093 * before, reset the local window options to the global | |
4094 * values. Also restores old folding stuff. */ | |
1289 | 4095 get_winopts(curbuf); |
1185 | 4096 #ifdef FEAT_SPELL |
4097 did_get_winopts = TRUE; | |
4098 #endif | |
7 | 4099 } |
4100 vim_free(new_name); | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
4101 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
|
4102 au_new_curbuf.br_buf_free_count = 0; |
7 | 4103 } |
4104 | |
4105 curwin->w_pcmark.lnum = 1; | |
4106 curwin->w_pcmark.col = 0; | |
4107 } | |
4108 else /* !other_file */ | |
4109 { | |
13553
04019fc3de93
patch 8.0.1650: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
4110 if ((flags & ECMD_ADDBUF) || check_fname() == FAIL) |
7 | 4111 goto theend; |
6531 | 4112 |
7 | 4113 oldbuf = (flags & ECMD_OLDBUF); |
4114 } | |
4115 | |
7941
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
4116 /* 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
|
4117 * autocommands may cause ml_get errors. */ |
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
4118 ++RedrawingDisabled; |
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
4119 did_inc_redrawing_disabled = TRUE; |
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
4120 |
6365 | 4121 buf = curbuf; |
7 | 4122 if ((flags & ECMD_SET_HELP) || keep_help_flag) |
4123 { | |
6365 | 4124 prepare_help_buffer(); |
7 | 4125 } |
4126 else | |
4127 { | |
4128 /* Don't make a buffer listed if it's a help buffer. Useful when | |
4129 * using CTRL-O to go back to a help file. */ | |
4130 if (!curbuf->b_help) | |
4131 set_buflisted(TRUE); | |
4132 } | |
4133 | |
4134 /* If autocommands change buffers under our fingers, forget about | |
4135 * editing the file. */ | |
4136 if (buf != curbuf) | |
4137 goto theend; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4138 #ifdef FEAT_EVAL |
7 | 4139 if (aborting()) /* autocmds may abort script processing */ |
4140 goto theend; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4141 #endif |
7 | 4142 |
4143 /* Since we are starting to edit a file, consider the filetype to be | |
4144 * unset. Helps for when an autocommand changes files and expects syntax | |
4145 * highlighting to work in the other file. */ | |
4146 did_filetype = FALSE; | |
4147 | |
4148 /* | |
4149 * other_file oldbuf | |
4150 * FALSE FALSE re-edit same file, buffer is re-used | |
4151 * FALSE TRUE re-edit same file, nothing changes | |
4152 * TRUE FALSE start editing new file, new buffer | |
4153 * TRUE TRUE start editing in existing buffer (nothing to do) | |
4154 */ | |
4155 if (!other_file && !oldbuf) /* re-use the buffer */ | |
4156 { | |
4157 set_last_cursor(curwin); /* may set b_last_cursor */ | |
4158 if (newlnum == ECMD_LAST || newlnum == ECMD_LASTL) | |
4159 { | |
4160 newlnum = curwin->w_cursor.lnum; | |
4161 solcol = curwin->w_cursor.col; | |
4162 } | |
4163 buf = curbuf; | |
4164 if (buf->b_fname != NULL) | |
4165 new_name = vim_strsave(buf->b_fname); | |
4166 else | |
4167 new_name = NULL; | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
4168 set_bufref(&bufref, buf); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4169 |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4170 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
|
4171 { |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4172 /* 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
|
4173 * 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
|
4174 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
|
4175 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
|
4176 == FAIL) |
9705
8c0871098dc9
commit https://github.com/vim/vim/commit/1e2258297bb31720bfbeb234f2dae4d1b3b04fbd
Christian Brabandt <cb@256bit.org>
parents:
9676
diff
changeset
|
4177 { |
8c0871098dc9
commit https://github.com/vim/vim/commit/1e2258297bb31720bfbeb234f2dae4d1b3b04fbd
Christian Brabandt <cb@256bit.org>
parents:
9676
diff
changeset
|
4178 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
|
4179 goto theend; |
9705
8c0871098dc9
commit https://github.com/vim/vim/commit/1e2258297bb31720bfbeb234f2dae4d1b3b04fbd
Christian Brabandt <cb@256bit.org>
parents:
9676
diff
changeset
|
4180 } |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4181 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
|
4182 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
|
4183 |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4184 /* 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
|
4185 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
|
4186 } |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4187 else |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4188 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
|
4189 |
7 | 4190 /* If autocommands deleted the buffer we were going to re-edit, give |
4191 * 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
|
4192 if (!bufref_valid(&bufref)) |
7 | 4193 { |
4194 delbuf_msg(new_name); /* frees new_name */ | |
4195 goto theend; | |
4196 } | |
4197 vim_free(new_name); | |
4198 | |
4199 /* If autocommands change buffers under our fingers, forget about | |
4200 * re-editing the file. Should do the buf_clear_file(), but perhaps | |
4201 * the autocommands changed the buffer... */ | |
4202 if (buf != curbuf) | |
4203 goto theend; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4204 #ifdef FEAT_EVAL |
7 | 4205 if (aborting()) /* autocmds may abort script processing */ |
4206 goto theend; | |
4207 #endif | |
4208 buf_clear_file(curbuf); | |
4209 curbuf->b_op_start.lnum = 0; /* clear '[ and '] marks */ | |
4210 curbuf->b_op_end.lnum = 0; | |
4211 } | |
4212 | |
4213 /* | |
4214 * If we get here we are sure to start editing | |
4215 */ | |
4216 /* Assume success now */ | |
4217 retval = OK; | |
4218 | |
4219 /* | |
4220 * Check if we are editing the w_arg_idx file in the argument list. | |
4221 */ | |
4222 check_arg_idx(curwin); | |
4223 | |
4224 if (!auto_buf) | |
4225 { | |
4226 /* | |
4227 * Set cursor and init window before reading the file and executing | |
4228 * autocommands. This allows for the autocommands to position the | |
4229 * cursor. | |
4230 */ | |
677 | 4231 curwin_init(); |
7 | 4232 |
4233 #ifdef FEAT_FOLDING | |
1370 | 4234 /* It's possible that all lines in the buffer changed. Need to update |
4235 * automatic folding for all windows where it's used. */ | |
4236 { | |
4237 win_T *win; | |
4238 tabpage_T *tp; | |
4239 | |
4240 FOR_ALL_TAB_WINDOWS(tp, win) | |
4241 if (win->w_buffer == curbuf) | |
4242 foldUpdateAll(win); | |
4243 } | |
7 | 4244 #endif |
4245 | |
961 | 4246 /* 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
|
4247 DO_AUTOCHDIR; |
961 | 4248 |
7 | 4249 /* |
4250 * Careful: open_buffer() and apply_autocmds() may change the current | |
4251 * buffer and window. | |
4252 */ | |
6702 | 4253 orig_pos = curwin->w_cursor; |
7 | 4254 topline = curwin->w_topline; |
4255 if (!oldbuf) /* need to read the file */ | |
4256 { | |
4257 swap_exists_action = SEA_DIALOG; | |
4258 curbuf->b_flags |= BF_CHECK_RO; /* set/reset 'ro' flag */ | |
4259 | |
4260 /* | |
4261 * Open the buffer and read the file. | |
4262 */ | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4263 #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
|
4264 if (should_abort(open_buffer(FALSE, eap, readfile_flags))) |
7 | 4265 retval = FAIL; |
4266 #else | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4267 (void)open_buffer(FALSE, eap, readfile_flags); |
7 | 4268 #endif |
4269 | |
4270 if (swap_exists_action == SEA_QUIT) | |
4271 retval = FAIL; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9481
diff
changeset
|
4272 handle_swap_exists(&old_curbuf); |
7 | 4273 } |
4274 else | |
4275 { | |
23 | 4276 /* Read the modelines, but only to set window-local options. Any |
4277 * buffer-local options have already been set and may have been | |
4278 * changed by the user. */ | |
717 | 4279 do_modelines(OPT_WINONLY); |
23 | 4280 |
7 | 4281 apply_autocmds_retval(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf, |
4282 &retval); | |
4283 apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf, | |
4284 &retval); | |
4285 } | |
4286 check_arg_idx(curwin); | |
4287 | |
6702 | 4288 /* 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
|
4289 * 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
|
4290 * 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
|
4291 if (!EQUAL_POS(curwin->w_cursor, orig_pos)) |
7 | 4292 { |
14033
bcda3b864c31
patch 8.1.0034: cursor not restored with ":edit #"
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
4293 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
|
4294 |
bcda3b864c31
patch 8.1.0034: cursor not restored with ":edit #"
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
4295 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
|
4296 || 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
|
4297 { |
bcda3b864c31
patch 8.1.0034: cursor not restored with ":edit #"
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
4298 newlnum = curwin->w_cursor.lnum; |
bcda3b864c31
patch 8.1.0034: cursor not restored with ":edit #"
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
4299 newcol = curwin->w_cursor.col; |
bcda3b864c31
patch 8.1.0034: cursor not restored with ":edit #"
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
4300 } |
7 | 4301 } |
4302 if (curwin->w_topline == topline) | |
4303 topline = 0; | |
4304 | |
4305 /* Even when cursor didn't move we need to recompute topline. */ | |
4306 changed_line_abv_curs(); | |
4307 | |
4308 #ifdef FEAT_TITLE | |
4309 maketitle(); | |
4310 #endif | |
4311 } | |
4312 | |
4313 #ifdef FEAT_DIFF | |
4314 /* Tell the diff stuff that this buffer is new and/or needs updating. | |
4315 * Also needed when re-editing the same buffer, because unloading will | |
4316 * have removed it as a diff buffer. */ | |
673 | 4317 if (curwin->w_p_diff) |
4318 { | |
4319 diff_buf_add(curbuf); | |
4320 diff_invalidate(curbuf); | |
4321 } | |
7 | 4322 #endif |
4323 | |
1185 | 4324 #ifdef FEAT_SPELL |
4325 /* If the window options were changed may need to set the spell language. | |
4326 * 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
|
4327 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
|
4328 (void)did_set_spelllang(curwin); |
1185 | 4329 #endif |
4330 | |
7 | 4331 if (command == NULL) |
4332 { | |
4333 if (newcol >= 0) /* position set by autocommands */ | |
4334 { | |
4335 curwin->w_cursor.lnum = newlnum; | |
4336 curwin->w_cursor.col = newcol; | |
4337 check_cursor(); | |
4338 } | |
4339 else if (newlnum > 0) /* line number from caller or old position */ | |
4340 { | |
4341 curwin->w_cursor.lnum = newlnum; | |
4342 check_cursor_lnum(); | |
4343 if (solcol >= 0 && !p_sol) | |
4344 { | |
4345 /* 'sol' is off: Use last known column. */ | |
4346 curwin->w_cursor.col = solcol; | |
4347 check_cursor_col(); | |
4348 curwin->w_cursor.coladd = 0; | |
4349 curwin->w_set_curswant = TRUE; | |
4350 } | |
4351 else | |
4352 beginline(BL_SOL | BL_FIX); | |
4353 } | |
4354 else /* no line number, go to last line in Ex mode */ | |
4355 { | |
4356 if (exmode_active) | |
4357 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4358 beginline(BL_WHITE | BL_FIX); | |
4359 } | |
4360 } | |
4361 | |
4362 /* Check if cursors in other windows on the same buffer are still valid */ | |
4363 check_lnums(FALSE); | |
4364 | |
4365 /* | |
4366 * Did not read the file, need to show some info about the file. | |
4367 * Do this after setting the cursor. | |
4368 */ | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4369 if (oldbuf && !auto_buf) |
7 | 4370 { |
4371 int msg_scroll_save = msg_scroll; | |
4372 | |
4373 /* Obey the 'O' flag in 'cpoptions': overwrite any previous file | |
4374 * message. */ | |
4375 if (shortmess(SHM_OVERALL) && !exiting && p_verbose == 0) | |
4376 msg_scroll = FALSE; | |
4377 if (!msg_scroll) /* wait a bit when overwriting an error msg */ | |
4378 check_for_delay(FALSE); | |
4379 msg_start(); | |
4380 msg_scroll = msg_scroll_save; | |
4381 msg_scrolled_ign = TRUE; | |
4382 | |
8560
f3c636c673f7
commit https://github.com/vim/vim/commit/426dd0219512af5f4abeb0901b533159253ffba3
Christian Brabandt <cb@256bit.org>
parents:
8556
diff
changeset
|
4383 if (!shortmess(SHM_FILEINFO)) |
f3c636c673f7
commit https://github.com/vim/vim/commit/426dd0219512af5f4abeb0901b533159253ffba3
Christian Brabandt <cb@256bit.org>
parents:
8556
diff
changeset
|
4384 fileinfo(FALSE, TRUE, FALSE); |
7 | 4385 |
4386 msg_scrolled_ign = FALSE; | |
4387 } | |
4388 | |
9414
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
4389 #ifdef FEAT_VIMINFO |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
4390 curbuf->b_last_used = vim_time(); |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
4391 #endif |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
4392 |
7 | 4393 if (command != NULL) |
4394 do_cmdline(command, NULL, NULL, DOCMD_VERBOSE); | |
4395 | |
4396 #ifdef FEAT_KEYMAP | |
4397 if (curbuf->b_kmap_state & KEYMAP_INIT) | |
1869 | 4398 (void)keymap_init(); |
7 | 4399 #endif |
4400 | |
4401 --RedrawingDisabled; | |
7941
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
4402 did_inc_redrawing_disabled = FALSE; |
7 | 4403 if (!skip_redraw) |
4404 { | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
4405 n = *so_ptr; |
7 | 4406 if (topline == 0 && command == NULL) |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
4407 *so_ptr = 9999; // force cursor halfway the window |
7 | 4408 update_topline(); |
4409 curwin->w_scbind_pos = curwin->w_topline; | |
15713
ad8b2c109b22
patch 8.1.0864: cannot have a local value for 'scrolloff' and 'sidescrolloff'
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
4410 *so_ptr = n; |
7 | 4411 redraw_curbuf_later(NOT_VALID); /* redraw this buffer later */ |
4412 } | |
4413 | |
4414 if (p_im) | |
4415 need_start_insertmode = TRUE; | |
4416 | |
13174
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4417 #ifdef FEAT_AUTOCHDIR |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4418 /* 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
|
4419 * 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
|
4420 * 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
|
4421 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
|
4422 { |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4423 char_u curdir[MAXPATHL]; |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4424 char_u filedir[MAXPATHL]; |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4425 |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4426 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
|
4427 *gettail_sep(filedir) = NUL; |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4428 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
|
4429 && vim_fnamecmp(curdir, filedir) != 0) |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4430 do_autochdir(); |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4431 } |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4432 #endif |
821 | 4433 |
15510
41fbbcea0f1b
patch 8.1.0763: nobody is using the Sun Workshop support
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
4434 #if defined(FEAT_NETBEANS_INTG) |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2178
diff
changeset
|
4435 if (curbuf->b_ffname != NULL) |
7 | 4436 { |
4437 # ifdef FEAT_NETBEANS_INTG | |
2210 | 4438 if ((flags & ECMD_SET_HELP) != ECMD_SET_HELP) |
34 | 4439 netbeans_file_opened(curbuf); |
7 | 4440 # endif |
4441 } | |
4442 #endif | |
4443 | |
4444 theend: | |
7941
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
4445 if (did_inc_redrawing_disabled) |
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
4446 --RedrawingDisabled; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4447 #if defined(FEAT_EVAL) |
716 | 4448 if (did_set_swapcommand) |
4449 set_vim_var_string(VV_SWAPCOMMAND, NULL, -1); | |
4450 #endif | |
7 | 4451 #ifdef FEAT_BROWSE |
4452 vim_free(browse_file); | |
4453 #endif | |
4454 vim_free(free_fname); | |
4455 return retval; | |
4456 } | |
4457 | |
4458 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4459 delbuf_msg(char_u *name) |
7 | 4460 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
4461 semsg(_("E143: Autocommands unexpectedly deleted new buffer %s"), |
7 | 4462 name == NULL ? (char_u *)"" : name); |
4463 vim_free(name); | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
4464 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
|
4465 au_new_curbuf.br_buf_free_count = 0; |
7 | 4466 } |
4467 | |
169 | 4468 static int append_indent = 0; /* autoindent for first line */ |
4469 | |
7 | 4470 /* |
4471 * ":insert" and ":append", also used by ":change" | |
4472 */ | |
4473 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4474 ex_append(exarg_T *eap) |
7 | 4475 { |
4476 char_u *theline; | |
4477 int did_undo = FALSE; | |
4478 linenr_T lnum = eap->line2; | |
165 | 4479 int indent = 0; |
4480 char_u *p; | |
4481 int vcol; | |
4482 int empty = (curbuf->b_ml.ml_flags & ML_EMPTY); | |
7 | 4483 |
169 | 4484 /* the ! flag toggles autoindent */ |
4485 if (eap->forceit) | |
4486 curbuf->b_p_ai = !curbuf->b_p_ai; | |
4487 | |
4488 /* First autoindent comes from the line we start on */ | |
4489 if (eap->cmdidx != CMD_change && curbuf->b_p_ai && lnum > 0) | |
4490 append_indent = get_indent_lnum(lnum); | |
4491 | |
7 | 4492 if (eap->cmdidx != CMD_append) |
4493 --lnum; | |
4494 | |
9377
5ec4fbfe38c5
commit https://github.com/vim/vim/commit/70e136e1d86ea1d795774824c7b712245912946d
Christian Brabandt <cb@256bit.org>
parents:
9347
diff
changeset
|
4495 /* when the buffer is empty need to delete the dummy line */ |
165 | 4496 if (empty && lnum == 1) |
4497 lnum = 0; | |
4498 | |
7 | 4499 State = INSERT; /* behave like in Insert mode */ |
4500 if (curbuf->b_p_iminsert == B_IMODE_LMAP) | |
4501 State |= LANGMAP; | |
165 | 4502 |
408 | 4503 for (;;) |
7 | 4504 { |
4505 msg_scroll = TRUE; | |
4506 need_wait_return = FALSE; | |
169 | 4507 if (curbuf->b_p_ai) |
4508 { | |
4509 if (append_indent >= 0) | |
4510 { | |
4511 indent = append_indent; | |
4512 append_indent = -1; | |
4513 } | |
4514 else if (lnum > 0) | |
4515 indent = get_indent_lnum(lnum); | |
4516 } | |
4517 ex_keep_indent = FALSE; | |
7 | 4518 if (eap->getline == NULL) |
169 | 4519 { |
4520 /* No getline() function, use the lines that follow. This ends | |
4521 * when there is no more. */ | |
4522 if (eap->nextcmd == NULL || *eap->nextcmd == NUL) | |
4523 break; | |
4524 p = vim_strchr(eap->nextcmd, NL); | |
4525 if (p == NULL) | |
4526 p = eap->nextcmd + STRLEN(eap->nextcmd); | |
4527 theline = vim_strnsave(eap->nextcmd, (int)(p - eap->nextcmd)); | |
4528 if (*p != NUL) | |
4529 ++p; | |
4530 eap->nextcmd = p; | |
4531 } | |
7 | 4532 else |
6164 | 4533 { |
4534 int save_State = State; | |
4535 | |
4536 /* Set State to avoid the cursor shape to be set to INSERT mode | |
4537 * when getline() returns. */ | |
4538 State = CMDLINE; | |
7 | 4539 theline = eap->getline( |
4540 #ifdef FEAT_EVAL | |
76 | 4541 eap->cstack->cs_looplevel > 0 ? -1 : |
7 | 4542 #endif |
165 | 4543 NUL, eap->cookie, indent); |
6164 | 4544 State = save_State; |
4545 } | |
7 | 4546 lines_left = Rows - 1; |
165 | 4547 if (theline == NULL) |
4548 break; | |
4549 | |
169 | 4550 /* Using ^ CTRL-D in getexmodeline() makes us repeat the indent. */ |
4551 if (ex_keep_indent) | |
4552 append_indent = indent; | |
4553 | |
165 | 4554 /* Look for the "." after automatic indent. */ |
4555 vcol = 0; | |
4556 for (p = theline; indent > vcol; ++p) | |
4557 { | |
4558 if (*p == ' ') | |
4559 ++vcol; | |
4560 else if (*p == TAB) | |
4561 vcol += 8 - vcol % 8; | |
4562 else | |
4563 break; | |
4564 } | |
4565 if ((p[0] == '.' && p[1] == NUL) | |
321 | 4566 || (!did_undo && u_save(lnum, lnum + 1 + (empty ? 1 : 0)) |
4567 == FAIL)) | |
7 | 4568 { |
4569 vim_free(theline); | |
4570 break; | |
4571 } | |
4572 | |
169 | 4573 /* don't use autoindent if nothing was typed. */ |
4574 if (p[0] == NUL) | |
4575 theline[0] = NUL; | |
4576 | |
7 | 4577 did_undo = TRUE; |
4578 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
|
4579 appended_lines_mark(lnum + (empty ? 1 : 0), 1L); |
7 | 4580 |
4581 vim_free(theline); | |
4582 ++lnum; | |
165 | 4583 |
4584 if (empty) | |
4585 { | |
4586 ml_delete(2L, FALSE); | |
4587 empty = FALSE; | |
4588 } | |
7 | 4589 } |
4590 State = NORMAL; | |
4591 | |
169 | 4592 if (eap->forceit) |
4593 curbuf->b_p_ai = !curbuf->b_p_ai; | |
4594 | |
7 | 4595 /* "start" is set to eap->line2+1 unless that position is invalid (when |
1227 | 4596 * eap->line2 pointed to the end of the buffer and nothing was appended) |
7 | 4597 * "end" is set to lnum when something has been appended, otherwise |
4598 * it is the same than "start" -- Acevedo */ | |
4599 curbuf->b_op_start.lnum = (eap->line2 < curbuf->b_ml.ml_line_count) ? | |
4600 eap->line2 + 1 : curbuf->b_ml.ml_line_count; | |
4601 if (eap->cmdidx != CMD_append) | |
4602 --curbuf->b_op_start.lnum; | |
4603 curbuf->b_op_end.lnum = (eap->line2 < lnum) | |
4604 ? lnum : curbuf->b_op_start.lnum; | |
4605 curbuf->b_op_start.col = curbuf->b_op_end.col = 0; | |
4606 curwin->w_cursor.lnum = lnum; | |
4607 check_cursor_lnum(); | |
4608 beginline(BL_SOL | BL_FIX); | |
4609 | |
4610 need_wait_return = FALSE; /* don't use wait_return() now */ | |
4611 ex_no_reprint = TRUE; | |
4612 } | |
4613 | |
4614 /* | |
4615 * ":change" | |
4616 */ | |
4617 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4618 ex_change(exarg_T *eap) |
7 | 4619 { |
4620 linenr_T lnum; | |
4621 | |
4622 if (eap->line2 >= eap->line1 | |
4623 && u_save(eap->line1 - 1, eap->line2 + 1) == FAIL) | |
4624 return; | |
4625 | |
169 | 4626 /* the ! flag toggles autoindent */ |
4627 if (eap->forceit ? !curbuf->b_p_ai : curbuf->b_p_ai) | |
4628 append_indent = get_indent_lnum(eap->line1); | |
4629 | |
7 | 4630 for (lnum = eap->line2; lnum >= eap->line1; --lnum) |
4631 { | |
4632 if (curbuf->b_ml.ml_flags & ML_EMPTY) /* nothing to delete */ | |
4633 break; | |
4634 ml_delete(eap->line1, FALSE); | |
4635 } | |
1929 | 4636 |
4637 /* make sure the cursor is not beyond the end of the file now */ | |
4638 check_cursor_lnum(); | |
7 | 4639 deleted_lines_mark(eap->line1, (long)(eap->line2 - lnum)); |
4640 | |
4641 /* ":append" on the line above the deleted lines. */ | |
4642 eap->line2 = eap->line1; | |
4643 ex_append(eap); | |
4644 } | |
4645 | |
4646 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4647 ex_z(exarg_T *eap) |
7 | 4648 { |
4649 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
|
4650 long bigness; |
165 | 4651 char_u *kind; |
7 | 4652 int minus = 0; |
4653 linenr_T start, end, curs, i; | |
4654 int j; | |
4655 linenr_T lnum = eap->line2; | |
4656 | |
165 | 4657 /* Vi compatible: ":z!" uses display height, without a count uses |
4658 * 'scroll' */ | |
4659 if (eap->forceit) | |
4660 bigness = curwin->w_height; | |
10357
59d01e335858
commit https://github.com/vim/vim/commit/459ca563128f2edb7e3bb190090bbb755a56dd55
Christian Brabandt <cb@256bit.org>
parents:
10299
diff
changeset
|
4661 else if (!ONE_WINDOW) |
5678 | 4662 bigness = curwin->w_height - 3; |
4663 else | |
165 | 4664 bigness = curwin->w_p_scr * 2; |
7 | 4665 if (bigness < 1) |
4666 bigness = 1; | |
4667 | |
4668 x = eap->arg; | |
165 | 4669 kind = x; |
4670 if (*kind == '-' || *kind == '+' || *kind == '=' | |
4671 || *kind == '^' || *kind == '.') | |
4672 ++x; | |
4673 while (*x == '-' || *x == '+') | |
7 | 4674 ++x; |
4675 | |
4676 if (*x != 0) | |
4677 { | |
4678 if (!VIM_ISDIGIT(*x)) | |
4679 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
4680 emsg(_("E144: non-numeric argument to :z")); |
7 | 4681 return; |
4682 } | |
4683 else | |
165 | 4684 { |
11303
ef32a5c74515
patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
11254
diff
changeset
|
4685 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
|
4686 |
ef32a5c74515
patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
11254
diff
changeset
|
4687 /* 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
|
4688 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
|
4689 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
|
4690 |
165 | 4691 p_window = bigness; |
169 | 4692 if (*kind == '=') |
4693 bigness += 2; | |
165 | 4694 } |
7 | 4695 } |
4696 | |
165 | 4697 /* the number of '-' and '+' multiplies the distance */ |
4698 if (*kind == '-' || *kind == '+') | |
4699 for (x = kind + 1; *x == *kind; ++x) | |
4700 ; | |
4701 | |
4702 switch (*kind) | |
7 | 4703 { |
4704 case '-': | |
2881 | 4705 start = lnum - bigness * (linenr_T)(x - kind) + 1; |
4706 end = start + bigness - 1; | |
165 | 4707 curs = end; |
7 | 4708 break; |
4709 | |
4710 case '=': | |
159 | 4711 start = lnum - (bigness + 1) / 2 + 1; |
4712 end = lnum + (bigness + 1) / 2 - 1; | |
7 | 4713 curs = lnum; |
4714 minus = 1; | |
4715 break; | |
4716 | |
4717 case '^': | |
4718 start = lnum - bigness * 2; | |
4719 end = lnum - bigness; | |
4720 curs = lnum - bigness; | |
4721 break; | |
4722 | |
4723 case '.': | |
159 | 4724 start = lnum - (bigness + 1) / 2 + 1; |
4725 end = lnum + (bigness + 1) / 2 - 1; | |
7 | 4726 curs = end; |
4727 break; | |
4728 | |
4729 default: /* '+' */ | |
4730 start = lnum; | |
165 | 4731 if (*kind == '+') |
835 | 4732 start += bigness * (linenr_T)(x - kind - 1) + 1; |
169 | 4733 else if (eap->addr_count == 0) |
4734 ++start; | |
4735 end = start + bigness - 1; | |
7 | 4736 curs = end; |
4737 break; | |
4738 } | |
4739 | |
4740 if (start < 1) | |
4741 start = 1; | |
4742 | |
4743 if (end > curbuf->b_ml.ml_line_count) | |
4744 end = curbuf->b_ml.ml_line_count; | |
4745 | |
4746 if (curs > curbuf->b_ml.ml_line_count) | |
4747 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
|
4748 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
|
4749 curs = 1; |
7 | 4750 |
4751 for (i = start; i <= end; i++) | |
4752 { | |
4753 if (minus && i == lnum) | |
4754 { | |
4755 msg_putchar('\n'); | |
4756 | |
4757 for (j = 1; j < Columns; j++) | |
4758 msg_putchar('-'); | |
4759 } | |
4760 | |
169 | 4761 print_line(i, eap->flags & EXFLAG_NR, eap->flags & EXFLAG_LIST); |
7 | 4762 |
4763 if (minus && i == lnum) | |
4764 { | |
4765 msg_putchar('\n'); | |
4766 | |
4767 for (j = 1; j < Columns; j++) | |
4768 msg_putchar('-'); | |
4769 } | |
4770 } | |
4771 | |
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
|
4772 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
|
4773 { |
1074f58e1673
patch 8.0.0571: negative line number when using :z^ in an empty buffer
Christian Brabandt <cb@256bit.org>
parents:
11303
diff
changeset
|
4774 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
|
4775 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
|
4776 } |
7 | 4777 ex_no_reprint = TRUE; |
4778 } | |
4779 | |
4780 /* | |
4781 * Check if the restricted flag is set. | |
4782 * If so, give an error message and return TRUE. | |
4783 * Otherwise, return FALSE. | |
4784 */ | |
4785 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4786 check_restricted(void) |
7 | 4787 { |
4788 if (restricted) | |
4789 { | |
15748
93b78c4a7cd5
patch 8.1.0881: can execute shell commands in rvim through interfaces
Bram Moolenaar <Bram@vim.org>
parents:
15713
diff
changeset
|
4790 emsg(_("E145: Shell commands and some functionality not allowed in rvim")); |
7 | 4791 return TRUE; |
4792 } | |
4793 return FALSE; | |
4794 } | |
4795 | |
4796 /* | |
4797 * Check if the secure flag is set (.exrc or .vimrc in current directory). | |
4798 * If so, give an error message and return TRUE. | |
4799 * Otherwise, return FALSE. | |
4800 */ | |
4801 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4802 check_secure(void) |
7 | 4803 { |
4804 if (secure) | |
4805 { | |
4806 secure = 2; | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
4807 emsg(_(e_curdir)); |
7 | 4808 return TRUE; |
4809 } | |
4810 #ifdef HAVE_SANDBOX | |
4811 /* | |
4812 * In the sandbox more things are not allowed, including the things | |
4813 * disallowed in secure mode. | |
4814 */ | |
4815 if (sandbox != 0) | |
4816 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
4817 emsg(_(e_sandbox)); |
7 | 4818 return TRUE; |
4819 } | |
4820 #endif | |
4821 return FALSE; | |
4822 } | |
4823 | |
4824 static char_u *old_sub = NULL; /* previous substitute pattern */ | |
4825 static int global_need_beginline; /* call beginline() after ":g" */ | |
4826 | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4827 /* |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4828 * 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
|
4829 */ |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4830 typedef struct { |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4831 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
|
4832 int do_ask; /* ask for confirmation */ |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4833 int do_count; /* count only */ |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4834 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
|
4835 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
|
4836 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
|
4837 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
|
4838 int do_ic; /* ignore case flag */ |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4839 } subflags_T; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4840 |
7 | 4841 /* do_sub() |
4842 * | |
4843 * Perform a substitution from line eap->line1 to line eap->line2 using the | |
4844 * command pointed to by eap->arg which should be of the form: | |
4845 * | |
4846 * /pattern/substitution/{flags} | |
4847 * | |
4848 * The usual escapes are supported as described in the regexp docs. | |
4849 */ | |
4850 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4851 do_sub(exarg_T *eap) |
7 | 4852 { |
4853 linenr_T lnum; | |
4854 long i = 0; | |
4855 regmmatch_T regmatch; | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4856 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
|
4857 FALSE, FALSE, 0}; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4858 #ifdef FEAT_EVAL |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4859 subflags_T subflags_save; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4860 #endif |
6789 | 4861 int save_do_all; /* remember user specified 'g' flag */ |
4862 int save_do_ask; /* remember user specified 'c' flag */ | |
7 | 4863 char_u *pat = NULL, *sub = NULL; /* init for GCC */ |
4864 int delimiter; | |
4865 int sublen; | |
4866 int got_quit = FALSE; | |
4867 int got_match = FALSE; | |
4868 int temp; | |
4869 int which_pat; | |
4870 char_u *cmd; | |
4871 int save_State; | |
165 | 4872 linenr_T first_line = 0; /* first changed line */ |
4873 linenr_T last_line= 0; /* below last changed line AFTER the | |
7 | 4874 * change */ |
4875 linenr_T old_line_count = curbuf->b_ml.ml_line_count; | |
4876 linenr_T line2; | |
165 | 4877 long nmatch; /* number of lines in match */ |
4878 char_u *sub_firstline; /* allocated copy of first sub line */ | |
4879 int endcolumn = FALSE; /* cursor in last column when done */ | |
170 | 4880 pos_T old_cursor = curwin->w_cursor; |
2126
e038754d419a
updated for version 7.2.408
Bram Moolenaar <bram@zimbu.org>
parents:
1929
diff
changeset
|
4881 int start_nsubs; |
3736 | 4882 #ifdef FEAT_EVAL |
5867 | 4883 int save_ma = 0; |
3736 | 4884 #endif |
7 | 4885 |
4886 cmd = eap->arg; | |
4887 if (!global_busy) | |
4888 { | |
4889 sub_nsubs = 0; | |
4890 sub_nlines = 0; | |
4891 } | |
2126
e038754d419a
updated for version 7.2.408
Bram Moolenaar <bram@zimbu.org>
parents:
1929
diff
changeset
|
4892 start_nsubs = sub_nsubs; |
7 | 4893 |
4894 if (eap->cmdidx == CMD_tilde) | |
4895 which_pat = RE_LAST; /* use last used regexp */ | |
4896 else | |
4897 which_pat = RE_SUBST; /* use last substitute regexp */ | |
4898 | |
4899 /* 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
|
4900 if (eap->cmd[0] == 's' && *cmd != NUL && !VIM_ISWHITE(*cmd) |
7 | 4901 && vim_strchr((char_u *)"0123456789cegriIp|\"", *cmd) == NULL) |
4902 { | |
4903 /* don't accept alphanumeric for separator */ | |
4904 if (isalpha(*cmd)) | |
4905 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
4906 emsg(_("E146: Regular expressions can't be delimited by letters")); |
7 | 4907 return; |
4908 } | |
4909 /* | |
4910 * undocumented vi feature: | |
4911 * "\/sub/" and "\?sub?" use last used search pattern (almost like | |
4912 * //sub/r). "\&sub&" use last substitute pattern (like //sub/). | |
4913 */ | |
4914 if (*cmd == '\\') | |
4915 { | |
4916 ++cmd; | |
4917 if (vim_strchr((char_u *)"/?&", *cmd) == NULL) | |
4918 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
4919 emsg(_(e_backslash)); |
7 | 4920 return; |
4921 } | |
4922 if (*cmd != '&') | |
4923 which_pat = RE_SEARCH; /* use last '/' pattern */ | |
4924 pat = (char_u *)""; /* empty search pattern */ | |
4925 delimiter = *cmd++; /* remember delimiter character */ | |
4926 } | |
4927 else /* find the end of the regexp */ | |
4928 { | |
4929 which_pat = RE_LAST; /* use last used regexp */ | |
4930 delimiter = *cmd++; /* remember delimiter character */ | |
4931 pat = cmd; /* remember start of search pat */ | |
4932 cmd = skip_regexp(cmd, delimiter, p_magic, &eap->arg); | |
4933 if (cmd[0] == delimiter) /* end delimiter found */ | |
4934 *cmd++ = NUL; /* replace it with a NUL */ | |
4935 } | |
4936 | |
4937 /* | |
4938 * Small incompatibility: vi sees '\n' as end of the command, but in | |
4939 * Vim we want to use '\n' to find/substitute a NUL. | |
4940 */ | |
4941 sub = cmd; /* remember the start of the substitution */ | |
4942 | |
4943 while (cmd[0]) | |
4944 { | |
4945 if (cmd[0] == delimiter) /* end delimiter found */ | |
4946 { | |
4947 *cmd++ = NUL; /* replace it with a NUL */ | |
4948 break; | |
4949 } | |
4950 if (cmd[0] == '\\' && cmd[1] != 0) /* skip escaped characters */ | |
4951 ++cmd; | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11123
diff
changeset
|
4952 MB_PTR_ADV(cmd); |
7 | 4953 } |
4954 | |
4955 if (!eap->skip) | |
4956 { | |
169 | 4957 /* In POSIX vi ":s/pat/%/" uses the previous subst. string. */ |
4958 if (STRCMP(sub, "%") == 0 | |
4959 && vim_strchr(p_cpo, CPO_SUBPERCENT) != NULL) | |
4960 { | |
4961 if (old_sub == NULL) /* there is no previous command */ | |
4962 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
4963 emsg(_(e_nopresub)); |
169 | 4964 return; |
4965 } | |
4966 sub = old_sub; | |
4967 } | |
4968 else | |
4969 { | |
4970 vim_free(old_sub); | |
4971 old_sub = vim_strsave(sub); | |
4972 } | |
7 | 4973 } |
4974 } | |
4975 else if (!eap->skip) /* use previous pattern and substitution */ | |
4976 { | |
4977 if (old_sub == NULL) /* there is no previous command */ | |
4978 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
4979 emsg(_(e_nopresub)); |
7 | 4980 return; |
4981 } | |
4982 pat = NULL; /* search_regcomp() will use previous pattern */ | |
4983 sub = old_sub; | |
163 | 4984 |
4985 /* Vi compatibility quirk: repeating with ":s" keeps the cursor in the | |
4986 * last column after using "$". */ | |
4987 endcolumn = (curwin->w_curswant == MAXCOL); | |
7 | 4988 } |
4989 | |
5776 | 4990 /* Recognize ":%s/\n//" and turn it into a join command, which is much |
4991 * more efficient. | |
4992 * TODO: find a generic solution to make line-joining operations more | |
4993 * efficient, avoid allocating a string that grows in size. | |
4994 */ | |
5802 | 4995 if (pat != NULL && STRCMP(pat, "\\n") == 0 |
5776 | 4996 && *sub == NUL |
4997 && (*cmd == NUL || (cmd[1] == NUL && (*cmd == 'g' || *cmd == 'l' | |
4998 || *cmd == 'p' || *cmd == '#')))) | |
4999 { | |
6426 | 5000 linenr_T joined_lines_count; |
5001 | |
5776 | 5002 curwin->w_cursor.lnum = eap->line1; |
5003 if (*cmd == 'l') | |
5004 eap->flags = EXFLAG_LIST; | |
5005 else if (*cmd == '#') | |
5006 eap->flags = EXFLAG_NR; | |
5007 else if (*cmd == 'p') | |
5008 eap->flags = EXFLAG_PRINT; | |
5009 | |
6426 | 5010 /* The number of lines joined is the number of lines in the range plus |
5011 * one. One less when the last line is included. */ | |
5012 joined_lines_count = eap->line2 - eap->line1 + 1; | |
5013 if (eap->line2 < curbuf->b_ml.ml_line_count) | |
5014 ++joined_lines_count; | |
5015 if (joined_lines_count > 1) | |
5016 { | |
5017 (void)do_join(joined_lines_count, FALSE, TRUE, FALSE, TRUE); | |
5018 sub_nsubs = joined_lines_count - 1; | |
5019 sub_nlines = 1; | |
5020 (void)do_sub_msg(FALSE); | |
5021 ex_may_print(eap); | |
5022 } | |
5023 | |
5024 if (!cmdmod.keeppatterns) | |
5025 save_re_pat(RE_SUBST, pat, p_magic); | |
5026 #ifdef FEAT_CMDHIST | |
5027 /* put pattern in history */ | |
5028 add_to_history(HIST_SEARCH, pat, TRUE, NUL); | |
5029 #endif | |
5030 | |
5776 | 5031 return; |
5032 } | |
5033 | |
7 | 5034 /* |
5035 * Find trailing options. When '&' is used, keep old options. | |
5036 */ | |
5037 if (*cmd == '&') | |
5038 ++cmd; | |
5039 else | |
5040 { | |
5041 if (!p_ed) | |
5042 { | |
5043 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
|
5044 subflags.do_all = TRUE; |
7 | 5045 else |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5046 subflags.do_all = FALSE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5047 subflags.do_ask = FALSE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5048 } |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5049 subflags.do_error = TRUE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5050 subflags.do_print = FALSE; |
15760
aa80c63f34bb
patch 8.1.0887: the 'l' flag in :subsitute is sticky
Bram Moolenaar <Bram@vim.org>
parents:
15748
diff
changeset
|
5051 subflags.do_list = FALSE; |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5052 subflags.do_count = FALSE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5053 subflags.do_number = FALSE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5054 subflags.do_ic = 0; |
7 | 5055 } |
5056 while (*cmd) | |
5057 { | |
5058 /* | |
5059 * Note that 'g' and 'c' are always inverted, also when p_ed is off. | |
5060 * 'r' is never inverted. | |
5061 */ | |
5062 if (*cmd == 'g') | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5063 subflags.do_all = !subflags.do_all; |
7 | 5064 else if (*cmd == 'c') |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5065 subflags.do_ask = !subflags.do_ask; |
170 | 5066 else if (*cmd == 'n') |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5067 subflags.do_count = TRUE; |
7 | 5068 else if (*cmd == 'e') |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5069 subflags.do_error = !subflags.do_error; |
7 | 5070 else if (*cmd == 'r') /* use last used regexp */ |
5071 which_pat = RE_LAST; | |
5072 else if (*cmd == 'p') | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5073 subflags.do_print = TRUE; |
169 | 5074 else if (*cmd == '#') |
5075 { | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5076 subflags.do_print = TRUE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5077 subflags.do_number = TRUE; |
169 | 5078 } |
5079 else if (*cmd == 'l') | |
5080 { | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5081 subflags.do_print = TRUE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5082 subflags.do_list = TRUE; |
169 | 5083 } |
7 | 5084 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
|
5085 subflags.do_ic = 'i'; |
7 | 5086 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
|
5087 subflags.do_ic = 'I'; |
7 | 5088 else |
5089 break; | |
5090 ++cmd; | |
5091 } | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5092 if (subflags.do_count) |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5093 subflags.do_ask = FALSE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5094 |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5095 save_do_all = subflags.do_all; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5096 save_do_ask = subflags.do_ask; |
6789 | 5097 |
7 | 5098 /* |
5099 * check for a trailing count | |
5100 */ | |
5101 cmd = skipwhite(cmd); | |
5102 if (VIM_ISDIGIT(*cmd)) | |
5103 { | |
5104 i = getdigits(&cmd); | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5105 if (i <= 0 && !eap->skip && subflags.do_error) |
7 | 5106 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
5107 emsg(_(e_zerocount)); |
7 | 5108 return; |
5109 } | |
5110 eap->line1 = eap->line2; | |
5111 eap->line2 += i - 1; | |
5112 if (eap->line2 > curbuf->b_ml.ml_line_count) | |
5113 eap->line2 = curbuf->b_ml.ml_line_count; | |
5114 } | |
5115 | |
5116 /* | |
5117 * check for trailing command or garbage | |
5118 */ | |
5119 cmd = skipwhite(cmd); | |
5120 if (*cmd && *cmd != '"') /* if not end-of-line or comment */ | |
5121 { | |
5122 eap->nextcmd = check_nextcmd(cmd); | |
5123 if (eap->nextcmd == NULL) | |
5124 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
5125 emsg(_(e_trailing)); |
7 | 5126 return; |
5127 } | |
5128 } | |
5129 | |
5130 if (eap->skip) /* not executing commands, only parsing */ | |
5131 return; | |
5132 | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5133 if (!subflags.do_count && !curbuf->b_p_ma) |
823 | 5134 { |
825 | 5135 /* Substitution is not allowed in non-'modifiable' buffer */ |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
5136 emsg(_(e_modifiable)); |
823 | 5137 return; |
5138 } | |
5139 | |
7 | 5140 if (search_regcomp(pat, RE_SUBST, which_pat, SEARCH_HIS, ®match) == FAIL) |
5141 { | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5142 if (subflags.do_error) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
5143 emsg(_(e_invcmd)); |
7 | 5144 return; |
5145 } | |
5146 | |
5147 /* 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
|
5148 if (subflags.do_ic == 'i') |
7 | 5149 regmatch.rmm_ic = TRUE; |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5150 else if (subflags.do_ic == 'I') |
7 | 5151 regmatch.rmm_ic = FALSE; |
5152 | |
5153 sub_firstline = NULL; | |
5154 | |
5155 /* | |
5156 * ~ in the substitute pattern is replaced with the old pattern. | |
5157 * We do it here once to avoid it to be replaced over and over again. | |
5158 * But don't do it when it starts with "\=", then it's an expression. | |
5159 */ | |
5160 if (!(sub[0] == '\\' && sub[1] == '=')) | |
5161 sub = regtilde(sub, p_magic); | |
5162 | |
5163 /* | |
5164 * Check for a match on each line. | |
5165 */ | |
5166 line2 = eap->line2; | |
5167 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
|
5168 #if defined(FEAT_EVAL) |
7 | 5169 || aborting() |
5170 #endif | |
5171 ); ++lnum) | |
5172 { | |
1521 | 5173 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
|
5174 (colnr_T)0, NULL, NULL); |
7 | 5175 if (nmatch) |
5176 { | |
5177 colnr_T copycol; | |
5178 colnr_T matchcol; | |
5179 colnr_T prev_matchcol = MAXCOL; | |
5180 char_u *new_end, *new_start = NULL; | |
5181 unsigned new_start_len = 0; | |
5182 char_u *p1; | |
5183 int did_sub = FALSE; | |
5184 int lastone; | |
1872 | 5185 int len, copy_len, needed_len; |
7 | 5186 long nmatch_tl = 0; /* nr of lines matched below lnum */ |
5187 int do_again; /* do it again after joining lines */ | |
15 | 5188 int skip_match = FALSE; |
1499 | 5189 linenr_T sub_firstlnum; /* nr of first sub line */ |
16698
23af483c4ceb
patch 8.1.1351: text property wrong after :substitute
Bram Moolenaar <Bram@vim.org>
parents:
16686
diff
changeset
|
5190 #ifdef FEAT_TEXT_PROP |
16714
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
5191 int apc_flags = APC_SAVE_FOR_UNDO | APC_SUBSTITUTE; |
16698
23af483c4ceb
patch 8.1.1351: text property wrong after :substitute
Bram Moolenaar <Bram@vim.org>
parents:
16686
diff
changeset
|
5192 #endif |
7 | 5193 |
5194 /* | |
5195 * The new text is build up step by step, to avoid too much | |
5196 * copying. There are these pieces: | |
1581 | 5197 * sub_firstline The old text, unmodified. |
7 | 5198 * copycol Column in the old text where we started |
5199 * looking for a match; from here old text still | |
5200 * needs to be copied to the new text. | |
5201 * matchcol Column number of the old text where to look | |
5202 * for the next match. It's just after the | |
5203 * previous match or one further. | |
5204 * prev_matchcol Column just after the previous match (if any). | |
5205 * Mostly equal to matchcol, except for the first | |
5206 * match and after skipping an empty match. | |
5207 * regmatch.*pos Where the pattern matched in the old text. | |
5208 * new_start The new text, all that has been produced so | |
5209 * far. | |
5210 * new_end The new text, where to append new text. | |
5211 * | |
1499 | 5212 * lnum The line number where we found the start of |
5213 * the match. Can be below the line we searched | |
5214 * when there is a \n before a \zs in the | |
5215 * pattern. | |
7 | 5216 * sub_firstlnum The line number in the buffer where to look |
5217 * for a match. Can be different from "lnum" | |
5218 * when the pattern or substitute string contains | |
5219 * line breaks. | |
5220 * | |
5221 * Special situations: | |
5222 * - When the substitute string contains a line break, the part up | |
5223 * to the line break is inserted in the text, but the copy of | |
5224 * the original line is kept. "sub_firstlnum" is adjusted for | |
5225 * the inserted lines. | |
5226 * - When the matched pattern contains a line break, the old line | |
5227 * is taken from the line at the end of the pattern. The lines | |
5228 * in the match are deleted later, "sub_firstlnum" is adjusted | |
5229 * accordingly. | |
5230 * | |
5231 * The new text is built up in new_start[]. It has some extra | |
5232 * room to avoid using alloc()/free() too often. new_start_len is | |
1389 | 5233 * the length of the allocated memory at new_start. |
7 | 5234 * |
5235 * Make a copy of the old line, so it won't be taken away when | |
5236 * updating the screen or handling a multi-line match. The "old_" | |
5237 * pointers point into this copy. | |
5238 */ | |
1499 | 5239 sub_firstlnum = lnum; |
7 | 5240 copycol = 0; |
5241 matchcol = 0; | |
5242 | |
5243 /* At first match, remember current cursor position. */ | |
5244 if (!got_match) | |
5245 { | |
5246 setpcmark(); | |
5247 got_match = TRUE; | |
5248 } | |
5249 | |
5250 /* | |
5251 * Loop until nothing more to replace in this line. | |
5252 * 1. Handle match with empty string. | |
5253 * 2. If do_ask is set, ask for confirmation. | |
5254 * 3. substitute the string. | |
5255 * 4. if do_all is set, find next match | |
5256 * 5. break if there isn't another match in this line | |
5257 */ | |
5258 for (;;) | |
5259 { | |
1499 | 5260 /* Advance "lnum" to the line where the match starts. The |
5261 * match does not start in the first line when there is a line | |
5262 * break before \zs. */ | |
5263 if (regmatch.startpos[0].lnum > 0) | |
5264 { | |
5265 lnum += regmatch.startpos[0].lnum; | |
5266 sub_firstlnum += regmatch.startpos[0].lnum; | |
5267 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
|
5268 VIM_CLEAR(sub_firstline); |
1499 | 5269 } |
5270 | |
5271 if (sub_firstline == NULL) | |
5272 { | |
5273 sub_firstline = vim_strsave(ml_get(sub_firstlnum)); | |
5274 if (sub_firstline == NULL) | |
5275 { | |
5276 vim_free(new_start); | |
5277 goto outofmem; | |
5278 } | |
5279 } | |
5280 | |
7 | 5281 /* Save the line number of the last change for the final |
5282 * cursor position (just like Vi). */ | |
5283 curwin->w_cursor.lnum = lnum; | |
5284 do_again = FALSE; | |
5285 | |
5286 /* | |
5287 * 1. Match empty string does not count, except for first | |
5288 * match. This reproduces the strange vi behaviour. | |
5289 * This also catches endless loops. | |
5290 */ | |
5291 if (matchcol == prev_matchcol | |
5292 && regmatch.endpos[0].lnum == 0 | |
5293 && matchcol == regmatch.endpos[0].col) | |
5294 { | |
15 | 5295 if (sub_firstline[matchcol] == NUL) |
5296 /* We already were at the end of the line. Don't look | |
5297 * for a match in this line again. */ | |
5298 skip_match = TRUE; | |
5299 else | |
2837 | 5300 { |
5301 /* search for a match at next column */ | |
5302 if (has_mbyte) | |
5303 matchcol += mb_ptr2len(sub_firstline + matchcol); | |
5304 else | |
5305 ++matchcol; | |
5306 } | |
7 | 5307 goto skip; |
5308 } | |
5309 | |
5310 /* Normally we continue searching for a match just after the | |
5311 * previous match. */ | |
5312 matchcol = regmatch.endpos[0].col; | |
5313 prev_matchcol = matchcol; | |
5314 | |
5315 /* | |
170 | 5316 * 2. If do_count is set only increase the counter. |
5317 * If do_ask is set, ask for confirmation. | |
7 | 5318 */ |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5319 if (subflags.do_count) |
170 | 5320 { |
5321 /* For a multi-line match, put matchcol at the NUL at | |
5322 * the end of the line and set nmatch to one, so that | |
5323 * we continue looking for a match on the next line. | |
5324 * Avoids that ":s/\nB\@=//gc" get stuck. */ | |
5325 if (nmatch > 1) | |
5326 { | |
835 | 5327 matchcol = (colnr_T)STRLEN(sub_firstline); |
170 | 5328 nmatch = 1; |
1483 | 5329 skip_match = TRUE; |
170 | 5330 } |
5331 sub_nsubs++; | |
5332 did_sub = TRUE; | |
3736 | 5333 #ifdef FEAT_EVAL |
5334 /* Skip the substitution, unless an expression is used, | |
5335 * then it is evaluated in the sandbox. */ | |
5336 if (!(sub[0] == '\\' && sub[1] == '=')) | |
5337 #endif | |
5338 goto skip; | |
170 | 5339 } |
5340 | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5341 if (subflags.do_ask) |
7 | 5342 { |
1874 | 5343 int typed = 0; |
1872 | 5344 |
7 | 5345 /* change State to CONFIRM, so that the mouse works |
5346 * properly */ | |
5347 save_State = State; | |
5348 State = CONFIRM; | |
5349 #ifdef FEAT_MOUSE | |
5350 setmouse(); /* disable mouse in xterm */ | |
5351 #endif | |
5352 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
|
5353 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
|
5354 do_check_cursorbind(); |
7 | 5355 |
5356 /* When 'cpoptions' contains "u" don't sync undo when | |
5357 * asking for confirmation. */ | |
5358 if (vim_strchr(p_cpo, CPO_UNDO) != NULL) | |
5359 ++no_u_sync; | |
5360 | |
5361 /* | |
5362 * Loop until 'y', 'n', 'q', CTRL-E or CTRL-Y typed. | |
5363 */ | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5364 while (subflags.do_ask) |
7 | 5365 { |
169 | 5366 if (exmode_active) |
5367 { | |
5368 char_u *resp; | |
5369 colnr_T sc, ec; | |
5370 | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5371 print_line_no_prefix(lnum, |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5372 subflags.do_number, subflags.do_list); |
169 | 5373 |
5374 getvcol(curwin, &curwin->w_cursor, &sc, NULL, NULL); | |
5375 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
|
5376 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
|
5377 curwin->w_cursor.col = 0; |
169 | 5378 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
|
5379 if (subflags.do_number || curwin->w_p_nu) |
5396 | 5380 { |
5381 int numw = number_width(curwin) + 1; | |
5382 sc += numw; | |
5383 ec += numw; | |
5384 } | |
169 | 5385 msg_start(); |
170 | 5386 for (i = 0; i < (long)sc; ++i) |
169 | 5387 msg_putchar(' '); |
170 | 5388 for ( ; i <= (long)ec; ++i) |
169 | 5389 msg_putchar('^'); |
5390 | |
5391 resp = getexmodeline('?', NULL, 0); | |
5392 if (resp != NULL) | |
5393 { | |
1872 | 5394 typed = *resp; |
169 | 5395 vim_free(resp); |
5396 } | |
5397 } | |
5398 else | |
5399 { | |
4076 | 5400 char_u *orig_line = NULL; |
5401 int len_change = 0; | |
7 | 5402 #ifdef FEAT_FOLDING |
169 | 5403 int save_p_fen = curwin->w_p_fen; |
5404 | |
5405 curwin->w_p_fen = FALSE; | |
5406 #endif | |
5407 /* Invert the matched string. | |
5408 * Remove the inversion afterwards. */ | |
5409 temp = RedrawingDisabled; | |
5410 RedrawingDisabled = 0; | |
5411 | |
4076 | 5412 if (new_start != NULL) |
5413 { | |
5414 /* There already was a substitution, we would | |
5415 * like to show this to the user. We cannot | |
5416 * really update the line, it would change | |
5417 * what matches. Temporarily replace the line | |
5418 * and change it back afterwards. */ | |
5419 orig_line = vim_strsave(ml_get(lnum)); | |
5420 if (orig_line != NULL) | |
5421 { | |
5422 char_u *new_line = concat_str(new_start, | |
5423 sub_firstline + copycol); | |
5424 | |
5425 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
|
5426 VIM_CLEAR(orig_line); |
4076 | 5427 else |
5428 { | |
5429 /* Position the cursor relative to the | |
5430 * end of the line, the previous | |
5431 * substitute may have inserted or | |
5432 * deleted characters before the | |
5433 * cursor. */ | |
4086 | 5434 len_change = (int)STRLEN(new_line) |
5435 - (int)STRLEN(orig_line); | |
4076 | 5436 curwin->w_cursor.col += len_change; |
5437 ml_replace(lnum, new_line, FALSE); | |
5438 } | |
5439 } | |
5440 } | |
5441 | |
1499 | 5442 search_match_lines = regmatch.endpos[0].lnum |
5443 - regmatch.startpos[0].lnum; | |
4076 | 5444 search_match_endcol = regmatch.endpos[0].col |
5445 + len_change; | |
169 | 5446 highlight_match = TRUE; |
5447 | |
5448 update_topline(); | |
5449 validate_cursor(); | |
748 | 5450 update_screen(SOME_VALID); |
169 | 5451 highlight_match = FALSE; |
748 | 5452 redraw_later(SOME_VALID); |
7 | 5453 |
5454 #ifdef FEAT_FOLDING | |
169 | 5455 curwin->w_p_fen = save_p_fen; |
5456 #endif | |
5457 if (msg_row == Rows - 1) | |
5458 msg_didout = FALSE; /* avoid a scroll-up */ | |
5459 msg_starthere(); | |
5460 i = msg_scroll; | |
5461 msg_scroll = 0; /* truncate msg when | |
5462 needed */ | |
5463 msg_no_more = TRUE; | |
5464 /* write message same highlighting as for | |
5465 * wait_return */ | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11144
diff
changeset
|
5466 smsg_attr(HL_ATTR(HLF_R), |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
5467 _("replace with %s (y/n/a/q/l/^E/^Y)?"), sub); |
169 | 5468 msg_no_more = FALSE; |
5469 msg_scroll = i; | |
5470 showruler(TRUE); | |
5471 windgoto(msg_row, msg_col); | |
5472 RedrawingDisabled = temp; | |
7 | 5473 |
5474 #ifdef USE_ON_FLY_SCROLL | |
169 | 5475 dont_scroll = FALSE; /* allow scrolling here */ |
5476 #endif | |
5477 ++no_mapping; /* don't map this key */ | |
5478 ++allow_keys; /* allow special keys */ | |
1872 | 5479 typed = plain_vgetc(); |
169 | 5480 --allow_keys; |
5481 --no_mapping; | |
5482 | |
5483 /* clear the question */ | |
5484 msg_didout = FALSE; /* don't scroll up */ | |
5485 msg_col = 0; | |
5486 gotocmdline(TRUE); | |
4076 | 5487 |
5488 /* restore the line */ | |
5489 if (orig_line != NULL) | |
5490 ml_replace(lnum, orig_line, FALSE); | |
169 | 5491 } |
5492 | |
7 | 5493 need_wait_return = FALSE; /* no hit-return prompt */ |
1872 | 5494 if (typed == 'q' || typed == ESC || typed == Ctrl_C |
7 | 5495 #ifdef UNIX |
1872 | 5496 || typed == intr_char |
7 | 5497 #endif |
5498 ) | |
5499 { | |
5500 got_quit = TRUE; | |
5501 break; | |
5502 } | |
1872 | 5503 if (typed == 'n') |
7 | 5504 break; |
1872 | 5505 if (typed == 'y') |
7 | 5506 break; |
1872 | 5507 if (typed == 'l') |
7 | 5508 { |
5509 /* last: replace and then stop */ | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5510 subflags.do_all = FALSE; |
7 | 5511 line2 = lnum; |
5512 break; | |
5513 } | |
1872 | 5514 if (typed == 'a') |
7 | 5515 { |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5516 subflags.do_ask = FALSE; |
7 | 5517 break; |
5518 } | |
5519 #ifdef FEAT_INS_EXPAND | |
1872 | 5520 if (typed == Ctrl_E) |
7 | 5521 scrollup_clamp(); |
1872 | 5522 else if (typed == Ctrl_Y) |
7 | 5523 scrolldown_clamp(); |
5524 #endif | |
5525 } | |
5526 State = save_State; | |
5527 #ifdef FEAT_MOUSE | |
5528 setmouse(); | |
5529 #endif | |
5530 if (vim_strchr(p_cpo, CPO_UNDO) != NULL) | |
5531 --no_u_sync; | |
5532 | |
1872 | 5533 if (typed == 'n') |
7 | 5534 { |
5535 /* For a multi-line match, put matchcol at the NUL at | |
5536 * the end of the line and set nmatch to one, so that | |
5537 * we continue looking for a match on the next line. | |
1091 | 5538 * Avoids that ":%s/\nB\@=//gc" and ":%s/\n/,\r/gc" |
5539 * get stuck when pressing 'n'. */ | |
7 | 5540 if (nmatch > 1) |
5541 { | |
835 | 5542 matchcol = (colnr_T)STRLEN(sub_firstline); |
1091 | 5543 skip_match = TRUE; |
7 | 5544 } |
5545 goto skip; | |
5546 } | |
5547 if (got_quit) | |
4099 | 5548 goto skip; |
7 | 5549 } |
5550 | |
5551 /* Move the cursor to the start of the match, so that we can | |
5552 * use "\=col("."). */ | |
5553 curwin->w_cursor.col = regmatch.startpos[0].col; | |
5554 | |
5555 /* | |
5556 * 3. substitute the string. | |
5557 */ | |
3736 | 5558 #ifdef FEAT_EVAL |
16716
5a541d459ef7
patch 8.1.1360: buffer left 'nomodifiable' after :substitute
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
5559 save_ma = curbuf->b_p_ma; |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5560 if (subflags.do_count) |
3736 | 5561 { |
16686
6ea3f93b4428
patch 8.1.1345: stuck in sandbox with ":s/../=Function/gn"
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
5562 // prevent accidentally changing the buffer by a function |
3736 | 5563 curbuf->b_p_ma = FALSE; |
5564 sandbox++; | |
5565 } | |
16686
6ea3f93b4428
patch 8.1.1345: stuck in sandbox with ":s/../=Function/gn"
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
5566 // Save flags for recursion. They can change for e.g. |
6ea3f93b4428
patch 8.1.1345: stuck in sandbox with ":s/../=Function/gn"
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
5567 // :s/^/\=execute("s#^##gn") |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5568 subflags_save = subflags; |
16686
6ea3f93b4428
patch 8.1.1345: stuck in sandbox with ":s/../=Function/gn"
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
5569 #endif |
6ea3f93b4428
patch 8.1.1345: stuck in sandbox with ":s/../=Function/gn"
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
5570 // get length of substitution part |
1499 | 5571 sublen = vim_regsub_multi(®match, |
5572 sub_firstlnum - regmatch.startpos[0].lnum, | |
7 | 5573 sub, sub_firstline, FALSE, p_magic, TRUE); |
3736 | 5574 #ifdef FEAT_EVAL |
16113
9994c50f7879
patch 8.1.1061: when substitute string throws error, substitute happens anyway
Bram Moolenaar <Bram@vim.org>
parents:
16021
diff
changeset
|
5575 // If getting the substitute string caused an error, don't do |
9994c50f7879
patch 8.1.1061: when substitute string throws error, substitute happens anyway
Bram Moolenaar <Bram@vim.org>
parents:
16021
diff
changeset
|
5576 // the replacement. |
9994c50f7879
patch 8.1.1061: when substitute string throws error, substitute happens anyway
Bram Moolenaar <Bram@vim.org>
parents:
16021
diff
changeset
|
5577 // Don't keep flags set by a recursive call. |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5578 subflags = subflags_save; |
16686
6ea3f93b4428
patch 8.1.1345: stuck in sandbox with ":s/../=Function/gn"
Bram Moolenaar <Bram@vim.org>
parents:
16662
diff
changeset
|
5579 if (aborting() || subflags.do_count) |
3736 | 5580 { |
5581 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
|
5582 if (sandbox > 0) |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5583 sandbox--; |
3736 | 5584 goto skip; |
5585 } | |
5586 #endif | |
7 | 5587 |
533 | 5588 /* When the match included the "$" of the last line it may |
819 | 5589 * go beyond the last line of the buffer. */ |
533 | 5590 if (nmatch > curbuf->b_ml.ml_line_count - sub_firstlnum + 1) |
5591 { | |
5592 nmatch = curbuf->b_ml.ml_line_count - sub_firstlnum + 1; | |
5593 skip_match = TRUE; | |
5594 } | |
5595 | |
7 | 5596 /* Need room for: |
5597 * - result so far in new_start (not for first sub in line) | |
5598 * - original text up to match | |
5599 * - length of substituted part | |
5600 * - original text after match | |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
5601 * Adjust text properties here, since we have all information |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
5602 * needed. |
7 | 5603 */ |
5604 if (nmatch == 1) | |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
5605 { |
7 | 5606 p1 = sub_firstline; |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
5607 #ifdef FEAT_TEXT_PROP |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
5608 if (curbuf->b_has_textprop) |
16698
23af483c4ceb
patch 8.1.1351: text property wrong after :substitute
Bram Moolenaar <Bram@vim.org>
parents:
16686
diff
changeset
|
5609 { |
23af483c4ceb
patch 8.1.1351: text property wrong after :substitute
Bram Moolenaar <Bram@vim.org>
parents:
16686
diff
changeset
|
5610 // When text properties are changed, need to save for |
23af483c4ceb
patch 8.1.1351: text property wrong after :substitute
Bram Moolenaar <Bram@vim.org>
parents:
16686
diff
changeset
|
5611 // undo first, unless done already. |
23af483c4ceb
patch 8.1.1351: text property wrong after :substitute
Bram Moolenaar <Bram@vim.org>
parents:
16686
diff
changeset
|
5612 if (adjust_prop_columns(lnum, regmatch.startpos[0].col, |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
5613 sublen - 1 - (regmatch.endpos[0].col |
16714
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
5614 - regmatch.startpos[0].col), |
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
5615 apc_flags)) |
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
5616 apc_flags &= ~APC_SAVE_FOR_UNDO; |
16698
23af483c4ceb
patch 8.1.1351: text property wrong after :substitute
Bram Moolenaar <Bram@vim.org>
parents:
16686
diff
changeset
|
5617 } |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
5618 #endif |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
5619 } |
7 | 5620 else |
5621 { | |
5622 p1 = ml_get(sub_firstlnum + nmatch - 1); | |
5623 nmatch_tl += nmatch - 1; | |
5624 } | |
1872 | 5625 copy_len = regmatch.startpos[0].col - copycol; |
5626 needed_len = copy_len + ((unsigned)STRLEN(p1) | |
5627 - regmatch.endpos[0].col) + sublen + 1; | |
7 | 5628 if (new_start == NULL) |
5629 { | |
5630 /* | |
5631 * Get some space for a temporary buffer to do the | |
5632 * substitution into (and some extra space to avoid | |
5633 * too many calls to alloc()/free()). | |
5634 */ | |
5635 new_start_len = needed_len + 50; | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
5636 if ((new_start = alloc(new_start_len)) == NULL) |
7 | 5637 goto outofmem; |
5638 *new_start = NUL; | |
5639 new_end = new_start; | |
5640 } | |
5641 else | |
5642 { | |
5643 /* | |
5644 * Check if the temporary buffer is long enough to do the | |
5645 * substitution into. If not, make it larger (with a bit | |
5646 * extra to avoid too many calls to alloc()/free()). | |
5647 */ | |
5648 len = (unsigned)STRLEN(new_start); | |
5649 needed_len += len; | |
1872 | 5650 if (needed_len > (int)new_start_len) |
7 | 5651 { |
5652 new_start_len = needed_len + 50; | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
5653 if ((p1 = alloc(new_start_len)) == NULL) |
7 | 5654 { |
5655 vim_free(new_start); | |
5656 goto outofmem; | |
5657 } | |
5658 mch_memmove(p1, new_start, (size_t)(len + 1)); | |
5659 vim_free(new_start); | |
5660 new_start = p1; | |
5661 } | |
5662 new_end = new_start + len; | |
5663 } | |
5664 | |
5665 /* | |
5666 * copy the text up to the part that matched | |
5667 */ | |
1872 | 5668 mch_memmove(new_end, sub_firstline + copycol, (size_t)copy_len); |
5669 new_end += copy_len; | |
7 | 5670 |
1499 | 5671 (void)vim_regsub_multi(®match, |
5672 sub_firstlnum - regmatch.startpos[0].lnum, | |
7 | 5673 sub, new_end, TRUE, p_magic, TRUE); |
5674 sub_nsubs++; | |
5675 did_sub = TRUE; | |
5676 | |
5677 /* Move the cursor to the start of the line, to avoid that it | |
5678 * is beyond the end of the line after the substitution. */ | |
5679 curwin->w_cursor.col = 0; | |
5680 | |
5681 /* For a multi-line match, make a copy of the last matched | |
5682 * line and continue in that one. */ | |
5683 if (nmatch > 1) | |
5684 { | |
5685 sub_firstlnum += nmatch - 1; | |
5686 vim_free(sub_firstline); | |
5687 sub_firstline = vim_strsave(ml_get(sub_firstlnum)); | |
5688 /* When going beyond the last line, stop substituting. */ | |
5689 if (sub_firstlnum <= line2) | |
5690 do_again = TRUE; | |
5691 else | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5692 subflags.do_all = FALSE; |
7 | 5693 } |
5694 | |
5695 /* Remember next character to be copied. */ | |
5696 copycol = regmatch.endpos[0].col; | |
5697 | |
819 | 5698 if (skip_match) |
5699 { | |
5700 /* Already hit end of the buffer, sub_firstlnum is one | |
5701 * less than what it ought to be. */ | |
5702 vim_free(sub_firstline); | |
5703 sub_firstline = vim_strsave((char_u *)""); | |
5704 copycol = 0; | |
5705 } | |
5706 | |
7 | 5707 /* |
5708 * Now the trick is to replace CTRL-M chars with a real line | |
5709 * break. This would make it impossible to insert a CTRL-M in | |
5710 * the text. The line break can be avoided by preceding the | |
5711 * CTRL-M with a backslash. To be able to insert a backslash, | |
5712 * they must be doubled in the string and are halved here. | |
5713 * That is Vi compatible. | |
5714 */ | |
5715 for (p1 = new_end; *p1; ++p1) | |
5716 { | |
5717 if (p1[0] == '\\' && p1[1] != NUL) /* remove backslash */ | |
16714
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
5718 { |
1624 | 5719 STRMOVE(p1, p1 + 1); |
16714
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
5720 #ifdef FEAT_TEXT_PROP |
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
5721 if (curbuf->b_has_textprop) |
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
5722 { |
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
5723 // When text properties are changed, need to save |
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
5724 // for undo first, unless done already. |
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
5725 if (adjust_prop_columns(lnum, |
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
5726 (colnr_T)(p1 - new_start), -1, |
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
5727 apc_flags)) |
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
5728 apc_flags &= ~APC_SAVE_FOR_UNDO; |
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
5729 } |
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
5730 #endif |
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
5731 } |
7 | 5732 else if (*p1 == CAR) |
5733 { | |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
5734 if (u_inssub(lnum) == OK) // prepare for undo |
7 | 5735 { |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
5736 colnr_T plen = (colnr_T)(p1 - new_start + 1); |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
5737 |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
5738 *p1 = NUL; // truncate up to the CR |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
5739 ml_append(lnum - 1, new_start, plen, FALSE); |
7 | 5740 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
|
5741 if (subflags.do_ask) |
7 | 5742 appended_lines(lnum - 1, 1L); |
5743 else | |
5744 { | |
5745 if (first_line == 0) | |
5746 first_line = lnum; | |
5747 last_line = lnum + 1; | |
5748 } | |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
5749 #ifdef FEAT_TEXT_PROP |
16662
1fc9cd08cf3c
patch 8.1.1333: text properties don't always move after changes
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
5750 adjust_props_for_split(lnum + 1, lnum, plen, 1); |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
5751 #endif |
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
5752 // all line numbers increase |
7 | 5753 ++sub_firstlnum; |
5754 ++lnum; | |
5755 ++line2; | |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
5756 // move the cursor to the new line, like Vi |
7 | 5757 ++curwin->w_cursor.lnum; |
15367
273649cad196
patch 8.1.0691: text properties are not adjusted for :substitute
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
5758 // copy the rest |
1624 | 5759 STRMOVE(new_start, p1 + 1); |
7 | 5760 p1 = new_start - 1; |
5761 } | |
5762 } | |
5763 else if (has_mbyte) | |
474 | 5764 p1 += (*mb_ptr2len)(p1) - 1; |
7 | 5765 } |
5766 | |
5767 /* | |
5768 * 4. If do_all is set, find next match. | |
5769 * Prevent endless loop with patterns that match empty | |
5770 * strings, e.g. :s/$/pat/g or :s/[a-z]* /(&)/g. | |
5771 * But ":s/\n/#/" is OK. | |
5772 */ | |
5773 skip: | |
5774 /* We already know that we did the last subst when we are at | |
5775 * the end of the line, except that a pattern like | |
1499 | 5776 * "bar\|\nfoo" may match at the NUL. "lnum" can be below |
5777 * "line2" when there is a \zs in the pattern after a line | |
5778 * break. */ | |
15 | 5779 lastone = (skip_match |
5780 || got_int | |
5781 || got_quit | |
1499 | 5782 || lnum > line2 |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5783 || !(subflags.do_all || do_again) |
15 | 5784 || (sub_firstline[matchcol] == NUL && nmatch <= 1 |
5785 && !re_multiline(regmatch.regprog))); | |
7 | 5786 nmatch = -1; |
5787 | |
5788 /* | |
5789 * Replace the line in the buffer when needed. This is | |
5790 * skipped when there are more matches. | |
5791 * The check for nmatch_tl is needed for when multi-line | |
5792 * matching must replace the lines before trying to do another | |
5793 * match, otherwise "\@<=" won't work. | |
1499 | 5794 * When the match starts below where we start searching also |
5795 * need to replace the line first (using \zs after \n). | |
7 | 5796 */ |
5797 if (lastone | |
5798 || nmatch_tl > 0 | |
5799 || (nmatch = vim_regexec_multi(®match, curwin, | |
1521 | 5800 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
|
5801 matchcol, NULL, NULL)) == 0 |
1499 | 5802 || regmatch.startpos[0].lnum > 0) |
7 | 5803 { |
5804 if (new_start != NULL) | |
5805 { | |
5806 /* | |
5807 * Copy the rest of the line, that didn't match. | |
5808 * "matchcol" has to be adjusted, we use the end of | |
5809 * the line as reference, because the substitute may | |
5810 * have changed the number of characters. Same for | |
5811 * "prev_matchcol". | |
5812 */ | |
5813 STRCAT(new_start, sub_firstline + copycol); | |
5814 matchcol = (colnr_T)STRLEN(sub_firstline) - matchcol; | |
5815 prev_matchcol = (colnr_T)STRLEN(sub_firstline) | |
5816 - prev_matchcol; | |
5817 | |
5818 if (u_savesub(lnum) != OK) | |
5819 break; | |
5820 ml_replace(lnum, new_start, TRUE); | |
5821 | |
5822 if (nmatch_tl > 0) | |
5823 { | |
5824 /* | |
5825 * Matched lines have now been substituted and are | |
5826 * useless, delete them. The part after the match | |
5827 * has been appended to new_start, we don't need | |
5828 * it in the buffer. | |
5829 */ | |
5830 ++lnum; | |
5831 if (u_savedel(lnum, nmatch_tl) != OK) | |
5832 break; | |
5833 for (i = 0; i < nmatch_tl; ++i) | |
5834 ml_delete(lnum, (int)FALSE); | |
5835 mark_adjust(lnum, lnum + nmatch_tl - 1, | |
5836 (long)MAXLNUM, -nmatch_tl); | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5837 if (subflags.do_ask) |
7 | 5838 deleted_lines(lnum, nmatch_tl); |
5839 --lnum; | |
5840 line2 -= nmatch_tl; /* nr of lines decreases */ | |
5841 nmatch_tl = 0; | |
5842 } | |
5843 | |
5844 /* When asking, undo is saved each time, must also set | |
5845 * changed flag each time. */ | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5846 if (subflags.do_ask) |
7 | 5847 changed_bytes(lnum, 0); |
5848 else | |
5849 { | |
5850 if (first_line == 0) | |
5851 first_line = lnum; | |
5852 last_line = lnum + 1; | |
5853 } | |
5854 | |
5855 sub_firstlnum = lnum; | |
5856 vim_free(sub_firstline); /* free the temp buffer */ | |
5857 sub_firstline = new_start; | |
5858 new_start = NULL; | |
5859 matchcol = (colnr_T)STRLEN(sub_firstline) - matchcol; | |
5860 prev_matchcol = (colnr_T)STRLEN(sub_firstline) | |
5861 - prev_matchcol; | |
5862 copycol = 0; | |
5863 } | |
5864 if (nmatch == -1 && !lastone) | |
5865 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
|
5866 sub_firstlnum, matchcol, NULL, NULL); |
7 | 5867 |
5868 /* | |
5869 * 5. break if there isn't another match in this line | |
5870 */ | |
5871 if (nmatch <= 0) | |
1499 | 5872 { |
5873 /* If the match found didn't start where we were | |
5874 * searching, do the next search in the line where we | |
5875 * found the match. */ | |
5876 if (nmatch == -1) | |
5877 lnum -= regmatch.startpos[0].lnum; | |
7 | 5878 break; |
1499 | 5879 } |
7 | 5880 } |
5881 | |
5882 line_breakcheck(); | |
5883 } | |
5884 | |
5885 if (did_sub) | |
5886 ++sub_nlines; | |
1720 | 5887 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
|
5888 VIM_CLEAR(sub_firstline); /* free the copy of the original line */ |
7 | 5889 } |
5890 | |
5891 line_breakcheck(); | |
5892 } | |
5893 | |
5894 if (first_line != 0) | |
5895 { | |
5896 /* Need to subtract the number of added lines from "last_line" to get | |
5897 * the line number before the change (same as adding the number of | |
5898 * deleted lines). */ | |
5899 i = curbuf->b_ml.ml_line_count - old_line_count; | |
5900 changed_lines(first_line, 0, last_line - i, i); | |
5901 } | |
5902 | |
5903 outofmem: | |
5904 vim_free(sub_firstline); /* may have to free allocated copy of the line */ | |
170 | 5905 |
5906 /* ":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
|
5907 if (subflags.do_count) |
170 | 5908 curwin->w_cursor = old_cursor; |
5909 | |
2126
e038754d419a
updated for version 7.2.408
Bram Moolenaar <bram@zimbu.org>
parents:
1929
diff
changeset
|
5910 if (sub_nsubs > start_nsubs) |
7 | 5911 { |
5912 /* Set the '[ and '] marks. */ | |
5913 curbuf->b_op_start.lnum = eap->line1; | |
5914 curbuf->b_op_end.lnum = line2; | |
5915 curbuf->b_op_start.col = curbuf->b_op_end.col = 0; | |
5916 | |
5917 if (!global_busy) | |
5918 { | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5919 /* 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
|
5920 if (!subflags.do_ask) |
3394 | 5921 { |
5922 if (endcolumn) | |
5923 coladvance((colnr_T)MAXCOL); | |
5924 else | |
5925 beginline(BL_WHITE | BL_FIX); | |
5926 } | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5927 if (!do_sub_msg(subflags.do_count) && subflags.do_ask) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
5928 msg(""); |
7 | 5929 } |
5930 else | |
5931 global_need_beginline = TRUE; | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5932 if (subflags.do_print) |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5933 print_line(curwin->w_cursor.lnum, |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5934 subflags.do_number, subflags.do_list); |
7 | 5935 } |
5936 else if (!global_busy) | |
5937 { | |
5938 if (got_int) /* interrupted */ | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
5939 emsg(_(e_interr)); |
7 | 5940 else if (got_match) /* did find something but nothing substituted */ |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
5941 msg(""); |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5942 else if (subflags.do_error) /* nothing found */ |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
5943 semsg(_(e_patnotf2), get_search_pat()); |
7 | 5944 } |
5945 | |
4035 | 5946 #ifdef FEAT_FOLDING |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5947 if (subflags.do_ask && hasAnyFolding(curwin)) |
4035 | 5948 /* Cursor position may require updating */ |
5949 changed_window_setting(); | |
5950 #endif | |
5951 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4613
diff
changeset
|
5952 vim_regfree(regmatch.regprog); |
6789 | 5953 |
5954 /* 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
|
5955 subflags.do_all = save_do_all; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5956 subflags.do_ask = save_do_ask; |
7 | 5957 } |
5958 | |
5959 /* | |
5960 * Give message for number of substitutions. | |
5961 * Can also be used after a ":global" command. | |
5962 * Return TRUE if a message was given. | |
5963 */ | |
484 | 5964 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5965 do_sub_msg( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5966 int count_only) /* used 'n' flag for ":s" */ |
7 | 5967 { |
5968 /* | |
5969 * Only report substitutions when: | |
5970 * - more than 'report' substitutions | |
5971 * - command was typed by user, or number of changed lines > 'report' | |
5972 * - giving messages is not disabled by 'lazyredraw' | |
5973 */ | |
170 | 5974 if (((sub_nsubs > p_report && (KeyTyped || sub_nlines > 1 || p_report < 1)) |
5975 || count_only) | |
7 | 5976 && messaging()) |
5977 { | |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14513
diff
changeset
|
5978 char *msg_single; |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14513
diff
changeset
|
5979 char *msg_plural; |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14513
diff
changeset
|
5980 |
7 | 5981 if (got_int) |
5982 STRCPY(msg_buf, _("(Interrupted) ")); | |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
5983 else |
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
5984 *msg_buf = NUL; |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14513
diff
changeset
|
5985 |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14513
diff
changeset
|
5986 msg_single = count_only |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14513
diff
changeset
|
5987 ? NGETTEXT("%ld match on %ld line", |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14513
diff
changeset
|
5988 "%ld matches on %ld line", sub_nsubs) |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14513
diff
changeset
|
5989 : NGETTEXT("%ld substitution on %ld line", |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14513
diff
changeset
|
5990 "%ld substitutions on %ld line", sub_nsubs); |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14513
diff
changeset
|
5991 msg_plural = count_only |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14513
diff
changeset
|
5992 ? NGETTEXT("%ld match on %ld lines", |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14513
diff
changeset
|
5993 "%ld matches on %ld lines", sub_nsubs) |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14513
diff
changeset
|
5994 : NGETTEXT("%ld substitution on %ld lines", |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14513
diff
changeset
|
5995 "%ld substitutions on %ld lines", sub_nsubs); |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14513
diff
changeset
|
5996 |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
5997 vim_snprintf_add(msg_buf, sizeof(msg_buf), |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14513
diff
changeset
|
5998 NGETTEXT(msg_single, msg_plural, sub_nlines), |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14513
diff
changeset
|
5999 sub_nsubs, (long)sub_nlines); |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14513
diff
changeset
|
6000 |
7 | 6001 if (msg(msg_buf)) |
6002 /* save message to display it after redraw */ | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
6003 set_keep_msg((char_u *)msg_buf, 0); |
7 | 6004 return TRUE; |
6005 } | |
6006 if (got_int) | |
6007 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
6008 emsg(_(e_interr)); |
7 | 6009 return TRUE; |
6010 } | |
6011 return FALSE; | |
6012 } | |
6013 | |
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
|
6014 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
|
6015 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
|
6016 { |
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
|
6017 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
|
6018 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
|
6019 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
|
6020 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
|
6021 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
|
6022 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
|
6023 } |
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
|
6024 |
7 | 6025 /* |
6026 * Execute a global command of the form: | |
6027 * | |
6028 * g/pattern/X : execute X on all lines where pattern matches | |
6029 * v/pattern/X : execute X on all lines where pattern does not match | |
6030 * | |
6031 * where 'X' is an EX command | |
6032 * | |
6033 * The command character (as well as the trailing slash) is optional, and | |
6034 * is assumed to be 'p' if missing. | |
6035 * | |
6036 * This is implemented in two passes: first we scan the file for the pattern and | |
3786 | 6037 * set a mark for each line that (not) matches. Secondly we execute the command |
7 | 6038 * for each line that has a mark. This is required because after deleting |
6039 * lines we do not know where to search for the next match. | |
6040 */ | |
6041 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6042 ex_global(exarg_T *eap) |
7 | 6043 { |
6044 linenr_T lnum; /* line number according to old situation */ | |
170 | 6045 int ndone = 0; |
7 | 6046 int type; /* first char of cmd: 'v' or 'g' */ |
6047 char_u *cmd; /* command argument */ | |
6048 | |
6049 char_u delim; /* delimiter, normally '/' */ | |
6050 char_u *pat; | |
6051 regmmatch_T regmatch; | |
6052 int match; | |
6053 int which_pat; | |
6054 | |
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
|
6055 /* 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
|
6056 * ":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
|
6057 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
|
6058 || 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
|
6059 { |
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
|
6060 /* will increment global_busy to break out of the loop */ |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
6061 emsg(_("E147: Cannot do :global recursive with a range")); |
7 | 6062 return; |
6063 } | |
6064 | |
6065 if (eap->forceit) /* ":global!" is like ":vglobal" */ | |
6066 type = 'v'; | |
6067 else | |
6068 type = *eap->cmd; | |
6069 cmd = eap->arg; | |
6070 which_pat = RE_LAST; /* default: use last used regexp */ | |
6071 | |
6072 /* | |
6073 * undocumented vi feature: | |
6074 * "\/" and "\?": use previous search pattern. | |
6075 * "\&": use previous substitute pattern. | |
6076 */ | |
6077 if (*cmd == '\\') | |
6078 { | |
6079 ++cmd; | |
6080 if (vim_strchr((char_u *)"/?&", *cmd) == NULL) | |
6081 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
6082 emsg(_(e_backslash)); |
7 | 6083 return; |
6084 } | |
6085 if (*cmd == '&') | |
6086 which_pat = RE_SUBST; /* use previous substitute pattern */ | |
6087 else | |
6088 which_pat = RE_SEARCH; /* use previous search pattern */ | |
6089 ++cmd; | |
6090 pat = (char_u *)""; | |
6091 } | |
6092 else if (*cmd == NUL) | |
6093 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
6094 emsg(_("E148: Regular expression missing from global")); |
7 | 6095 return; |
6096 } | |
6097 else | |
6098 { | |
6099 delim = *cmd; /* get the delimiter */ | |
6100 if (delim) | |
6101 ++cmd; /* skip delimiter if there is one */ | |
6102 pat = cmd; /* remember start of pattern */ | |
6103 cmd = skip_regexp(cmd, delim, p_magic, &eap->arg); | |
6104 if (cmd[0] == delim) /* end delimiter found */ | |
6105 *cmd++ = NUL; /* replace it with a NUL */ | |
6106 } | |
6107 | |
6108 if (search_regcomp(pat, RE_BOTH, which_pat, SEARCH_HIS, ®match) == FAIL) | |
6109 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
6110 emsg(_(e_invcmd)); |
7 | 6111 return; |
6112 } | |
6113 | |
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
|
6114 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
|
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 lnum = curwin->w_cursor.lnum; |
1521 | 6117 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
|
6118 (colnr_T)0, NULL, NULL); |
7 | 6119 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
|
6120 global_exe_one(cmd, lnum); |
7 | 6121 } |
6122 else | |
6116 | 6123 { |
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
|
6124 /* |
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
|
6125 * 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
|
6126 */ |
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
|
6127 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
|
6128 { |
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
|
6129 /* 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
|
6130 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
|
6131 (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
|
6132 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
|
6133 { |
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
|
6134 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
|
6135 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
|
6136 } |
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
|
6137 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
|
6138 } |
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
|
6139 |
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
|
6140 /* |
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
|
6141 * 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
|
6142 */ |
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
|
6143 if (got_int) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
6144 msg(_(e_interr)); |
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
|
6145 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
|
6146 { |
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
|
6147 if (type == 'v') |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
6148 smsg(_("Pattern found in every line: %s"), pat); |
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
|
6149 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
6150 smsg(_("Pattern not found: %s"), pat); |
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
|
6151 } |
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
|
6152 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
|
6153 { |
6116 | 6154 #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
|
6155 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
|
6156 #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
|
6157 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
|
6158 #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
|
6159 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
|
6160 #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
|
6161 } |
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
|
6162 |
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
|
6163 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
|
6164 } |
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
|
6165 |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4613
diff
changeset
|
6166 vim_regfree(regmatch.regprog); |
7 | 6167 } |
6168 | |
6169 /* | |
6170 * Execute "cmd" on lines marked with ml_setmarked(). | |
6171 */ | |
6172 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6173 global_exe(char_u *cmd) |
7 | 6174 { |
2819 | 6175 linenr_T old_lcount; /* b_ml.ml_line_count before the command */ |
6176 buf_T *old_buf = curbuf; /* remember what buffer we started in */ | |
6177 linenr_T lnum; /* line number according to old situation */ | |
7 | 6178 |
6179 /* | |
6180 * Set current position only once for a global command. | |
6181 * If global_busy is set, setpcmark() will not do anything. | |
6182 * If there is an error, global_busy will be incremented. | |
6183 */ | |
6184 setpcmark(); | |
6185 | |
6186 /* When the command writes a message, don't overwrite the command. */ | |
6187 msg_didout = TRUE; | |
6188 | |
2127
4e22214f8464
updated for version 7.2.409
Bram Moolenaar <bram@zimbu.org>
parents:
2126
diff
changeset
|
6189 sub_nsubs = 0; |
4e22214f8464
updated for version 7.2.409
Bram Moolenaar <bram@zimbu.org>
parents:
2126
diff
changeset
|
6190 sub_nlines = 0; |
7 | 6191 global_need_beginline = FALSE; |
6192 global_busy = 1; | |
6193 old_lcount = curbuf->b_ml.ml_line_count; | |
6194 while (!got_int && (lnum = ml_firstmarked()) != 0 && global_busy == 1) | |
6195 { | |
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
|
6196 global_exe_one(cmd, lnum); |
7 | 6197 ui_breakcheck(); |
6198 } | |
6199 | |
6200 global_busy = 0; | |
6201 if (global_need_beginline) | |
6202 beginline(BL_WHITE | BL_FIX); | |
6203 else | |
6204 check_cursor(); /* cursor may be beyond the end of the line */ | |
6205 | |
39 | 6206 /* the cursor may not have moved in the text but a change in a previous |
6207 * line may move it on the screen */ | |
6208 changed_line_abv_curs(); | |
6209 | |
7 | 6210 /* If it looks like no message was written, allow overwriting the |
6211 * command with the report for number of changes. */ | |
6212 if (msg_col == 0 && msg_scrolled == 0) | |
6213 msg_didout = FALSE; | |
6214 | |
1227 | 6215 /* If substitutes done, report number of substitutes, otherwise report |
2819 | 6216 * number of extra or deleted lines. |
6217 * Don't report extra or deleted lines in the edge case where the buffer | |
6218 * we are in after execution is different from the buffer we started in. */ | |
6219 if (!do_sub_msg(FALSE) && curbuf == old_buf) | |
7 | 6220 msgmore(curbuf->b_ml.ml_line_count - old_lcount); |
6221 } | |
6222 | |
6223 #ifdef FEAT_VIMINFO | |
6224 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6225 read_viminfo_sub_string(vir_T *virp, int force) |
7 | 6226 { |
2690 | 6227 if (force) |
7 | 6228 vim_free(old_sub); |
6229 if (force || old_sub == NULL) | |
6230 old_sub = viminfo_readstring(virp, 1, TRUE); | |
6231 return viminfo_readline(virp); | |
6232 } | |
6233 | |
6234 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6235 write_viminfo_sub_string(FILE *fp) |
7 | 6236 { |
6237 if (get_viminfo_parameter('/') != 0 && old_sub != NULL) | |
6238 { | |
2545
298d8d6e69be
Avoid warnings from the clang compiler. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2394
diff
changeset
|
6239 fputs(_("\n# Last Substitute String:\n$"), fp); |
7 | 6240 viminfo_writestring(fp, old_sub); |
6241 } | |
6242 } | |
6243 #endif /* FEAT_VIMINFO */ | |
6244 | |
359 | 6245 #if defined(EXITFREE) || defined(PROTO) |
6246 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6247 free_old_sub(void) |
359 | 6248 { |
6249 vim_free(old_sub); | |
6250 } | |
6251 #endif | |
6252 | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12297
diff
changeset
|
6253 #if defined(FEAT_QUICKFIX) || defined(PROTO) |
7 | 6254 /* |
6255 * Set up for a tagpreview. | |
735 | 6256 * Return TRUE when it was created. |
7 | 6257 */ |
735 | 6258 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6259 prepare_tagpreview( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6260 int undo_sync) /* sync undo when leaving the window */ |
7 | 6261 { |
6262 win_T *wp; | |
6263 | |
6264 # ifdef FEAT_GUI | |
6265 need_mouse_correct = TRUE; | |
6266 # endif | |
6267 | |
6268 /* | |
6269 * If there is already a preview window open, use that one. | |
6270 */ | |
6271 if (!curwin->w_p_pvw) | |
6272 { | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
6273 FOR_ALL_WINDOWS(wp) |
7 | 6274 if (wp->w_p_pvw) |
6275 break; | |
6276 if (wp != NULL) | |
816 | 6277 win_enter(wp, undo_sync); |
7 | 6278 else |
6279 { | |
6280 /* | |
6281 * There is no preview window open yet. Create one. | |
6282 */ | |
6283 if (win_split(g_do_tagpreview > 0 ? g_do_tagpreview : 0, 0) | |
6284 == FAIL) | |
735 | 6285 return FALSE; |
7 | 6286 curwin->w_p_pvw = TRUE; |
6287 curwin->w_p_wfh = TRUE; | |
2583 | 6288 RESET_BINDING(curwin); /* don't take over 'scrollbind' |
6289 and 'cursorbind' */ | |
7 | 6290 # ifdef FEAT_DIFF |
6291 curwin->w_p_diff = FALSE; /* no 'diff' */ | |
6292 # endif | |
6293 # ifdef FEAT_FOLDING | |
6294 curwin->w_p_fdc = 0; /* no 'foldcolumn' */ | |
6295 # endif | |
735 | 6296 return TRUE; |
7 | 6297 } |
6298 } | |
735 | 6299 return FALSE; |
7 | 6300 } |
6301 | |
6302 #endif | |
6303 | |
6304 | |
6305 /* | |
6306 * ":help": open a read-only window on a help file | |
6307 */ | |
6308 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6309 ex_help(exarg_T *eap) |
7 | 6310 { |
6311 char_u *arg; | |
6312 char_u *tag; | |
6313 FILE *helpfd; /* file descriptor of help file */ | |
6314 int n; | |
6315 int i; | |
6316 win_T *wp; | |
6317 int num_matches; | |
6318 char_u **matches; | |
6319 char_u *p; | |
6320 int empty_fnum = 0; | |
6321 int alt_fnum = 0; | |
6322 buf_T *buf; | |
6323 #ifdef FEAT_MULTI_LANG | |
6324 int len; | |
9 | 6325 char_u *lang; |
7 | 6326 #endif |
3112 | 6327 #ifdef FEAT_FOLDING |
6328 int old_KeyTyped = KeyTyped; | |
6329 #endif | |
7 | 6330 |
6331 if (eap != NULL) | |
6332 { | |
6333 /* | |
6334 * A ":help" command ends at the first LF, or at a '|' that is | |
6335 * followed by some text. Set nextcmd to the following command. | |
6336 */ | |
6337 for (arg = eap->arg; *arg; ++arg) | |
6338 { | |
6339 if (*arg == '\n' || *arg == '\r' | |
6340 || (*arg == '|' && arg[1] != NUL && arg[1] != '|')) | |
6341 { | |
6342 *arg++ = NUL; | |
6343 eap->nextcmd = arg; | |
6344 break; | |
6345 } | |
6346 } | |
6347 arg = eap->arg; | |
6348 | |
3446 | 6349 if (eap->forceit && *arg == NUL && !curbuf->b_help) |
7 | 6350 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
6351 emsg(_("E478: Don't panic!")); |
7 | 6352 return; |
6353 } | |
6354 | |
6355 if (eap->skip) /* not executing commands */ | |
6356 return; | |
6357 } | |
6358 else | |
6359 arg = (char_u *)""; | |
6360 | |
6361 /* remove trailing blanks */ | |
6362 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
|
6363 while (p > arg && VIM_ISWHITE(*p) && p[-1] != '\\') |
7 | 6364 *p-- = NUL; |
6365 | |
6366 #ifdef FEAT_MULTI_LANG | |
6367 /* Check for a specified language */ | |
9 | 6368 lang = check_help_lang(arg); |
7 | 6369 #endif |
6370 | |
6371 /* When no argument given go to the index. */ | |
6372 if (*arg == NUL) | |
6373 arg = (char_u *)"help.txt"; | |
6374 | |
6375 /* | |
6376 * Check if there is a match for the argument. | |
6377 */ | |
6378 n = find_help_tags(arg, &num_matches, &matches, | |
6379 eap != NULL && eap->forceit); | |
6380 | |
6381 i = 0; | |
6382 #ifdef FEAT_MULTI_LANG | |
6383 if (n != FAIL && lang != NULL) | |
6384 /* Find first item with the requested language. */ | |
6385 for (i = 0; i < num_matches; ++i) | |
6386 { | |
835 | 6387 len = (int)STRLEN(matches[i]); |
7 | 6388 if (len > 3 && matches[i][len - 3] == '@' |
6389 && STRICMP(matches[i] + len - 2, lang) == 0) | |
6390 break; | |
6391 } | |
6392 #endif | |
6393 if (i >= num_matches || n == FAIL) | |
6394 { | |
6395 #ifdef FEAT_MULTI_LANG | |
6396 if (lang != NULL) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
6397 semsg(_("E661: Sorry, no '%s' help for %s"), lang, arg); |
7 | 6398 else |
6399 #endif | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
6400 semsg(_("E149: Sorry, no help for %s"), arg); |
7 | 6401 if (n != FAIL) |
6402 FreeWild(num_matches, matches); | |
6403 return; | |
6404 } | |
6405 | |
6406 /* The first match (in the requested language) is the best match. */ | |
6407 tag = vim_strsave(matches[i]); | |
6408 FreeWild(num_matches, matches); | |
6409 | |
6410 #ifdef FEAT_GUI | |
6411 need_mouse_correct = TRUE; | |
6412 #endif | |
6413 | |
6414 /* | |
6415 * Re-use an existing help window or open a new one. | |
684 | 6416 * Always open a new one for ":tab help". |
7 | 6417 */ |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12297
diff
changeset
|
6418 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
|
6419 { |
684 | 6420 if (cmdmod.tab != 0) |
6421 wp = NULL; | |
6422 else | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
6423 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
|
6424 if (bt_help(wp->w_buffer)) |
684 | 6425 break; |
7 | 6426 if (wp != NULL && wp->w_buffer->b_nwindows > 0) |
6427 win_enter(wp, TRUE); | |
6428 else | |
6429 { | |
6430 /* | |
6431 * There is no help window yet. | |
6432 * Try to open the file specified by the "helpfile" option. | |
6433 */ | |
6434 if ((helpfd = mch_fopen((char *)p_hf, READBIN)) == NULL) | |
6435 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
6436 smsg(_("Sorry, help file \"%s\" not found"), p_hf); |
7 | 6437 goto erret; |
6438 } | |
6439 fclose(helpfd); | |
6440 | |
6441 /* Split off help window; put it at far top if no position | |
684 | 6442 * specified, the current window is vertically split and |
6443 * narrow. */ | |
7 | 6444 n = WSP_HELP; |
6445 if (cmdmod.split == 0 && curwin->w_width != Columns | |
684 | 6446 && curwin->w_width < 80) |
7 | 6447 n |= WSP_TOP; |
6448 if (win_split(0, n) == FAIL) | |
684 | 6449 goto erret; |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12297
diff
changeset
|
6450 |
7 | 6451 if (curwin->w_height < p_hh) |
6452 win_setheight((int)p_hh); | |
6453 | |
6454 /* | |
6455 * Open help file (do_ecmd() will set b_help flag, readfile() will | |
6456 * set b_p_ro flag). | |
6457 * Set the alternate file to the previously edited file. | |
6458 */ | |
6459 alt_fnum = curbuf->b_fnum; | |
6460 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_LASTL, | |
1743 | 6461 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
|
6462 NULL); /* buffer is still open, don't store info */ |
22 | 6463 if (!cmdmod.keepalt) |
6464 curwin->w_alt_fnum = alt_fnum; | |
7 | 6465 empty_fnum = curbuf->b_fnum; |
6466 } | |
6467 } | |
6468 | |
6469 if (!p_im) | |
6470 restart_edit = 0; /* don't want insert mode in help file */ | |
6471 | |
3112 | 6472 #ifdef FEAT_FOLDING |
6473 /* Restore KeyTyped, setting 'filetype=help' may reset it. | |
6474 * It is needed for do_tag top open folds under the cursor. */ | |
6475 KeyTyped = old_KeyTyped; | |
6476 #endif | |
6477 | |
7 | 6478 if (tag != NULL) |
6479 do_tag(tag, DT_HELP, 1, FALSE, TRUE); | |
6480 | |
819 | 6481 /* Delete the empty buffer if we're not using it. Careful: autocommands |
6482 * may have jumped to another window, check that the buffer is not in a | |
6483 * window. */ | |
7 | 6484 if (empty_fnum != 0 && curbuf->b_fnum != empty_fnum) |
6485 { | |
6486 buf = buflist_findnr(empty_fnum); | |
819 | 6487 if (buf != NULL && buf->b_nwindows == 0) |
7 | 6488 wipe_buffer(buf, TRUE); |
6489 } | |
6490 | |
6491 /* keep the previous alternate file */ | |
22 | 6492 if (alt_fnum != 0 && curwin->w_alt_fnum == empty_fnum && !cmdmod.keepalt) |
7 | 6493 curwin->w_alt_fnum = alt_fnum; |
6494 | |
6495 erret: | |
6496 vim_free(tag); | |
6497 } | |
6498 | |
6228 | 6499 /* |
6234 | 6500 * ":helpclose": Close one help window |
6228 | 6501 */ |
6502 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6503 ex_helpclose(exarg_T *eap UNUSED) |
6228 | 6504 { |
6505 win_T *win; | |
6506 | |
6507 FOR_ALL_WINDOWS(win) | |
6508 { | |
11800
5ceaecedbad2
patch 8.0.0782: using freed memory in quickfix code
Christian Brabandt <cb@256bit.org>
parents:
11666
diff
changeset
|
6509 if (bt_help(win->w_buffer)) |
6228 | 6510 { |
6511 win_close(win, FALSE); | |
6234 | 6512 return; |
6228 | 6513 } |
6514 } | |
6515 } | |
7 | 6516 |
9 | 6517 #if defined(FEAT_MULTI_LANG) || defined(PROTO) |
6518 /* | |
6519 * In an argument search for a language specifiers in the form "@xx". | |
6520 * Changes the "@" to NUL if found, and returns a pointer to "xx". | |
6521 * Returns NULL if not found. | |
6522 */ | |
6523 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6524 check_help_lang(char_u *arg) |
9 | 6525 { |
835 | 6526 int len = (int)STRLEN(arg); |
9 | 6527 |
6528 if (len >= 3 && arg[len - 3] == '@' && ASCII_ISALPHA(arg[len - 2]) | |
6529 && ASCII_ISALPHA(arg[len - 1])) | |
6530 { | |
6531 arg[len - 3] = NUL; /* remove the '@' */ | |
6532 return arg + len - 2; | |
6533 } | |
6534 return NULL; | |
6535 } | |
6536 #endif | |
6537 | |
7 | 6538 /* |
6539 * Return a heuristic indicating how well the given string matches. The | |
6540 * smaller the number, the better the match. This is the order of priorities, | |
6541 * from best match to worst match: | |
6542 * - Match with least alpha-numeric characters is better. | |
6543 * - Match with least total characters is better. | |
6544 * - Match towards the start is better. | |
6545 * - Match starting with "+" is worse (feature instead of command) | |
6546 * Assumption is made that the matched_string passed has already been found to | |
6547 * match some string for which help is requested. webb. | |
6548 */ | |
6549 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6550 help_heuristic( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6551 char_u *matched_string, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6552 int offset, /* offset for match */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6553 int wrong_case) /* no matching case */ |
7 | 6554 { |
6555 int num_letters; | |
6556 char_u *p; | |
6557 | |
6558 num_letters = 0; | |
6559 for (p = matched_string; *p; p++) | |
6560 if (ASCII_ISALNUM(*p)) | |
6561 num_letters++; | |
6562 | |
6563 /* | |
6564 * Multiply the number of letters by 100 to give it a much bigger | |
6565 * weighting than the number of characters. | |
6566 * If there only is a match while ignoring case, add 5000. | |
6567 * If the match starts in the middle of a word, add 10000 to put it | |
6568 * somewhere in the last half. | |
6569 * If the match is more than 2 chars from the start, multiply by 200 to | |
6570 * put it after matches at the start. | |
6571 */ | |
6572 if (ASCII_ISALNUM(matched_string[offset]) && offset > 0 | |
6573 && ASCII_ISALNUM(matched_string[offset - 1])) | |
6574 offset += 10000; | |
6575 else if (offset > 2) | |
6576 offset *= 200; | |
6577 if (wrong_case) | |
6578 offset += 5000; | |
6579 /* Features are less interesting than the subjects themselves, but "+" | |
6580 * alone is not a feature. */ | |
6581 if (matched_string[0] == '+' && matched_string[1] != NUL) | |
6582 offset += 100; | |
6583 return (int)(100 * num_letters + STRLEN(matched_string) + offset); | |
6584 } | |
6585 | |
6586 /* | |
6587 * Compare functions for qsort() below, that checks the help heuristics number | |
6588 * that has been put after the tagname by find_tags(). | |
6589 */ | |
6590 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6591 help_compare(const void *s1, const void *s2) |
7 | 6592 { |
6593 char *p1; | |
6594 char *p2; | |
6595 | |
6596 p1 = *(char **)s1 + strlen(*(char **)s1) + 1; | |
6597 p2 = *(char **)s2 + strlen(*(char **)s2) + 1; | |
6598 return strcmp(p1, p2); | |
6599 } | |
6600 | |
6601 /* | |
6602 * Find all help tags matching "arg", sort them and return in matches[], with | |
6603 * the number of matches in num_matches. | |
6604 * The matches will be sorted with a "best" match algorithm. | |
6605 * When "keep_lang" is TRUE try keeping the language of the current buffer. | |
6606 */ | |
6607 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6608 find_help_tags( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6609 char_u *arg, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6610 int *num_matches, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6611 char_u ***matches, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6612 int keep_lang) |
7 | 6613 { |
6614 char_u *s, *d; | |
6615 int i; | |
6616 static char *(mtable[]) = {"*", "g*", "[*", "]*", ":*", | |
445 | 6617 "/*", "/\\*", "\"*", "**", |
5269
7d1f89b27103
updated for version 7.4b.011
Bram Moolenaar <bram@vim.org>
parents:
5257
diff
changeset
|
6618 "cpo-*", "/\\(\\)", "/\\%(\\)", |
14443
e1c6aee62a72
patch 8.1.0235: more help tags that jump to the wrong location
Christian Brabandt <cb@256bit.org>
parents:
14435
diff
changeset
|
6619 "?", ":?", "?<CR>", "g?", "g?g?", "g??", |
e1c6aee62a72
patch 8.1.0235: more help tags that jump to the wrong location
Christian Brabandt <cb@256bit.org>
parents:
14435
diff
changeset
|
6620 "-?", "q?", "v_g?", |
279 | 6621 "/\\?", "/\\z(\\)", "\\=", ":s\\=", |
10851
256b1b96c2ad
patch 8.0.0315: :help :[range] does not work
Christian Brabandt <cb@256bit.org>
parents:
10638
diff
changeset
|
6622 "[count]", "[quotex]", |
256b1b96c2ad
patch 8.0.0315: :help :[range] does not work
Christian Brabandt <cb@256bit.org>
parents:
10638
diff
changeset
|
6623 "[range]", ":[range]", |
5647 | 6624 "[pattern]", "\\|", "\\%$", |
6625 "s/\\~", "s/\\U", "s/\\L", | |
6626 "s/\\1", "s/\\2", "s/\\3", "s/\\9"}; | |
7 | 6627 static char *(rtable[]) = {"star", "gstar", "[star", "]star", ":star", |
445 | 6628 "/star", "/\\\\star", "quotestar", "starstar", |
5269
7d1f89b27103
updated for version 7.4b.011
Bram Moolenaar <bram@vim.org>
parents:
5257
diff
changeset
|
6629 "cpo-star", "/\\\\(\\\\)", "/\\\\%(\\\\)", |
14443
e1c6aee62a72
patch 8.1.0235: more help tags that jump to the wrong location
Christian Brabandt <cb@256bit.org>
parents:
14435
diff
changeset
|
6630 "?", ":?", "?<CR>", "g?", "g?g?", "g??", |
e1c6aee62a72
patch 8.1.0235: more help tags that jump to the wrong location
Christian Brabandt <cb@256bit.org>
parents:
14435
diff
changeset
|
6631 "-?", "q?", "v_g?", |
279 | 6632 "/\\\\?", "/\\\\z(\\\\)", "\\\\=", ":s\\\\=", |
10851
256b1b96c2ad
patch 8.0.0315: :help :[range] does not work
Christian Brabandt <cb@256bit.org>
parents:
10638
diff
changeset
|
6633 "\\[count]", "\\[quotex]", |
256b1b96c2ad
patch 8.0.0315: :help :[range] does not work
Christian Brabandt <cb@256bit.org>
parents:
10638
diff
changeset
|
6634 "\\[range]", ":\\[range]", |
5647 | 6635 "\\[pattern]", "\\\\bar", "/\\\\%\\$", |
5867 | 6636 "s/\\\\\\~", "s/\\\\U", "s/\\\\L", |
5647 | 6637 "s/\\\\1", "s/\\\\2", "s/\\\\3", "s/\\\\9"}; |
14443
e1c6aee62a72
patch 8.1.0235: more help tags that jump to the wrong location
Christian Brabandt <cb@256bit.org>
parents:
14435
diff
changeset
|
6638 static char *(expr_table[]) = {"!=?", "!~?", "<=?", "<?", "==?", "=~?", |
e1c6aee62a72
patch 8.1.0235: more help tags that jump to the wrong location
Christian Brabandt <cb@256bit.org>
parents:
14435
diff
changeset
|
6639 ">=?", ">?", "is?", "isnot?"}; |
7 | 6640 int flags; |
6641 | |
6642 d = IObuff; /* assume IObuff is long enough! */ | |
6643 | |
14443
e1c6aee62a72
patch 8.1.0235: more help tags that jump to the wrong location
Christian Brabandt <cb@256bit.org>
parents:
14435
diff
changeset
|
6644 if (STRNICMP(arg, "expr-", 5) == 0) |
e1c6aee62a72
patch 8.1.0235: more help tags that jump to the wrong location
Christian Brabandt <cb@256bit.org>
parents:
14435
diff
changeset
|
6645 { |
e1c6aee62a72
patch 8.1.0235: more help tags that jump to the wrong location
Christian Brabandt <cb@256bit.org>
parents:
14435
diff
changeset
|
6646 // When the string starting with "expr-" and containing '?' and matches |
e1c6aee62a72
patch 8.1.0235: more help tags that jump to the wrong location
Christian Brabandt <cb@256bit.org>
parents:
14435
diff
changeset
|
6647 // the table, it is taken literally. Otherwise '?' is recognized as a |
e1c6aee62a72
patch 8.1.0235: more help tags that jump to the wrong location
Christian Brabandt <cb@256bit.org>
parents:
14435
diff
changeset
|
6648 // wildcard. |
e1c6aee62a72
patch 8.1.0235: more help tags that jump to the wrong location
Christian Brabandt <cb@256bit.org>
parents:
14435
diff
changeset
|
6649 for (i = (int)(sizeof(expr_table) / sizeof(char *)); --i >= 0; ) |
e1c6aee62a72
patch 8.1.0235: more help tags that jump to the wrong location
Christian Brabandt <cb@256bit.org>
parents:
14435
diff
changeset
|
6650 if (STRCMP(arg + 5, expr_table[i]) == 0) |
e1c6aee62a72
patch 8.1.0235: more help tags that jump to the wrong location
Christian Brabandt <cb@256bit.org>
parents:
14435
diff
changeset
|
6651 { |
e1c6aee62a72
patch 8.1.0235: more help tags that jump to the wrong location
Christian Brabandt <cb@256bit.org>
parents:
14435
diff
changeset
|
6652 STRCPY(d, arg); |
e1c6aee62a72
patch 8.1.0235: more help tags that jump to the wrong location
Christian Brabandt <cb@256bit.org>
parents:
14435
diff
changeset
|
6653 break; |
e1c6aee62a72
patch 8.1.0235: more help tags that jump to the wrong location
Christian Brabandt <cb@256bit.org>
parents:
14435
diff
changeset
|
6654 } |
e1c6aee62a72
patch 8.1.0235: more help tags that jump to the wrong location
Christian Brabandt <cb@256bit.org>
parents:
14435
diff
changeset
|
6655 } |
e1c6aee62a72
patch 8.1.0235: more help tags that jump to the wrong location
Christian Brabandt <cb@256bit.org>
parents:
14435
diff
changeset
|
6656 else |
e1c6aee62a72
patch 8.1.0235: more help tags that jump to the wrong location
Christian Brabandt <cb@256bit.org>
parents:
14435
diff
changeset
|
6657 { |
e1c6aee62a72
patch 8.1.0235: more help tags that jump to the wrong location
Christian Brabandt <cb@256bit.org>
parents:
14435
diff
changeset
|
6658 // Recognize a few exceptions to the rule. Some strings that contain |
e1c6aee62a72
patch 8.1.0235: more help tags that jump to the wrong location
Christian Brabandt <cb@256bit.org>
parents:
14435
diff
changeset
|
6659 // '*' with "star". Otherwise '*' is recognized as a wildcard. |
e1c6aee62a72
patch 8.1.0235: more help tags that jump to the wrong location
Christian Brabandt <cb@256bit.org>
parents:
14435
diff
changeset
|
6660 for (i = (int)(sizeof(mtable) / sizeof(char *)); --i >= 0; ) |
e1c6aee62a72
patch 8.1.0235: more help tags that jump to the wrong location
Christian Brabandt <cb@256bit.org>
parents:
14435
diff
changeset
|
6661 if (STRCMP(arg, mtable[i]) == 0) |
e1c6aee62a72
patch 8.1.0235: more help tags that jump to the wrong location
Christian Brabandt <cb@256bit.org>
parents:
14435
diff
changeset
|
6662 { |
e1c6aee62a72
patch 8.1.0235: more help tags that jump to the wrong location
Christian Brabandt <cb@256bit.org>
parents:
14435
diff
changeset
|
6663 STRCPY(d, rtable[i]); |
e1c6aee62a72
patch 8.1.0235: more help tags that jump to the wrong location
Christian Brabandt <cb@256bit.org>
parents:
14435
diff
changeset
|
6664 break; |
e1c6aee62a72
patch 8.1.0235: more help tags that jump to the wrong location
Christian Brabandt <cb@256bit.org>
parents:
14435
diff
changeset
|
6665 } |
e1c6aee62a72
patch 8.1.0235: more help tags that jump to the wrong location
Christian Brabandt <cb@256bit.org>
parents:
14435
diff
changeset
|
6666 } |
7 | 6667 |
6668 if (i < 0) /* no match in table */ | |
6669 { | |
6670 /* Replace "\S" with "/\\S", etc. Otherwise every tag is matched. | |
6671 * Also replace "\%^" and "\%(", they match every tag too. | |
6672 * Also "\zs", "\z1", etc. | |
6673 * Also "\@<", "\@=", "\@<=", etc. | |
6674 * And also "\_$" and "\_^". */ | |
6675 if (arg[0] == '\\' | |
6676 && ((arg[1] != NUL && arg[2] == NUL) | |
6677 || (vim_strchr((char_u *)"%_z@", arg[1]) != NULL | |
6678 && arg[2] != NUL))) | |
6679 { | |
6680 STRCPY(d, "/\\\\"); | |
6681 STRCPY(d + 3, arg + 1); | |
6682 /* Check for "/\\_$", should be "/\\_\$" */ | |
6683 if (d[3] == '_' && d[4] == '$') | |
6684 STRCPY(d + 4, "\\$"); | |
6685 } | |
6686 else | |
6687 { | |
3786 | 6688 /* Replace: |
6689 * "[:...:]" with "\[:...:]" | |
6690 * "[++...]" with "\[++...]" | |
5867 | 6691 * "\{" with "\\{" -- matching "} \}" |
3786 | 6692 */ |
6693 if ((arg[0] == '[' && (arg[1] == ':' | |
6694 || (arg[1] == '+' && arg[2] == '+'))) | |
6695 || (arg[0] == '\\' && arg[1] == '{')) | |
7 | 6696 *d++ = '\\'; |
6697 | |
8556
f4dca5239317
commit https://github.com/vim/vim/commit/00f9e0dbbd3472db217d56639fad9346b9eb3b82
Christian Brabandt <cb@256bit.org>
parents:
8544
diff
changeset
|
6698 /* |
f4dca5239317
commit https://github.com/vim/vim/commit/00f9e0dbbd3472db217d56639fad9346b9eb3b82
Christian Brabandt <cb@256bit.org>
parents:
8544
diff
changeset
|
6699 * 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
|
6700 */ |
f4dca5239317
commit https://github.com/vim/vim/commit/00f9e0dbbd3472db217d56639fad9346b9eb3b82
Christian Brabandt <cb@256bit.org>
parents:
8544
diff
changeset
|
6701 if (*arg == '(' && arg[1] == '\'') |
f4dca5239317
commit https://github.com/vim/vim/commit/00f9e0dbbd3472db217d56639fad9346b9eb3b82
Christian Brabandt <cb@256bit.org>
parents:
8544
diff
changeset
|
6702 arg++; |
7 | 6703 for (s = arg; *s; ++s) |
6704 { | |
6705 /* | |
6706 * Replace "|" with "bar" and '"' with "quote" to match the name of | |
6707 * the tags for these commands. | |
6708 * Replace "*" with ".*" and "?" with "." to match command line | |
6709 * completion. | |
6710 * Insert a backslash before '~', '$' and '.' to avoid their | |
6711 * special meaning. | |
6712 */ | |
6713 if (d - IObuff > IOSIZE - 10) /* getting too long!? */ | |
6714 break; | |
6715 switch (*s) | |
6716 { | |
6717 case '|': STRCPY(d, "bar"); | |
6718 d += 3; | |
6719 continue; | |
6720 case '"': STRCPY(d, "quote"); | |
6721 d += 5; | |
6722 continue; | |
6723 case '*': *d++ = '.'; | |
6724 break; | |
6725 case '?': *d++ = '.'; | |
6726 continue; | |
6727 case '$': | |
6728 case '.': | |
6729 case '~': *d++ = '\\'; | |
6730 break; | |
6731 } | |
6732 | |
6733 /* | |
6734 * Replace "^x" by "CTRL-X". Don't do this for "^_" to make | |
6735 * ":help i_^_CTRL-D" work. | |
6736 * Insert '-' before and after "CTRL-X" when applicable. | |
6737 */ | |
6738 if (*s < ' ' || (*s == '^' && s[1] && (ASCII_ISALPHA(s[1]) | |
6739 || vim_strchr((char_u *)"?@[\\]^", s[1]) != NULL))) | |
6740 { | |
5282
8c42772f0543
updated for version 7.4b.017
Bram Moolenaar <bram@vim.org>
parents:
5269
diff
changeset
|
6741 if (d > IObuff && d[-1] != '_' && d[-1] != '\\') |
8c42772f0543
updated for version 7.4b.017
Bram Moolenaar <bram@vim.org>
parents:
5269
diff
changeset
|
6742 *d++ = '_'; /* prepend a '_' to make x_CTRL-x */ |
7 | 6743 STRCPY(d, "CTRL-"); |
6744 d += 5; | |
6745 if (*s < ' ') | |
6746 { | |
6747 #ifdef EBCDIC | |
6748 *d++ = CtrlChar(*s); | |
6749 #else | |
6750 *d++ = *s + '@'; | |
6751 #endif | |
6752 if (d[-1] == '\\') | |
6753 *d++ = '\\'; /* double a backslash */ | |
6754 } | |
6755 else | |
6756 *d++ = *++s; | |
6757 if (s[1] != NUL && s[1] != '_') | |
6758 *d++ = '_'; /* append a '_' */ | |
6759 continue; | |
6760 } | |
6761 else if (*s == '^') /* "^" or "CTRL-^" or "^_" */ | |
6762 *d++ = '\\'; | |
6763 | |
6764 /* | |
6765 * Insert a backslash before a backslash after a slash, for search | |
6766 * pattern tags: "/\|" --> "/\\|". | |
6767 */ | |
6768 else if (s[0] == '\\' && s[1] != '\\' | |
6769 && *arg == '/' && s == arg + 1) | |
6770 *d++ = '\\'; | |
6771 | |
6772 /* "CTRL-\_" -> "CTRL-\\_" to avoid the special meaning of "\_" in | |
6773 * "CTRL-\_CTRL-N" */ | |
6774 if (STRNICMP(s, "CTRL-\\_", 7) == 0) | |
6775 { | |
6776 STRCPY(d, "CTRL-\\\\"); | |
6777 d += 7; | |
6778 s += 6; | |
6779 } | |
6780 | |
6781 *d++ = *s; | |
6782 | |
6783 /* | |
8883
b7de875169e6
commit https://github.com/vim/vim/commit/81edd171a9465cf99cede4fa4a7b7bca3d538b0f
Christian Brabandt <cb@256bit.org>
parents:
8879
diff
changeset
|
6784 * 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
|
6785 * 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
|
6786 */ |
b7de875169e6
commit https://github.com/vim/vim/commit/81edd171a9465cf99cede4fa4a7b7bca3d538b0f
Christian Brabandt <cb@256bit.org>
parents:
8879
diff
changeset
|
6787 if (*s == '(' && (s[1] == '{' || s[1] =='[')) |
b7de875169e6
commit https://github.com/vim/vim/commit/81edd171a9465cf99cede4fa4a7b7bca3d538b0f
Christian Brabandt <cb@256bit.org>
parents:
8879
diff
changeset
|
6788 break; |
b7de875169e6
commit https://github.com/vim/vim/commit/81edd171a9465cf99cede4fa4a7b7bca3d538b0f
Christian Brabandt <cb@256bit.org>
parents:
8879
diff
changeset
|
6789 |
b7de875169e6
commit https://github.com/vim/vim/commit/81edd171a9465cf99cede4fa4a7b7bca3d538b0f
Christian Brabandt <cb@256bit.org>
parents:
8879
diff
changeset
|
6790 /* |
7 | 6791 * If tag starts with ', toss everything after a second '. Fixes |
6792 * CTRL-] on 'option'. (would include the trailing '.'). | |
6793 */ | |
6794 if (*s == '\'' && s > arg && *arg == '\'') | |
6795 break; | |
9234
6e80397a592c
commit https://github.com/vim/vim/commit/28b942a064dd486cc241894b625ab72f5a5c6d1b
Christian Brabandt <cb@256bit.org>
parents:
8883
diff
changeset
|
6796 /* Also '{' and '}'. */ |
6e80397a592c
commit https://github.com/vim/vim/commit/28b942a064dd486cc241894b625ab72f5a5c6d1b
Christian Brabandt <cb@256bit.org>
parents:
8883
diff
changeset
|
6797 if (*s == '}' && s > arg && *arg == '{') |
6e80397a592c
commit https://github.com/vim/vim/commit/28b942a064dd486cc241894b625ab72f5a5c6d1b
Christian Brabandt <cb@256bit.org>
parents:
8883
diff
changeset
|
6798 break; |
7 | 6799 } |
6800 *d = NUL; | |
3480 | 6801 |
6802 if (*IObuff == '`') | |
6803 { | |
6804 if (d > IObuff + 2 && d[-1] == '`') | |
6805 { | |
6806 /* remove the backticks from `command` */ | |
6807 mch_memmove(IObuff, IObuff + 1, STRLEN(IObuff)); | |
6808 d[-2] = NUL; | |
6809 } | |
6810 else if (d > IObuff + 3 && d[-2] == '`' && d[-1] == ',') | |
6811 { | |
6812 /* remove the backticks and comma from `command`, */ | |
6813 mch_memmove(IObuff, IObuff + 1, STRLEN(IObuff)); | |
6814 d[-3] = NUL; | |
6815 } | |
6816 else if (d > IObuff + 4 && d[-3] == '`' | |
6817 && d[-2] == '\\' && d[-1] == '.') | |
6818 { | |
6819 /* remove the backticks and dot from `command`\. */ | |
6820 mch_memmove(IObuff, IObuff + 1, STRLEN(IObuff)); | |
6821 d[-4] = NUL; | |
6822 } | |
6823 } | |
7 | 6824 } |
6825 } | |
6826 | |
6827 *matches = (char_u **)""; | |
6828 *num_matches = 0; | |
16447
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
6829 flags = TAG_HELP | TAG_REGEXP | TAG_NAMES | TAG_VERBOSE | TAG_NO_TAGFUNC; |
7 | 6830 if (keep_lang) |
6831 flags |= TAG_KEEP_LANG; | |
1696 | 6832 if (find_tags(IObuff, num_matches, matches, flags, (int)MAXCOL, NULL) == OK |
7 | 6833 && *num_matches > 0) |
1696 | 6834 { |
7 | 6835 /* Sort the matches found on the heuristic number that is after the |
6836 * tag name. */ | |
6837 qsort((void *)*matches, (size_t)*num_matches, | |
6838 sizeof(char_u *), help_compare); | |
1696 | 6839 /* Delete more than TAG_MANY to reduce the size of the listing. */ |
6840 while (*num_matches > TAG_MANY) | |
6841 vim_free((*matches)[--*num_matches]); | |
6842 } | |
7 | 6843 return OK; |
6844 } | |
6845 | |
6846 /* | |
6365 | 6847 * Called when starting to edit a buffer for a help file. |
6848 */ | |
6849 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6850 prepare_help_buffer(void) |
6365 | 6851 { |
6852 char_u *p; | |
6853 | |
6854 curbuf->b_help = TRUE; | |
6855 #ifdef FEAT_QUICKFIX | |
6856 set_string_option_direct((char_u *)"buftype", -1, | |
6857 (char_u *)"help", OPT_FREE|OPT_LOCAL, 0); | |
6858 #endif | |
6859 | |
6860 /* | |
6861 * Always set these options after jumping to a help tag, because the | |
6862 * user may have an autocommand that gets in the way. | |
6863 * Accept all ASCII chars for keywords, except ' ', '*', '"', '|', and | |
6864 * latin1 word characters (for translated help files). | |
6865 * Only set it when needed, buf_init_chartab() is some work. | |
6866 */ | |
6867 p = | |
6868 #ifdef EBCDIC | |
6869 (char_u *)"65-255,^*,^|,^\""; | |
6870 #else | |
6871 (char_u *)"!-~,^*,^|,^\",192-255"; | |
6872 #endif | |
6873 if (STRCMP(curbuf->b_p_isk, p) != 0) | |
6874 { | |
6875 set_string_option_direct((char_u *)"isk", -1, p, OPT_FREE|OPT_LOCAL, 0); | |
6876 check_buf_options(curbuf); | |
6877 (void)buf_init_chartab(curbuf, FALSE); | |
6878 } | |
6879 | |
6415 | 6880 #ifdef FEAT_FOLDING |
6365 | 6881 /* Don't use the global foldmethod.*/ |
6882 set_string_option_direct((char_u *)"fdm", -1, (char_u *)"manual", | |
6883 OPT_FREE|OPT_LOCAL, 0); | |
6415 | 6884 #endif |
6365 | 6885 |
6886 curbuf->b_p_ts = 8; /* 'tabstop' is 8 */ | |
6887 curwin->w_p_list = FALSE; /* no list mode */ | |
6888 | |
6889 curbuf->b_p_ma = FALSE; /* not modifiable */ | |
6890 curbuf->b_p_bin = FALSE; /* reset 'bin' before reading file */ | |
6891 curwin->w_p_nu = 0; /* no line numbers */ | |
6892 curwin->w_p_rnu = 0; /* no relative line numbers */ | |
6893 RESET_BINDING(curwin); /* no scroll or cursor binding */ | |
6894 #ifdef FEAT_ARABIC | |
6895 curwin->w_p_arab = FALSE; /* no arabic mode */ | |
6896 #endif | |
6897 #ifdef FEAT_RIGHTLEFT | |
6898 curwin->w_p_rl = FALSE; /* help window is left-to-right */ | |
6899 #endif | |
6900 #ifdef FEAT_FOLDING | |
6901 curwin->w_p_fen = FALSE; /* No folding in the help window */ | |
6902 #endif | |
6903 #ifdef FEAT_DIFF | |
6904 curwin->w_p_diff = FALSE; /* No 'diff' */ | |
6905 #endif | |
6906 #ifdef FEAT_SPELL | |
6907 curwin->w_p_spell = FALSE; /* No spell checking */ | |
6908 #endif | |
6909 | |
6910 set_buflisted(FALSE); | |
6911 } | |
6912 | |
6913 /* | |
7 | 6914 * After reading a help file: May cleanup a help buffer when syntax |
6915 * highlighting is not used. | |
6916 */ | |
6917 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6918 fix_help_buffer(void) |
7 | 6919 { |
6920 linenr_T lnum; | |
6921 char_u *line; | |
6922 int in_example = FALSE; | |
6923 int len; | |
3141 | 6924 char_u *fname; |
7 | 6925 char_u *p; |
6926 char_u *rt; | |
6927 int mustfree; | |
6928 | |
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
|
6929 /* 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
|
6930 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
|
6931 { |
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11537
diff
changeset
|
6932 ++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
|
6933 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
|
6934 --curbuf_lock; |
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11537
diff
changeset
|
6935 } |
7 | 6936 |
6937 #ifdef FEAT_SYN_HL | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
6938 if (!syntax_present(curwin)) |
7 | 6939 #endif |
6940 { | |
6941 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) | |
6942 { | |
6943 line = ml_get_buf(curbuf, lnum, FALSE); | |
6944 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
|
6945 if (in_example && len > 0 && !VIM_ISWHITE(line[0])) |
7 | 6946 { |
6947 /* End of example: non-white or '<' in first column. */ | |
6948 if (line[0] == '<') | |
6949 { | |
6950 /* blank-out a '<' in the first column */ | |
6951 line = ml_get_buf(curbuf, lnum, TRUE); | |
6952 line[0] = ' '; | |
6953 } | |
6954 in_example = FALSE; | |
6955 } | |
6956 if (!in_example && len > 0) | |
6957 { | |
6958 if (line[len - 1] == '>' && (len == 1 || line[len - 2] == ' ')) | |
6959 { | |
6960 /* blank-out a '>' in the last column (start of example) */ | |
6961 line = ml_get_buf(curbuf, lnum, TRUE); | |
6962 line[len - 1] = ' '; | |
6963 in_example = TRUE; | |
6964 } | |
6965 else if (line[len - 1] == '~') | |
6966 { | |
6967 /* blank-out a '~' at the end of line (header marker) */ | |
6968 line = ml_get_buf(curbuf, lnum, TRUE); | |
6969 line[len - 1] = ' '; | |
6970 } | |
6971 } | |
6972 } | |
6973 } | |
6974 | |
6975 /* | |
3141 | 6976 * In the "help.txt" and "help.abx" file, add the locally added help |
6977 * files. This uses the very first line in the help file. | |
7 | 6978 */ |
3141 | 6979 fname = gettail(curbuf->b_fname); |
6980 if (fnamecmp(fname, "help.txt") == 0 | |
6981 #ifdef FEAT_MULTI_LANG | |
6982 || (fnamencmp(fname, "help.", 5) == 0 | |
6983 && ASCII_ISALPHA(fname[5]) | |
6984 && ASCII_ISALPHA(fname[6]) | |
6985 && TOLOWER_ASC(fname[7]) == 'x' | |
6986 && fname[8] == NUL) | |
6987 #endif | |
6988 ) | |
7 | 6989 { |
6990 for (lnum = 1; lnum < curbuf->b_ml.ml_line_count; ++lnum) | |
6991 { | |
6992 line = ml_get_buf(curbuf, lnum, FALSE); | |
3141 | 6993 if (strstr((char *)line, "*local-additions*") == NULL) |
6994 continue; | |
6995 | |
6996 /* Go through all directories in 'runtimepath', skipping | |
6997 * $VIMRUNTIME. */ | |
6998 p = p_rtp; | |
6999 while (*p != NUL) | |
7 | 7000 { |
3141 | 7001 copy_option_part(&p, NameBuff, MAXPATHL, ","); |
7002 mustfree = FALSE; | |
7003 rt = vim_getenv((char_u *)"VIMRUNTIME", &mustfree); | |
16738
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16716
diff
changeset
|
7004 if (rt != NULL && |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16716
diff
changeset
|
7005 fullpathcmp(rt, NameBuff, FALSE, TRUE) != FPC_SAME) |
7 | 7006 { |
3141 | 7007 int fcount; |
7008 char_u **fnames; | |
7009 FILE *fd; | |
7010 char_u *s; | |
7011 int fi; | |
7012 vimconv_T vc; | |
7013 char_u *cp; | |
7014 | |
7015 /* Find all "doc/ *.txt" files in this directory. */ | |
7016 add_pathsep(NameBuff); | |
7017 #ifdef FEAT_MULTI_LANG | |
7018 STRCAT(NameBuff, "doc/*.??[tx]"); | |
7 | 7019 #else |
3141 | 7020 STRCAT(NameBuff, "doc/*.txt"); |
7021 #endif | |
7022 if (gen_expand_wildcards(1, &NameBuff, &fcount, | |
7023 &fnames, EW_FILE|EW_SILENT) == OK | |
7024 && fcount > 0) | |
7025 { | |
7026 #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
|
7027 int i1, i2; |
e1deb00ffc27
patch 8.0.1383: local additions in help skips some files
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
7028 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
|
7029 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
|
7030 char_u *e1, *e2; |
3141 | 7031 |
7032 /* If foo.abx is found use it instead of foo.txt in | |
7033 * the same directory. */ | |
7034 for (i1 = 0; i1 < fcount; ++i1) | |
7035 { | |
7036 for (i2 = 0; i2 < fcount; ++i2) | |
7037 { | |
7038 if (i1 == i2) | |
7039 continue; | |
7040 if (fnames[i1] == NULL || fnames[i2] == NULL) | |
7041 continue; | |
7042 f1 = fnames[i1]; | |
7043 f2 = fnames[i2]; | |
7044 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
|
7045 t2 = gettail(f2); |
3141 | 7046 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
|
7047 e2 = vim_strrchr(t2, '.'); |
10299
7b2f95633e28
commit https://github.com/vim/vim/commit/7756e7465d627ff9cd01e59625484a8c302ef853
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
7048 if (e1 == NULL || e2 == NULL) |
3141 | 7049 continue; |
7050 if (fnamecmp(e1, ".txt") != 0 | |
7051 && fnamecmp(e1, fname + 4) != 0) | |
7052 { | |
7053 /* 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
|
7054 VIM_CLEAR(fnames[i1]); |
3141 | 7055 continue; |
7056 } | |
13014
e1deb00ffc27
patch 8.0.1383: local additions in help skips some files
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
7057 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
|
7058 || fnamencmp(f1, f2, e1 - f1) != 0) |
3141 | 7059 continue; |
7060 if (fnamecmp(e1, ".txt") == 0 | |
7061 && fnamecmp(e2, fname + 4) == 0) | |
7062 /* 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
|
7063 VIM_CLEAR(fnames[i1]); |
7 | 7064 } |
7065 } | |
3141 | 7066 #endif |
7067 for (fi = 0; fi < fcount; ++fi) | |
7068 { | |
7069 if (fnames[fi] == NULL) | |
7070 continue; | |
7071 fd = mch_fopen((char *)fnames[fi], "r"); | |
7072 if (fd != NULL) | |
7073 { | |
7074 vim_fgets(IObuff, IOSIZE, fd); | |
7075 if (IObuff[0] == '*' | |
7076 && (s = vim_strchr(IObuff + 1, '*')) | |
7077 != NULL) | |
7078 { | |
7079 int this_utf = MAYBE; | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
7080 |
3141 | 7081 /* Change tag definition to a |
7082 * reference and remove <CR>/<NL>. */ | |
7083 IObuff[0] = '|'; | |
7084 *s = '|'; | |
7085 while (*s != NUL) | |
7086 { | |
7087 if (*s == '\r' || *s == '\n') | |
7088 *s = NUL; | |
7089 /* The text is utf-8 when a byte | |
7090 * above 127 is found and no | |
7091 * illegal byte sequence is found. | |
7092 */ | |
7093 if (*s >= 0x80 && this_utf != FALSE) | |
7094 { | |
7095 int l; | |
7096 | |
7097 this_utf = TRUE; | |
7098 l = utf_ptr2len(s); | |
7099 if (l == 1) | |
7100 this_utf = FALSE; | |
7101 s += l - 1; | |
7102 } | |
7103 ++s; | |
7104 } | |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
7105 |
3141 | 7106 /* The help file is latin1 or utf-8; |
7107 * conversion to the current | |
7108 * 'encoding' may be required. */ | |
7109 vc.vc_type = CONV_NONE; | |
7110 convert_setup(&vc, (char_u *)( | |
7111 this_utf == TRUE ? "utf-8" | |
7112 : "latin1"), p_enc); | |
7113 if (vc.vc_type == CONV_NONE) | |
7114 /* No conversion needed. */ | |
7115 cp = IObuff; | |
7116 else | |
7117 { | |
7118 /* Do the conversion. If it fails | |
7119 * use the unconverted text. */ | |
7120 cp = string_convert(&vc, IObuff, | |
7121 NULL); | |
7122 if (cp == NULL) | |
7123 cp = IObuff; | |
7124 } | |
7125 convert_setup(&vc, NULL, NULL); | |
7126 | |
7127 ml_append(lnum, cp, (colnr_T)0, FALSE); | |
7128 if (cp != IObuff) | |
7129 vim_free(cp); | |
7130 ++lnum; | |
7131 } | |
7132 fclose(fd); | |
7133 } | |
7134 } | |
7135 FreeWild(fcount, fnames); | |
7 | 7136 } |
7137 } | |
3141 | 7138 if (mustfree) |
7139 vim_free(rt); | |
7 | 7140 } |
3141 | 7141 break; |
7 | 7142 } |
7143 } | |
7144 } | |
7145 | |
40 | 7146 /* |
7147 * ":exusage" | |
7148 */ | |
7149 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7150 ex_exusage(exarg_T *eap UNUSED) |
40 | 7151 { |
7152 do_cmdline_cmd((char_u *)"help ex-cmd-index"); | |
7153 } | |
7154 | |
7155 /* | |
7156 * ":viusage" | |
7157 */ | |
7158 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7159 ex_viusage(exarg_T *eap UNUSED) |
40 | 7160 { |
7161 do_cmdline_cmd((char_u *)"help normal-index"); | |
7162 } | |
7163 | |
7 | 7164 /* |
8522
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7165 * Generate tags in one help directory. |
7 | 7166 */ |
7167 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7168 helptags_one( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7169 char_u *dir, /* doc directory */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7170 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
|
7171 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
|
7172 int add_help_tags) /* add "help-tags" tag */ |
7 | 7173 { |
7174 FILE *fd_tags; | |
7175 FILE *fd; | |
7176 garray_T ga; | |
7177 int filecount; | |
7178 char_u **files; | |
7179 char_u *p1, *p2; | |
7180 int fi; | |
7181 char_u *s; | |
7182 int i; | |
7183 char_u *fname; | |
3957 | 7184 int dirlen; |
7 | 7185 int utf8 = MAYBE; |
7186 int this_utf8; | |
7187 int firstline; | |
7188 int mix = FALSE; /* detected mixed encodings */ | |
7189 | |
7190 /* | |
7191 * Find all *.txt files. | |
7192 */ | |
3978 | 7193 dirlen = (int)STRLEN(dir); |
7 | 7194 STRCPY(NameBuff, dir); |
3957 | 7195 STRCAT(NameBuff, "/**/*"); |
7 | 7196 STRCAT(NameBuff, ext); |
7197 if (gen_expand_wildcards(1, &NameBuff, &filecount, &files, | |
7198 EW_FILE|EW_SILENT) == FAIL | |
7199 || filecount == 0) | |
7200 { | |
7201 if (!got_int) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
7202 semsg(_("E151: No match: %s"), NameBuff); |
7 | 7203 return; |
7204 } | |
7205 | |
7206 /* | |
7207 * Open the tags file for writing. | |
7208 * Do this before scanning through all the files. | |
7209 */ | |
7210 STRCPY(NameBuff, dir); | |
7211 add_pathsep(NameBuff); | |
7212 STRCAT(NameBuff, tagfname); | |
531 | 7213 fd_tags = mch_fopen((char *)NameBuff, "w"); |
7 | 7214 if (fd_tags == NULL) |
7215 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
7216 semsg(_("E152: Cannot open %s for writing"), NameBuff); |
7 | 7217 FreeWild(filecount, files); |
7218 return; | |
7219 } | |
7220 | |
7221 /* | |
1502 | 7222 * If using the "++t" argument or generating tags for "$VIMRUNTIME/doc" |
7223 * add the "help-tags" tag. | |
7 | 7224 */ |
7225 ga_init2(&ga, (int)sizeof(char_u *), 100); | |
1502 | 7226 if (add_help_tags || fullpathcmp((char_u *)"$VIMRUNTIME/doc", |
16738
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16716
diff
changeset
|
7227 dir, FALSE, TRUE) == FPC_SAME) |
7 | 7228 { |
7229 if (ga_grow(&ga, 1) == FAIL) | |
7230 got_int = TRUE; | |
7231 else | |
7232 { | |
835 | 7233 s = alloc(18 + (unsigned)STRLEN(tagfname)); |
7 | 7234 if (s == NULL) |
7235 got_int = TRUE; | |
7236 else | |
7237 { | |
7238 sprintf((char *)s, "help-tags\t%s\t1\n", tagfname); | |
7239 ((char_u **)ga.ga_data)[ga.ga_len] = s; | |
7240 ++ga.ga_len; | |
7241 } | |
7242 } | |
7243 } | |
7244 | |
7245 /* | |
7246 * Go over all the files and extract the tags. | |
7247 */ | |
7248 for (fi = 0; fi < filecount && !got_int; ++fi) | |
7249 { | |
531 | 7250 fd = mch_fopen((char *)files[fi], "r"); |
7 | 7251 if (fd == NULL) |
7252 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
7253 semsg(_("E153: Unable to open %s for reading"), files[fi]); |
7 | 7254 continue; |
7255 } | |
3957 | 7256 fname = files[fi] + dirlen + 1; |
7 | 7257 |
7258 firstline = TRUE; | |
7259 while (!vim_fgets(IObuff, IOSIZE, fd) && !got_int) | |
7260 { | |
7261 if (firstline) | |
7262 { | |
7263 /* Detect utf-8 file by a non-ASCII char in the first line. */ | |
7264 this_utf8 = MAYBE; | |
7265 for (s = IObuff; *s != NUL; ++s) | |
7266 if (*s >= 0x80) | |
7267 { | |
7268 int l; | |
7269 | |
7270 this_utf8 = TRUE; | |
474 | 7271 l = utf_ptr2len(s); |
7 | 7272 if (l == 1) |
7273 { | |
7274 /* Illegal UTF-8 byte sequence. */ | |
7275 this_utf8 = FALSE; | |
7276 break; | |
7277 } | |
7278 s += l - 1; | |
7279 } | |
7280 if (this_utf8 == MAYBE) /* only ASCII characters found */ | |
7281 this_utf8 = FALSE; | |
7282 if (utf8 == MAYBE) /* first file */ | |
7283 utf8 = this_utf8; | |
7284 else if (utf8 != this_utf8) | |
7285 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
7286 semsg(_("E670: Mix of help file encodings within a language: %s"), files[fi]); |
7 | 7287 mix = !got_int; |
7288 got_int = TRUE; | |
7289 } | |
7290 firstline = FALSE; | |
7291 } | |
7292 p1 = vim_strchr(IObuff, '*'); /* find first '*' */ | |
7293 while (p1 != NULL) | |
7294 { | |
3514 | 7295 /* Use vim_strbyte() instead of vim_strchr() so that when |
7296 * 'encoding' is dbcs it still works, don't find '*' in the | |
7297 * second byte. */ | |
7298 p2 = vim_strbyte(p1 + 1, '*'); /* find second '*' */ | |
7 | 7299 if (p2 != NULL && p2 > p1 + 1) /* skip "*" and "**" */ |
7300 { | |
7301 for (s = p1 + 1; s < p2; ++s) | |
7302 if (*s == ' ' || *s == '\t' || *s == '|') | |
7303 break; | |
7304 | |
7305 /* | |
7306 * Only accept a *tag* when it consists of valid | |
7307 * characters, there is white space before it and is | |
7308 * followed by a white character or end-of-line. | |
7309 */ | |
7310 if (s == p2 | |
7311 && (p1 == IObuff || p1[-1] == ' ' || p1[-1] == '\t') | |
7312 && (vim_strchr((char_u *)" \t\n\r", s[1]) != NULL | |
7313 || s[1] == '\0')) | |
7314 { | |
7315 *p2 = '\0'; | |
7316 ++p1; | |
7317 if (ga_grow(&ga, 1) == FAIL) | |
7318 { | |
7319 got_int = TRUE; | |
7320 break; | |
7321 } | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
7322 s = alloc(p2 - p1 + STRLEN(fname) + 2); |
7 | 7323 if (s == NULL) |
7324 { | |
7325 got_int = TRUE; | |
7326 break; | |
7327 } | |
7328 ((char_u **)ga.ga_data)[ga.ga_len] = s; | |
7329 ++ga.ga_len; | |
7330 sprintf((char *)s, "%s\t%s", p1, fname); | |
7331 | |
7332 /* find next '*' */ | |
7333 p2 = vim_strchr(p2 + 1, '*'); | |
7334 } | |
7335 } | |
7336 p1 = p2; | |
7337 } | |
7338 line_breakcheck(); | |
7339 } | |
7340 | |
7341 fclose(fd); | |
7342 } | |
7343 | |
7344 FreeWild(filecount, files); | |
7345 | |
7346 if (!got_int) | |
7347 { | |
7348 /* | |
7349 * Sort the tags. | |
7350 */ | |
7009 | 7351 if (ga.ga_data != NULL) |
7352 sort_strings((char_u **)ga.ga_data, ga.ga_len); | |
7 | 7353 |
7354 /* | |
7355 * Check for duplicates. | |
7356 */ | |
7357 for (i = 1; i < ga.ga_len; ++i) | |
7358 { | |
7359 p1 = ((char_u **)ga.ga_data)[i - 1]; | |
7360 p2 = ((char_u **)ga.ga_data)[i]; | |
7361 while (*p1 == *p2) | |
7362 { | |
7363 if (*p2 == '\t') | |
7364 { | |
7365 *p2 = NUL; | |
274 | 7366 vim_snprintf((char *)NameBuff, MAXPATHL, |
7 | 7367 _("E154: Duplicate tag \"%s\" in file %s/%s"), |
7368 ((char_u **)ga.ga_data)[i], dir, p2 + 1); | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
7369 emsg((char *)NameBuff); |
7 | 7370 *p2 = '\t'; |
7371 break; | |
7372 } | |
7373 ++p1; | |
7374 ++p2; | |
7375 } | |
7376 } | |
7377 | |
7378 if (utf8 == TRUE) | |
7379 fprintf(fd_tags, "!_TAG_FILE_ENCODING\tutf-8\t//\n"); | |
7380 | |
7381 /* | |
7382 * Write the tags into the file. | |
7383 */ | |
7384 for (i = 0; i < ga.ga_len; ++i) | |
7385 { | |
7386 s = ((char_u **)ga.ga_data)[i]; | |
1325 | 7387 if (STRNCMP(s, "help-tags\t", 10) == 0) |
7 | 7388 /* help-tags entry was added in formatted form */ |
1325 | 7389 fputs((char *)s, fd_tags); |
7 | 7390 else |
7391 { | |
7392 fprintf(fd_tags, "%s\t/*", s); | |
7393 for (p1 = s; *p1 != '\t'; ++p1) | |
7394 { | |
7395 /* insert backslash before '\\' and '/' */ | |
7396 if (*p1 == '\\' || *p1 == '/') | |
7397 putc('\\', fd_tags); | |
7398 putc(*p1, fd_tags); | |
7399 } | |
7400 fprintf(fd_tags, "*\n"); | |
7401 } | |
7402 } | |
7403 } | |
7404 if (mix) | |
7405 got_int = FALSE; /* continue with other languages */ | |
7406 | |
7407 for (i = 0; i < ga.ga_len; ++i) | |
7408 vim_free(((char_u **)ga.ga_data)[i]); | |
7409 ga_clear(&ga); | |
7410 fclose(fd_tags); /* there is no check for an error... */ | |
7411 } | |
7412 | |
8522
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7413 /* |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7414 * 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
|
7415 */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7416 static void |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7417 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
|
7418 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7419 #ifdef FEAT_MULTI_LANG |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7420 int len; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7421 int i, j; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7422 garray_T ga; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7423 char_u lang[2]; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7424 char_u ext[5]; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7425 char_u fname[8]; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7426 int filecount; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7427 char_u **files; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7428 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7429 /* 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
|
7430 STRCPY(NameBuff, dirname); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7431 add_pathsep(NameBuff); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7432 STRCAT(NameBuff, "**"); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7433 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
|
7434 EW_FILE|EW_SILENT) == FAIL |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7435 || filecount == 0) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7436 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
7437 semsg(_("E151: No match: %s"), NameBuff); |
8522
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7438 return; |
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 /* 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
|
7442 * present. */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7443 ga_init2(&ga, 1, 10); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7444 for (i = 0; i < filecount; ++i) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7445 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7446 len = (int)STRLEN(files[i]); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7447 if (len > 4) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7448 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7449 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
|
7450 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7451 /* ".txt" -> language "en" */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7452 lang[0] = 'e'; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7453 lang[1] = 'n'; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7454 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7455 else if (files[i][len - 4] == '.' |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7456 && ASCII_ISALPHA(files[i][len - 3]) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7457 && ASCII_ISALPHA(files[i][len - 2]) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7458 && 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
|
7459 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7460 /* ".abx" -> language "ab" */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7461 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
|
7462 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
|
7463 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7464 else |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7465 continue; |
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 /* Did we find this language already? */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7468 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
|
7469 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
|
7470 break; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7471 if (j == ga.ga_len) |
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 /* New language, add it. */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7474 if (ga_grow(&ga, 2) == FAIL) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7475 break; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7476 ((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
|
7477 ((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
|
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 } |
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 /* |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7483 * 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
|
7484 */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7485 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
|
7486 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7487 STRCPY(fname, "tags-xx"); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7488 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
|
7489 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
|
7490 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
|
7491 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7492 /* 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
|
7493 fname[4] = NUL; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7494 STRCPY(ext, ".txt"); |
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 else |
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 /* 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
|
7499 STRCPY(ext, ".xxx"); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7500 ext[1] = fname[5]; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7501 ext[2] = fname[6]; |
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 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
|
7504 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7505 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7506 ga_clear(&ga); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7507 FreeWild(filecount, files); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7508 |
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 /* 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
|
7511 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
|
7512 #endif |
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 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7515 static void |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7516 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
|
7517 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7518 do_helptags(fname, *(int *)cookie); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7519 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7520 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7521 /* |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7522 * ":helptags" |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7523 */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7524 void |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7525 ex_helptags(exarg_T *eap) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7526 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7527 expand_T xpc; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7528 char_u *dirname; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7529 int add_help_tags = FALSE; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7530 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7531 /* 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
|
7532 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
|
7533 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7534 add_help_tags = TRUE; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7535 eap->arg = skipwhite(eap->arg + 3); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7536 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7537 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7538 if (STRCMP(eap->arg, "ALL") == 0) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7539 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7540 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
|
7541 helptags_cb, &add_help_tags); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7542 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7543 else |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7544 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7545 ExpandInit(&xpc); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7546 xpc.xp_context = EXPAND_DIRECTORIES; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7547 dirname = ExpandOne(&xpc, eap->arg, NULL, |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7548 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
|
7549 if (dirname == NULL || !mch_isdir(dirname)) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15367
diff
changeset
|
7550 semsg(_("E150: Not a directory: %s"), eap->arg); |
8522
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7551 else |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7552 do_helptags(dirname, add_help_tags); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7553 vim_free(dirname); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7554 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7555 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7556 |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7557 /* |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7558 * Make the user happy. |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7559 */ |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7560 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7561 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
|
7562 { |
8879
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
7563 static char *code[] = { |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
7564 "\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
|
7565 "\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
|
7566 }; |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7567 char *p; |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7568 int n; |
8879
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
7569 int i; |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7570 |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7571 msg_start(); |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7572 msg_putchar('\n'); |
8879
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
7573 for (i = 0; i < 2; ++i) |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
7574 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
|
7575 if (*p == 'x') |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
7576 msg_putchar('\n'); |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
7577 else |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
7578 for (n = *p++; n > 0; --n) |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
7579 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
|
7580 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
|
7581 else |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
7582 msg_putchar(*p); |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7583 msg_clr_eos(); |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7584 } |
7 | 7585 |
7586 /* | |
7587 * ":drop" | |
7588 * Opens the first argument in a window. When there are two or more arguments | |
7589 * the argument list is redefined. | |
7590 */ | |
7591 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7592 ex_drop(exarg_T *eap) |
7 | 7593 { |
7594 int split = FALSE; | |
7595 win_T *wp; | |
7596 buf_T *buf; | |
735 | 7597 tabpage_T *tp; |
7 | 7598 |
7599 /* | |
7600 * Check if the first argument is already being edited in a window. If | |
7601 * so, jump to that window. | |
7602 * We would actually need to check all arguments, but that's complicated | |
7603 * and mostly only one file is dropped. | |
7604 * This also ignores wildcards, since it is very unlikely the user is | |
7605 * editing a file name with a wildcard character. | |
7606 */ | |
735 | 7607 set_arglist(eap->arg); |
7608 | |
1067 | 7609 /* |
7610 * Expanding wildcards may result in an empty argument list. E.g. when | |
7611 * editing "foo.pyc" and ".pyc" is in 'wildignore'. Assume that we | |
7612 * already did an error message for this. | |
7613 */ | |
7614 if (ARGCOUNT == 0) | |
7615 return; | |
7616 | |
735 | 7617 if (cmdmod.tab) |
7618 { | |
7619 /* ":tab drop file ...": open a tab for each argument that isn't | |
7620 * edited in a window yet. It's like ":tab all" but without closing | |
7621 * windows or tabs. */ | |
7622 ex_all(eap); | |
7623 } | |
7624 else | |
7625 { | |
7626 /* ":drop file ...": Edit the first argument. Jump to an existing | |
7627 * window if possible, edit in current window if the current buffer | |
7628 * can be abandoned, otherwise open a new window. */ | |
7629 buf = buflist_findnr(ARGLIST[0].ae_fnum); | |
7630 | |
7631 FOR_ALL_TAB_WINDOWS(tp, wp) | |
7632 { | |
7633 if (wp->w_buffer == buf) | |
7 | 7634 { |
825 | 7635 goto_tabpage_win(tp, wp); |
7 | 7636 curwin->w_arg_idx = 0; |
7637 return; | |
7638 } | |
7639 } | |
735 | 7640 |
7641 /* | |
7642 * Check whether the current buffer is changed. If so, we will need | |
7643 * to split the current window or data could be lost. | |
7644 * Skip the check if the 'hidden' option is set, as in this case the | |
7645 * buffer won't be lost. | |
7646 */ | |
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
|
7647 if (!buf_hide(curbuf)) |
735 | 7648 { |
7649 ++emsg_off; | |
5464 | 7650 split = check_changed(curbuf, CCGD_AW | CCGD_EXCMD); |
735 | 7651 --emsg_off; |
7652 } | |
7653 | |
7654 /* Fake a ":sfirst" or ":first" command edit the first argument. */ | |
7655 if (split) | |
7656 { | |
7657 eap->cmdidx = CMD_sfirst; | |
7658 eap->cmd[0] = 's'; | |
7659 } | |
7660 else | |
7661 eap->cmdidx = CMD_first; | |
7662 ex_rewind(eap); | |
7663 } | |
7 | 7664 } |
9915
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7665 |
9931
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7666 /* |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7667 * 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
|
7668 * 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
|
7669 * 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
|
7670 * 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
|
7671 * 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
|
7672 */ |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7673 char_u * |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7674 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
|
7675 { |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7676 int c; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7677 |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7678 if (vim_isIDc(*p)) |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7679 { |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7680 /* ":vimgrep pattern fname" */ |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7681 if (s != NULL) |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7682 *s = p; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7683 p = skiptowhite(p); |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7684 if (s != NULL && *p != NUL) |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7685 *p++ = NUL; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7686 } |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7687 else |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7688 { |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7689 /* ":vimgrep /pattern/[g][j] fname" */ |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7690 if (s != NULL) |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7691 *s = p + 1; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7692 c = *p; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7693 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
|
7694 if (*p != c) |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7695 return NULL; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7696 |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7697 /* Truncate the pattern. */ |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7698 if (s != NULL) |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7699 *p = NUL; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7700 ++p; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7701 |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7702 /* Find the flags */ |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7703 while (*p == 'g' || *p == 'j') |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7704 { |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7705 if (flags != NULL) |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7706 { |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7707 if (*p == 'g') |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7708 *flags |= VGR_GLOBAL; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7709 else |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7710 *flags |= VGR_NOJUMP; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7711 } |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7712 ++p; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7713 } |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7714 } |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7715 return p; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7716 } |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
7717 |
9915
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7718 #if defined(FEAT_EVAL) || defined(PROTO) |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7719 /* |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7720 * 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
|
7721 */ |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7722 void |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7723 ex_oldfiles(exarg_T *eap UNUSED) |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7724 { |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7725 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
|
7726 listitem_T *li; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7727 int nr = 0; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7728 char_u *fname; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7729 |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7730 if (l == NULL) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
7731 msg(_("No old files")); |
9915
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7732 else |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7733 { |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7734 msg_start(); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7735 msg_scroll = TRUE; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7736 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
|
7737 { |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7738 ++nr; |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15209
diff
changeset
|
7739 fname = tv_get_string(&li->li_tv); |
9945
d63a89b526ea
commit https://github.com/vim/vim/commit/d6f2ee32dcfa18c781ef157918b524318a2215a2
Christian Brabandt <cb@256bit.org>
parents:
9931
diff
changeset
|
7740 if (!message_filtered(fname)) |
9915
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7741 { |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7742 msg_outnum((long)nr); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
7743 msg_puts(": "); |
9915
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7744 msg_outtrans(fname); |
10021
5fc4bec66c33
commit https://github.com/vim/vim/commit/885c00eabe6d1fd757d4f0eb531ad3a15a35ec04
Christian Brabandt <cb@256bit.org>
parents:
9980
diff
changeset
|
7745 msg_clr_eos(); |
9915
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7746 msg_putchar('\n'); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7747 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
|
7748 ui_breakcheck(); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7749 } |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7750 } |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7751 |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7752 /* 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
|
7753 got_int = FALSE; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7754 |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7755 # ifdef FEAT_BROWSE_CMD |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7756 if (cmdmod.browse) |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7757 { |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7758 quit_more = FALSE; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7759 nr = prompt_for_number(FALSE); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7760 msg_starthere(); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7761 if (nr > 0) |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7762 { |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7763 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
|
7764 (long)nr); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7765 |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7766 if (p != NULL) |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7767 { |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7768 p = expand_env_save(p); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7769 eap->arg = p; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7770 eap->cmdidx = CMD_edit; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7771 cmdmod.browse = FALSE; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7772 do_exedit(eap, NULL); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7773 vim_free(p); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7774 } |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7775 } |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7776 } |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7777 # endif |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7778 } |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7779 } |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
7780 #endif |