Mercurial > vim
annotate src/ex_cmds.c @ 11121:778c10516955 v8.0.0448
patch 8.0.0448: some macros are in lower case
commit https://github.com/vim/vim/commit/b5aedf3e228d35821591da9ae8501b61cf2e264c
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Mar 12 18:23:53 2017 +0100
patch 8.0.0448: some macros are in lower case
Problem: Some macros are in lower case, which can be confusing.
Solution: Make a few lower case macros upper case.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 12 Mar 2017 18:30:06 +0100 |
parents | ab9f7bbe4439 |
children | 9bfc9d7b07a7 |
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); |
7 | 31 #ifdef FEAT_AUTOCMD |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
32 static void delbuf_msg(char_u *name); |
7 | 33 #endif |
34 static int | |
35 #ifdef __BORLANDC__ | |
36 _RTLENTRYF | |
37 #endif | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
38 help_compare(const void *s1, const void *s2); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
39 static void prepare_help_buffer(void); |
7 | 40 |
41 /* | |
42 * ":ascii" and "ga". | |
43 */ | |
44 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
45 do_ascii(exarg_T *eap UNUSED) |
7 | 46 { |
47 int c; | |
1784 | 48 int cval; |
7 | 49 char buf1[20]; |
50 char buf2[20]; | |
51 char_u buf3[7]; | |
52 #ifdef FEAT_MBYTE | |
714 | 53 int cc[MAX_MCO]; |
54 int ci = 0; | |
7 | 55 int len; |
56 | |
57 if (enc_utf8) | |
714 | 58 c = utfc_ptr2char(ml_get_cursor(), cc); |
7 | 59 else |
60 #endif | |
61 c = gchar_cursor(); | |
62 if (c == NUL) | |
63 { | |
64 MSG("NUL"); | |
65 return; | |
66 } | |
67 | |
68 #ifdef FEAT_MBYTE | |
69 IObuff[0] = NUL; | |
70 if (!has_mbyte || (enc_dbcs != 0 && c < 0x100) || c < 0x80) | |
71 #endif | |
72 { | |
73 if (c == NL) /* NUL is stored as NL */ | |
74 c = NUL; | |
1784 | 75 if (c == CAR && get_fileformat(curbuf) == EOL_MAC) |
76 cval = NL; /* NL is stored as CR */ | |
77 else | |
78 cval = c; | |
7 | 79 if (vim_isprintc_strict(c) && (c < ' ' |
80 #ifndef EBCDIC | |
81 || c > '~' | |
82 #endif | |
83 )) | |
84 { | |
85 transchar_nonprint(buf3, c); | |
1872 | 86 vim_snprintf(buf1, sizeof(buf1), " <%s>", (char *)buf3); |
7 | 87 } |
88 else | |
89 buf1[0] = NUL; | |
90 #ifndef EBCDIC | |
91 if (c >= 0x80) | |
1872 | 92 vim_snprintf(buf2, sizeof(buf2), " <M-%s>", |
93 (char *)transchar(c & 0x7f)); | |
7 | 94 else |
95 #endif | |
96 buf2[0] = NUL; | |
274 | 97 vim_snprintf((char *)IObuff, IOSIZE, |
98 _("<%s>%s%s %d, Hex %02x, Octal %03o"), | |
1784 | 99 transchar(c), buf1, buf2, cval, cval, cval); |
7 | 100 #ifdef FEAT_MBYTE |
963 | 101 if (enc_utf8) |
102 c = cc[ci++]; | |
103 else | |
104 c = 0; | |
7 | 105 #endif |
106 } | |
107 | |
108 #ifdef FEAT_MBYTE | |
109 /* Repeat for combining characters. */ | |
110 while (has_mbyte && (c >= 0x100 || (enc_utf8 && c >= 0x80))) | |
111 { | |
112 len = (int)STRLEN(IObuff); | |
113 /* This assumes every multi-byte char is printable... */ | |
114 if (len > 0) | |
115 IObuff[len++] = ' '; | |
116 IObuff[len++] = '<'; | |
963 | 117 if (enc_utf8 && utf_iscomposing(c) |
625 | 118 # ifdef USE_GUI |
7 | 119 && !gui.in_use |
625 | 120 # endif |
7 | 121 ) |
122 IObuff[len++] = ' '; /* draw composing char on top of a space */ | |
274 | 123 len += (*mb_char2bytes)(c, IObuff + len); |
124 vim_snprintf((char *)IObuff + len, IOSIZE - len, | |
7 | 125 c < 0x10000 ? _("> %d, Hex %04x, Octal %o") |
126 : _("> %d, Hex %08x, Octal %o"), c, c, c); | |
714 | 127 if (ci == MAX_MCO) |
128 break; | |
963 | 129 if (enc_utf8) |
130 c = cc[ci++]; | |
131 else | |
132 c = 0; | |
7 | 133 } |
134 #endif | |
135 | |
136 msg(IObuff); | |
137 } | |
138 | |
139 /* | |
140 * ":left", ":center" and ":right": align text. | |
141 */ | |
142 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
143 ex_align(exarg_T *eap) |
7 | 144 { |
145 pos_T save_curpos; | |
146 int len; | |
147 int indent = 0; | |
148 int new_indent; | |
149 int has_tab; | |
150 int width; | |
151 | |
152 #ifdef FEAT_RIGHTLEFT | |
153 if (curwin->w_p_rl) | |
154 { | |
155 /* switch left and right aligning */ | |
156 if (eap->cmdidx == CMD_right) | |
157 eap->cmdidx = CMD_left; | |
158 else if (eap->cmdidx == CMD_left) | |
159 eap->cmdidx = CMD_right; | |
160 } | |
161 #endif | |
162 | |
163 width = atoi((char *)eap->arg); | |
164 save_curpos = curwin->w_cursor; | |
165 if (eap->cmdidx == CMD_left) /* width is used for new indent */ | |
166 { | |
167 if (width >= 0) | |
168 indent = width; | |
169 } | |
170 else | |
171 { | |
172 /* | |
173 * if 'textwidth' set, use it | |
174 * else if 'wrapmargin' set, use it | |
175 * if invalid value, use 80 | |
176 */ | |
177 if (width <= 0) | |
178 width = curbuf->b_p_tw; | |
179 if (width == 0 && curbuf->b_p_wm > 0) | |
180 width = W_WIDTH(curwin) - curbuf->b_p_wm; | |
181 if (width <= 0) | |
182 width = 80; | |
183 } | |
184 | |
185 if (u_save((linenr_T)(eap->line1 - 1), (linenr_T)(eap->line2 + 1)) == FAIL) | |
186 return; | |
187 | |
188 for (curwin->w_cursor.lnum = eap->line1; | |
189 curwin->w_cursor.lnum <= eap->line2; ++curwin->w_cursor.lnum) | |
190 { | |
191 if (eap->cmdidx == CMD_left) /* left align */ | |
192 new_indent = indent; | |
193 else | |
194 { | |
944 | 195 has_tab = FALSE; /* avoid uninit warnings */ |
7 | 196 len = linelen(eap->cmdidx == CMD_right ? &has_tab |
197 : NULL) - get_indent(); | |
198 | |
199 if (len <= 0) /* skip blank lines */ | |
200 continue; | |
201 | |
202 if (eap->cmdidx == CMD_center) | |
203 new_indent = (width - len) / 2; | |
204 else | |
205 { | |
206 new_indent = width - len; /* right align */ | |
207 | |
208 /* | |
209 * Make sure that embedded TABs don't make the text go too far | |
210 * to the right. | |
211 */ | |
212 if (has_tab) | |
213 while (new_indent > 0) | |
214 { | |
215 (void)set_indent(new_indent, 0); | |
216 if (linelen(NULL) <= width) | |
217 { | |
218 /* | |
219 * Now try to move the line as much as possible to | |
220 * the right. Stop when it moves too far. | |
221 */ | |
222 do | |
223 (void)set_indent(++new_indent, 0); | |
224 while (linelen(NULL) <= width); | |
225 --new_indent; | |
226 break; | |
227 } | |
228 --new_indent; | |
229 } | |
230 } | |
231 } | |
232 if (new_indent < 0) | |
233 new_indent = 0; | |
234 (void)set_indent(new_indent, 0); /* set indent */ | |
235 } | |
236 changed_lines(eap->line1, 0, eap->line2 + 1, 0L); | |
237 curwin->w_cursor = save_curpos; | |
238 beginline(BL_WHITE | BL_FIX); | |
239 } | |
240 | |
241 /* | |
242 * Get the length of the current line, excluding trailing white space. | |
243 */ | |
244 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
245 linelen(int *has_tab) |
7 | 246 { |
247 char_u *line; | |
248 char_u *first; | |
249 char_u *last; | |
250 int save; | |
251 int len; | |
252 | |
253 /* find the first non-blank character */ | |
254 line = ml_get_curline(); | |
255 first = skipwhite(line); | |
256 | |
257 /* find the character after the last non-blank character */ | |
258 for (last = first + STRLEN(first); | |
259 last > first && vim_iswhite(last[-1]); --last) | |
260 ; | |
261 save = *last; | |
262 *last = NUL; | |
263 len = linetabsize(line); /* get line length */ | |
264 if (has_tab != NULL) /* check for embedded TAB */ | |
265 *has_tab = (vim_strrchr(first, TAB) != NULL); | |
266 *last = save; | |
267 | |
268 return len; | |
269 } | |
270 | |
826 | 271 /* Buffer for two lines used during sorting. They are allocated to |
272 * contain the longest line being sorted. */ | |
273 static char_u *sortbuf1; | |
274 static char_u *sortbuf2; | |
284 | 275 |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
276 static int sort_ic; /* ignore case */ |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
277 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
|
278 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
|
279 #ifdef FEAT_FLOAT |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
280 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
|
281 #endif |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
282 |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
283 static int sort_abort; /* flag to indicate if sorting has been interrupted */ |
294 | 284 |
285 /* Struct to store info to be sorted. */ | |
286 typedef struct | |
287 { | |
288 linenr_T lnum; /* line number */ | |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
289 union { |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
290 struct |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
291 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
292 varnumber_T start_col_nr; /* starting column number */ |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
293 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
|
294 } line; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
295 varnumber_T value; /* value if sorting by integer */ |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
296 #ifdef FEAT_FLOAT |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
297 float_T value_flt; /* value if sorting by float */ |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
298 #endif |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
299 } st_u; |
294 | 300 } sorti_T; |
284 | 301 |
302 static int | |
303 #ifdef __BORLANDC__ | |
304 _RTLENTRYF | |
305 #endif | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
306 sort_compare(const void *s1, const void *s2); |
284 | 307 |
308 static int | |
309 #ifdef __BORLANDC__ | |
310 _RTLENTRYF | |
311 #endif | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
312 sort_compare(const void *s1, const void *s2) |
284 | 313 { |
294 | 314 sorti_T l1 = *(sorti_T *)s1; |
315 sorti_T l2 = *(sorti_T *)s2; | |
826 | 316 int result = 0; |
317 | |
318 /* If the user interrupts, there's no way to stop qsort() immediately, but | |
834 | 319 * if we return 0 every time, qsort will assume it's done sorting and |
320 * exit. */ | |
826 | 321 if (sort_abort) |
322 return 0; | |
323 fast_breakcheck(); | |
324 if (got_int) | |
325 sort_abort = TRUE; | |
326 | |
834 | 327 /* When sorting numbers "start_col_nr" is the number, not the column |
328 * number. */ | |
294 | 329 if (sort_nr) |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
330 result = l1.st_u.value == l2.st_u.value ? 0 |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
331 : l1.st_u.value > l2.st_u.value ? 1 : -1; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
332 #ifdef FEAT_FLOAT |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
333 else if (sort_flt) |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
334 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
|
335 : 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
|
336 #endif |
826 | 337 else |
338 { | |
834 | 339 /* We need to copy one line into "sortbuf1", because there is no |
340 * guarantee that the first pointer becomes invalid when obtaining the | |
341 * second one. */ | |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
342 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
|
343 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
|
344 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
|
345 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
|
346 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
|
347 sortbuf2[l2.st_u.line.end_col_nr - l2.st_u.line.start_col_nr] = 0; |
826 | 348 |
834 | 349 result = sort_ic ? STRICMP(sortbuf1, sortbuf2) |
350 : STRCMP(sortbuf1, sortbuf2); | |
351 } | |
352 | |
353 /* If two lines have the same value, preserve the original line order. */ | |
826 | 354 if (result == 0) |
834 | 355 return (int)(l1.lnum - l2.lnum); |
356 return result; | |
284 | 357 } |
358 | |
359 /* | |
360 * ":sort". | |
361 */ | |
362 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
363 ex_sort(exarg_T *eap) |
284 | 364 { |
365 regmatch_T regmatch; | |
366 int len; | |
367 linenr_T lnum; | |
368 long maxlen = 0; | |
294 | 369 sorti_T *nrs; |
1872 | 370 size_t count = (size_t)(eap->line2 - eap->line1 + 1); |
294 | 371 size_t i; |
284 | 372 char_u *p; |
373 char_u *s; | |
826 | 374 char_u *s2; |
375 char_u c; /* temporary character storage */ | |
284 | 376 int unique = FALSE; |
377 long deleted; | |
826 | 378 colnr_T start_col; |
379 colnr_T end_col; | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
380 int sort_what = 0; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
381 int format_found = 0; |
284 | 382 |
1538 | 383 /* Sorting one line is really quick! */ |
384 if (count <= 1) | |
385 return; | |
386 | |
284 | 387 if (u_save((linenr_T)(eap->line1 - 1), (linenr_T)(eap->line2 + 1)) == FAIL) |
388 return; | |
826 | 389 sortbuf1 = NULL; |
390 sortbuf2 = NULL; | |
284 | 391 regmatch.regprog = NULL; |
294 | 392 nrs = (sorti_T *)lalloc((long_u)(count * sizeof(sorti_T)), TRUE); |
284 | 393 if (nrs == NULL) |
826 | 394 goto sortend; |
395 | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
396 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
|
397 #ifdef FEAT_FLOAT |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
398 sort_flt = 0; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
399 #endif |
294 | 400 |
284 | 401 for (p = eap->arg; *p != NUL; ++p) |
402 { | |
403 if (vim_iswhite(*p)) | |
404 ; | |
405 else if (*p == 'i') | |
406 sort_ic = TRUE; | |
826 | 407 else if (*p == 'r') |
408 sort_rx = TRUE; | |
294 | 409 else if (*p == 'n') |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
410 { |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
411 sort_nr = 1; |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
412 ++format_found; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
413 } |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
414 #ifdef FEAT_FLOAT |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
415 else if (*p == 'f') |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
416 { |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
417 sort_flt = 1; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
418 ++format_found; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
419 } |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
420 #endif |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
421 else if (*p == 'b') |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
422 { |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
423 sort_what = STR2NR_BIN + STR2NR_FORCE; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
424 ++format_found; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
425 } |
294 | 426 else if (*p == 'o') |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
427 { |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
428 sort_what = STR2NR_OCT + STR2NR_FORCE; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
429 ++format_found; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
430 } |
294 | 431 else if (*p == 'x') |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
432 { |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
433 sort_what = STR2NR_HEX + STR2NR_FORCE; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
434 ++format_found; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
435 } |
284 | 436 else if (*p == 'u') |
437 unique = TRUE; | |
289 | 438 else if (*p == '"') /* comment start */ |
439 break; | |
440 else if (check_nextcmd(p) != NULL) | |
441 { | |
442 eap->nextcmd = check_nextcmd(p); | |
443 break; | |
444 } | |
445 else if (!ASCII_ISALPHA(*p) && regmatch.regprog == NULL) | |
284 | 446 { |
447 s = skip_regexp(p + 1, *p, TRUE, NULL); | |
448 if (*s != *p) | |
449 { | |
450 EMSG(_(e_invalpat)); | |
826 | 451 goto sortend; |
284 | 452 } |
453 *s = NUL; | |
1314 | 454 /* Use last search pattern if sort pattern is empty. */ |
4199 | 455 if (s == p + 1) |
456 { | |
457 if (last_search_pat() == NULL) | |
458 { | |
459 EMSG(_(e_noprevre)); | |
460 goto sortend; | |
461 } | |
1314 | 462 regmatch.regprog = vim_regcomp(last_search_pat(), RE_MAGIC); |
4199 | 463 } |
1314 | 464 else |
465 regmatch.regprog = vim_regcomp(p + 1, RE_MAGIC); | |
284 | 466 if (regmatch.regprog == NULL) |
826 | 467 goto sortend; |
289 | 468 p = s; /* continue after the regexp */ |
284 | 469 regmatch.rm_ic = p_ic; |
470 } | |
471 else | |
472 { | |
473 EMSG2(_(e_invarg2), p); | |
826 | 474 goto sortend; |
284 | 475 } |
476 } | |
477 | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
478 /* 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
|
479 if (format_found > 1) |
294 | 480 { |
481 EMSG(_(e_invarg)); | |
826 | 482 goto sortend; |
294 | 483 } |
484 | |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
485 /* 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
|
486 * sorting. */ |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
487 sort_nr += sort_what; |
294 | 488 |
284 | 489 /* |
294 | 490 * Make an array with all line numbers. This avoids having to copy all |
284 | 491 * the lines into allocated memory. |
826 | 492 * When sorting on strings "start_col_nr" is the offset in the line, for |
493 * numbers sorting it's the number to sort on. This means the pattern | |
494 * matching and number conversion only has to be done once per line. | |
294 | 495 * Also get the longest line length for allocating "sortbuf". |
284 | 496 */ |
497 for (lnum = eap->line1; lnum <= eap->line2; ++lnum) | |
498 { | |
499 s = ml_get(lnum); | |
835 | 500 len = (int)STRLEN(s); |
284 | 501 if (maxlen < len) |
502 maxlen = len; | |
294 | 503 |
826 | 504 start_col = 0; |
505 end_col = len; | |
294 | 506 if (regmatch.regprog != NULL && vim_regexec(®match, s, 0)) |
826 | 507 { |
508 if (sort_rx) | |
509 { | |
835 | 510 start_col = (colnr_T)(regmatch.startp[0] - s); |
511 end_col = (colnr_T)(regmatch.endp[0] - s); | |
826 | 512 } |
513 else | |
835 | 514 start_col = (colnr_T)(regmatch.endp[0] - s); |
826 | 515 } |
294 | 516 else |
826 | 517 if (regmatch.regprog != NULL) |
518 end_col = 0; | |
294 | 519 |
7844
6669966db9e9
commit https://github.com/vim/vim/commit/937204a9175d0fe2f13c8bc4ebeb043003d7e7d7
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
520 if (sort_nr |
6669966db9e9
commit https://github.com/vim/vim/commit/937204a9175d0fe2f13c8bc4ebeb043003d7e7d7
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
521 #ifdef FEAT_FLOAT |
6669966db9e9
commit https://github.com/vim/vim/commit/937204a9175d0fe2f13c8bc4ebeb043003d7e7d7
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
522 || sort_flt |
6669966db9e9
commit https://github.com/vim/vim/commit/937204a9175d0fe2f13c8bc4ebeb043003d7e7d7
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
523 #endif |
6669966db9e9
commit https://github.com/vim/vim/commit/937204a9175d0fe2f13c8bc4ebeb043003d7e7d7
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
524 ) |
294 | 525 { |
826 | 526 /* Make sure vim_str2nr doesn't read any digits past the end |
527 * of the match, by temporarily terminating the string there */ | |
528 s2 = s + end_col; | |
529 c = *s2; | |
2606 | 530 *s2 = NUL; |
294 | 531 /* Sorting on number: Store the number itself. */ |
1687 | 532 p = s + start_col; |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
533 if (sort_nr) |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
534 { |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
535 if (sort_what & STR2NR_HEX) |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
536 s = skiptohex(p); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
537 else if (sort_what & STR2NR_BIN) |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
538 s = skiptobin(p); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
539 else |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
540 s = skiptodigit(p); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
541 if (s > p && s[-1] == '-') |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
542 --s; /* include preceding negative sign */ |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
543 if (*s == NUL) |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
544 /* 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
|
545 nrs[lnum - eap->line1].st_u.value = -MAXLNUM; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
546 else |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
547 vim_str2nr(s, NULL, NULL, sort_what, |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
548 &nrs[lnum - eap->line1].st_u.value, NULL, 0); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
549 } |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
550 #ifdef FEAT_FLOAT |
294 | 551 else |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
552 { |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
553 s = skipwhite(p); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
554 if (*s == '+') |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
555 s = skipwhite(s + 1); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
556 |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
557 if (*s == NUL) |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
558 /* 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
|
559 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
|
560 else |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
561 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
|
562 strtod((char *)s, NULL); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
563 } |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
564 #endif |
2606 | 565 *s2 = c; |
294 | 566 } |
567 else | |
826 | 568 { |
294 | 569 /* 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
|
570 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
|
571 nrs[lnum - eap->line1].st_u.line.end_col_nr = end_col; |
826 | 572 } |
294 | 573 |
574 nrs[lnum - eap->line1].lnum = lnum; | |
481 | 575 |
576 if (regmatch.regprog != NULL) | |
577 fast_breakcheck(); | |
578 if (got_int) | |
826 | 579 goto sortend; |
284 | 580 } |
581 | |
294 | 582 /* Allocate a buffer that can hold the longest line. */ |
826 | 583 sortbuf1 = alloc((unsigned)maxlen + 1); |
584 if (sortbuf1 == NULL) | |
585 goto sortend; | |
586 sortbuf2 = alloc((unsigned)maxlen + 1); | |
587 if (sortbuf2 == NULL) | |
588 goto sortend; | |
284 | 589 |
481 | 590 /* Sort the array of line numbers. Note: can't be interrupted! */ |
294 | 591 qsort((void *)nrs, count, sizeof(sorti_T), sort_compare); |
284 | 592 |
826 | 593 if (sort_abort) |
594 goto sortend; | |
595 | |
284 | 596 /* Insert the lines in the sorted order below the last one. */ |
597 lnum = eap->line2; | |
598 for (i = 0; i < count; ++i) | |
599 { | |
600 s = ml_get(nrs[eap->forceit ? count - i - 1 : i].lnum); | |
601 if (!unique || i == 0 | |
826 | 602 || (sort_ic ? STRICMP(s, sortbuf1) : STRCMP(s, sortbuf1)) != 0) |
284 | 603 { |
7340
645abb8d8daf
commit https://github.com/vim/vim/commit/75e3ad019933f4879137775549261bf51985ab7d
Christian Brabandt <cb@256bit.org>
parents:
7226
diff
changeset
|
604 /* Copy the line into a buffer, it may become invalid in |
645abb8d8daf
commit https://github.com/vim/vim/commit/75e3ad019933f4879137775549261bf51985ab7d
Christian Brabandt <cb@256bit.org>
parents:
7226
diff
changeset
|
605 * ml_append(). And it's needed for "unique". */ |
645abb8d8daf
commit https://github.com/vim/vim/commit/75e3ad019933f4879137775549261bf51985ab7d
Christian Brabandt <cb@256bit.org>
parents:
7226
diff
changeset
|
606 STRCPY(sortbuf1, s); |
645abb8d8daf
commit https://github.com/vim/vim/commit/75e3ad019933f4879137775549261bf51985ab7d
Christian Brabandt <cb@256bit.org>
parents:
7226
diff
changeset
|
607 if (ml_append(lnum++, sortbuf1, (colnr_T)0, FALSE) == FAIL) |
284 | 608 break; |
609 } | |
481 | 610 fast_breakcheck(); |
611 if (got_int) | |
826 | 612 goto sortend; |
284 | 613 } |
614 | |
615 /* delete the original lines if appending worked */ | |
616 if (i == count) | |
617 for (i = 0; i < count; ++i) | |
618 ml_delete(eap->line1, FALSE); | |
619 else | |
620 count = 0; | |
621 | |
294 | 622 /* Adjust marks for deleted (or added) lines and prepare for displaying. */ |
835 | 623 deleted = (long)(count - (lnum - eap->line2)); |
284 | 624 if (deleted > 0) |
625 mark_adjust(eap->line2 - deleted, eap->line2, (long)MAXLNUM, -deleted); | |
626 else if (deleted < 0) | |
627 mark_adjust(eap->line2, MAXLNUM, -deleted, 0L); | |
628 changed_lines(eap->line1, 0, eap->line2 + 1, -deleted); | |
294 | 629 |
284 | 630 curwin->w_cursor.lnum = eap->line1; |
631 beginline(BL_WHITE | BL_FIX); | |
632 | |
826 | 633 sortend: |
284 | 634 vim_free(nrs); |
826 | 635 vim_free(sortbuf1); |
636 vim_free(sortbuf2); | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4613
diff
changeset
|
637 vim_regfree(regmatch.regprog); |
481 | 638 if (got_int) |
639 EMSG(_(e_interr)); | |
284 | 640 } |
641 | |
7 | 642 /* |
643 * ":retab". | |
644 */ | |
645 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
646 ex_retab(exarg_T *eap) |
7 | 647 { |
648 linenr_T lnum; | |
649 int got_tab = FALSE; | |
650 long num_spaces = 0; | |
651 long num_tabs; | |
652 long len; | |
653 long col; | |
654 long vcol; | |
655 long start_col = 0; /* For start of white-space string */ | |
656 long start_vcol = 0; /* For start of white-space string */ | |
657 int temp; | |
658 long old_len; | |
659 char_u *ptr; | |
660 char_u *new_line = (char_u *)1; /* init to non-NULL */ | |
661 int did_undo; /* called u_save for current line */ | |
662 int new_ts; | |
663 int save_list; | |
664 linenr_T first_line = 0; /* first changed line */ | |
665 linenr_T last_line = 0; /* last changed line */ | |
666 | |
667 save_list = curwin->w_p_list; | |
668 curwin->w_p_list = 0; /* don't want list mode here */ | |
669 | |
670 new_ts = getdigits(&(eap->arg)); | |
671 if (new_ts < 0) | |
672 { | |
673 EMSG(_(e_positive)); | |
674 return; | |
675 } | |
676 if (new_ts == 0) | |
677 new_ts = curbuf->b_p_ts; | |
678 for (lnum = eap->line1; !got_int && lnum <= eap->line2; ++lnum) | |
679 { | |
680 ptr = ml_get(lnum); | |
681 col = 0; | |
682 vcol = 0; | |
683 did_undo = FALSE; | |
684 for (;;) | |
685 { | |
686 if (vim_iswhite(ptr[col])) | |
687 { | |
688 if (!got_tab && num_spaces == 0) | |
689 { | |
690 /* First consecutive white-space */ | |
691 start_vcol = vcol; | |
692 start_col = col; | |
693 } | |
694 if (ptr[col] == ' ') | |
695 num_spaces++; | |
696 else | |
697 got_tab = TRUE; | |
698 } | |
699 else | |
700 { | |
701 if (got_tab || (eap->forceit && num_spaces > 1)) | |
702 { | |
703 /* Retabulate this string of white-space */ | |
704 | |
705 /* len is virtual length of white string */ | |
706 len = num_spaces = vcol - start_vcol; | |
707 num_tabs = 0; | |
708 if (!curbuf->b_p_et) | |
709 { | |
710 temp = new_ts - (start_vcol % new_ts); | |
711 if (num_spaces >= temp) | |
712 { | |
713 num_spaces -= temp; | |
714 num_tabs++; | |
715 } | |
716 num_tabs += num_spaces / new_ts; | |
717 num_spaces -= (num_spaces / new_ts) * new_ts; | |
718 } | |
719 if (curbuf->b_p_et || got_tab || | |
720 (num_spaces + num_tabs < len)) | |
721 { | |
722 if (did_undo == FALSE) | |
723 { | |
724 did_undo = TRUE; | |
725 if (u_save((linenr_T)(lnum - 1), | |
726 (linenr_T)(lnum + 1)) == FAIL) | |
727 { | |
728 new_line = NULL; /* flag out-of-memory */ | |
729 break; | |
730 } | |
731 } | |
732 | |
733 /* len is actual number of white characters used */ | |
734 len = num_spaces + num_tabs; | |
735 old_len = (long)STRLEN(ptr); | |
736 new_line = lalloc(old_len - col + start_col + len + 1, | |
737 TRUE); | |
738 if (new_line == NULL) | |
739 break; | |
740 if (start_col > 0) | |
741 mch_memmove(new_line, ptr, (size_t)start_col); | |
742 mch_memmove(new_line + start_col + len, | |
743 ptr + col, (size_t)(old_len - col + 1)); | |
744 ptr = new_line + start_col; | |
745 for (col = 0; col < len; col++) | |
746 ptr[col] = (col < num_tabs) ? '\t' : ' '; | |
747 ml_replace(lnum, new_line, FALSE); | |
748 if (first_line == 0) | |
749 first_line = lnum; | |
750 last_line = lnum; | |
751 ptr = new_line; | |
752 col = start_col + len; | |
753 } | |
754 } | |
755 got_tab = FALSE; | |
756 num_spaces = 0; | |
757 } | |
758 if (ptr[col] == NUL) | |
759 break; | |
760 vcol += chartabsize(ptr + col, (colnr_T)vcol); | |
761 #ifdef FEAT_MBYTE | |
762 if (has_mbyte) | |
474 | 763 col += (*mb_ptr2len)(ptr + col); |
7 | 764 else |
765 #endif | |
766 ++col; | |
767 } | |
768 if (new_line == NULL) /* out of memory */ | |
769 break; | |
770 line_breakcheck(); | |
771 } | |
772 if (got_int) | |
773 EMSG(_(e_interr)); | |
774 | |
775 if (curbuf->b_p_ts != new_ts) | |
776 redraw_curbuf_later(NOT_VALID); | |
777 if (first_line != 0) | |
778 changed_lines(first_line, 0, last_line + 1, 0L); | |
779 | |
780 curwin->w_p_list = save_list; /* restore 'list' */ | |
781 | |
782 curbuf->b_p_ts = new_ts; | |
783 coladvance(curwin->w_curswant); | |
784 | |
785 u_clearline(); | |
786 } | |
787 | |
788 /* | |
789 * :move command - move lines line1-line2 to line dest | |
790 * | |
791 * return FAIL for failure, OK otherwise | |
792 */ | |
793 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
794 do_move(linenr_T line1, linenr_T line2, linenr_T dest) |
7 | 795 { |
796 char_u *str; | |
797 linenr_T l; | |
798 linenr_T extra; /* Num lines added before line1 */ | |
799 linenr_T num_lines; /* Num lines moved */ | |
800 linenr_T last_line; /* Last line in file after adding new text */ | |
6755 | 801 #ifdef FEAT_FOLDING |
802 int isFolded; | |
803 | |
804 /* Moving lines seems to corrupt the folds, delete folding info now | |
805 * and recreate it when finished. Don't do this for manual folding, it | |
806 * would delete all folds. */ | |
807 isFolded = hasAnyFolding(curwin) && !foldmethodIsManual(curwin); | |
808 if (isFolded) | |
809 deleteFoldRecurse(&curwin->w_folds); | |
810 #endif | |
7 | 811 |
812 if (dest >= line1 && dest < line2) | |
813 { | |
814 EMSG(_("E134: Move lines into themselves")); | |
815 return FAIL; | |
816 } | |
817 | |
818 num_lines = line2 - line1 + 1; | |
819 | |
820 /* | |
821 * First we copy the old text to its new location -- webb | |
822 * Also copy the flag that ":global" command uses. | |
823 */ | |
824 if (u_save(dest, dest + 1) == FAIL) | |
825 return FAIL; | |
826 for (extra = 0, l = line1; l <= line2; l++) | |
827 { | |
828 str = vim_strsave(ml_get(l + extra)); | |
829 if (str != NULL) | |
830 { | |
831 ml_append(dest + l - line1, str, (colnr_T)0, FALSE); | |
832 vim_free(str); | |
833 if (dest < line1) | |
834 extra++; | |
835 } | |
836 } | |
837 | |
838 /* | |
839 * Now we must be careful adjusting our marks so that we don't overlap our | |
840 * mark_adjust() calls. | |
841 * | |
842 * We adjust the marks within the old text so that they refer to the | |
843 * last lines of the file (temporarily), because we know no other marks | |
844 * will be set there since these line numbers did not exist until we added | |
845 * our new lines. | |
846 * | |
847 * Then we adjust the marks on lines between the old and new text positions | |
848 * (either forwards or backwards). | |
849 * | |
850 * And Finally we adjust the marks we put at the end of the file back to | |
851 * their final destination at the new text position -- webb | |
852 */ | |
853 last_line = curbuf->b_ml.ml_line_count; | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
854 mark_adjust_nofold(line1, line2, last_line - line2, 0L); |
7 | 855 if (dest >= line2) |
856 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
857 mark_adjust_nofold(line2 + 1, dest, -num_lines, 0L); |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
858 #ifdef FEAT_FOLDING |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
859 win_T *win; |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
860 tabpage_T *tp; |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
861 |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
862 FOR_ALL_TAB_WINDOWS(tp, win) { |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
863 if (win->w_buffer == curbuf) |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
864 foldSwapRange(&win->w_folds, line1, line2, dest + 1, |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
865 dest + num_lines); |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
866 } |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
867 #endif |
7 | 868 curbuf->b_op_start.lnum = dest - num_lines + 1; |
869 curbuf->b_op_end.lnum = dest; | |
870 } | |
871 else | |
872 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
873 mark_adjust_nofold(dest + 1, line1 - 1, num_lines, 0L); |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
874 #ifdef FEAT_FOLDING |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
875 win_T *win; |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
876 tabpage_T *tp; |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
877 |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
878 FOR_ALL_TAB_WINDOWS(tp, win) { |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
879 if (win->w_buffer == curbuf) |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
880 foldSwapRange(&win->w_folds, dest + 1, line1 - 1, line1, line2); |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
881 } |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
882 #endif |
7 | 883 curbuf->b_op_start.lnum = dest + 1; |
884 curbuf->b_op_end.lnum = dest + num_lines; | |
885 } | |
886 curbuf->b_op_start.col = curbuf->b_op_end.col = 0; | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
887 mark_adjust_nofold(last_line - num_lines + 1, last_line, |
7 | 888 -(last_line - dest - extra), 0L); |
889 | |
890 /* | |
891 * Now we delete the original text -- webb | |
892 */ | |
893 if (u_save(line1 + extra - 1, line2 + extra + 1) == FAIL) | |
894 return FAIL; | |
895 | |
896 for (l = line1; l <= line2; l++) | |
897 ml_delete(line1 + extra, TRUE); | |
898 | |
899 if (!global_busy && num_lines > p_report) | |
900 { | |
901 if (num_lines == 1) | |
902 MSG(_("1 line moved")); | |
903 else | |
904 smsg((char_u *)_("%ld lines moved"), num_lines); | |
905 } | |
906 | |
907 /* | |
908 * Leave the cursor on the last of the moved lines. | |
909 */ | |
910 if (dest >= line1) | |
911 curwin->w_cursor.lnum = dest; | |
912 else | |
913 curwin->w_cursor.lnum = dest + (line2 - line1) + 1; | |
914 | |
915 if (line1 < dest) | |
3184 | 916 { |
917 dest += num_lines + 1; | |
918 last_line = curbuf->b_ml.ml_line_count; | |
919 if (dest > last_line + 1) | |
920 dest = last_line + 1; | |
921 changed_lines(line1, 0, dest, 0L); | |
922 } | |
7 | 923 else |
924 changed_lines(dest + 1, 0, line1 + num_lines, 0L); | |
925 | |
6755 | 926 #ifdef FEAT_FOLDING |
927 /* recreate folds */ | |
928 if (isFolded) | |
929 foldUpdateAll(curwin); | |
930 #endif | |
931 | |
7 | 932 return OK; |
933 } | |
934 | |
935 /* | |
936 * ":copy" | |
937 */ | |
938 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
939 ex_copy(linenr_T line1, linenr_T line2, linenr_T n) |
7 | 940 { |
941 linenr_T count; | |
942 char_u *p; | |
943 | |
944 count = line2 - line1 + 1; | |
945 curbuf->b_op_start.lnum = n + 1; | |
946 curbuf->b_op_end.lnum = n + count; | |
947 curbuf->b_op_start.col = curbuf->b_op_end.col = 0; | |
948 | |
949 /* | |
950 * there are three situations: | |
951 * 1. destination is above line1 | |
952 * 2. destination is between line1 and line2 | |
953 * 3. destination is below line2 | |
954 * | |
955 * n = destination (when starting) | |
956 * curwin->w_cursor.lnum = destination (while copying) | |
957 * line1 = start of source (while copying) | |
958 * line2 = end of source (while copying) | |
959 */ | |
960 if (u_save(n, n + 1) == FAIL) | |
961 return; | |
962 | |
963 curwin->w_cursor.lnum = n; | |
964 while (line1 <= line2) | |
965 { | |
966 /* need to use vim_strsave() because the line will be unlocked within | |
967 * ml_append() */ | |
968 p = vim_strsave(ml_get(line1)); | |
969 if (p != NULL) | |
970 { | |
971 ml_append(curwin->w_cursor.lnum, p, (colnr_T)0, FALSE); | |
972 vim_free(p); | |
973 } | |
974 /* situation 2: skip already copied lines */ | |
975 if (line1 == n) | |
976 line1 = curwin->w_cursor.lnum; | |
977 ++line1; | |
978 if (curwin->w_cursor.lnum < line1) | |
979 ++line1; | |
980 if (curwin->w_cursor.lnum < line2) | |
981 ++line2; | |
982 ++curwin->w_cursor.lnum; | |
983 } | |
984 | |
985 appended_lines_mark(n, count); | |
986 | |
987 msgmore((long)count); | |
988 } | |
989 | |
359 | 990 static char_u *prevcmd = NULL; /* the previous command */ |
991 | |
992 #if defined(EXITFREE) || defined(PROTO) | |
993 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
994 free_prev_shellcmd(void) |
359 | 995 { |
996 vim_free(prevcmd); | |
997 } | |
998 #endif | |
999 | |
7 | 1000 /* |
1001 * Handle the ":!cmd" command. Also for ":r !cmd" and ":w !cmd" | |
1002 * Bangs in the argument are replaced with the previously entered command. | |
1003 * Remember the argument. | |
1004 */ | |
1005 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1006 do_bang( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1007 int addr_count, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1008 exarg_T *eap, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1009 int forceit, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1010 int do_in, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1011 int do_out) |
7 | 1012 { |
1013 char_u *arg = eap->arg; /* command */ | |
1014 linenr_T line1 = eap->line1; /* start of range */ | |
1015 linenr_T line2 = eap->line2; /* end of range */ | |
1016 char_u *newcmd = NULL; /* the new command */ | |
1017 int free_newcmd = FALSE; /* need to free() newcmd */ | |
1018 int ins_prevcmd; | |
1019 char_u *t; | |
1020 char_u *p; | |
1021 char_u *trailarg; | |
1022 int len; | |
1023 int scroll_save = msg_scroll; | |
1024 | |
1025 /* | |
1026 * Disallow shell commands for "rvim". | |
1027 * Disallow shell commands from .exrc and .vimrc in current directory for | |
1028 * security reasons. | |
1029 */ | |
1030 if (check_restricted() || check_secure()) | |
1031 return; | |
1032 | |
1033 if (addr_count == 0) /* :! */ | |
1034 { | |
1035 msg_scroll = FALSE; /* don't scroll here */ | |
1036 autowrite_all(); | |
1037 msg_scroll = scroll_save; | |
1038 } | |
1039 | |
1040 /* | |
1041 * Try to find an embedded bang, like in :!<cmd> ! [args] | |
1042 * (:!! is indicated by the 'forceit' variable) | |
1043 */ | |
1044 ins_prevcmd = forceit; | |
1045 trailarg = arg; | |
1046 do | |
1047 { | |
1048 len = (int)STRLEN(trailarg) + 1; | |
1049 if (newcmd != NULL) | |
1050 len += (int)STRLEN(newcmd); | |
1051 if (ins_prevcmd) | |
1052 { | |
1053 if (prevcmd == NULL) | |
1054 { | |
1055 EMSG(_(e_noprev)); | |
1056 vim_free(newcmd); | |
1057 return; | |
1058 } | |
1059 len += (int)STRLEN(prevcmd); | |
1060 } | |
1872 | 1061 if ((t = alloc((unsigned)len)) == NULL) |
7 | 1062 { |
1063 vim_free(newcmd); | |
1064 return; | |
1065 } | |
1066 *t = NUL; | |
1067 if (newcmd != NULL) | |
1068 STRCAT(t, newcmd); | |
1069 if (ins_prevcmd) | |
1070 STRCAT(t, prevcmd); | |
1071 p = t + STRLEN(t); | |
1072 STRCAT(t, trailarg); | |
1073 vim_free(newcmd); | |
1074 newcmd = t; | |
1075 | |
1076 /* | |
1077 * Scan the rest of the argument for '!', which is replaced by the | |
1078 * previous command. "\!" is replaced by "!" (this is vi compatible). | |
1079 */ | |
1080 trailarg = NULL; | |
1081 while (*p) | |
1082 { | |
2823 | 1083 if (*p == '!') |
7 | 1084 { |
1085 if (p > newcmd && p[-1] == '\\') | |
1624 | 1086 STRMOVE(p - 1, p); |
7 | 1087 else |
1088 { | |
1089 trailarg = p; | |
1090 *trailarg++ = NUL; | |
1091 ins_prevcmd = TRUE; | |
1092 break; | |
1093 } | |
1094 } | |
1095 ++p; | |
1096 } | |
1097 } while (trailarg != NULL); | |
1098 | |
1099 vim_free(prevcmd); | |
1100 prevcmd = newcmd; | |
1101 | |
1102 if (bangredo) /* put cmd in redo buffer for ! command */ | |
1103 { | |
5728 | 1104 /* If % or # appears in the command, it must have been escaped. |
1105 * Reescape them, so that redoing them does not substitute them by the | |
1106 * buffername. */ | |
1107 char_u *cmd = vim_strsave_escaped(prevcmd, (char_u *)"%#"); | |
1108 | |
1109 if (cmd != NULL) | |
1110 { | |
1111 AppendToRedobuffLit(cmd, -1); | |
1112 vim_free(cmd); | |
1113 } | |
1114 else | |
1115 AppendToRedobuffLit(prevcmd, -1); | |
7 | 1116 AppendToRedobuff((char_u *)"\n"); |
1117 bangredo = FALSE; | |
1118 } | |
1119 /* | |
1120 * Add quotes around the command, for shells that need them. | |
1121 */ | |
1122 if (*p_shq != NUL) | |
1123 { | |
1124 newcmd = alloc((unsigned)(STRLEN(prevcmd) + 2 * STRLEN(p_shq) + 1)); | |
1125 if (newcmd == NULL) | |
1126 return; | |
1127 STRCPY(newcmd, p_shq); | |
1128 STRCAT(newcmd, prevcmd); | |
1129 STRCAT(newcmd, p_shq); | |
1130 free_newcmd = TRUE; | |
1131 } | |
1132 if (addr_count == 0) /* :! */ | |
1133 { | |
1134 /* echo the command */ | |
1135 msg_start(); | |
1136 msg_putchar(':'); | |
1137 msg_putchar('!'); | |
1138 msg_outtrans(newcmd); | |
1139 msg_clr_eos(); | |
1140 windgoto(msg_row, msg_col); | |
1141 | |
1142 do_shell(newcmd, 0); | |
1143 } | |
1144 else /* :range! */ | |
725 | 1145 { |
7 | 1146 /* Careful: This may recursively call do_bang() again! (because of |
1147 * autocommands) */ | |
1148 do_filter(line1, line2, eap, newcmd, do_in, do_out); | |
725 | 1149 #ifdef FEAT_AUTOCMD |
1150 apply_autocmds(EVENT_SHELLFILTERPOST, NULL, NULL, FALSE, curbuf); | |
1151 #endif | |
1152 } | |
7 | 1153 if (free_newcmd) |
1154 vim_free(newcmd); | |
1155 } | |
1156 | |
1157 /* | |
1158 * do_filter: filter lines through a command given by the user | |
1159 * | |
169 | 1160 * We mostly use temp files and the call_shell() routine here. This would |
1161 * normally be done using pipes on a UNIX machine, but this is more portable | |
1162 * to non-unix machines. The call_shell() routine needs to be able | |
7 | 1163 * to deal with redirection somehow, and should handle things like looking |
1164 * at the PATH env. variable, and adding reasonable extensions to the | |
1165 * command name given by the user. All reasonable versions of call_shell() | |
1166 * do this. | |
169 | 1167 * Alternatively, if on Unix and redirecting input or output, but not both, |
1168 * and the 'shelltemp' option isn't set, use pipes. | |
7 | 1169 * We use input redirection if do_in is TRUE. |
1170 * We use output redirection if do_out is TRUE. | |
1171 */ | |
1172 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1173 do_filter( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1174 linenr_T line1, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1175 linenr_T line2, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1176 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
|
1177 char_u *cmd, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1178 int do_in, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1179 int do_out) |
7 | 1180 { |
1181 char_u *itmp = NULL; | |
1182 char_u *otmp = NULL; | |
1183 linenr_T linecount; | |
1184 linenr_T read_linecount; | |
1185 pos_T cursor_save; | |
1186 char_u *cmd_buf; | |
1187 #ifdef FEAT_AUTOCMD | |
1188 buf_T *old_curbuf = curbuf; | |
1189 #endif | |
169 | 1190 int shell_flags = 0; |
7 | 1191 |
1192 if (*cmd == NUL) /* no filter command */ | |
1193 return; | |
1194 | |
1195 cursor_save = curwin->w_cursor; | |
1196 linecount = line2 - line1 + 1; | |
1197 curwin->w_cursor.lnum = line1; | |
1198 curwin->w_cursor.col = 0; | |
1199 changed_line_abv_curs(); | |
1200 invalidate_botline(); | |
1201 | |
1202 /* | |
169 | 1203 * When using temp files: |
1204 * 1. * Form temp file names | |
1205 * 2. * Write the lines to a temp file | |
1206 * 3. Run the filter command on the temp file | |
1207 * 4. * Read the output of the command into the buffer | |
1208 * 5. * Delete the original lines to be filtered | |
1209 * 6. * Remove the temp files | |
1210 * | |
1211 * When writing the input with a pipe or when catching the output with a | |
1212 * pipe only need to do 3. | |
7 | 1213 */ |
1214 | |
169 | 1215 if (do_out) |
1216 shell_flags |= SHELL_DOOUT; | |
1217 | |
3482 | 1218 #ifdef FEAT_FILTERPIPE |
169 | 1219 if (!do_in && do_out && !p_stmp) |
1220 { | |
1221 /* Use a pipe to fetch stdout of the command, do not use a temp file. */ | |
1222 shell_flags |= SHELL_READ; | |
1223 curwin->w_cursor.lnum = line2; | |
1224 } | |
1225 else if (do_in && !do_out && !p_stmp) | |
7 | 1226 { |
169 | 1227 /* Use a pipe to write stdin of the command, do not use a temp file. */ |
1228 shell_flags |= SHELL_WRITE; | |
1229 curbuf->b_op_start.lnum = line1; | |
1230 curbuf->b_op_end.lnum = line2; | |
7 | 1231 } |
169 | 1232 else if (do_in && do_out && !p_stmp) |
1233 { | |
1234 /* Use a pipe to write stdin and fetch stdout of the command, do not | |
1235 * use a temp file. */ | |
1236 shell_flags |= SHELL_READ|SHELL_WRITE; | |
1237 curbuf->b_op_start.lnum = line1; | |
1238 curbuf->b_op_end.lnum = line2; | |
1239 curwin->w_cursor.lnum = line2; | |
1240 } | |
1241 else | |
1242 #endif | |
6721 | 1243 if ((do_in && (itmp = vim_tempname('i', FALSE)) == NULL) |
1244 || (do_out && (otmp = vim_tempname('o', FALSE)) == NULL)) | |
169 | 1245 { |
1246 EMSG(_(e_notmp)); | |
1247 goto filterend; | |
1248 } | |
7 | 1249 |
1250 /* | |
1251 * The writing and reading of temp files will not be shown. | |
1252 * Vi also doesn't do this and the messages are not very informative. | |
1253 */ | |
1254 ++no_wait_return; /* don't call wait_return() while busy */ | |
169 | 1255 if (itmp != NULL && buf_write(curbuf, itmp, NULL, line1, line2, eap, |
7 | 1256 FALSE, FALSE, FALSE, TRUE) == FAIL) |
1257 { | |
1258 msg_putchar('\n'); /* keep message from buf_write() */ | |
1259 --no_wait_return; | |
1260 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | |
1261 if (!aborting()) | |
1262 #endif | |
1263 (void)EMSG2(_(e_notcreate), itmp); /* will call wait_return */ | |
1264 goto filterend; | |
1265 } | |
1266 #ifdef FEAT_AUTOCMD | |
1267 if (curbuf != old_curbuf) | |
1268 goto filterend; | |
1269 #endif | |
1270 | |
1271 if (!do_out) | |
1272 msg_putchar('\n'); | |
1273 | |
1581 | 1274 /* Create the shell command in allocated memory. */ |
7 | 1275 cmd_buf = make_filter_cmd(cmd, itmp, otmp); |
1276 if (cmd_buf == NULL) | |
1277 goto filterend; | |
1278 | |
1279 windgoto((int)Rows - 1, 0); | |
1280 cursor_on(); | |
1281 | |
1282 /* | |
1283 * When not redirecting the output the command can write anything to the | |
1284 * screen. If 'shellredir' is equal to ">", screen may be messed up by | |
1285 * stderr output of external command. Clear the screen later. | |
1286 * If do_in is FALSE, this could be something like ":r !cat", which may | |
1287 * also mess up the screen, clear it later. | |
1288 */ | |
1289 if (!do_out || STRCMP(p_srr, ">") == 0 || !do_in) | |
1290 redraw_later_clear(); | |
1291 | |
169 | 1292 if (do_out) |
1293 { | |
1294 if (u_save((linenr_T)(line2), (linenr_T)(line2 + 1)) == FAIL) | |
1581 | 1295 { |
1296 vim_free(cmd_buf); | |
169 | 1297 goto error; |
1581 | 1298 } |
169 | 1299 redraw_curbuf_later(VALID); |
1300 } | |
1301 read_linecount = curbuf->b_ml.ml_line_count; | |
1302 | |
7 | 1303 /* |
1304 * When call_shell() fails wait_return() is called to give the user a | |
1305 * chance to read the error messages. Otherwise errors are ignored, so you | |
1306 * can see the error messages from the command that appear on stdout; use | |
1307 * 'u' to fix the text | |
1308 * Switch to cooked mode when not redirecting stdin, avoids that something | |
1309 * like ":r !cat" hangs. | |
1310 * Pass on the SHELL_DOOUT flag when the output is being redirected. | |
1311 */ | |
169 | 1312 if (call_shell(cmd_buf, SHELL_FILTER | SHELL_COOKED | shell_flags)) |
7 | 1313 { |
1314 redraw_later_clear(); | |
1315 wait_return(FALSE); | |
1316 } | |
1317 vim_free(cmd_buf); | |
1318 | |
1319 did_check_timestamps = FALSE; | |
1320 need_check_timestamps = TRUE; | |
1321 | |
1322 /* When interrupting the shell command, it may still have produced some | |
1323 * useful output. Reset got_int here, so that readfile() won't cancel | |
1324 * reading. */ | |
1325 ui_breakcheck(); | |
1326 got_int = FALSE; | |
1327 | |
1328 if (do_out) | |
1329 { | |
169 | 1330 if (otmp != NULL) |
7 | 1331 { |
169 | 1332 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
|
1333 eap, READ_FILTER) != OK) |
169 | 1334 { |
7 | 1335 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) |
169 | 1336 if (!aborting()) |
1337 #endif | |
1338 { | |
1339 msg_putchar('\n'); | |
1340 EMSG2(_(e_notread), otmp); | |
1341 } | |
1342 goto error; | |
7 | 1343 } |
169 | 1344 #ifdef FEAT_AUTOCMD |
1345 if (curbuf != old_curbuf) | |
1346 goto filterend; | |
1347 #endif | |
7 | 1348 } |
169 | 1349 |
1350 read_linecount = curbuf->b_ml.ml_line_count - read_linecount; | |
1351 | |
1352 if (shell_flags & SHELL_READ) | |
1353 { | |
1354 curbuf->b_op_start.lnum = line2 + 1; | |
1355 curbuf->b_op_end.lnum = curwin->w_cursor.lnum; | |
1356 appended_lines_mark(line2, read_linecount); | |
1357 } | |
7 | 1358 |
1359 if (do_in) | |
1360 { | |
1361 if (cmdmod.keepmarks || vim_strchr(p_cpo, CPO_REMMARK) == NULL) | |
1362 { | |
1363 if (read_linecount >= linecount) | |
1364 /* move all marks from old lines to new lines */ | |
1365 mark_adjust(line1, line2, linecount, 0L); | |
1366 else | |
1367 { | |
1368 /* move marks from old lines to new lines, delete marks | |
1369 * that are in deleted lines */ | |
1370 mark_adjust(line1, line1 + read_linecount - 1, | |
1371 linecount, 0L); | |
1372 mark_adjust(line1 + read_linecount, line2, MAXLNUM, 0L); | |
1373 } | |
1374 } | |
1375 | |
1376 /* | |
1377 * Put cursor on first filtered line for ":range!cmd". | |
1378 * Adjust '[ and '] (set by buf_write()). | |
1379 */ | |
1380 curwin->w_cursor.lnum = line1; | |
1381 del_lines(linecount, TRUE); | |
1382 curbuf->b_op_start.lnum -= linecount; /* adjust '[ */ | |
1383 curbuf->b_op_end.lnum -= linecount; /* adjust '] */ | |
1384 write_lnum_adjust(-linecount); /* adjust last line | |
1385 for next write */ | |
100 | 1386 #ifdef FEAT_FOLDING |
1387 foldUpdate(curwin, curbuf->b_op_start.lnum, curbuf->b_op_end.lnum); | |
1388 #endif | |
7 | 1389 } |
1390 else | |
1391 { | |
1392 /* | |
1393 * Put cursor on last new line for ":r !cmd". | |
1394 */ | |
169 | 1395 linecount = curbuf->b_op_end.lnum - curbuf->b_op_start.lnum + 1; |
7 | 1396 curwin->w_cursor.lnum = curbuf->b_op_end.lnum; |
1397 } | |
100 | 1398 |
7 | 1399 beginline(BL_WHITE | BL_FIX); /* cursor on first non-blank */ |
1400 --no_wait_return; | |
1401 | |
1402 if (linecount > p_report) | |
1403 { | |
1404 if (do_in) | |
1405 { | |
274 | 1406 vim_snprintf((char *)msg_buf, sizeof(msg_buf), |
1407 _("%ld lines filtered"), (long)linecount); | |
7 | 1408 if (msg(msg_buf) && !msg_scroll) |
1409 /* save message to display it after redraw */ | |
680 | 1410 set_keep_msg(msg_buf, 0); |
7 | 1411 } |
1412 else | |
1413 msgmore((long)linecount); | |
1414 } | |
1415 } | |
1416 else | |
1417 { | |
1418 error: | |
1419 /* put cursor back in same position for ":w !cmd" */ | |
1420 curwin->w_cursor = cursor_save; | |
1421 --no_wait_return; | |
1422 wait_return(FALSE); | |
1423 } | |
1424 | |
1425 filterend: | |
1426 | |
1427 #ifdef FEAT_AUTOCMD | |
1428 if (curbuf != old_curbuf) | |
1429 { | |
1430 --no_wait_return; | |
1431 EMSG(_("E135: *Filter* Autocommands must not change current buffer")); | |
1432 } | |
1433 #endif | |
1434 if (itmp != NULL) | |
1435 mch_remove(itmp); | |
1436 if (otmp != NULL) | |
1437 mch_remove(otmp); | |
1438 vim_free(itmp); | |
1439 vim_free(otmp); | |
1440 } | |
1441 | |
1442 /* | |
1443 * Call a shell to execute a command. | |
1444 * When "cmd" is NULL start an interactive shell. | |
1445 */ | |
1446 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1447 do_shell( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1448 char_u *cmd, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1449 int flags) /* may be SHELL_DOOUT when output is redirected */ |
7 | 1450 { |
1451 buf_T *buf; | |
1452 #ifndef FEAT_GUI_MSWIN | |
1453 int save_nwr; | |
1454 #endif | |
1455 #ifdef MSWIN | |
1456 int winstart = FALSE; | |
1457 #endif | |
1458 | |
1459 /* | |
1460 * Disallow shell commands for "rvim". | |
1461 * Disallow shell commands from .exrc and .vimrc in current directory for | |
1462 * security reasons. | |
1463 */ | |
1464 if (check_restricted() || check_secure()) | |
1465 { | |
1466 msg_end(); | |
1467 return; | |
1468 } | |
1469 | |
1470 #ifdef MSWIN | |
1471 /* | |
1472 * Check if ":!start" is used. | |
1473 */ | |
1474 if (cmd != NULL) | |
1475 winstart = (STRNICMP(cmd, "start ", 6) == 0); | |
1476 #endif | |
1477 | |
1478 /* | |
1479 * For autocommands we want to get the output on the current screen, to | |
1480 * avoid having to type return below. | |
1481 */ | |
1482 msg_putchar('\r'); /* put cursor at start of line */ | |
1483 #ifdef FEAT_AUTOCMD | |
1484 if (!autocmd_busy) | |
1485 #endif | |
1486 { | |
1487 #ifdef MSWIN | |
1488 if (!winstart) | |
1489 #endif | |
1490 stoptermcap(); | |
1491 } | |
1492 #ifdef MSWIN | |
1493 if (!winstart) | |
1494 #endif | |
1495 msg_putchar('\n'); /* may shift screen one line up */ | |
1496 | |
1497 /* warning message before calling the shell */ | |
1498 if (p_warn | |
1499 #ifdef FEAT_AUTOCMD | |
1500 && !autocmd_busy | |
1501 #endif | |
1502 && msg_silent == 0) | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1503 FOR_ALL_BUFFERS(buf) |
7 | 1504 if (bufIsChanged(buf)) |
1505 { | |
1506 #ifdef FEAT_GUI_MSWIN | |
1507 if (!winstart) | |
1508 starttermcap(); /* don't want a message box here */ | |
1509 #endif | |
1510 MSG_PUTS(_("[No write since last change]\n")); | |
1511 #ifdef FEAT_GUI_MSWIN | |
1512 if (!winstart) | |
1513 stoptermcap(); | |
1514 #endif | |
1515 break; | |
1516 } | |
1517 | |
1518 /* This windgoto is required for when the '\n' resulted in a "delete line | |
1519 * 1" command to the terminal. */ | |
1520 if (!swapping_screen()) | |
1521 windgoto(msg_row, msg_col); | |
1522 cursor_on(); | |
1523 (void)call_shell(cmd, SHELL_COOKED | flags); | |
1524 did_check_timestamps = FALSE; | |
1525 need_check_timestamps = TRUE; | |
1526 | |
1527 /* | |
1528 * put the message cursor at the end of the screen, avoids wait_return() | |
1529 * to overwrite the text that the external command showed | |
1530 */ | |
1531 if (!swapping_screen()) | |
1532 { | |
1533 msg_row = Rows - 1; | |
1534 msg_col = 0; | |
1535 } | |
1536 | |
1537 #ifdef FEAT_AUTOCMD | |
1538 if (autocmd_busy) | |
1539 { | |
1540 if (msg_silent == 0) | |
1541 redraw_later_clear(); | |
1542 } | |
1543 else | |
1544 #endif | |
1545 { | |
1546 /* | |
1547 * For ":sh" there is no need to call wait_return(), just redraw. | |
1548 * Also for the Win32 GUI (the output is in a console window). | |
1549 * Otherwise there is probably text on the screen that the user wants | |
1550 * to read before redrawing, so call wait_return(). | |
1551 */ | |
1552 #ifndef FEAT_GUI_MSWIN | |
1553 if (cmd == NULL | |
1554 # ifdef WIN3264 | |
1555 || (winstart && !need_wait_return) | |
1556 # endif | |
1557 ) | |
1558 { | |
1559 if (msg_silent == 0) | |
1560 redraw_later_clear(); | |
1561 need_wait_return = FALSE; | |
1562 } | |
1563 else | |
1564 { | |
1565 /* | |
1566 * If we switch screens when starttermcap() is called, we really | |
1567 * want to wait for "hit return to continue". | |
1568 */ | |
1569 save_nwr = no_wait_return; | |
1570 if (swapping_screen()) | |
1571 no_wait_return = FALSE; | |
1572 # ifdef AMIGA | |
1573 wait_return(term_console ? -1 : msg_silent == 0); /* see below */ | |
1574 # else | |
1575 wait_return(msg_silent == 0); | |
1576 # endif | |
1577 no_wait_return = save_nwr; | |
1578 } | |
1579 #endif /* FEAT_GUI_W32 */ | |
1580 | |
1581 #ifdef MSWIN | |
1582 if (!winstart) /* if winstart==TRUE, never stopped termcap! */ | |
1583 #endif | |
1584 starttermcap(); /* start termcap if not done by wait_return() */ | |
1585 | |
1586 /* | |
1587 * In an Amiga window redrawing is caused by asking the window size. | |
1588 * If we got an interrupt this will not work. The chance that the | |
1589 * window size is wrong is very small, but we need to redraw the | |
1590 * screen. Don't do this if ':' hit in wait_return(). THIS IS UGLY | |
1591 * but it saves an extra redraw. | |
1592 */ | |
1593 #ifdef AMIGA | |
1594 if (skip_redraw) /* ':' hit in wait_return() */ | |
1595 { | |
1596 if (msg_silent == 0) | |
1597 redraw_later_clear(); | |
1598 } | |
1599 else if (term_console) | |
1600 { | |
1601 OUT_STR(IF_EB("\033[0 q", ESC_STR "[0 q")); /* get window size */ | |
1602 if (got_int && msg_silent == 0) | |
1603 redraw_later_clear(); /* if got_int is TRUE, redraw needed */ | |
1604 else | |
1605 must_redraw = 0; /* no extra redraw needed */ | |
1606 } | |
1607 #endif | |
1608 } | |
1609 | |
1610 /* display any error messages now */ | |
1611 display_errors(); | |
725 | 1612 |
1613 #ifdef FEAT_AUTOCMD | |
1614 apply_autocmds(EVENT_SHELLCMDPOST, NULL, NULL, FALSE, curbuf); | |
1615 #endif | |
7 | 1616 } |
1617 | |
1618 /* | |
1619 * Create a shell command from a command string, input redirection file and | |
1620 * output redirection file. | |
1621 * Returns an allocated string with the shell command, or NULL for failure. | |
1622 */ | |
1623 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1624 make_filter_cmd( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1625 char_u *cmd, /* command */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1626 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
|
1627 char_u *otmp) /* NULL or name of output file */ |
7 | 1628 { |
1629 char_u *buf; | |
1630 long_u len; | |
5867 | 1631 |
7410
08e62c4fc17d
commit https://github.com/vim/vim/commit/53076830fea6df737455523f7e235bfe4f79864d
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
1632 #if defined(UNIX) |
5881 | 1633 int is_fish_shell; |
5911 | 1634 char_u *shell_name = get_isolated_shell_name(); |
5881 | 1635 |
5867 | 1636 /* Account for fish's different syntax for subshells */ |
5911 | 1637 is_fish_shell = (fnamecmp(shell_name, "fish") == 0); |
1638 vim_free(shell_name); | |
5867 | 1639 if (is_fish_shell) |
1640 len = (long_u)STRLEN(cmd) + 13; /* "begin; " + "; end" + NUL */ | |
1641 else | |
1642 #endif | |
1643 len = (long_u)STRLEN(cmd) + 3; /* "()" + NUL */ | |
7 | 1644 if (itmp != NULL) |
1645 len += (long_u)STRLEN(itmp) + 9; /* " { < " + " } " */ | |
1646 if (otmp != NULL) | |
1647 len += (long_u)STRLEN(otmp) + (long_u)STRLEN(p_srr) + 2; /* " " */ | |
1648 buf = lalloc(len, TRUE); | |
1649 if (buf == NULL) | |
1650 return NULL; | |
1651 | |
7410
08e62c4fc17d
commit https://github.com/vim/vim/commit/53076830fea6df737455523f7e235bfe4f79864d
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
1652 #if defined(UNIX) |
7 | 1653 /* |
169 | 1654 * Put braces around the command (for concatenated commands) when |
1655 * redirecting input and/or output. | |
7 | 1656 */ |
169 | 1657 if (itmp != NULL || otmp != NULL) |
5867 | 1658 { |
1659 if (is_fish_shell) | |
1660 vim_snprintf((char *)buf, len, "begin; %s; end", (char *)cmd); | |
1661 else | |
1662 vim_snprintf((char *)buf, len, "(%s)", (char *)cmd); | |
1663 } | |
169 | 1664 else |
1665 STRCPY(buf, cmd); | |
7 | 1666 if (itmp != NULL) |
1667 { | |
1668 STRCAT(buf, " < "); | |
1669 STRCAT(buf, itmp); | |
1670 } | |
1671 #else | |
1672 /* | |
5867 | 1673 * For shells that don't understand braces around commands, at least allow |
7 | 1674 * the use of commands in a pipe. |
1675 */ | |
1676 STRCPY(buf, cmd); | |
1677 if (itmp != NULL) | |
1678 { | |
1679 char_u *p; | |
1680 | |
1681 /* | |
1682 * If there is a pipe, we have to put the '<' in front of it. | |
1683 * Don't do this when 'shellquote' is not empty, otherwise the | |
1684 * redirection would be inside the quotes. | |
1685 */ | |
1686 if (*p_shq == NUL) | |
1687 { | |
1688 p = vim_strchr(buf, '|'); | |
1689 if (p != NULL) | |
1690 *p = NUL; | |
1691 } | |
1692 STRCAT(buf, " <"); /* " < " causes problems on Amiga */ | |
1693 STRCAT(buf, itmp); | |
1694 if (*p_shq == NUL) | |
1695 { | |
1696 p = vim_strchr(cmd, '|'); | |
1697 if (p != NULL) | |
1698 { | |
1699 STRCAT(buf, " "); /* insert a space before the '|' for DOS */ | |
1700 STRCAT(buf, p); | |
1701 } | |
1702 } | |
1703 } | |
1704 #endif | |
1705 if (otmp != NULL) | |
1872 | 1706 append_redir(buf, (int)len, p_srr, otmp); |
7 | 1707 |
1708 return buf; | |
1709 } | |
1710 | |
1711 /* | |
1872 | 1712 * Append output redirection for file "fname" to the end of string buffer |
1713 * "buf[buflen]" | |
7 | 1714 * Works with the 'shellredir' and 'shellpipe' options. |
1715 * The caller should make sure that there is enough room: | |
1716 * STRLEN(opt) + STRLEN(fname) + 3 | |
1717 */ | |
1718 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1719 append_redir( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1720 char_u *buf, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1721 int buflen, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1722 char_u *opt, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1723 char_u *fname) |
7 | 1724 { |
1725 char_u *p; | |
1872 | 1726 char_u *end; |
1727 | |
1728 end = buf + STRLEN(buf); | |
5257
e63e4b4be923
updated for version 7.4b.005
Bram Moolenaar <bram@vim.org>
parents:
5242
diff
changeset
|
1729 /* find "%s" */ |
7 | 1730 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
|
1731 { |
e63e4b4be923
updated for version 7.4b.005
Bram Moolenaar <bram@vim.org>
parents:
5242
diff
changeset
|
1732 if (p[1] == 's') /* found %s */ |
7 | 1733 break; |
5257
e63e4b4be923
updated for version 7.4b.005
Bram Moolenaar <bram@vim.org>
parents:
5242
diff
changeset
|
1734 if (p[1] == '%') /* skip %% */ |
e63e4b4be923
updated for version 7.4b.005
Bram Moolenaar <bram@vim.org>
parents:
5242
diff
changeset
|
1735 ++p; |
e63e4b4be923
updated for version 7.4b.005
Bram Moolenaar <bram@vim.org>
parents:
5242
diff
changeset
|
1736 } |
7 | 1737 if (p != NULL) |
1738 { | |
1872 | 1739 *end = ' '; /* not really needed? Not with sh, ksh or bash */ |
1740 vim_snprintf((char *)end + 1, (size_t)(buflen - (end + 1 - buf)), | |
1741 (char *)opt, (char *)fname); | |
7 | 1742 } |
1743 else | |
1872 | 1744 vim_snprintf((char *)end, (size_t)(buflen - (end - buf)), |
7 | 1745 #ifdef FEAT_QUICKFIX |
1746 " %s %s", | |
1747 #else | |
1748 " %s%s", /* " > %s" causes problems on Amiga */ | |
1749 #endif | |
1750 (char *)opt, (char *)fname); | |
1751 } | |
1752 | |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
1753 #if defined(FEAT_VIMINFO) || defined(PROTO) |
7 | 1754 |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
1755 static int no_viminfo(void); |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
1756 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
|
1757 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
|
1758 static void write_viminfo_barlines(vir_T *virp, FILE *fp_out); |
7 | 1759 static int viminfo_errcnt; |
1760 | |
1761 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1762 no_viminfo(void) |
7 | 1763 { |
1764 /* "vim -i NONE" does not read or write a viminfo file */ | |
1765 return (use_viminfo != NULL && STRCMP(use_viminfo, "NONE") == 0); | |
1766 } | |
1767 | |
1768 /* | |
1769 * Report an error for reading a viminfo file. | |
1770 * Count the number of errors. When there are more than 10, return TRUE. | |
1771 */ | |
1772 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1773 viminfo_error(char *errnum, char *message, char_u *line) |
7 | 1774 { |
274 | 1775 vim_snprintf((char *)IObuff, IOSIZE, _("%sviminfo: %s in line: "), |
1776 errnum, message); | |
1459 | 1777 STRNCAT(IObuff, line, IOSIZE - STRLEN(IObuff) - 1); |
156 | 1778 if (IObuff[STRLEN(IObuff) - 1] == '\n') |
1779 IObuff[STRLEN(IObuff) - 1] = NUL; | |
7 | 1780 emsg(IObuff); |
1781 if (++viminfo_errcnt >= 10) | |
1782 { | |
1783 EMSG(_("E136: viminfo: Too many errors, skipping rest of file")); | |
1784 return TRUE; | |
1785 } | |
1786 return FALSE; | |
1787 } | |
1788 | |
1789 /* | |
1790 * read_viminfo() -- Read the viminfo file. Registers etc. which are already | |
1733 | 1791 * set are not over-written unless "flags" includes VIF_FORCEIT. -- webb |
7 | 1792 */ |
1793 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1794 read_viminfo( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1795 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
|
1796 int flags) /* VIF_WANT_INFO et al. */ |
7 | 1797 { |
1798 FILE *fp; | |
1799 char_u *fname; | |
1800 | |
1801 if (no_viminfo()) | |
1802 return FAIL; | |
1803 | |
1733 | 1804 fname = viminfo_filename(file); /* get file name in allocated buffer */ |
7 | 1805 if (fname == NULL) |
1806 return FAIL; | |
1807 fp = mch_fopen((char *)fname, READBIN); | |
1808 | |
1809 if (p_verbose > 0) | |
294 | 1810 { |
1811 verbose_enter(); | |
274 | 1812 smsg((char_u *)_("Reading viminfo file \"%s\"%s%s%s"), |
1813 fname, | |
1733 | 1814 (flags & VIF_WANT_INFO) ? _(" info") : "", |
1815 (flags & VIF_WANT_MARKS) ? _(" marks") : "", | |
1816 (flags & VIF_GET_OLDFILES) ? _(" oldfiles") : "", | |
274 | 1817 fp == NULL ? _(" FAILED") : ""); |
294 | 1818 verbose_leave(); |
1819 } | |
7 | 1820 |
1821 vim_free(fname); | |
1822 if (fp == NULL) | |
1823 return FAIL; | |
1824 | |
1825 viminfo_errcnt = 0; | |
1733 | 1826 do_viminfo(fp, NULL, flags); |
7 | 1827 |
1828 fclose(fp); | |
1829 return OK; | |
1830 } | |
1831 | |
1832 /* | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1833 * 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
|
1834 * 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
|
1835 * run simultaneously, without losing any marks etc. |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1836 * 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
|
1837 * info is written to the file. |
7 | 1838 */ |
1839 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1840 write_viminfo(char_u *file, int forceit) |
7 | 1841 { |
1842 char_u *fname; | |
1843 FILE *fp_in = NULL; /* input viminfo file, if any */ | |
1844 FILE *fp_out = NULL; /* output viminfo file */ | |
1845 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
|
1846 stat_T st_new; /* mch_stat() of potential new file */ |
7 | 1847 char_u *wp; |
1848 #if defined(UNIX) || defined(VMS) | |
1849 mode_t umask_save; | |
1850 #endif | |
1851 #ifdef UNIX | |
1852 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
|
1853 stat_T st_old; /* mch_stat() of existing viminfo file */ |
7 | 1854 #endif |
601 | 1855 #ifdef WIN3264 |
7194
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1856 int hidden = FALSE; |
601 | 1857 #endif |
7 | 1858 |
1859 if (no_viminfo()) | |
1860 return; | |
1861 | |
1862 fname = viminfo_filename(file); /* may set to default if NULL */ | |
1863 if (fname == NULL) | |
1864 return; | |
1865 | |
1866 fp_in = mch_fopen((char *)fname, READBIN); | |
1867 if (fp_in == NULL) | |
1868 { | |
1869 /* if it does exist, but we can't read it, don't try writing */ | |
1870 if (mch_stat((char *)fname, &st_new) == 0) | |
1871 goto end; | |
1872 #if defined(UNIX) || defined(VMS) | |
1873 /* | |
1874 * For Unix we create the .viminfo non-accessible for others, | |
1875 * because it may contain text from non-accessible documents. | |
1876 */ | |
1877 umask_save = umask(077); | |
1878 #endif | |
1879 fp_out = mch_fopen((char *)fname, WRITEBIN); | |
1880 #if defined(UNIX) || defined(VMS) | |
1881 (void)umask(umask_save); | |
1882 #endif | |
1883 } | |
1884 else | |
1885 { | |
1886 /* | |
1887 * There is an existing viminfo file. Create a temporary file to | |
1888 * write the new viminfo into, in the same directory as the | |
1889 * existing viminfo file, which will be renamed later. | |
1890 */ | |
1891 #ifdef UNIX | |
1892 /* | |
1893 * For Unix we check the owner of the file. It's not very nice to | |
1894 * overwrite a user's viminfo file after a "su root", with a | |
1895 * viminfo file that the user can't read. | |
1896 */ | |
1869 | 1897 st_old.st_dev = (dev_t)0; |
1438 | 1898 st_old.st_ino = 0; |
7 | 1899 st_old.st_mode = 0600; |
1076 | 1900 if (mch_stat((char *)fname, &st_old) == 0 |
1901 && getuid() != ROOT_UID | |
560 | 1902 && !(st_old.st_uid == getuid() |
7 | 1903 ? (st_old.st_mode & 0200) |
1904 : (st_old.st_gid == getgid() | |
1905 ? (st_old.st_mode & 0020) | |
1906 : (st_old.st_mode & 0002)))) | |
1907 { | |
944 | 1908 int tt = msg_didany; |
7 | 1909 |
1910 /* avoid a wait_return for this message, it's annoying */ | |
1911 EMSG2(_("E137: Viminfo file is not writable: %s"), fname); | |
1912 msg_didany = tt; | |
840 | 1913 fclose(fp_in); |
7 | 1914 goto end; |
1915 } | |
1916 #endif | |
601 | 1917 #ifdef WIN3264 |
1918 /* 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
|
1919 hidden = mch_ishidden(fname); |
601 | 1920 #endif |
7 | 1921 |
1922 /* | |
1923 * Make tempname. | |
1924 * May try twice: Once normal and once with shortname set, just in | |
1925 * case somebody puts his viminfo file in an 8.3 filesystem. | |
1926 */ | |
1927 for (;;) | |
1928 { | |
1929 tempname = buf_modname( | |
1930 #ifdef UNIX | |
1931 shortname, | |
1932 #else | |
1933 FALSE, | |
1934 #endif | |
1935 fname, | |
1936 #ifdef VMS | |
1937 (char_u *)"-tmp", | |
1938 #else | |
1939 (char_u *)".tmp", | |
1940 #endif | |
1941 FALSE); | |
1942 if (tempname == NULL) /* out of memory */ | |
1943 break; | |
1944 | |
1945 /* | |
1946 * Check if tempfile already exists. Never overwrite an | |
1947 * existing file! | |
1948 */ | |
1949 if (mch_stat((char *)tempname, &st_new) == 0) | |
1950 { | |
1951 #ifdef UNIX | |
1952 /* | |
1953 * Check if tempfile is same as original file. May happen | |
1954 * when modname() gave the same file back. E.g. silly | |
1955 * link, or file name-length reached. Try again with | |
1956 * shortname set. | |
1957 */ | |
560 | 1958 if (!shortname && st_new.st_dev == st_old.st_dev |
1959 && st_new.st_ino == st_old.st_ino) | |
7 | 1960 { |
1961 vim_free(tempname); | |
1962 tempname = NULL; | |
1963 shortname = TRUE; | |
1964 continue; | |
1965 } | |
1966 #endif | |
1967 /* | |
1968 * Try another name. Change one character, just before | |
1969 * the extension. This should also work for an 8.3 | |
1970 * file name, when after adding the extension it still is | |
1971 * the same file as the original. | |
1972 */ | |
1973 wp = tempname + STRLEN(tempname) - 5; | |
1974 if (wp < gettail(tempname)) /* empty file name? */ | |
1975 wp = gettail(tempname); | |
1976 for (*wp = 'z'; mch_stat((char *)tempname, &st_new) == 0; | |
1977 --*wp) | |
1978 { | |
1979 /* | |
1980 * They all exist? Must be something wrong! Don't | |
1981 * write the viminfo file then. | |
1982 */ | |
1983 if (*wp == 'a') | |
1984 { | |
9284
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
1985 EMSG2(_("E929: Too many viminfo temp files, like %s!"), |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
1986 tempname); |
7 | 1987 vim_free(tempname); |
1988 tempname = NULL; | |
1989 break; | |
1990 } | |
1991 } | |
1992 } | |
1993 break; | |
1994 } | |
1995 | |
1996 if (tempname != NULL) | |
1997 { | |
762 | 1998 #ifdef VMS |
1999 /* fdopen() fails for some reason */ | |
770 | 2000 umask_save = umask(077); |
2001 fp_out = mch_fopen((char *)tempname, WRITEBIN); | |
2002 (void)umask(umask_save); | |
762 | 2003 #else |
557 | 2004 int fd; |
2005 | |
2006 /* Use mch_open() to be able to use O_NOFOLLOW and set file | |
601 | 2007 * protection: |
673 | 2008 * Unix: same as original file, but strip s-bit. Reset umask to |
2009 * avoid it getting in the way. | |
601 | 2010 * Others: r&w for user only. */ |
762 | 2011 # ifdef UNIX |
673 | 2012 umask_save = umask(0); |
557 | 2013 fd = mch_open((char *)tempname, |
2014 O_CREAT|O_EXTRA|O_EXCL|O_WRONLY|O_NOFOLLOW, | |
569 | 2015 (int)((st_old.st_mode & 0777) | 0600)); |
673 | 2016 (void)umask(umask_save); |
762 | 2017 # else |
569 | 2018 fd = mch_open((char *)tempname, |
673 | 2019 O_CREAT|O_EXTRA|O_EXCL|O_WRONLY|O_NOFOLLOW, 0600); |
762 | 2020 # endif |
557 | 2021 if (fd < 0) |
2022 fp_out = NULL; | |
2023 else | |
2024 fp_out = fdopen(fd, WRITEBIN); | |
762 | 2025 #endif /* VMS */ |
7 | 2026 |
2027 /* | |
2028 * If we can't create in the same directory, try creating a | |
2029 * "normal" temp file. | |
2030 */ | |
2031 if (fp_out == NULL) | |
2032 { | |
2033 vim_free(tempname); | |
6721 | 2034 if ((tempname = vim_tempname('o', TRUE)) != NULL) |
7 | 2035 fp_out = mch_fopen((char *)tempname, WRITEBIN); |
2036 } | |
557 | 2037 |
2038 #if defined(UNIX) && defined(HAVE_FCHOWN) | |
7 | 2039 /* |
557 | 2040 * Make sure the owner can read/write it. This only works for |
2041 * root. | |
7 | 2042 */ |
2043 if (fp_out != NULL) | |
1757 | 2044 ignored = fchown(fileno(fp_out), st_old.st_uid, st_old.st_gid); |
7 | 2045 #endif |
2046 } | |
2047 } | |
2048 | |
2049 /* | |
2050 * Check if the new viminfo file can be written to. | |
2051 */ | |
2052 if (fp_out == NULL) | |
2053 { | |
2054 EMSG2(_("E138: Can't write viminfo file %s!"), | |
301 | 2055 (fp_in == NULL || tempname == NULL) ? fname : tempname); |
7 | 2056 if (fp_in != NULL) |
2057 fclose(fp_in); | |
2058 goto end; | |
2059 } | |
2060 | |
2061 if (p_verbose > 0) | |
294 | 2062 { |
2063 verbose_enter(); | |
274 | 2064 smsg((char_u *)_("Writing viminfo file \"%s\""), fname); |
294 | 2065 verbose_leave(); |
2066 } | |
7 | 2067 |
2068 viminfo_errcnt = 0; | |
1733 | 2069 do_viminfo(fp_in, fp_out, forceit ? 0 : (VIF_WANT_INFO | VIF_WANT_MARKS)); |
7 | 2070 |
8573
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2071 if (fclose(fp_out) == EOF) |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2072 ++viminfo_errcnt; |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2073 |
7 | 2074 if (fp_in != NULL) |
2075 { | |
2076 fclose(fp_in); | |
601 | 2077 |
6049 | 2078 /* In case of an error keep the original viminfo file. Otherwise |
2079 * 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
|
2080 if (viminfo_errcnt == 0) |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2081 { |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2082 if (vim_rename(tempname, fname) == -1) |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2083 { |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2084 ++viminfo_errcnt; |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2085 EMSG2(_("E886: Can't rename viminfo file to %s!"), fname); |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2086 } |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2087 # ifdef WIN3264 |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2088 /* 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
|
2089 else if (hidden) |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2090 mch_hide(fname); |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2091 # endif |
6049 | 2092 } |
2093 if (viminfo_errcnt > 0) | |
7 | 2094 mch_remove(tempname); |
601 | 2095 } |
2096 | |
7 | 2097 end: |
2098 vim_free(fname); | |
2099 vim_free(tempname); | |
2100 } | |
2101 | |
2102 /* | |
2103 * Get the viminfo file name to use. | |
2104 * If "file" is given and not empty, use it (has already been expanded by | |
2105 * cmdline functions). | |
2106 * Otherwise use "-i file_name", value from 'viminfo' or the default, and | |
2107 * expand environment variables. | |
2108 * Returns an allocated string. NULL when out of memory. | |
2109 */ | |
2110 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2111 viminfo_filename(char_u *file) |
7 | 2112 { |
2113 if (file == NULL || *file == NUL) | |
2114 { | |
2115 if (use_viminfo != NULL) | |
2116 file = use_viminfo; | |
2117 else if ((file = find_viminfo_parameter('n')) == NULL || *file == NUL) | |
2118 { | |
2119 #ifdef VIMINFO_FILE2 | |
2120 /* don't use $HOME when not defined (turned into "c:/"!). */ | |
2121 # ifdef VMS | |
2122 if (mch_getenv((char_u *)"SYS$LOGIN") == NULL) | |
2123 # else | |
2124 if (mch_getenv((char_u *)"HOME") == NULL) | |
2125 # endif | |
2126 { | |
2127 /* don't use $VIM when not available. */ | |
2128 expand_env((char_u *)"$VIM", NameBuff, MAXPATHL); | |
2129 if (STRCMP("$VIM", NameBuff) != 0) /* $VIM was expanded */ | |
2130 file = (char_u *)VIMINFO_FILE2; | |
2131 else | |
2132 file = (char_u *)VIMINFO_FILE; | |
2133 } | |
2134 else | |
2135 #endif | |
2136 file = (char_u *)VIMINFO_FILE; | |
2137 } | |
2138 expand_env(file, NameBuff, MAXPATHL); | |
2139 file = NameBuff; | |
2140 } | |
2141 return vim_strsave(file); | |
2142 } | |
2143 | |
2144 /* | |
2145 * do_viminfo() -- Should only be called from read_viminfo() & write_viminfo(). | |
2146 */ | |
2147 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2148 do_viminfo(FILE *fp_in, FILE *fp_out, int flags) |
7 | 2149 { |
2150 int eof = FALSE; | |
2151 vir_T vir; | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2152 int merge = FALSE; |
9414
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2153 int do_copy_marks = FALSE; |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2154 garray_T buflist; |
7 | 2155 |
2156 if ((vir.vir_line = alloc(LSIZE)) == NULL) | |
2157 return; | |
2158 vir.vir_fd = fp_in; | |
2159 #ifdef FEAT_MBYTE | |
2160 vir.vir_conv.vc_type = CONV_NONE; | |
2161 #endif | |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2162 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
|
2163 vir.vir_version = -1; |
7 | 2164 |
2165 if (fp_in != NULL) | |
2166 { | |
1733 | 2167 if (flags & VIF_WANT_INFO) |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2168 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2169 if (fp_out != NULL) |
9284
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2170 { |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2171 /* 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
|
2172 * 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
|
2173 prepare_viminfo_registers(); |
9284
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2174 prepare_viminfo_marks(); |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2175 } |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2176 |
1733 | 2177 eof = read_viminfo_up_to_marks(&vir, |
2178 flags & VIF_FORCEIT, fp_out != NULL); | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2179 merge = TRUE; |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2180 } |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2181 else if (flags != 0) |
7 | 2182 /* Skip info, find start of marks */ |
2183 while (!(eof = viminfo_readline(&vir)) | |
2184 && vir.vir_line[0] != '>') | |
2185 ; | |
9414
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2186 |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2187 do_copy_marks = (flags & |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2188 (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
|
2189 } |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2190 |
7 | 2191 if (fp_out != NULL) |
2192 { | |
2193 /* Write the info: */ | |
2194 fprintf(fp_out, _("# This viminfo file was generated by Vim %s.\n"), | |
2195 VIM_VERSION_MEDIUM); | |
2545
298d8d6e69be
Avoid warnings from the clang compiler. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2394
diff
changeset
|
2196 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
|
2197 write_viminfo_version(fp_out); |
7 | 2198 #ifdef FEAT_MBYTE |
2545
298d8d6e69be
Avoid warnings from the clang compiler. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2394
diff
changeset
|
2199 fputs(_("# Value of 'encoding' when this file was written\n"), fp_out); |
7 | 2200 fprintf(fp_out, "*encoding=%s\n\n", p_enc); |
2201 #endif | |
2202 write_viminfo_search_pattern(fp_out); | |
2203 write_viminfo_sub_string(fp_out); | |
2204 #ifdef FEAT_CMDHIST | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2205 write_viminfo_history(fp_out, merge); |
7 | 2206 #endif |
2207 write_viminfo_registers(fp_out); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2208 finish_viminfo_registers(); |
7 | 2209 #ifdef FEAT_EVAL |
2210 write_viminfo_varlist(fp_out); | |
2211 #endif | |
2212 write_viminfo_filemarks(fp_out); | |
9284
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2213 finish_viminfo_marks(); |
7 | 2214 write_viminfo_bufferlist(fp_out); |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2215 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
|
2216 |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2217 if (do_copy_marks) |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2218 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
|
2219 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
|
2220 } |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2221 |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2222 if (do_copy_marks) |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2223 { |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2224 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
|
2225 if (fp_out != NULL) |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2226 ga_clear(&buflist); |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2227 } |
7 | 2228 |
2229 vim_free(vir.vir_line); | |
2230 #ifdef FEAT_MBYTE | |
2231 if (vir.vir_conv.vc_type != CONV_NONE) | |
2232 convert_setup(&vir.vir_conv, NULL, NULL); | |
2233 #endif | |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2234 ga_clear_strings(&vir.vir_barlines); |
7 | 2235 } |
2236 | |
2237 /* | |
2238 * read_viminfo_up_to_marks() -- Only called from do_viminfo(). Reads in the | |
2239 * first part of the viminfo file which contains everything but the marks that | |
2240 * are local to a file. Returns TRUE when end-of-file is reached. -- webb | |
2241 */ | |
2242 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2243 read_viminfo_up_to_marks( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2244 vir_T *virp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2245 int forceit, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2246 int writing) |
7 | 2247 { |
2248 int eof; | |
2249 buf_T *buf; | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2250 int got_encoding = FALSE; |
7 | 2251 |
2252 #ifdef FEAT_CMDHIST | |
4285 | 2253 prepare_viminfo_history(forceit ? 9999 : 0, writing); |
7 | 2254 #endif |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2255 |
7 | 2256 eof = viminfo_readline(virp); |
2257 while (!eof && virp->vir_line[0] != '>') | |
2258 { | |
2259 switch (virp->vir_line[0]) | |
2260 { | |
2261 /* Characters reserved for future expansion, ignored now */ | |
2262 case '+': /* "+40 /path/dir file", for running vim without args */ | |
2263 case '^': /* to be defined */ | |
2264 case '<': /* long line - ignored */ | |
2265 /* A comment or empty line. */ | |
2266 case NUL: | |
2267 case '\r': | |
2268 case '\n': | |
2269 case '#': | |
2270 eof = viminfo_readline(virp); | |
2271 break; | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2272 case '|': |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2273 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
|
2274 forceit, writing); |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2275 break; |
7 | 2276 case '*': /* "*encoding=value" */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2277 got_encoding = TRUE; |
7 | 2278 eof = viminfo_encoding(virp); |
2279 break; | |
2280 case '!': /* global variable */ | |
2281 #ifdef FEAT_EVAL | |
2282 eof = read_viminfo_varlist(virp, writing); | |
2283 #else | |
2284 eof = viminfo_readline(virp); | |
2285 #endif | |
2286 break; | |
2287 case '%': /* entry for buffer list */ | |
2288 eof = read_viminfo_bufferlist(virp, writing); | |
2289 break; | |
2290 case '"': | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2291 /* 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
|
2292 * lines. */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2293 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
|
2294 eof = read_viminfo_register(virp, forceit); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2295 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2296 do { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2297 eof = viminfo_readline(virp); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2298 } 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
|
2299 || virp->vir_line[0] == '<')); |
7 | 2300 break; |
2301 case '/': /* Search string */ | |
2302 case '&': /* Substitute search string */ | |
2303 case '~': /* Last search string, followed by '/' or '&' */ | |
2304 eof = read_viminfo_search_pattern(virp, forceit); | |
2305 break; | |
2306 case '$': | |
2307 eof = read_viminfo_sub_string(virp, forceit); | |
2308 break; | |
2309 case ':': | |
2310 case '?': | |
2311 case '=': | |
2312 case '@': | |
2313 #ifdef FEAT_CMDHIST | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2314 /* 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
|
2315 * lines. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2316 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
|
2317 eof = read_viminfo_history(virp, writing); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2318 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2319 #endif |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2320 eof = viminfo_readline(virp); |
7 | 2321 break; |
2322 case '-': | |
2323 case '\'': | |
9297
9c663cda189f
commit https://github.com/vim/vim/commit/a641e1d4da3f9152c489318c06a93fcd1c746637
Christian Brabandt <cb@256bit.org>
parents:
9284
diff
changeset
|
2324 /* 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
|
2325 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
|
2326 eof = read_viminfo_filemark(virp, forceit); |
9c663cda189f
commit https://github.com/vim/vim/commit/a641e1d4da3f9152c489318c06a93fcd1c746637
Christian Brabandt <cb@256bit.org>
parents:
9284
diff
changeset
|
2327 else |
9c663cda189f
commit https://github.com/vim/vim/commit/a641e1d4da3f9152c489318c06a93fcd1c746637
Christian Brabandt <cb@256bit.org>
parents:
9284
diff
changeset
|
2328 eof = viminfo_readline(virp); |
7 | 2329 break; |
2330 default: | |
2331 if (viminfo_error("E575: ", _("Illegal starting char"), | |
2332 virp->vir_line)) | |
2333 eof = TRUE; | |
2334 else | |
2335 eof = viminfo_readline(virp); | |
2336 break; | |
2337 } | |
2338 } | |
2339 | |
2340 #ifdef FEAT_CMDHIST | |
2341 /* Finish reading history items. */ | |
4285 | 2342 if (!writing) |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9248
diff
changeset
|
2343 finish_viminfo_history(virp); |
7 | 2344 #endif |
2345 | |
2346 /* 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
|
2347 FOR_ALL_BUFFERS(buf) |
7 | 2348 fmarks_check_names(buf); |
2349 | |
2350 return eof; | |
2351 } | |
2352 | |
2353 /* | |
2354 * Compare the 'encoding' value in the viminfo file with the current value of | |
2355 * 'encoding'. If different and the 'c' flag is in 'viminfo', setup for | |
2356 * conversion of text with iconv() in viminfo_readstring(). | |
2357 */ | |
2358 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2359 viminfo_encoding(vir_T *virp) |
7 | 2360 { |
2361 #ifdef FEAT_MBYTE | |
2362 char_u *p; | |
2363 int i; | |
2364 | |
2365 if (get_viminfo_parameter('c') != 0) | |
2366 { | |
2367 p = vim_strchr(virp->vir_line, '='); | |
2368 if (p != NULL) | |
2369 { | |
2370 /* remove trailing newline */ | |
2371 ++p; | |
2372 for (i = 0; vim_isprintc(p[i]); ++i) | |
2373 ; | |
2374 p[i] = NUL; | |
2375 | |
2376 convert_setup(&virp->vir_conv, p, p_enc); | |
2377 } | |
2378 } | |
2379 #endif | |
2380 return viminfo_readline(virp); | |
2381 } | |
2382 | |
2383 /* | |
2384 * Read a line from the viminfo file. | |
2385 * Returns TRUE for end-of-file; | |
2386 */ | |
2387 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2388 viminfo_readline(vir_T *virp) |
7 | 2389 { |
2390 return vim_fgets(virp->vir_line, LSIZE, virp->vir_fd); | |
2391 } | |
2392 | |
2393 /* | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2394 * Check string read from viminfo file. |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2395 * Remove '\n' at the end of the line. |
7 | 2396 * - replace CTRL-V CTRL-V with CTRL-V |
2397 * - replace CTRL-V 'n' with '\n' | |
2398 * | |
2399 * Check for a long line as written by viminfo_writestring(). | |
2400 * | |
2401 * Return the string in allocated memory (NULL when out of memory). | |
2402 */ | |
2403 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2404 viminfo_readstring( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2405 vir_T *virp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2406 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
|
2407 int convert UNUSED) /* convert the string */ |
7 | 2408 { |
2409 char_u *retval; | |
2410 char_u *s, *d; | |
2411 long len; | |
2412 | |
2413 if (virp->vir_line[off] == Ctrl_V && vim_isdigit(virp->vir_line[off + 1])) | |
2414 { | |
2415 len = atol((char *)virp->vir_line + off + 1); | |
2416 retval = lalloc(len, TRUE); | |
2417 if (retval == NULL) | |
2418 { | |
2419 /* Line too long? File messed up? Skip next line. */ | |
2420 (void)vim_fgets(virp->vir_line, 10, virp->vir_fd); | |
2421 return NULL; | |
2422 } | |
2423 (void)vim_fgets(retval, (int)len, virp->vir_fd); | |
2424 s = retval + 1; /* Skip the leading '<' */ | |
2425 } | |
2426 else | |
2427 { | |
2428 retval = vim_strsave(virp->vir_line + off); | |
2429 if (retval == NULL) | |
2430 return NULL; | |
2431 s = retval; | |
2432 } | |
2433 | |
2434 /* Change CTRL-V CTRL-V to CTRL-V and CTRL-V n to \n in-place. */ | |
2435 d = retval; | |
2436 while (*s != NUL && *s != '\n') | |
2437 { | |
2438 if (s[0] == Ctrl_V && s[1] != NUL) | |
2439 { | |
2440 if (s[1] == 'n') | |
2441 *d++ = '\n'; | |
2442 else | |
2443 *d++ = Ctrl_V; | |
2444 s += 2; | |
2445 } | |
2446 else | |
2447 *d++ = *s++; | |
2448 } | |
2449 *d = NUL; | |
2450 | |
2451 #ifdef FEAT_MBYTE | |
2452 if (convert && virp->vir_conv.vc_type != CONV_NONE && *retval != NUL) | |
2453 { | |
2454 d = string_convert(&virp->vir_conv, retval, NULL); | |
2455 if (d != NULL) | |
2456 { | |
2457 vim_free(retval); | |
2458 retval = d; | |
2459 } | |
2460 } | |
2461 #endif | |
2462 | |
2463 return retval; | |
2464 } | |
2465 | |
2466 /* | |
2467 * write string to viminfo file | |
2468 * - replace CTRL-V with CTRL-V CTRL-V | |
2469 * - replace '\n' with CTRL-V 'n' | |
2470 * - add a '\n' at the end | |
2471 * | |
2472 * For a long line: | |
2473 * - write " CTRL-V <length> \n " in first line | |
2474 * - write " < <string> \n " in second line | |
2475 */ | |
2476 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2477 viminfo_writestring(FILE *fd, char_u *p) |
7 | 2478 { |
2479 int c; | |
2480 char_u *s; | |
2481 int len = 0; | |
2482 | |
2483 for (s = p; *s != NUL; ++s) | |
2484 { | |
2485 if (*s == Ctrl_V || *s == '\n') | |
2486 ++len; | |
2487 ++len; | |
2488 } | |
2489 | |
2490 /* If the string will be too long, write its length and put it in the next | |
2491 * line. Take into account that some room is needed for what comes before | |
2492 * the string (e.g., variable name). Add something to the length for the | |
2493 * '<', NL and trailing NUL. */ | |
2494 if (len > LSIZE / 2) | |
2495 fprintf(fd, IF_EB("\026%d\n<", CTRL_V_STR "%d\n<"), len + 3); | |
2496 | |
2497 while ((c = *p++) != NUL) | |
2498 { | |
2499 if (c == Ctrl_V || c == '\n') | |
2500 { | |
2501 putc(Ctrl_V, fd); | |
2502 if (c == '\n') | |
2503 c = 'n'; | |
2504 } | |
2505 putc(c, fd); | |
2506 } | |
2507 putc('\n', fd); | |
2508 } | |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2509 |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2510 /* |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2511 * 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
|
2512 * 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
|
2513 * Returns remaining characters in the line. |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2514 */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2515 int |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2516 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
|
2517 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2518 char_u *p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2519 int remaining = remaining_start; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2520 int len = 2; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2521 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2522 /* 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
|
2523 for (p = s; *p != NUL; ++p) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2524 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2525 if (*p == NL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2526 len += 2; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2527 else if (*p == '"' || *p == '\\') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2528 len += 2; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2529 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2530 ++len; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2531 } |
9978
baad324e9fbc
commit https://github.com/vim/vim/commit/257095760732597983bdd026e791907b7980e295
Christian Brabandt <cb@256bit.org>
parents:
9959
diff
changeset
|
2532 if (len > remaining - 2) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2533 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2534 fprintf(fd, ">%d\n|<", len); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2535 remaining = LSIZE - 20; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2536 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2537 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2538 putc('"', fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2539 for (p = s; *p != NUL; ++p) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2540 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2541 if (*p == NL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2542 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2543 putc('\\', fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2544 putc('n', fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2545 --remaining; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2546 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2547 else if (*p == '"' || *p == '\\') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2548 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2549 putc('\\', fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2550 putc(*p, fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2551 --remaining; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2552 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2553 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2554 putc(*p, fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2555 --remaining; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2556 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2557 if (remaining < 3) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2558 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2559 putc('\n', fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2560 putc('|', fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2561 putc('<', fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2562 /* Leave enough space for another continuation. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2563 remaining = LSIZE - 20; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2564 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2565 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2566 putc('"', fd); |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2567 return remaining - 2; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2568 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2569 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2570 /* |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2571 * 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
|
2572 * 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
|
2573 * 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
|
2574 */ |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2575 static int |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2576 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
|
2577 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2578 char_u *p = text; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2579 char_u *nextp = NULL; |
9244
931bbf7b6ee3
commit https://github.com/vim/vim/commit/fdd82fe365d0e287bafc71f98c039cb5af8ed827
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
2580 char_u *buf = NULL; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2581 bval_T *value; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2582 int i; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2583 int allocated = FALSE; |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2584 int eof; |
9268
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2585 #ifdef FEAT_MBYTE |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2586 char_u *sconv; |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2587 int converted; |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2588 #endif |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2589 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2590 while (*p == ',') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2591 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2592 ++p; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2593 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
|
2594 break; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2595 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
|
2596 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2597 if (*p == '>') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2598 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2599 /* 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
|
2600 * 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
|
2601 if (!allocated) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2602 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2603 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
|
2604 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2605 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
|
2606 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2607 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
|
2608 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2609 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
|
2610 vp->bv_allocated = TRUE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2611 } |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2612 } |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2613 allocated = TRUE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2614 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2615 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2616 if (vim_isdigit(p[1])) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2617 { |
9248
9c751c33dc0f
commit https://github.com/vim/vim/commit/1d5f1d07aedb6f149f5de145b1dfd6528a769c93
Christian Brabandt <cb@256bit.org>
parents:
9244
diff
changeset
|
2618 size_t len; |
9c751c33dc0f
commit https://github.com/vim/vim/commit/1d5f1d07aedb6f149f5de145b1dfd6528a769c93
Christian Brabandt <cb@256bit.org>
parents:
9244
diff
changeset
|
2619 size_t todo; |
9c751c33dc0f
commit https://github.com/vim/vim/commit/1d5f1d07aedb6f149f5de145b1dfd6528a769c93
Christian Brabandt <cb@256bit.org>
parents:
9244
diff
changeset
|
2620 size_t n; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2621 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2622 /* 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
|
2623 * than LSIZE: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2624 * |{bartype},>{length of "{text}{text2}"} |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2625 * |<"{text1} |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2626 * |<{text2}",{value} |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2627 * Length includes the quotes. |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2628 */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2629 ++p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2630 len = getdigits(&p); |
9248
9c751c33dc0f
commit https://github.com/vim/vim/commit/1d5f1d07aedb6f149f5de145b1dfd6528a769c93
Christian Brabandt <cb@256bit.org>
parents:
9244
diff
changeset
|
2631 buf = alloc((int)(len + 1)); |
9270
79cb08f0d812
commit https://github.com/vim/vim/commit/62f8b4e18014b259bcde4a2845c602b0a44a3714
Christian Brabandt <cb@256bit.org>
parents:
9268
diff
changeset
|
2632 if (buf == NULL) |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2633 return TRUE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2634 p = buf; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2635 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
|
2636 { |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2637 eof = viminfo_readline(virp); |
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2638 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
|
2639 || virp->vir_line[1] != '<') |
9270
79cb08f0d812
commit https://github.com/vim/vim/commit/62f8b4e18014b259bcde4a2845c602b0a44a3714
Christian Brabandt <cb@256bit.org>
parents:
9268
diff
changeset
|
2640 { |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2641 /* 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
|
2642 * this one starts with '|'. */ |
9270
79cb08f0d812
commit https://github.com/vim/vim/commit/62f8b4e18014b259bcde4a2845c602b0a44a3714
Christian Brabandt <cb@256bit.org>
parents:
9268
diff
changeset
|
2643 vim_free(buf); |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2644 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
|
2645 } |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2646 /* 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
|
2647 n = STRLEN(virp->vir_line); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2648 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
|
2649 || virp->vir_line[n - 1] == CAR)) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2650 --n; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2651 n -= 2; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2652 if (n > todo) |
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 /* more values follow after the string */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2655 nextp = virp->vir_line + 2 + todo; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2656 n = todo; |
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 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
|
2659 p += n; |
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 *p = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2662 p = buf; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2663 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2664 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2665 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2666 /* 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
|
2667 * |{bartype},{lots of values},> |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2668 * |<{value},{value} |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2669 */ |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2670 eof = viminfo_readline(virp); |
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2671 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
|
2672 || virp->vir_line[1] != '<') |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2673 /* 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
|
2674 * this one starts with '|'. */ |
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2675 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
|
2676 p = virp->vir_line + 2; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2677 } |
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 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2680 if (isdigit(*p)) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2681 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2682 value->bv_type = BVAL_NR; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2683 value->bv_nr = getdigits(&p); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2684 ++values->ga_len; |
9240
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 else if (*p == '"') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2687 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2688 int len = 0; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2689 char_u *s = p; |
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 /* Unescape special characters in-place. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2692 ++p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2693 while (*p != '"') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2694 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2695 if (*p == NL || *p == NUL) |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2696 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
|
2697 if (*p == '\\') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2698 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2699 ++p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2700 if (*p == 'n') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2701 s[len++] = '\n'; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2702 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2703 s[len++] = *p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2704 ++p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2705 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2706 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2707 s[len++] = *p++; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2708 } |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2709 ++p; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2710 s[len] = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2711 |
9268
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2712 #ifdef FEAT_MBYTE |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2713 converted = FALSE; |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2714 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
|
2715 { |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2716 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
|
2717 if (sconv != NULL) |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2718 { |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2719 if (s == buf) |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2720 vim_free(s); |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2721 s = sconv; |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2722 buf = s; |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2723 converted = TRUE; |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2724 } |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2725 } |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2726 #endif |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2727 /* 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
|
2728 * 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
|
2729 if (s != buf && allocated) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2730 s = vim_strsave(s); |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2731 value->bv_string = s; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2732 value->bv_type = BVAL_STRING; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2733 value->bv_len = len; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2734 value->bv_allocated = allocated |
9268
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2735 #ifdef FEAT_MBYTE |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2736 || converted |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2737 #endif |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2738 ; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2739 ++values->ga_len; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2740 if (nextp != NULL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2741 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2742 /* values following a long string */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2743 p = nextp; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2744 nextp = NULL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2745 } |
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 else if (*p == ',') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2748 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2749 value->bv_type = BVAL_EMPTY; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2750 ++values->ga_len; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2751 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2752 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2753 break; |
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 return TRUE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2756 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2757 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2758 static int |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2759 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
|
2760 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2761 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
|
2762 int bartype; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2763 garray_T values; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2764 bval_T *vp; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2765 int i; |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2766 int read_next = TRUE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2767 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2768 /* The format is: |{bartype},{value},... |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2769 * For a very long string: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2770 * |{bartype},>{length of "{text}{text2}"} |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2771 * |<{text1} |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2772 * |<{text2},{value} |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2773 * 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
|
2774 * |{bartype},{lots of values},> |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2775 * |<{value},{value} |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2776 */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2777 if (*p == '<') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2778 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2779 /* Continuation line of an unrecognized item. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2780 if (writing) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2781 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
|
2782 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2783 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2784 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2785 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
|
2786 bartype = getdigits(&p); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2787 switch (bartype) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2788 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2789 case BARTYPE_VERSION: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2790 /* 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
|
2791 * 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
|
2792 * doesn't understand the version. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2793 if (!got_encoding) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2794 { |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2795 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
|
2796 vp = (bval_T *)values.ga_data; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2797 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
|
2798 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
|
2799 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2800 break; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2801 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2802 case BARTYPE_HISTORY: |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2803 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
|
2804 handle_viminfo_history(&values, writing); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2805 break; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2806 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2807 case BARTYPE_REGISTER: |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2808 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
|
2809 handle_viminfo_register(&values, force); |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2810 break; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2811 |
9284
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2812 case BARTYPE_MARK: |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2813 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
|
2814 handle_viminfo_mark(&values, force); |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2815 break; |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2816 |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2817 default: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2818 /* copy unrecognized line (for future use) */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2819 if (writing) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2820 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
|
2821 } |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2822 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
|
2823 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2824 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
|
2825 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
|
2826 vim_free(vp->bv_string); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2827 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2828 ga_clear(&values); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2829 } |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2830 |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2831 if (read_next) |
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2832 return viminfo_readline(virp); |
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2833 return FALSE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2834 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2835 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2836 static void |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2837 write_viminfo_version(FILE *fp_out) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2838 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2839 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
|
2840 BARTYPE_VERSION, VIMINFO_VERSION); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2841 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2842 |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2843 static void |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2844 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
|
2845 { |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2846 int i; |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2847 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
|
2848 int seen_useful = FALSE; |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2849 char *line; |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2850 |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2851 if (gap->ga_len > 0) |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2852 { |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2853 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
|
2854 |
9412
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2855 /* 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
|
2856 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
|
2857 { |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2858 line = ((char **)(gap->ga_data))[i]; |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2859 if (seen_useful || line[1] != '<') |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2860 { |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2861 fputs(line, fp_out); |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2862 seen_useful = TRUE; |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2863 } |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2864 } |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2865 } |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2866 } |
7 | 2867 #endif /* FEAT_VIMINFO */ |
2868 | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2869 /* |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2870 * 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
|
2871 * was used. |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2872 */ |
9347
25c562442f8c
commit https://github.com/vim/vim/commit/f4fba6dcd508cb369ffa6916d9cb3fcf3d7ed548
Christian Brabandt <cb@256bit.org>
parents:
9330
diff
changeset
|
2873 time_T |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2874 vim_time(void) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2875 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2876 # ifdef FEAT_EVAL |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2877 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
|
2878 # else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2879 return time(NULL); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2880 # endif |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2881 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2882 |
7 | 2883 /* |
2884 * Implementation of ":fixdel", also used by get_stty(). | |
2885 * <BS> resulting <Del> | |
2886 * ^? ^H | |
2887 * not ^? ^? | |
2888 */ | |
2889 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2890 do_fixdel(exarg_T *eap UNUSED) |
7 | 2891 { |
2892 char_u *p; | |
2893 | |
2894 p = find_termcode((char_u *)"kb"); | |
2895 add_termcode((char_u *)"kD", p != NULL | |
2896 && *p == DEL ? (char_u *)CTRL_H_STR : DEL_STR, FALSE); | |
2897 } | |
2898 | |
2899 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2900 print_line_no_prefix( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2901 linenr_T lnum, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2902 int use_number, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2903 int list) |
7 | 2904 { |
13 | 2905 char_u numbuf[30]; |
7 | 2906 |
2907 if (curwin->w_p_nu || use_number) | |
2908 { | |
1872 | 2909 vim_snprintf((char *)numbuf, sizeof(numbuf), |
2910 "%*ld ", number_width(curwin), (long)lnum); | |
7 | 2911 msg_puts_attr(numbuf, hl_attr(HLF_N)); /* Highlight line nrs */ |
2912 } | |
169 | 2913 msg_prt_line(ml_get(lnum), list); |
7 | 2914 } |
2915 | |
2916 /* | |
2917 * Print a text line. Also in silent mode ("ex -s"). | |
2918 */ | |
2919 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2920 print_line(linenr_T lnum, int use_number, int list) |
7 | 2921 { |
2922 int save_silent = silent_mode; | |
2923 | |
9980
b222552cf0c4
commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents:
9978
diff
changeset
|
2924 /* apply :filter /pat/ */ |
b222552cf0c4
commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents:
9978
diff
changeset
|
2925 if (message_filtered(ml_get(lnum))) |
b222552cf0c4
commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents:
9978
diff
changeset
|
2926 return; |
b222552cf0c4
commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents:
9978
diff
changeset
|
2927 |
169 | 2928 msg_start(); |
7 | 2929 silent_mode = FALSE; |
169 | 2930 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */ |
2931 print_line_no_prefix(lnum, use_number, list); | |
7 | 2932 if (save_silent) |
2933 { | |
2934 msg_putchar('\n'); | |
2935 cursor_on(); /* msg_start() switches it off */ | |
2936 out_flush(); | |
2937 silent_mode = save_silent; | |
1798 | 2938 } |
2939 info_message = FALSE; | |
7 | 2940 } |
2941 | |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2942 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2943 rename_buffer(char_u *new_fname) |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2944 { |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2945 char_u *fname, *sfname, *xfname; |
4613
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
2946 buf_T *buf; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
2947 |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2948 #ifdef FEAT_AUTOCMD |
4613
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
2949 buf = curbuf; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
2950 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
|
2951 /* buffer changed, don't change name now */ |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2952 if (buf != curbuf) |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2953 return FAIL; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2954 # ifdef FEAT_EVAL |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2955 if (aborting()) /* autocmds may abort script processing */ |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2956 return FAIL; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2957 # endif |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2958 #endif |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2959 /* |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2960 * 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
|
2961 * 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
|
2962 * name, which will become the alternate file name. |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2963 * 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
|
2964 * name. |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2965 */ |
4613
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
2966 fname = curbuf->b_ffname; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
2967 sfname = curbuf->b_sfname; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
2968 xfname = curbuf->b_fname; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
2969 curbuf->b_ffname = NULL; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
2970 curbuf->b_sfname = NULL; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
2971 if (setfname(curbuf, new_fname, NULL, TRUE) == FAIL) |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
2972 { |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
2973 curbuf->b_ffname = fname; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
2974 curbuf->b_sfname = sfname; |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2975 return FAIL; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2976 } |
4613
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
2977 curbuf->b_flags |= BF_NOTEDITED; |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2978 if (xfname != NULL && *xfname != NUL) |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2979 { |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2980 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
|
2981 if (buf != NULL && !cmdmod.keepalt) |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2982 curwin->w_alt_fnum = buf->b_fnum; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2983 } |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2984 vim_free(fname); |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2985 vim_free(sfname); |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2986 #ifdef FEAT_AUTOCMD |
4613
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
2987 apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, curbuf); |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2988 #endif |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2989 /* Change directories when the 'acd' option is set. */ |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2990 DO_AUTOCHDIR |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2991 return OK; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2992 } |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
2993 |
7 | 2994 /* |
2995 * ":file[!] [fname]". | |
2996 */ | |
2997 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2998 ex_file(exarg_T *eap) |
7 | 2999 { |
14 | 3000 /* ":0file" removes the file name. Check for illegal uses ":3file", |
3001 * "0file name", etc. */ | |
3002 if (eap->addr_count > 0 | |
3003 && (*eap->arg != NUL | |
3004 || eap->line2 > 0 | |
3005 || eap->addr_count > 1)) | |
3006 { | |
3007 EMSG(_(e_invarg)); | |
3008 return; | |
3009 } | |
3010 | |
3011 if (*eap->arg != NUL || eap->addr_count == 1) | |
7 | 3012 { |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3013 if (rename_buffer(eap->arg) == FAIL) |
7 | 3014 return; |
3015 } | |
3016 /* print full file name if :cd used */ | |
8560
f3c636c673f7
commit https://github.com/vim/vim/commit/426dd0219512af5f4abeb0901b533159253ffba3
Christian Brabandt <cb@256bit.org>
parents:
8556
diff
changeset
|
3017 if (!shortmess(SHM_FILEINFO)) |
f3c636c673f7
commit https://github.com/vim/vim/commit/426dd0219512af5f4abeb0901b533159253ffba3
Christian Brabandt <cb@256bit.org>
parents:
8556
diff
changeset
|
3018 fileinfo(FALSE, FALSE, eap->forceit); |
7 | 3019 } |
3020 | |
3021 /* | |
3022 * ":update". | |
3023 */ | |
3024 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3025 ex_update(exarg_T *eap) |
7 | 3026 { |
3027 if (curbufIsChanged()) | |
3028 (void)do_write(eap); | |
3029 } | |
3030 | |
3031 /* | |
3032 * ":write" and ":saveas". | |
3033 */ | |
3034 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3035 ex_write(exarg_T *eap) |
7 | 3036 { |
3037 if (eap->usefilter) /* input lines to shell command */ | |
3038 do_bang(1, eap, FALSE, TRUE, FALSE); | |
3039 else | |
3040 (void)do_write(eap); | |
3041 } | |
3042 | |
3043 /* | |
3044 * write current buffer to file 'eap->arg' | |
3045 * if 'eap->append' is TRUE, append to the file | |
3046 * | |
3047 * if *eap->arg == NUL write to current file | |
3048 * | |
3049 * return FAIL for failure, OK otherwise | |
3050 */ | |
3051 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3052 do_write(exarg_T *eap) |
7 | 3053 { |
3054 int other; | |
3055 char_u *fname = NULL; /* init to shut up gcc */ | |
3056 char_u *ffname; | |
3057 int retval = FAIL; | |
3058 char_u *free_fname = NULL; | |
3059 #ifdef FEAT_BROWSE | |
3060 char_u *browse_file = NULL; | |
3061 #endif | |
3062 buf_T *alt_buf = NULL; | |
9469
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
3063 int name_was_missing; |
7 | 3064 |
3065 if (not_writing()) /* check 'write' option */ | |
3066 return FAIL; | |
3067 | |
3068 ffname = eap->arg; | |
3069 #ifdef FEAT_BROWSE | |
3070 if (cmdmod.browse) | |
3071 { | |
29 | 3072 browse_file = do_browse(BROWSE_SAVE, (char_u *)_("Save As"), ffname, |
7 | 3073 NULL, NULL, NULL, curbuf); |
3074 if (browse_file == NULL) | |
3075 goto theend; | |
3076 ffname = browse_file; | |
3077 } | |
3078 #endif | |
3079 if (*ffname == NUL) | |
3080 { | |
3081 if (eap->cmdidx == CMD_saveas) | |
3082 { | |
3083 EMSG(_(e_argreq)); | |
3084 goto theend; | |
3085 } | |
3086 other = FALSE; | |
3087 } | |
3088 else | |
3089 { | |
3090 fname = ffname; | |
3091 free_fname = fix_fname(ffname); | |
3092 /* | |
3093 * When out-of-memory, keep unexpanded file name, because we MUST be | |
3094 * able to write the file in this situation. | |
3095 */ | |
3096 if (free_fname != NULL) | |
3097 ffname = free_fname; | |
3098 other = otherfile(ffname); | |
3099 } | |
3100 | |
3101 /* | |
3102 * If we have a new file, put its name in the list of alternate file names. | |
3103 */ | |
3104 if (other) | |
3105 { | |
3106 if (vim_strchr(p_cpo, CPO_ALTWRITE) != NULL | |
3107 || eap->cmdidx == CMD_saveas) | |
3108 alt_buf = setaltfname(ffname, fname, (linenr_T)1); | |
3109 else | |
3110 alt_buf = buflist_findname(ffname); | |
3111 if (alt_buf != NULL && alt_buf->b_ml.ml_mfp != NULL) | |
3112 { | |
3113 /* Overwriting a file that is loaded in another buffer is not a | |
3114 * good idea. */ | |
315 | 3115 EMSG(_(e_bufloaded)); |
7 | 3116 goto theend; |
3117 } | |
3118 } | |
3119 | |
3120 /* | |
3121 * Writing to the current file is not allowed in readonly mode | |
3122 * and a file name is required. | |
3123 * "nofile" and "nowrite" buffers cannot be written implicitly either. | |
3124 */ | |
3125 if (!other && ( | |
3126 #ifdef FEAT_QUICKFIX | |
3127 bt_dontwrite_msg(curbuf) || | |
3128 #endif | |
3129 check_fname() == FAIL || check_readonly(&eap->forceit, curbuf))) | |
3130 goto theend; | |
3131 | |
3132 if (!other) | |
3133 { | |
3134 ffname = curbuf->b_ffname; | |
3135 fname = curbuf->b_fname; | |
3136 /* | |
3137 * Not writing the whole file is only allowed with '!'. | |
3138 */ | |
3139 if ( (eap->line1 != 1 | |
3140 || eap->line2 != curbuf->b_ml.ml_line_count) | |
3141 && !eap->forceit | |
3142 && !eap->append | |
3143 && !p_wa) | |
3144 { | |
3145 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
3146 if (p_confirm || cmdmod.confirm) | |
3147 { | |
3148 if (vim_dialog_yesno(VIM_QUESTION, NULL, | |
3149 (char_u *)_("Write partial file?"), 2) != VIM_YES) | |
3150 goto theend; | |
3151 eap->forceit = TRUE; | |
3152 } | |
3153 else | |
3154 #endif | |
3155 { | |
3156 EMSG(_("E140: Use ! to write partial buffer")); | |
3157 goto theend; | |
3158 } | |
3159 } | |
3160 } | |
3161 | |
3162 if (check_overwrite(eap, curbuf, fname, ffname, other) == OK) | |
3163 { | |
3164 if (eap->cmdidx == CMD_saveas && alt_buf != NULL) | |
3165 { | |
3166 #ifdef FEAT_AUTOCMD | |
3167 buf_T *was_curbuf = curbuf; | |
3168 | |
3169 apply_autocmds(EVENT_BUFFILEPRE, NULL, NULL, FALSE, curbuf); | |
21 | 3170 apply_autocmds(EVENT_BUFFILEPRE, NULL, NULL, FALSE, alt_buf); |
7 | 3171 # ifdef FEAT_EVAL |
3172 if (curbuf != was_curbuf || aborting()) | |
3173 # else | |
3174 if (curbuf != was_curbuf) | |
3175 # endif | |
3176 { | |
3177 /* buffer changed, don't change name now */ | |
3178 retval = FAIL; | |
3179 goto theend; | |
3180 } | |
3181 #endif | |
3182 /* Exchange the file names for the current and the alternate | |
3183 * buffer. This makes it look like we are now editing the buffer | |
3184 * under the new name. Must be done before buf_write(), because | |
3185 * if there is no file name and 'cpo' contains 'F', it will set | |
3186 * the file name. */ | |
3187 fname = alt_buf->b_fname; | |
3188 alt_buf->b_fname = curbuf->b_fname; | |
3189 curbuf->b_fname = fname; | |
3190 fname = alt_buf->b_ffname; | |
3191 alt_buf->b_ffname = curbuf->b_ffname; | |
3192 curbuf->b_ffname = fname; | |
3193 fname = alt_buf->b_sfname; | |
3194 alt_buf->b_sfname = curbuf->b_sfname; | |
3195 curbuf->b_sfname = fname; | |
3196 buf_name_changed(curbuf); | |
3197 #ifdef FEAT_AUTOCMD | |
3198 apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, curbuf); | |
21 | 3199 apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, alt_buf); |
7 | 3200 if (!alt_buf->b_p_bl) |
3201 { | |
3202 alt_buf->b_p_bl = TRUE; | |
3203 apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, alt_buf); | |
3204 } | |
3205 # ifdef FEAT_EVAL | |
3206 if (curbuf != was_curbuf || aborting()) | |
3207 # else | |
3208 if (curbuf != was_curbuf) | |
3209 # endif | |
3210 { | |
3211 /* buffer changed, don't write the file */ | |
3212 retval = FAIL; | |
3213 goto theend; | |
3214 } | |
634 | 3215 |
3216 /* If 'filetype' was empty try detecting it now. */ | |
3217 if (*curbuf->b_p_ft == NUL) | |
3218 { | |
819 | 3219 if (au_has_group((char_u *)"filetypedetect")) |
3220 (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
|
3221 TRUE, NULL); |
717 | 3222 do_modelines(0); |
634 | 3223 } |
2648 | 3224 |
3225 /* Autocommands may have changed buffer names, esp. when | |
3226 * 'autochdir' is set. */ | |
3227 fname = curbuf->b_sfname; | |
7 | 3228 #endif |
3229 } | |
3230 | |
9469
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
3231 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
|
3232 |
7 | 3233 retval = buf_write(curbuf, ffname, fname, eap->line1, eap->line2, |
3234 eap, eap->append, eap->forceit, TRUE, FALSE); | |
634 | 3235 |
819 | 3236 /* After ":saveas fname" reset 'readonly'. */ |
961 | 3237 if (eap->cmdidx == CMD_saveas) |
3238 { | |
3239 if (retval == OK) | |
1806 | 3240 { |
961 | 3241 curbuf->b_p_ro = FALSE; |
1806 | 3242 #ifdef FEAT_WINDOWS |
3243 redraw_tabline = TRUE; | |
3244 #endif | |
3245 } | |
9469
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
3246 } |
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
3247 |
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
3248 /* 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
|
3249 * got changed or set. */ |
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
3250 if (eap->cmdidx == CMD_saveas || name_was_missing) |
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
3251 { |
961 | 3252 DO_AUTOCHDIR |
3253 } | |
7 | 3254 } |
3255 | |
3256 theend: | |
3257 #ifdef FEAT_BROWSE | |
3258 vim_free(browse_file); | |
3259 #endif | |
3260 vim_free(free_fname); | |
3261 return retval; | |
3262 } | |
3263 | |
3264 /* | |
3265 * Check if it is allowed to overwrite a file. If b_flags has BF_NOTEDITED, | |
3266 * BF_NEW or BF_READERR, check for overwriting current file. | |
3267 * May set eap->forceit if a dialog says it's OK to overwrite. | |
3268 * Return OK if it's OK, FAIL if it is not. | |
3269 */ | |
3486 | 3270 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3271 check_overwrite( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3272 exarg_T *eap, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3273 buf_T *buf, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3274 char_u *fname, /* file name to be used (can differ from |
7 | 3275 buf->ffname) */ |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3276 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
|
3277 int other) /* writing under other name */ |
7 | 3278 { |
3279 /* | |
3280 * write to other file or b_flags set or not writing the whole file: | |
3281 * overwriting only allowed with '!' | |
3282 */ | |
3283 if ( (other | |
3284 || (buf->b_flags & BF_NOTEDITED) | |
3285 || ((buf->b_flags & BF_NEW) | |
3286 && vim_strchr(p_cpo, CPO_OVERNEW) == NULL) | |
3287 || (buf->b_flags & BF_READERR)) | |
3288 && !p_wa | |
1457 | 3289 #ifdef FEAT_QUICKFIX |
3290 && !bt_nofile(buf) | |
3291 #endif | |
7 | 3292 && vim_fexists(ffname)) |
3293 { | |
460 | 3294 if (!eap->forceit && !eap->append) |
7 | 3295 { |
460 | 3296 #ifdef UNIX |
637 | 3297 /* with UNIX it is possible to open a directory */ |
460 | 3298 if (mch_isdir(ffname)) |
3299 { | |
3300 EMSG2(_(e_isadir2), ffname); | |
3301 return FAIL; | |
3302 } | |
7 | 3303 #endif |
3304 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
460 | 3305 if (p_confirm || cmdmod.confirm) |
3306 { | |
2770 | 3307 char_u buff[DIALOG_MSG_SIZE]; |
460 | 3308 |
3309 dialog_msg(buff, _("Overwrite existing file \"%s\"?"), fname); | |
3310 if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) != VIM_YES) | |
3311 return FAIL; | |
3312 eap->forceit = TRUE; | |
3313 } | |
3314 else | |
3315 #endif | |
3316 { | |
3317 EMSG(_(e_exists)); | |
7 | 3318 return FAIL; |
460 | 3319 } |
7 | 3320 } |
460 | 3321 |
3322 /* For ":w! filename" check that no swap file exists for "filename". */ | |
3323 if (other && !emsg_silent) | |
7 | 3324 { |
2770 | 3325 char_u *dir; |
460 | 3326 char_u *p; |
3327 int r; | |
3328 char_u *swapname; | |
3329 | |
3330 /* We only try the first entry in 'directory', without checking if | |
3331 * it's writable. If the "." directory is not writable the write | |
3332 * will probably fail anyway. | |
3333 * Use 'shortname' of the current buffer, since there is no buffer | |
3334 * for the written file. */ | |
3335 if (*p_dir == NUL) | |
2770 | 3336 { |
3337 dir = alloc(5); | |
3338 if (dir == NULL) | |
3339 return FAIL; | |
460 | 3340 STRCPY(dir, "."); |
2770 | 3341 } |
460 | 3342 else |
3343 { | |
2770 | 3344 dir = alloc(MAXPATHL); |
3345 if (dir == NULL) | |
3346 return FAIL; | |
460 | 3347 p = p_dir; |
3348 copy_option_part(&p, dir, MAXPATHL, ","); | |
3349 } | |
3350 swapname = makeswapname(fname, ffname, curbuf, dir); | |
2770 | 3351 vim_free(dir); |
460 | 3352 r = vim_fexists(swapname); |
3353 if (r) | |
3354 { | |
3355 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
3356 if (p_confirm || cmdmod.confirm) | |
3357 { | |
2770 | 3358 char_u buff[DIALOG_MSG_SIZE]; |
460 | 3359 |
3360 dialog_msg(buff, | |
3361 _("Swap file \"%s\" exists, overwrite anyway?"), | |
3362 swapname); | |
3363 if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) | |
3364 != VIM_YES) | |
819 | 3365 { |
3366 vim_free(swapname); | |
460 | 3367 return FAIL; |
819 | 3368 } |
460 | 3369 eap->forceit = TRUE; |
3370 } | |
3371 else | |
3372 #endif | |
3373 { | |
3374 EMSG2(_("E768: Swap file exists: %s (:silent! overrides)"), | |
3375 swapname); | |
819 | 3376 vim_free(swapname); |
460 | 3377 return FAIL; |
3378 } | |
3379 } | |
819 | 3380 vim_free(swapname); |
7 | 3381 } |
3382 } | |
3383 return OK; | |
3384 } | |
3385 | |
3386 /* | |
3387 * Handle ":wnext", ":wNext" and ":wprevious" commands. | |
3388 */ | |
3389 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3390 ex_wnext(exarg_T *eap) |
7 | 3391 { |
3392 int i; | |
3393 | |
3394 if (eap->cmd[1] == 'n') | |
3395 i = curwin->w_arg_idx + (int)eap->line2; | |
3396 else | |
3397 i = curwin->w_arg_idx - (int)eap->line2; | |
3398 eap->line1 = 1; | |
3399 eap->line2 = curbuf->b_ml.ml_line_count; | |
3400 if (do_write(eap) != FAIL) | |
3401 do_argfile(eap, i); | |
3402 } | |
3403 | |
3404 /* | |
3405 * ":wall", ":wqall" and ":xall": Write all changed files (and exit). | |
3406 */ | |
3407 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3408 do_wqall(exarg_T *eap) |
7 | 3409 { |
3410 buf_T *buf; | |
3411 int error = 0; | |
3412 int save_forceit = eap->forceit; | |
3413 | |
3414 if (eap->cmdidx == CMD_xall || eap->cmdidx == CMD_wqall) | |
3415 exiting = TRUE; | |
3416 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
3417 FOR_ALL_BUFFERS(buf) |
7 | 3418 { |
3419 if (bufIsChanged(buf)) | |
3420 { | |
3421 /* | |
3422 * Check if there is a reason the buffer cannot be written: | |
3423 * 1. if the 'write' option is set | |
3424 * 2. if there is no file name (even after browsing) | |
3425 * 3. if the 'readonly' is set (even after a dialog) | |
3426 * 4. if overwriting is allowed (even after a dialog) | |
3427 */ | |
3428 if (not_writing()) | |
3429 { | |
3430 ++error; | |
3431 break; | |
3432 } | |
3433 #ifdef FEAT_BROWSE | |
3434 /* ":browse wall": ask for file name if there isn't one */ | |
3435 if (buf->b_ffname == NULL && cmdmod.browse) | |
3436 browse_save_fname(buf); | |
3437 #endif | |
3438 if (buf->b_ffname == NULL) | |
3439 { | |
3440 EMSGN(_("E141: No file name for buffer %ld"), (long)buf->b_fnum); | |
3441 ++error; | |
3442 } | |
3443 else if (check_readonly(&eap->forceit, buf) | |
3444 || check_overwrite(eap, buf, buf->b_fname, buf->b_ffname, | |
3445 FALSE) == FAIL) | |
3446 { | |
3447 ++error; | |
3448 } | |
3449 else | |
3450 { | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3451 #ifdef FEAT_AUTOCMD |
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3452 bufref_T bufref; |
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3453 |
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3454 set_bufref(&bufref, buf); |
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3455 #endif |
7 | 3456 if (buf_write_all(buf, eap->forceit) == FAIL) |
3457 ++error; | |
3458 #ifdef FEAT_AUTOCMD | |
3459 /* 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
|
3460 if (!bufref_valid(&bufref)) |
7 | 3461 buf = firstbuf; |
3462 #endif | |
3463 } | |
3464 eap->forceit = save_forceit; /* check_overwrite() may set it */ | |
3465 } | |
3466 } | |
3467 if (exiting) | |
3468 { | |
3469 if (!error) | |
3470 getout(0); /* exit Vim */ | |
3471 not_exiting(); | |
3472 } | |
3473 } | |
3474 | |
3475 /* | |
3476 * Check the 'write' option. | |
3477 * Return TRUE and give a message when it's not st. | |
3478 */ | |
3479 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3480 not_writing(void) |
7 | 3481 { |
3482 if (p_write) | |
3483 return FALSE; | |
3484 EMSG(_("E142: File not written: Writing is disabled by 'write' option")); | |
3485 return TRUE; | |
3486 } | |
3487 | |
3488 /* | |
1303 | 3489 * Check if a buffer is read-only (either 'readonly' option is set or file is |
3490 * read-only). Ask for overruling in a dialog. Return TRUE and give an error | |
3491 * message when the buffer is readonly. | |
7 | 3492 */ |
3493 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3494 check_readonly(int *forceit, buf_T *buf) |
7 | 3495 { |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9377
diff
changeset
|
3496 stat_T st; |
1303 | 3497 |
3498 /* Handle a file being readonly when the 'readonly' option is set or when | |
3499 * the file exists and permissions are read-only. | |
3500 * We will send 0777 to check_file_readonly(), as the "perm" variable is | |
3501 * important for device checks but not here. */ | |
3502 if (!*forceit && (buf->b_p_ro | |
3503 || (mch_stat((char *)buf->b_ffname, &st) >= 0 | |
3504 && check_file_readonly(buf->b_ffname, 0777)))) | |
7 | 3505 { |
3506 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
3507 if ((p_confirm || cmdmod.confirm) && buf->b_fname != NULL) | |
3508 { | |
2770 | 3509 char_u buff[DIALOG_MSG_SIZE]; |
7 | 3510 |
1303 | 3511 if (buf->b_p_ro) |
3512 dialog_msg(buff, _("'readonly' option is set for \"%s\".\nDo you wish to write anyway?"), | |
3513 buf->b_fname); | |
3514 else | |
3515 dialog_msg(buff, _("File permissions of \"%s\" are read-only.\nIt may still be possible to write it.\nDo you wish to try?"), | |
7 | 3516 buf->b_fname); |
3517 | |
3518 if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) == VIM_YES) | |
3519 { | |
3520 /* Set forceit, to force the writing of a readonly file */ | |
3521 *forceit = TRUE; | |
3522 return FALSE; | |
3523 } | |
3524 else | |
3525 return TRUE; | |
3526 } | |
3527 else | |
3528 #endif | |
1303 | 3529 if (buf->b_p_ro) |
7 | 3530 EMSG(_(e_readonly)); |
1303 | 3531 else |
3532 EMSG2(_("E505: \"%s\" is read-only (add ! to override)"), | |
3533 buf->b_fname); | |
7 | 3534 return TRUE; |
3535 } | |
1303 | 3536 |
7 | 3537 return FALSE; |
3538 } | |
3539 | |
3540 /* | |
632 | 3541 * Try to abandon current file and edit a new or existing file. |
3542 * 'fnum' is the number of the file, if zero use ffname/sfname. | |
7 | 3543 * |
632 | 3544 * Return 1 for "normal" error, 2 for "not written" error, 0 for success |
1370 | 3545 * -1 for successfully opening another file. |
7 | 3546 * 'lnum' is the line number for the cursor in the new file (if non-zero). |
3547 */ | |
3548 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3549 getfile( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3550 int fnum, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3551 char_u *ffname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3552 char_u *sfname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3553 int setpm, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3554 linenr_T lnum, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3555 int forceit) |
7 | 3556 { |
3557 int other; | |
3558 int retval; | |
3559 char_u *free_me = NULL; | |
3560 | |
634 | 3561 if (text_locked()) |
7 | 3562 return 1; |
819 | 3563 #ifdef FEAT_AUTOCMD |
3564 if (curbuf_locked()) | |
3565 return 1; | |
3566 #endif | |
7 | 3567 |
3568 if (fnum == 0) | |
3569 { | |
3570 /* make ffname full path, set sfname */ | |
3571 fname_expand(curbuf, &ffname, &sfname); | |
3572 other = otherfile(ffname); | |
3573 free_me = ffname; /* has been allocated, free() later */ | |
3574 } | |
3575 else | |
3576 other = (fnum != curbuf->b_fnum); | |
3577 | |
3578 if (other) | |
3579 ++no_wait_return; /* don't wait for autowrite message */ | |
3580 if (other && !forceit && curbuf->b_nwindows == 1 && !P_HID(curbuf) | |
3581 && curbufIsChanged() && autowrite(curbuf, forceit) == FAIL) | |
3582 { | |
3583 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
3584 if (p_confirm && p_write) | |
3585 dialog_changed(curbuf, FALSE); | |
3586 if (curbufIsChanged()) | |
3587 #endif | |
3588 { | |
3589 if (other) | |
3590 --no_wait_return; | |
3591 EMSG(_(e_nowrtmsg)); | |
3592 retval = 2; /* file has been changed */ | |
3593 goto theend; | |
3594 } | |
3595 } | |
3596 if (other) | |
3597 --no_wait_return; | |
3598 if (setpm) | |
3599 setpcmark(); | |
3600 if (!other) | |
3601 { | |
3602 if (lnum != 0) | |
3603 curwin->w_cursor.lnum = lnum; | |
3604 check_cursor_lnum(); | |
3605 beginline(BL_SOL | BL_FIX); | |
3606 retval = 0; /* it's in the same file */ | |
3607 } | |
3608 else if (do_ecmd(fnum, ffname, sfname, NULL, lnum, | |
1743 | 3609 (P_HID(curbuf) ? ECMD_HIDE : 0) + (forceit ? ECMD_FORCEIT : 0), |
3610 curwin) == OK) | |
7 | 3611 retval = -1; /* opened another file */ |
3612 else | |
3613 retval = 1; /* error encountered */ | |
3614 | |
3615 theend: | |
3616 vim_free(free_me); | |
3617 return retval; | |
3618 } | |
3619 | |
3620 /* | |
3621 * start editing a new file | |
3622 * | |
3623 * fnum: file number; if zero use ffname/sfname | |
3624 * ffname: the file name | |
3625 * - full path if sfname used, | |
3626 * - any file name if sfname is NULL | |
3627 * - empty string to re-edit with the same file name (but may be | |
3628 * in a different directory) | |
3629 * - NULL to start an empty buffer | |
3630 * sfname: the short file name (or NULL) | |
3631 * eap: contains the command to be executed after loading the file and | |
3632 * forced 'ff' and 'fenc' | |
3633 * newlnum: if > 0: put cursor on this line number (if possible) | |
3634 * if ECMD_LASTL: use last position in loaded file | |
3635 * if ECMD_LAST: use last position in all files | |
3636 * if ECMD_ONE: use first line | |
3637 * flags: | |
3638 * ECMD_HIDE: if TRUE don't free the current buffer | |
3639 * ECMD_SET_HELP: set b_help flag of (new) buffer before opening file | |
3640 * ECMD_OLDBUF: use existing buffer if it exists | |
3641 * ECMD_FORCEIT: ! used for Ex command | |
3642 * ECMD_ADDBUF: don't edit, just add to buffer list | |
1743 | 3643 * 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
|
3644 * 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
|
3645 * of the previous buffer for "oldwin" is stored. |
7 | 3646 * |
3647 * return FAIL for failure, OK otherwise | |
3648 */ | |
3649 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3650 do_ecmd( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3651 int fnum, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3652 char_u *ffname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3653 char_u *sfname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3654 exarg_T *eap, /* can be NULL! */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3655 linenr_T newlnum, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3656 int flags, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3657 win_T *oldwin) |
7 | 3658 { |
3659 int other_file; /* TRUE if editing another file */ | |
3660 int oldbuf; /* TRUE if using existing buffer */ | |
3661 #ifdef FEAT_AUTOCMD | |
3662 int auto_buf = FALSE; /* TRUE if autocommands brought us | |
3663 into the buffer unexpectedly */ | |
3664 char_u *new_name = NULL; | |
716 | 3665 int did_set_swapcommand = FALSE; |
7 | 3666 #endif |
3667 buf_T *buf; | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3668 bufref_T bufref; |
7 | 3669 #if defined(FEAT_AUTOCMD) || defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9481
diff
changeset
|
3670 bufref_T old_curbuf; |
7 | 3671 #endif |
3672 char_u *free_fname = NULL; | |
3673 #ifdef FEAT_BROWSE | |
3674 char_u *browse_file = NULL; | |
3675 #endif | |
3676 int retval = FAIL; | |
3677 long n; | |
6702 | 3678 pos_T orig_pos; |
7 | 3679 linenr_T topline = 0; |
3680 int newcol = -1; | |
3681 int solcol = -1; | |
3682 pos_T *pos; | |
3683 #ifdef FEAT_SUN_WORKSHOP | |
3684 char_u *cp; | |
3685 #endif | |
3686 char_u *command = NULL; | |
1185 | 3687 #ifdef FEAT_SPELL |
3688 int did_get_winopts = FALSE; | |
3689 #endif | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
3690 int readfile_flags = 0; |
7941
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
3691 int did_inc_redrawing_disabled = FALSE; |
7 | 3692 |
3693 if (eap != NULL) | |
3694 command = eap->do_ecmd_cmd; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9481
diff
changeset
|
3695 #if defined(FEAT_AUTOCMD) || defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9481
diff
changeset
|
3696 set_bufref(&old_curbuf, curbuf); |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9481
diff
changeset
|
3697 #endif |
7 | 3698 |
3699 if (fnum != 0) | |
3700 { | |
3701 if (fnum == curbuf->b_fnum) /* file is already being edited */ | |
3702 return OK; /* nothing to do */ | |
3703 other_file = TRUE; | |
3704 } | |
3705 else | |
3706 { | |
3707 #ifdef FEAT_BROWSE | |
3708 if (cmdmod.browse) | |
3709 { | |
1683 | 3710 # ifdef FEAT_AUTOCMD |
462 | 3711 if ( |
1683 | 3712 # ifdef FEAT_GUI |
462 | 3713 !gui.in_use && |
1683 | 3714 # endif |
462 | 3715 au_has_group((char_u *)"FileExplorer")) |
3716 { | |
3717 /* No browsing supported but we do have the file explorer: | |
3718 * Edit the directory. */ | |
3719 if (ffname == NULL || !mch_isdir(ffname)) | |
3720 ffname = (char_u *)"."; | |
3721 } | |
3722 else | |
1683 | 3723 # endif |
462 | 3724 { |
3725 browse_file = do_browse(0, (char_u *)_("Edit File"), ffname, | |
7 | 3726 NULL, NULL, NULL, curbuf); |
462 | 3727 if (browse_file == NULL) |
3728 goto theend; | |
3729 ffname = browse_file; | |
3730 } | |
7 | 3731 } |
3732 #endif | |
3733 /* if no short name given, use ffname for short name */ | |
3734 if (sfname == NULL) | |
3735 sfname = ffname; | |
3736 #ifdef USE_FNAME_CASE | |
3737 # ifdef USE_LONG_FNAME | |
3738 if (USE_LONG_FNAME) | |
3739 # endif | |
436 | 3740 if (sfname != NULL) |
3741 fname_case(sfname, 0); /* set correct case for sfname */ | |
7 | 3742 #endif |
3743 | |
3744 #ifdef FEAT_LISTCMDS | |
3745 if ((flags & ECMD_ADDBUF) && (ffname == NULL || *ffname == NUL)) | |
3746 goto theend; | |
3747 #endif | |
3748 | |
3749 if (ffname == NULL) | |
3750 other_file = TRUE; | |
3751 /* there is no file name */ | |
3752 else if (*ffname == NUL && curbuf->b_ffname == NULL) | |
3753 other_file = FALSE; | |
3754 else | |
3755 { | |
3756 if (*ffname == NUL) /* re-edit with same file name */ | |
3757 { | |
3758 ffname = curbuf->b_ffname; | |
3759 sfname = curbuf->b_fname; | |
3760 } | |
3761 free_fname = fix_fname(ffname); /* may expand to full path name */ | |
3762 if (free_fname != NULL) | |
3763 ffname = free_fname; | |
3764 other_file = otherfile(ffname); | |
3765 #ifdef FEAT_SUN_WORKSHOP | |
3766 if (usingSunWorkShop && p_acd | |
3767 && (cp = vim_strrchr(sfname, '/')) != NULL) | |
3768 sfname = ++cp; | |
3769 #endif | |
3770 } | |
3771 } | |
3772 | |
3773 /* | |
3774 * if the file was changed we may not be allowed to abandon it | |
3775 * - if we are going to re-edit the same file | |
3776 * - or if we are the only window on this file and if ECMD_HIDE is FALSE | |
3777 */ | |
3778 if ( ((!other_file && !(flags & ECMD_OLDBUF)) | |
3779 || (curbuf->b_nwindows == 1 | |
3780 && !(flags & (ECMD_HIDE | ECMD_ADDBUF)))) | |
5464 | 3781 && check_changed(curbuf, (p_awa ? CCGD_AW : 0) |
3782 | (other_file ? 0 : CCGD_MULTWIN) | |
3783 | ((flags & ECMD_FORCEIT) ? CCGD_FORCEIT : 0) | |
3784 | (eap == NULL ? 0 : CCGD_EXCMD))) | |
7 | 3785 { |
3786 if (fnum == 0 && other_file && ffname != NULL) | |
3787 (void)setaltfname(ffname, sfname, newlnum < 0 ? 0 : newlnum); | |
3788 goto theend; | |
3789 } | |
3790 | |
3791 /* | |
3792 * End Visual mode before switching to another buffer, so the text can be | |
3793 * copied into the GUI selection buffer. | |
3794 */ | |
3795 reset_VIsual(); | |
3796 | |
716 | 3797 #ifdef FEAT_AUTOCMD |
3798 if ((command != NULL || newlnum > (linenr_T)0) | |
3799 && *get_vim_var_str(VV_SWAPCOMMAND) == NUL) | |
3800 { | |
3801 int len; | |
3802 char_u *p; | |
3803 | |
3804 /* Set v:swapcommand for the SwapExists autocommands. */ | |
3805 if (command != NULL) | |
835 | 3806 len = (int)STRLEN(command) + 3; |
716 | 3807 else |
3808 len = 30; | |
3809 p = alloc((unsigned)len); | |
3810 if (p != NULL) | |
3811 { | |
3812 if (command != NULL) | |
3813 vim_snprintf((char *)p, len, ":%s\r", command); | |
3814 else | |
3815 vim_snprintf((char *)p, len, "%ldG", (long)newlnum); | |
3816 set_vim_var_string(VV_SWAPCOMMAND, p, -1); | |
3817 did_set_swapcommand = TRUE; | |
3818 vim_free(p); | |
3819 } | |
3820 } | |
3821 #endif | |
3822 | |
7 | 3823 /* |
3824 * If we are starting to edit another file, open a (new) buffer. | |
3825 * Otherwise we re-use the current buffer. | |
3826 */ | |
3827 if (other_file) | |
3828 { | |
3829 #ifdef FEAT_LISTCMDS | |
3830 if (!(flags & ECMD_ADDBUF)) | |
3831 #endif | |
3832 { | |
22 | 3833 if (!cmdmod.keepalt) |
3834 curwin->w_alt_fnum = curbuf->b_fnum; | |
1743 | 3835 if (oldwin != NULL) |
3836 buflist_altfpos(oldwin); | |
7 | 3837 } |
3838 | |
3839 if (fnum) | |
3840 buf = buflist_findnr(fnum); | |
3841 else | |
3842 { | |
3843 #ifdef FEAT_LISTCMDS | |
3844 if (flags & ECMD_ADDBUF) | |
3845 { | |
3846 linenr_T tlnum = 1L; | |
3847 | |
3848 if (command != NULL) | |
3849 { | |
3850 tlnum = atol((char *)command); | |
3851 if (tlnum <= 0) | |
3852 tlnum = 1L; | |
3853 } | |
3854 (void)buflist_new(ffname, sfname, tlnum, BLN_LISTED); | |
3855 goto theend; | |
3856 } | |
3857 #endif | |
3858 buf = buflist_new(ffname, sfname, 0L, | |
3859 BLN_CURBUF | ((flags & ECMD_SET_HELP) ? 0 : BLN_LISTED)); | |
5816 | 3860 #ifdef FEAT_AUTOCMD |
3861 /* autocommands may change curwin and curbuf */ | |
3862 if (oldwin != NULL) | |
3863 oldwin = curwin; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9481
diff
changeset
|
3864 set_bufref(&old_curbuf, curbuf); |
5816 | 3865 #endif |
7 | 3866 } |
3867 if (buf == NULL) | |
3868 goto theend; | |
3869 if (buf->b_ml.ml_mfp == NULL) /* no memfile yet */ | |
3870 { | |
3871 oldbuf = FALSE; | |
3872 } | |
3873 else /* existing memfile */ | |
3874 { | |
3875 oldbuf = TRUE; | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3876 set_bufref(&bufref, buf); |
7 | 3877 (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
|
3878 /* 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
|
3879 * current buffer. */ |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3880 if (!bufref_valid(&bufref) |
7 | 3881 #ifdef FEAT_AUTOCMD |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9481
diff
changeset
|
3882 || curbuf != old_curbuf.br_buf |
7 | 3883 #endif |
3884 ) | |
3885 goto theend; | |
3886 #ifdef FEAT_EVAL | |
3887 if (aborting()) /* autocmds may abort script processing */ | |
3888 goto theend; | |
3889 #endif | |
3890 } | |
3891 | |
3892 /* May jump to last used line number for a loaded buffer or when asked | |
3893 * for explicitly */ | |
3894 if ((oldbuf && newlnum == ECMD_LASTL) || newlnum == ECMD_LAST) | |
3895 { | |
3896 pos = buflist_findfpos(buf); | |
3897 newlnum = pos->lnum; | |
3898 solcol = pos->col; | |
3899 } | |
3900 | |
3901 /* | |
3902 * Make the (new) buffer the one used by the current window. | |
3903 * If the old buffer becomes unused, free it if ECMD_HIDE is FALSE. | |
3904 * If the current buffer was empty and has no file name, curbuf | |
6639 | 3905 * is returned by buflist_new(), nothing to do here. |
7 | 3906 */ |
3907 if (buf != curbuf) | |
3908 { | |
3909 #ifdef FEAT_AUTOCMD | |
3910 /* | |
3911 * Be careful: The autocommands may delete any buffer and change | |
3912 * the current buffer. | |
3913 * - If the buffer we are going to edit is deleted, give up. | |
3914 * - If the current buffer is deleted, prefer to load the new | |
3915 * buffer when loading a buffer is required. This avoids | |
3916 * loading another buffer which then must be closed again. | |
3917 * - If we ended up in the new buffer already, need to skip a few | |
3918 * things, set auto_buf. | |
3919 */ | |
3920 if (buf->b_fname != NULL) | |
3921 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
|
3922 set_bufref(&au_new_curbuf, buf); |
7 | 3923 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
|
3924 if (!bufref_valid(&au_new_curbuf)) |
7 | 3925 { |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3926 /* new buffer has been deleted */ |
7 | 3927 delbuf_msg(new_name); /* frees new_name */ |
3928 goto theend; | |
3929 } | |
3930 # ifdef FEAT_EVAL | |
3931 if (aborting()) /* autocmds may abort script processing */ | |
3932 { | |
3933 vim_free(new_name); | |
3934 goto theend; | |
3935 } | |
3936 # endif | |
3937 if (buf == curbuf) /* already in new buffer */ | |
3938 auto_buf = TRUE; | |
3939 else | |
3940 { | |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3941 win_T *the_curwin = curwin; |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3942 |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3943 /* 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
|
3944 * 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
|
3945 the_curwin->w_closing = TRUE; |
10106
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
3946 ++buf->b_locked; |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3947 |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9481
diff
changeset
|
3948 if (curbuf == old_curbuf.br_buf) |
7 | 3949 #endif |
3950 buf_copy_options(buf, BCO_ENTER); | |
3951 | |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3952 /* 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
|
3953 * oldwin->w_buffer to NULL. */ |
825 | 3954 u_sync(FALSE); |
1743 | 3955 close_buffer(oldwin, curbuf, |
3365 | 3956 (flags & ECMD_HIDE) ? 0 : DOBUF_UNLOAD, FALSE); |
7 | 3957 |
3958 #ifdef FEAT_AUTOCMD | |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3959 the_curwin->w_closing = FALSE; |
10106
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
3960 --buf->b_locked; |
3242 | 3961 |
7 | 3962 # ifdef FEAT_EVAL |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3963 /* autocmds may abort script processing */ |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3964 if (aborting() && curwin->w_buffer != NULL) |
7 | 3965 { |
3966 vim_free(new_name); | |
3967 goto theend; | |
3968 } | |
3969 # endif | |
3970 /* Be careful again, like above. */ | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3971 if (!bufref_valid(&au_new_curbuf)) |
7 | 3972 { |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3973 /* new buffer has been deleted */ |
7 | 3974 delbuf_msg(new_name); /* frees new_name */ |
3975 goto theend; | |
3976 } | |
3977 if (buf == curbuf) /* already in new buffer */ | |
3978 auto_buf = TRUE; | |
3979 else | |
3980 #endif | |
3981 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
3982 #ifdef FEAT_SYN_HL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
3983 /* |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
3984 * <VN> We could instead free the synblock |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
3985 * and re-attach to buffer, perhaps. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
3986 */ |
10482
712acb0ad6a8
commit https://github.com/vim/vim/commit/c4bfedabe057c05f09a455a5851089e177fa9c00
Christian Brabandt <cb@256bit.org>
parents:
10357
diff
changeset
|
3987 if (curwin->w_buffer != NULL |
712acb0ad6a8
commit https://github.com/vim/vim/commit/c4bfedabe057c05f09a455a5851089e177fa9c00
Christian Brabandt <cb@256bit.org>
parents:
10357
diff
changeset
|
3988 && curwin->w_s == &(curwin->w_buffer->b_s)) |
3480 | 3989 curwin->w_s = &(buf->b_s); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
3990 #endif |
7 | 3991 curwin->w_buffer = buf; |
3992 curbuf = buf; | |
3993 ++curbuf->b_nwindows; | |
5231
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
3994 |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
3995 /* Set 'fileformat', 'binary' and 'fenc' when forced. */ |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
3996 if (!oldbuf && eap != NULL) |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
3997 { |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
3998 set_file_options(TRUE, eap); |
5242
f0361e297d9c
updated for version 7.4a.046
Bram Moolenaar <bram@vim.org>
parents:
5231
diff
changeset
|
3999 #ifdef FEAT_MBYTE |
5231
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
4000 set_forced_fenc(eap); |
5242
f0361e297d9c
updated for version 7.4a.046
Bram Moolenaar <bram@vim.org>
parents:
5231
diff
changeset
|
4001 #endif |
5231
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
4002 } |
7 | 4003 } |
4004 | |
4005 /* May get the window options from the last time this buffer | |
4006 * was in this window (or another window). If not used | |
4007 * before, reset the local window options to the global | |
4008 * values. Also restores old folding stuff. */ | |
1289 | 4009 get_winopts(curbuf); |
1185 | 4010 #ifdef FEAT_SPELL |
4011 did_get_winopts = TRUE; | |
4012 #endif | |
7 | 4013 |
4014 #ifdef FEAT_AUTOCMD | |
4015 } | |
4016 vim_free(new_name); | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
4017 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
|
4018 au_new_curbuf.br_buf_free_count = 0; |
7 | 4019 #endif |
4020 } | |
4021 | |
4022 curwin->w_pcmark.lnum = 1; | |
4023 curwin->w_pcmark.col = 0; | |
4024 } | |
4025 else /* !other_file */ | |
4026 { | |
4027 if ( | |
4028 #ifdef FEAT_LISTCMDS | |
4029 (flags & ECMD_ADDBUF) || | |
4030 #endif | |
4031 check_fname() == FAIL) | |
4032 goto theend; | |
6531 | 4033 |
7 | 4034 oldbuf = (flags & ECMD_OLDBUF); |
4035 } | |
4036 | |
7941
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
4037 /* 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
|
4038 * autocommands may cause ml_get errors. */ |
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
4039 ++RedrawingDisabled; |
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
4040 did_inc_redrawing_disabled = TRUE; |
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
4041 |
6365 | 4042 #ifdef FEAT_AUTOCMD |
4043 buf = curbuf; | |
4044 #endif | |
7 | 4045 if ((flags & ECMD_SET_HELP) || keep_help_flag) |
4046 { | |
6365 | 4047 prepare_help_buffer(); |
7 | 4048 } |
4049 else | |
4050 { | |
4051 /* Don't make a buffer listed if it's a help buffer. Useful when | |
4052 * using CTRL-O to go back to a help file. */ | |
4053 if (!curbuf->b_help) | |
4054 set_buflisted(TRUE); | |
4055 } | |
4056 | |
4057 #ifdef FEAT_AUTOCMD | |
4058 /* If autocommands change buffers under our fingers, forget about | |
4059 * editing the file. */ | |
4060 if (buf != curbuf) | |
4061 goto theend; | |
4062 # ifdef FEAT_EVAL | |
4063 if (aborting()) /* autocmds may abort script processing */ | |
4064 goto theend; | |
4065 # endif | |
4066 | |
4067 /* Since we are starting to edit a file, consider the filetype to be | |
4068 * unset. Helps for when an autocommand changes files and expects syntax | |
4069 * highlighting to work in the other file. */ | |
4070 did_filetype = FALSE; | |
4071 #endif | |
4072 | |
4073 /* | |
4074 * other_file oldbuf | |
4075 * FALSE FALSE re-edit same file, buffer is re-used | |
4076 * FALSE TRUE re-edit same file, nothing changes | |
4077 * TRUE FALSE start editing new file, new buffer | |
4078 * TRUE TRUE start editing in existing buffer (nothing to do) | |
4079 */ | |
4080 if (!other_file && !oldbuf) /* re-use the buffer */ | |
4081 { | |
4082 set_last_cursor(curwin); /* may set b_last_cursor */ | |
4083 if (newlnum == ECMD_LAST || newlnum == ECMD_LASTL) | |
4084 { | |
4085 newlnum = curwin->w_cursor.lnum; | |
4086 solcol = curwin->w_cursor.col; | |
4087 } | |
4088 #ifdef FEAT_AUTOCMD | |
4089 buf = curbuf; | |
4090 if (buf->b_fname != NULL) | |
4091 new_name = vim_strsave(buf->b_fname); | |
4092 else | |
4093 new_name = NULL; | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
4094 set_bufref(&bufref, buf); |
7 | 4095 #endif |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4096 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
|
4097 { |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4098 /* 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
|
4099 * 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
|
4100 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
|
4101 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
|
4102 == FAIL) |
9705
8c0871098dc9
commit https://github.com/vim/vim/commit/1e2258297bb31720bfbeb234f2dae4d1b3b04fbd
Christian Brabandt <cb@256bit.org>
parents:
9676
diff
changeset
|
4103 { |
9715
dc2237f19ce2
commit https://github.com/vim/vim/commit/fc1f2015e833e69b89b994faf4b2c4fc1e09220f
Christian Brabandt <cb@256bit.org>
parents:
9705
diff
changeset
|
4104 #ifdef FEAT_AUTOCMD |
9705
8c0871098dc9
commit https://github.com/vim/vim/commit/1e2258297bb31720bfbeb234f2dae4d1b3b04fbd
Christian Brabandt <cb@256bit.org>
parents:
9676
diff
changeset
|
4105 vim_free(new_name); |
9715
dc2237f19ce2
commit https://github.com/vim/vim/commit/fc1f2015e833e69b89b994faf4b2c4fc1e09220f
Christian Brabandt <cb@256bit.org>
parents:
9705
diff
changeset
|
4106 #endif |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4107 goto theend; |
9705
8c0871098dc9
commit https://github.com/vim/vim/commit/1e2258297bb31720bfbeb234f2dae4d1b3b04fbd
Christian Brabandt <cb@256bit.org>
parents:
9676
diff
changeset
|
4108 } |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4109 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
|
4110 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
|
4111 |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4112 /* 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
|
4113 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
|
4114 } |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4115 else |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4116 buf_freeall(curbuf, 0); /* free all things for buffer */ |
7 | 4117 #ifdef FEAT_AUTOCMD |
4118 /* If autocommands deleted the buffer we were going to re-edit, give | |
4119 * 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
|
4120 if (!bufref_valid(&bufref)) |
7 | 4121 { |
4122 delbuf_msg(new_name); /* frees new_name */ | |
4123 goto theend; | |
4124 } | |
4125 vim_free(new_name); | |
4126 | |
4127 /* If autocommands change buffers under our fingers, forget about | |
4128 * re-editing the file. Should do the buf_clear_file(), but perhaps | |
4129 * the autocommands changed the buffer... */ | |
4130 if (buf != curbuf) | |
4131 goto theend; | |
4132 # ifdef FEAT_EVAL | |
4133 if (aborting()) /* autocmds may abort script processing */ | |
4134 goto theend; | |
4135 # endif | |
4136 #endif | |
4137 buf_clear_file(curbuf); | |
4138 curbuf->b_op_start.lnum = 0; /* clear '[ and '] marks */ | |
4139 curbuf->b_op_end.lnum = 0; | |
4140 } | |
4141 | |
4142 /* | |
4143 * If we get here we are sure to start editing | |
4144 */ | |
4145 /* Assume success now */ | |
4146 retval = OK; | |
4147 | |
4148 /* | |
4149 * Check if we are editing the w_arg_idx file in the argument list. | |
4150 */ | |
4151 check_arg_idx(curwin); | |
4152 | |
4153 #ifdef FEAT_AUTOCMD | |
4154 if (!auto_buf) | |
4155 #endif | |
4156 { | |
4157 /* | |
4158 * Set cursor and init window before reading the file and executing | |
4159 * autocommands. This allows for the autocommands to position the | |
4160 * cursor. | |
4161 */ | |
677 | 4162 curwin_init(); |
7 | 4163 |
4164 #ifdef FEAT_FOLDING | |
1370 | 4165 /* It's possible that all lines in the buffer changed. Need to update |
4166 * automatic folding for all windows where it's used. */ | |
4167 # ifdef FEAT_WINDOWS | |
4168 { | |
4169 win_T *win; | |
4170 tabpage_T *tp; | |
4171 | |
4172 FOR_ALL_TAB_WINDOWS(tp, win) | |
4173 if (win->w_buffer == curbuf) | |
4174 foldUpdateAll(win); | |
4175 } | |
4176 # else | |
7 | 4177 foldUpdateAll(curwin); |
1370 | 4178 # endif |
7 | 4179 #endif |
4180 | |
961 | 4181 /* Change directories when the 'acd' option is set. */ |
4182 DO_AUTOCHDIR | |
4183 | |
7 | 4184 /* |
4185 * Careful: open_buffer() and apply_autocmds() may change the current | |
4186 * buffer and window. | |
4187 */ | |
6702 | 4188 orig_pos = curwin->w_cursor; |
7 | 4189 topline = curwin->w_topline; |
4190 if (!oldbuf) /* need to read the file */ | |
4191 { | |
580 | 4192 #if defined(HAS_SWAP_EXISTS_ACTION) |
7 | 4193 swap_exists_action = SEA_DIALOG; |
4194 #endif | |
4195 curbuf->b_flags |= BF_CHECK_RO; /* set/reset 'ro' flag */ | |
4196 | |
4197 /* | |
4198 * Open the buffer and read the file. | |
4199 */ | |
4200 #if defined(FEAT_AUTOCMD) && 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
|
4201 if (should_abort(open_buffer(FALSE, eap, readfile_flags))) |
7 | 4202 retval = FAIL; |
4203 #else | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4204 (void)open_buffer(FALSE, eap, readfile_flags); |
7 | 4205 #endif |
4206 | |
580 | 4207 #if defined(HAS_SWAP_EXISTS_ACTION) |
7 | 4208 if (swap_exists_action == SEA_QUIT) |
4209 retval = FAIL; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9481
diff
changeset
|
4210 handle_swap_exists(&old_curbuf); |
7 | 4211 #endif |
4212 } | |
4213 #ifdef FEAT_AUTOCMD | |
4214 else | |
4215 { | |
23 | 4216 /* Read the modelines, but only to set window-local options. Any |
4217 * buffer-local options have already been set and may have been | |
4218 * changed by the user. */ | |
717 | 4219 do_modelines(OPT_WINONLY); |
23 | 4220 |
7 | 4221 apply_autocmds_retval(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf, |
4222 &retval); | |
4223 apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf, | |
4224 &retval); | |
4225 } | |
4226 check_arg_idx(curwin); | |
4227 #endif | |
4228 | |
6702 | 4229 /* If autocommands change the cursor position or topline, we should |
4230 * keep it. Also when it moves within a line. */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
4231 if (!EQUAL_POS(curwin->w_cursor, orig_pos)) |
7 | 4232 { |
4233 newlnum = curwin->w_cursor.lnum; | |
4234 newcol = curwin->w_cursor.col; | |
4235 } | |
4236 if (curwin->w_topline == topline) | |
4237 topline = 0; | |
4238 | |
4239 /* Even when cursor didn't move we need to recompute topline. */ | |
4240 changed_line_abv_curs(); | |
4241 | |
4242 #ifdef FEAT_TITLE | |
4243 maketitle(); | |
4244 #endif | |
4245 } | |
4246 | |
4247 #ifdef FEAT_DIFF | |
4248 /* Tell the diff stuff that this buffer is new and/or needs updating. | |
4249 * Also needed when re-editing the same buffer, because unloading will | |
4250 * have removed it as a diff buffer. */ | |
673 | 4251 if (curwin->w_p_diff) |
4252 { | |
4253 diff_buf_add(curbuf); | |
4254 diff_invalidate(curbuf); | |
4255 } | |
7 | 4256 #endif |
4257 | |
1185 | 4258 #ifdef FEAT_SPELL |
4259 /* If the window options were changed may need to set the spell language. | |
4260 * 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
|
4261 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
|
4262 (void)did_set_spelllang(curwin); |
1185 | 4263 #endif |
4264 | |
7 | 4265 if (command == NULL) |
4266 { | |
4267 if (newcol >= 0) /* position set by autocommands */ | |
4268 { | |
4269 curwin->w_cursor.lnum = newlnum; | |
4270 curwin->w_cursor.col = newcol; | |
4271 check_cursor(); | |
4272 } | |
4273 else if (newlnum > 0) /* line number from caller or old position */ | |
4274 { | |
4275 curwin->w_cursor.lnum = newlnum; | |
4276 check_cursor_lnum(); | |
4277 if (solcol >= 0 && !p_sol) | |
4278 { | |
4279 /* 'sol' is off: Use last known column. */ | |
4280 curwin->w_cursor.col = solcol; | |
4281 check_cursor_col(); | |
4282 #ifdef FEAT_VIRTUALEDIT | |
4283 curwin->w_cursor.coladd = 0; | |
4284 #endif | |
4285 curwin->w_set_curswant = TRUE; | |
4286 } | |
4287 else | |
4288 beginline(BL_SOL | BL_FIX); | |
4289 } | |
4290 else /* no line number, go to last line in Ex mode */ | |
4291 { | |
4292 if (exmode_active) | |
4293 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4294 beginline(BL_WHITE | BL_FIX); | |
4295 } | |
4296 } | |
4297 | |
4298 #ifdef FEAT_WINDOWS | |
4299 /* Check if cursors in other windows on the same buffer are still valid */ | |
4300 check_lnums(FALSE); | |
4301 #endif | |
4302 | |
4303 /* | |
4304 * Did not read the file, need to show some info about the file. | |
4305 * Do this after setting the cursor. | |
4306 */ | |
4307 if (oldbuf | |
4308 #ifdef FEAT_AUTOCMD | |
4309 && !auto_buf | |
4310 #endif | |
4311 ) | |
4312 { | |
4313 int msg_scroll_save = msg_scroll; | |
4314 | |
4315 /* Obey the 'O' flag in 'cpoptions': overwrite any previous file | |
4316 * message. */ | |
4317 if (shortmess(SHM_OVERALL) && !exiting && p_verbose == 0) | |
4318 msg_scroll = FALSE; | |
4319 if (!msg_scroll) /* wait a bit when overwriting an error msg */ | |
4320 check_for_delay(FALSE); | |
4321 msg_start(); | |
4322 msg_scroll = msg_scroll_save; | |
4323 msg_scrolled_ign = TRUE; | |
4324 | |
8560
f3c636c673f7
commit https://github.com/vim/vim/commit/426dd0219512af5f4abeb0901b533159253ffba3
Christian Brabandt <cb@256bit.org>
parents:
8556
diff
changeset
|
4325 if (!shortmess(SHM_FILEINFO)) |
f3c636c673f7
commit https://github.com/vim/vim/commit/426dd0219512af5f4abeb0901b533159253ffba3
Christian Brabandt <cb@256bit.org>
parents:
8556
diff
changeset
|
4326 fileinfo(FALSE, TRUE, FALSE); |
7 | 4327 |
4328 msg_scrolled_ign = FALSE; | |
4329 } | |
4330 | |
9414
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
4331 #ifdef FEAT_VIMINFO |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
4332 curbuf->b_last_used = vim_time(); |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
4333 #endif |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
4334 |
7 | 4335 if (command != NULL) |
4336 do_cmdline(command, NULL, NULL, DOCMD_VERBOSE); | |
4337 | |
4338 #ifdef FEAT_KEYMAP | |
4339 if (curbuf->b_kmap_state & KEYMAP_INIT) | |
1869 | 4340 (void)keymap_init(); |
7 | 4341 #endif |
4342 | |
4343 --RedrawingDisabled; | |
7941
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
4344 did_inc_redrawing_disabled = FALSE; |
7 | 4345 if (!skip_redraw) |
4346 { | |
4347 n = p_so; | |
4348 if (topline == 0 && command == NULL) | |
4349 p_so = 999; /* force cursor halfway the window */ | |
4350 update_topline(); | |
4351 #ifdef FEAT_SCROLLBIND | |
4352 curwin->w_scbind_pos = curwin->w_topline; | |
4353 #endif | |
4354 p_so = n; | |
4355 redraw_curbuf_later(NOT_VALID); /* redraw this buffer later */ | |
4356 } | |
4357 | |
4358 if (p_im) | |
4359 need_start_insertmode = TRUE; | |
4360 | |
961 | 4361 /* Change directories when the 'acd' option is set. */ |
4362 DO_AUTOCHDIR | |
821 | 4363 |
4364 #if defined(FEAT_SUN_WORKSHOP) || defined(FEAT_NETBEANS_INTG) | |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2178
diff
changeset
|
4365 if (curbuf->b_ffname != NULL) |
7 | 4366 { |
4367 # ifdef FEAT_SUN_WORKSHOP | |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2178
diff
changeset
|
4368 if (gui.in_use && usingSunWorkShop) |
7 | 4369 workshop_file_opened((char *)curbuf->b_ffname, curbuf->b_p_ro); |
4370 # endif | |
4371 # ifdef FEAT_NETBEANS_INTG | |
2210 | 4372 if ((flags & ECMD_SET_HELP) != ECMD_SET_HELP) |
34 | 4373 netbeans_file_opened(curbuf); |
7 | 4374 # endif |
4375 } | |
4376 #endif | |
4377 | |
4378 theend: | |
7941
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
4379 if (did_inc_redrawing_disabled) |
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
4380 --RedrawingDisabled; |
716 | 4381 #ifdef FEAT_AUTOCMD |
4382 if (did_set_swapcommand) | |
4383 set_vim_var_string(VV_SWAPCOMMAND, NULL, -1); | |
4384 #endif | |
7 | 4385 #ifdef FEAT_BROWSE |
4386 vim_free(browse_file); | |
4387 #endif | |
4388 vim_free(free_fname); | |
4389 return retval; | |
4390 } | |
4391 | |
4392 #ifdef FEAT_AUTOCMD | |
4393 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4394 delbuf_msg(char_u *name) |
7 | 4395 { |
4396 EMSG2(_("E143: Autocommands unexpectedly deleted new buffer %s"), | |
4397 name == NULL ? (char_u *)"" : name); | |
4398 vim_free(name); | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
4399 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
|
4400 au_new_curbuf.br_buf_free_count = 0; |
7 | 4401 } |
4402 #endif | |
4403 | |
169 | 4404 static int append_indent = 0; /* autoindent for first line */ |
4405 | |
7 | 4406 /* |
4407 * ":insert" and ":append", also used by ":change" | |
4408 */ | |
4409 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4410 ex_append(exarg_T *eap) |
7 | 4411 { |
4412 char_u *theline; | |
4413 int did_undo = FALSE; | |
4414 linenr_T lnum = eap->line2; | |
165 | 4415 int indent = 0; |
4416 char_u *p; | |
4417 int vcol; | |
4418 int empty = (curbuf->b_ml.ml_flags & ML_EMPTY); | |
7 | 4419 |
169 | 4420 /* the ! flag toggles autoindent */ |
4421 if (eap->forceit) | |
4422 curbuf->b_p_ai = !curbuf->b_p_ai; | |
4423 | |
4424 /* First autoindent comes from the line we start on */ | |
4425 if (eap->cmdidx != CMD_change && curbuf->b_p_ai && lnum > 0) | |
4426 append_indent = get_indent_lnum(lnum); | |
4427 | |
7 | 4428 if (eap->cmdidx != CMD_append) |
4429 --lnum; | |
4430 | |
9377
5ec4fbfe38c5
commit https://github.com/vim/vim/commit/70e136e1d86ea1d795774824c7b712245912946d
Christian Brabandt <cb@256bit.org>
parents:
9347
diff
changeset
|
4431 /* when the buffer is empty need to delete the dummy line */ |
165 | 4432 if (empty && lnum == 1) |
4433 lnum = 0; | |
4434 | |
7 | 4435 State = INSERT; /* behave like in Insert mode */ |
4436 if (curbuf->b_p_iminsert == B_IMODE_LMAP) | |
4437 State |= LANGMAP; | |
165 | 4438 |
408 | 4439 for (;;) |
7 | 4440 { |
4441 msg_scroll = TRUE; | |
4442 need_wait_return = FALSE; | |
169 | 4443 if (curbuf->b_p_ai) |
4444 { | |
4445 if (append_indent >= 0) | |
4446 { | |
4447 indent = append_indent; | |
4448 append_indent = -1; | |
4449 } | |
4450 else if (lnum > 0) | |
4451 indent = get_indent_lnum(lnum); | |
4452 } | |
4453 ex_keep_indent = FALSE; | |
7 | 4454 if (eap->getline == NULL) |
169 | 4455 { |
4456 /* No getline() function, use the lines that follow. This ends | |
4457 * when there is no more. */ | |
4458 if (eap->nextcmd == NULL || *eap->nextcmd == NUL) | |
4459 break; | |
4460 p = vim_strchr(eap->nextcmd, NL); | |
4461 if (p == NULL) | |
4462 p = eap->nextcmd + STRLEN(eap->nextcmd); | |
4463 theline = vim_strnsave(eap->nextcmd, (int)(p - eap->nextcmd)); | |
4464 if (*p != NUL) | |
4465 ++p; | |
4466 eap->nextcmd = p; | |
4467 } | |
7 | 4468 else |
6164 | 4469 { |
4470 int save_State = State; | |
4471 | |
4472 /* Set State to avoid the cursor shape to be set to INSERT mode | |
4473 * when getline() returns. */ | |
4474 State = CMDLINE; | |
7 | 4475 theline = eap->getline( |
4476 #ifdef FEAT_EVAL | |
76 | 4477 eap->cstack->cs_looplevel > 0 ? -1 : |
7 | 4478 #endif |
165 | 4479 NUL, eap->cookie, indent); |
6164 | 4480 State = save_State; |
4481 } | |
7 | 4482 lines_left = Rows - 1; |
165 | 4483 if (theline == NULL) |
4484 break; | |
4485 | |
169 | 4486 /* Using ^ CTRL-D in getexmodeline() makes us repeat the indent. */ |
4487 if (ex_keep_indent) | |
4488 append_indent = indent; | |
4489 | |
165 | 4490 /* Look for the "." after automatic indent. */ |
4491 vcol = 0; | |
4492 for (p = theline; indent > vcol; ++p) | |
4493 { | |
4494 if (*p == ' ') | |
4495 ++vcol; | |
4496 else if (*p == TAB) | |
4497 vcol += 8 - vcol % 8; | |
4498 else | |
4499 break; | |
4500 } | |
4501 if ((p[0] == '.' && p[1] == NUL) | |
321 | 4502 || (!did_undo && u_save(lnum, lnum + 1 + (empty ? 1 : 0)) |
4503 == FAIL)) | |
7 | 4504 { |
4505 vim_free(theline); | |
4506 break; | |
4507 } | |
4508 | |
169 | 4509 /* don't use autoindent if nothing was typed. */ |
4510 if (p[0] == NUL) | |
4511 theline[0] = NUL; | |
4512 | |
7 | 4513 did_undo = TRUE; |
4514 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
|
4515 appended_lines_mark(lnum + (empty ? 1 : 0), 1L); |
7 | 4516 |
4517 vim_free(theline); | |
4518 ++lnum; | |
165 | 4519 |
4520 if (empty) | |
4521 { | |
4522 ml_delete(2L, FALSE); | |
4523 empty = FALSE; | |
4524 } | |
7 | 4525 } |
4526 State = NORMAL; | |
4527 | |
169 | 4528 if (eap->forceit) |
4529 curbuf->b_p_ai = !curbuf->b_p_ai; | |
4530 | |
7 | 4531 /* "start" is set to eap->line2+1 unless that position is invalid (when |
1227 | 4532 * eap->line2 pointed to the end of the buffer and nothing was appended) |
7 | 4533 * "end" is set to lnum when something has been appended, otherwise |
4534 * it is the same than "start" -- Acevedo */ | |
4535 curbuf->b_op_start.lnum = (eap->line2 < curbuf->b_ml.ml_line_count) ? | |
4536 eap->line2 + 1 : curbuf->b_ml.ml_line_count; | |
4537 if (eap->cmdidx != CMD_append) | |
4538 --curbuf->b_op_start.lnum; | |
4539 curbuf->b_op_end.lnum = (eap->line2 < lnum) | |
4540 ? lnum : curbuf->b_op_start.lnum; | |
4541 curbuf->b_op_start.col = curbuf->b_op_end.col = 0; | |
4542 curwin->w_cursor.lnum = lnum; | |
4543 check_cursor_lnum(); | |
4544 beginline(BL_SOL | BL_FIX); | |
4545 | |
4546 need_wait_return = FALSE; /* don't use wait_return() now */ | |
4547 ex_no_reprint = TRUE; | |
4548 } | |
4549 | |
4550 /* | |
4551 * ":change" | |
4552 */ | |
4553 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4554 ex_change(exarg_T *eap) |
7 | 4555 { |
4556 linenr_T lnum; | |
4557 | |
4558 if (eap->line2 >= eap->line1 | |
4559 && u_save(eap->line1 - 1, eap->line2 + 1) == FAIL) | |
4560 return; | |
4561 | |
169 | 4562 /* the ! flag toggles autoindent */ |
4563 if (eap->forceit ? !curbuf->b_p_ai : curbuf->b_p_ai) | |
4564 append_indent = get_indent_lnum(eap->line1); | |
4565 | |
7 | 4566 for (lnum = eap->line2; lnum >= eap->line1; --lnum) |
4567 { | |
4568 if (curbuf->b_ml.ml_flags & ML_EMPTY) /* nothing to delete */ | |
4569 break; | |
4570 ml_delete(eap->line1, FALSE); | |
4571 } | |
1929 | 4572 |
4573 /* make sure the cursor is not beyond the end of the file now */ | |
4574 check_cursor_lnum(); | |
7 | 4575 deleted_lines_mark(eap->line1, (long)(eap->line2 - lnum)); |
4576 | |
4577 /* ":append" on the line above the deleted lines. */ | |
4578 eap->line2 = eap->line1; | |
4579 ex_append(eap); | |
4580 } | |
4581 | |
4582 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4583 ex_z(exarg_T *eap) |
7 | 4584 { |
4585 char_u *x; | |
165 | 4586 int bigness; |
4587 char_u *kind; | |
7 | 4588 int minus = 0; |
4589 linenr_T start, end, curs, i; | |
4590 int j; | |
4591 linenr_T lnum = eap->line2; | |
4592 | |
165 | 4593 /* Vi compatible: ":z!" uses display height, without a count uses |
4594 * 'scroll' */ | |
4595 if (eap->forceit) | |
4596 bigness = curwin->w_height; | |
5678 | 4597 #ifdef FEAT_WINDOWS |
10357
59d01e335858
commit https://github.com/vim/vim/commit/459ca563128f2edb7e3bb190090bbb755a56dd55
Christian Brabandt <cb@256bit.org>
parents:
10299
diff
changeset
|
4598 else if (!ONE_WINDOW) |
5678 | 4599 bigness = curwin->w_height - 3; |
4600 #endif | |
4601 else | |
165 | 4602 bigness = curwin->w_p_scr * 2; |
7 | 4603 if (bigness < 1) |
4604 bigness = 1; | |
4605 | |
4606 x = eap->arg; | |
165 | 4607 kind = x; |
4608 if (*kind == '-' || *kind == '+' || *kind == '=' | |
4609 || *kind == '^' || *kind == '.') | |
4610 ++x; | |
4611 while (*x == '-' || *x == '+') | |
7 | 4612 ++x; |
4613 | |
4614 if (*x != 0) | |
4615 { | |
4616 if (!VIM_ISDIGIT(*x)) | |
4617 { | |
4618 EMSG(_("E144: non-numeric argument to :z")); | |
4619 return; | |
4620 } | |
4621 else | |
165 | 4622 { |
7 | 4623 bigness = atoi((char *)x); |
165 | 4624 p_window = bigness; |
169 | 4625 if (*kind == '=') |
4626 bigness += 2; | |
165 | 4627 } |
7 | 4628 } |
4629 | |
165 | 4630 /* the number of '-' and '+' multiplies the distance */ |
4631 if (*kind == '-' || *kind == '+') | |
4632 for (x = kind + 1; *x == *kind; ++x) | |
4633 ; | |
4634 | |
4635 switch (*kind) | |
7 | 4636 { |
4637 case '-': | |
2881 | 4638 start = lnum - bigness * (linenr_T)(x - kind) + 1; |
4639 end = start + bigness - 1; | |
165 | 4640 curs = end; |
7 | 4641 break; |
4642 | |
4643 case '=': | |
159 | 4644 start = lnum - (bigness + 1) / 2 + 1; |
4645 end = lnum + (bigness + 1) / 2 - 1; | |
7 | 4646 curs = lnum; |
4647 minus = 1; | |
4648 break; | |
4649 | |
4650 case '^': | |
4651 start = lnum - bigness * 2; | |
4652 end = lnum - bigness; | |
4653 curs = lnum - bigness; | |
4654 break; | |
4655 | |
4656 case '.': | |
159 | 4657 start = lnum - (bigness + 1) / 2 + 1; |
4658 end = lnum + (bigness + 1) / 2 - 1; | |
7 | 4659 curs = end; |
4660 break; | |
4661 | |
4662 default: /* '+' */ | |
4663 start = lnum; | |
165 | 4664 if (*kind == '+') |
835 | 4665 start += bigness * (linenr_T)(x - kind - 1) + 1; |
169 | 4666 else if (eap->addr_count == 0) |
4667 ++start; | |
4668 end = start + bigness - 1; | |
7 | 4669 curs = end; |
4670 break; | |
4671 } | |
4672 | |
4673 if (start < 1) | |
4674 start = 1; | |
4675 | |
4676 if (end > curbuf->b_ml.ml_line_count) | |
4677 end = curbuf->b_ml.ml_line_count; | |
4678 | |
4679 if (curs > curbuf->b_ml.ml_line_count) | |
4680 curs = curbuf->b_ml.ml_line_count; | |
4681 | |
4682 for (i = start; i <= end; i++) | |
4683 { | |
4684 if (minus && i == lnum) | |
4685 { | |
4686 msg_putchar('\n'); | |
4687 | |
4688 for (j = 1; j < Columns; j++) | |
4689 msg_putchar('-'); | |
4690 } | |
4691 | |
169 | 4692 print_line(i, eap->flags & EXFLAG_NR, eap->flags & EXFLAG_LIST); |
7 | 4693 |
4694 if (minus && i == lnum) | |
4695 { | |
4696 msg_putchar('\n'); | |
4697 | |
4698 for (j = 1; j < Columns; j++) | |
4699 msg_putchar('-'); | |
4700 } | |
4701 } | |
4702 | |
4703 curwin->w_cursor.lnum = curs; | |
4704 ex_no_reprint = TRUE; | |
4705 } | |
4706 | |
4707 /* | |
4708 * Check if the restricted flag is set. | |
4709 * If so, give an error message and return TRUE. | |
4710 * Otherwise, return FALSE. | |
4711 */ | |
4712 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4713 check_restricted(void) |
7 | 4714 { |
4715 if (restricted) | |
4716 { | |
4717 EMSG(_("E145: Shell commands not allowed in rvim")); | |
4718 return TRUE; | |
4719 } | |
4720 return FALSE; | |
4721 } | |
4722 | |
4723 /* | |
4724 * Check if the secure flag is set (.exrc or .vimrc in current directory). | |
4725 * If so, give an error message and return TRUE. | |
4726 * Otherwise, return FALSE. | |
4727 */ | |
4728 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4729 check_secure(void) |
7 | 4730 { |
4731 if (secure) | |
4732 { | |
4733 secure = 2; | |
4734 EMSG(_(e_curdir)); | |
4735 return TRUE; | |
4736 } | |
4737 #ifdef HAVE_SANDBOX | |
4738 /* | |
4739 * In the sandbox more things are not allowed, including the things | |
4740 * disallowed in secure mode. | |
4741 */ | |
4742 if (sandbox != 0) | |
4743 { | |
4744 EMSG(_(e_sandbox)); | |
4745 return TRUE; | |
4746 } | |
4747 #endif | |
4748 return FALSE; | |
4749 } | |
4750 | |
4751 static char_u *old_sub = NULL; /* previous substitute pattern */ | |
4752 static int global_need_beginline; /* call beginline() after ":g" */ | |
4753 | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4754 /* |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4755 * 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
|
4756 */ |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4757 typedef struct { |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4758 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
|
4759 int do_ask; /* ask for confirmation */ |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4760 int do_count; /* count only */ |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4761 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
|
4762 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
|
4763 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
|
4764 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
|
4765 int do_ic; /* ignore case flag */ |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4766 } subflags_T; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4767 |
7 | 4768 /* do_sub() |
4769 * | |
4770 * Perform a substitution from line eap->line1 to line eap->line2 using the | |
4771 * command pointed to by eap->arg which should be of the form: | |
4772 * | |
4773 * /pattern/substitution/{flags} | |
4774 * | |
4775 * The usual escapes are supported as described in the regexp docs. | |
4776 */ | |
4777 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4778 do_sub(exarg_T *eap) |
7 | 4779 { |
4780 linenr_T lnum; | |
4781 long i = 0; | |
4782 regmmatch_T regmatch; | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4783 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
|
4784 FALSE, FALSE, 0}; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4785 #ifdef FEAT_EVAL |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4786 subflags_T subflags_save; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4787 #endif |
6789 | 4788 int save_do_all; /* remember user specified 'g' flag */ |
4789 int save_do_ask; /* remember user specified 'c' flag */ | |
7 | 4790 char_u *pat = NULL, *sub = NULL; /* init for GCC */ |
4791 int delimiter; | |
4792 int sublen; | |
4793 int got_quit = FALSE; | |
4794 int got_match = FALSE; | |
4795 int temp; | |
4796 int which_pat; | |
4797 char_u *cmd; | |
4798 int save_State; | |
165 | 4799 linenr_T first_line = 0; /* first changed line */ |
4800 linenr_T last_line= 0; /* below last changed line AFTER the | |
7 | 4801 * change */ |
4802 linenr_T old_line_count = curbuf->b_ml.ml_line_count; | |
4803 linenr_T line2; | |
165 | 4804 long nmatch; /* number of lines in match */ |
4805 char_u *sub_firstline; /* allocated copy of first sub line */ | |
4806 int endcolumn = FALSE; /* cursor in last column when done */ | |
170 | 4807 pos_T old_cursor = curwin->w_cursor; |
2126
e038754d419a
updated for version 7.2.408
Bram Moolenaar <bram@zimbu.org>
parents:
1929
diff
changeset
|
4808 int start_nsubs; |
3736 | 4809 #ifdef FEAT_EVAL |
5867 | 4810 int save_ma = 0; |
3736 | 4811 #endif |
7 | 4812 |
4813 cmd = eap->arg; | |
4814 if (!global_busy) | |
4815 { | |
4816 sub_nsubs = 0; | |
4817 sub_nlines = 0; | |
4818 } | |
2126
e038754d419a
updated for version 7.2.408
Bram Moolenaar <bram@zimbu.org>
parents:
1929
diff
changeset
|
4819 start_nsubs = sub_nsubs; |
7 | 4820 |
4821 if (eap->cmdidx == CMD_tilde) | |
4822 which_pat = RE_LAST; /* use last used regexp */ | |
4823 else | |
4824 which_pat = RE_SUBST; /* use last substitute regexp */ | |
4825 | |
4826 /* new pattern and substitution */ | |
4827 if (eap->cmd[0] == 's' && *cmd != NUL && !vim_iswhite(*cmd) | |
4828 && vim_strchr((char_u *)"0123456789cegriIp|\"", *cmd) == NULL) | |
4829 { | |
4830 /* don't accept alphanumeric for separator */ | |
4831 if (isalpha(*cmd)) | |
4832 { | |
4833 EMSG(_("E146: Regular expressions can't be delimited by letters")); | |
4834 return; | |
4835 } | |
4836 /* | |
4837 * undocumented vi feature: | |
4838 * "\/sub/" and "\?sub?" use last used search pattern (almost like | |
4839 * //sub/r). "\&sub&" use last substitute pattern (like //sub/). | |
4840 */ | |
4841 if (*cmd == '\\') | |
4842 { | |
4843 ++cmd; | |
4844 if (vim_strchr((char_u *)"/?&", *cmd) == NULL) | |
4845 { | |
4846 EMSG(_(e_backslash)); | |
4847 return; | |
4848 } | |
4849 if (*cmd != '&') | |
4850 which_pat = RE_SEARCH; /* use last '/' pattern */ | |
4851 pat = (char_u *)""; /* empty search pattern */ | |
4852 delimiter = *cmd++; /* remember delimiter character */ | |
4853 } | |
4854 else /* find the end of the regexp */ | |
4855 { | |
1466 | 4856 #ifdef FEAT_FKMAP /* reverse the flow of the Farsi characters */ |
4857 if (p_altkeymap && curwin->w_p_rl) | |
4858 lrF_sub(cmd); | |
4859 #endif | |
7 | 4860 which_pat = RE_LAST; /* use last used regexp */ |
4861 delimiter = *cmd++; /* remember delimiter character */ | |
4862 pat = cmd; /* remember start of search pat */ | |
4863 cmd = skip_regexp(cmd, delimiter, p_magic, &eap->arg); | |
4864 if (cmd[0] == delimiter) /* end delimiter found */ | |
4865 *cmd++ = NUL; /* replace it with a NUL */ | |
4866 } | |
4867 | |
4868 /* | |
4869 * Small incompatibility: vi sees '\n' as end of the command, but in | |
4870 * Vim we want to use '\n' to find/substitute a NUL. | |
4871 */ | |
4872 sub = cmd; /* remember the start of the substitution */ | |
4873 | |
4874 while (cmd[0]) | |
4875 { | |
4876 if (cmd[0] == delimiter) /* end delimiter found */ | |
4877 { | |
4878 *cmd++ = NUL; /* replace it with a NUL */ | |
4879 break; | |
4880 } | |
4881 if (cmd[0] == '\\' && cmd[1] != 0) /* skip escaped characters */ | |
4882 ++cmd; | |
39 | 4883 mb_ptr_adv(cmd); |
7 | 4884 } |
4885 | |
4886 if (!eap->skip) | |
4887 { | |
169 | 4888 /* In POSIX vi ":s/pat/%/" uses the previous subst. string. */ |
4889 if (STRCMP(sub, "%") == 0 | |
4890 && vim_strchr(p_cpo, CPO_SUBPERCENT) != NULL) | |
4891 { | |
4892 if (old_sub == NULL) /* there is no previous command */ | |
4893 { | |
4894 EMSG(_(e_nopresub)); | |
4895 return; | |
4896 } | |
4897 sub = old_sub; | |
4898 } | |
4899 else | |
4900 { | |
4901 vim_free(old_sub); | |
4902 old_sub = vim_strsave(sub); | |
4903 } | |
7 | 4904 } |
4905 } | |
4906 else if (!eap->skip) /* use previous pattern and substitution */ | |
4907 { | |
4908 if (old_sub == NULL) /* there is no previous command */ | |
4909 { | |
4910 EMSG(_(e_nopresub)); | |
4911 return; | |
4912 } | |
4913 pat = NULL; /* search_regcomp() will use previous pattern */ | |
4914 sub = old_sub; | |
163 | 4915 |
4916 /* Vi compatibility quirk: repeating with ":s" keeps the cursor in the | |
4917 * last column after using "$". */ | |
4918 endcolumn = (curwin->w_curswant == MAXCOL); | |
7 | 4919 } |
4920 | |
5776 | 4921 /* Recognize ":%s/\n//" and turn it into a join command, which is much |
4922 * more efficient. | |
4923 * TODO: find a generic solution to make line-joining operations more | |
4924 * efficient, avoid allocating a string that grows in size. | |
4925 */ | |
5802 | 4926 if (pat != NULL && STRCMP(pat, "\\n") == 0 |
5776 | 4927 && *sub == NUL |
4928 && (*cmd == NUL || (cmd[1] == NUL && (*cmd == 'g' || *cmd == 'l' | |
4929 || *cmd == 'p' || *cmd == '#')))) | |
4930 { | |
6426 | 4931 linenr_T joined_lines_count; |
4932 | |
5776 | 4933 curwin->w_cursor.lnum = eap->line1; |
4934 if (*cmd == 'l') | |
4935 eap->flags = EXFLAG_LIST; | |
4936 else if (*cmd == '#') | |
4937 eap->flags = EXFLAG_NR; | |
4938 else if (*cmd == 'p') | |
4939 eap->flags = EXFLAG_PRINT; | |
4940 | |
6426 | 4941 /* The number of lines joined is the number of lines in the range plus |
4942 * one. One less when the last line is included. */ | |
4943 joined_lines_count = eap->line2 - eap->line1 + 1; | |
4944 if (eap->line2 < curbuf->b_ml.ml_line_count) | |
4945 ++joined_lines_count; | |
4946 if (joined_lines_count > 1) | |
4947 { | |
4948 (void)do_join(joined_lines_count, FALSE, TRUE, FALSE, TRUE); | |
4949 sub_nsubs = joined_lines_count - 1; | |
4950 sub_nlines = 1; | |
4951 (void)do_sub_msg(FALSE); | |
4952 ex_may_print(eap); | |
4953 } | |
4954 | |
4955 if (!cmdmod.keeppatterns) | |
4956 save_re_pat(RE_SUBST, pat, p_magic); | |
4957 #ifdef FEAT_CMDHIST | |
4958 /* put pattern in history */ | |
4959 add_to_history(HIST_SEARCH, pat, TRUE, NUL); | |
4960 #endif | |
4961 | |
5776 | 4962 return; |
4963 } | |
4964 | |
7 | 4965 /* |
4966 * Find trailing options. When '&' is used, keep old options. | |
4967 */ | |
4968 if (*cmd == '&') | |
4969 ++cmd; | |
4970 else | |
4971 { | |
4972 if (!p_ed) | |
4973 { | |
4974 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
|
4975 subflags.do_all = TRUE; |
7 | 4976 else |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4977 subflags.do_all = FALSE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4978 subflags.do_ask = FALSE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4979 } |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4980 subflags.do_error = TRUE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4981 subflags.do_print = FALSE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4982 subflags.do_count = FALSE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4983 subflags.do_number = FALSE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4984 subflags.do_ic = 0; |
7 | 4985 } |
4986 while (*cmd) | |
4987 { | |
4988 /* | |
4989 * Note that 'g' and 'c' are always inverted, also when p_ed is off. | |
4990 * 'r' is never inverted. | |
4991 */ | |
4992 if (*cmd == 'g') | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4993 subflags.do_all = !subflags.do_all; |
7 | 4994 else if (*cmd == 'c') |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4995 subflags.do_ask = !subflags.do_ask; |
170 | 4996 else if (*cmd == 'n') |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4997 subflags.do_count = TRUE; |
7 | 4998 else if (*cmd == 'e') |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4999 subflags.do_error = !subflags.do_error; |
7 | 5000 else if (*cmd == 'r') /* use last used regexp */ |
5001 which_pat = RE_LAST; | |
5002 else if (*cmd == 'p') | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5003 subflags.do_print = TRUE; |
169 | 5004 else if (*cmd == '#') |
5005 { | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5006 subflags.do_print = TRUE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5007 subflags.do_number = TRUE; |
169 | 5008 } |
5009 else if (*cmd == 'l') | |
5010 { | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5011 subflags.do_print = TRUE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5012 subflags.do_list = TRUE; |
169 | 5013 } |
7 | 5014 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
|
5015 subflags.do_ic = 'i'; |
7 | 5016 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
|
5017 subflags.do_ic = 'I'; |
7 | 5018 else |
5019 break; | |
5020 ++cmd; | |
5021 } | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5022 if (subflags.do_count) |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5023 subflags.do_ask = FALSE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5024 |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5025 save_do_all = subflags.do_all; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5026 save_do_ask = subflags.do_ask; |
6789 | 5027 |
7 | 5028 /* |
5029 * check for a trailing count | |
5030 */ | |
5031 cmd = skipwhite(cmd); | |
5032 if (VIM_ISDIGIT(*cmd)) | |
5033 { | |
5034 i = getdigits(&cmd); | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5035 if (i <= 0 && !eap->skip && subflags.do_error) |
7 | 5036 { |
5037 EMSG(_(e_zerocount)); | |
5038 return; | |
5039 } | |
5040 eap->line1 = eap->line2; | |
5041 eap->line2 += i - 1; | |
5042 if (eap->line2 > curbuf->b_ml.ml_line_count) | |
5043 eap->line2 = curbuf->b_ml.ml_line_count; | |
5044 } | |
5045 | |
5046 /* | |
5047 * check for trailing command or garbage | |
5048 */ | |
5049 cmd = skipwhite(cmd); | |
5050 if (*cmd && *cmd != '"') /* if not end-of-line or comment */ | |
5051 { | |
5052 eap->nextcmd = check_nextcmd(cmd); | |
5053 if (eap->nextcmd == NULL) | |
5054 { | |
5055 EMSG(_(e_trailing)); | |
5056 return; | |
5057 } | |
5058 } | |
5059 | |
5060 if (eap->skip) /* not executing commands, only parsing */ | |
5061 return; | |
5062 | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5063 if (!subflags.do_count && !curbuf->b_p_ma) |
823 | 5064 { |
825 | 5065 /* Substitution is not allowed in non-'modifiable' buffer */ |
823 | 5066 EMSG(_(e_modifiable)); |
5067 return; | |
5068 } | |
5069 | |
7 | 5070 if (search_regcomp(pat, RE_SUBST, which_pat, SEARCH_HIS, ®match) == FAIL) |
5071 { | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5072 if (subflags.do_error) |
7 | 5073 EMSG(_(e_invcmd)); |
5074 return; | |
5075 } | |
5076 | |
5077 /* 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
|
5078 if (subflags.do_ic == 'i') |
7 | 5079 regmatch.rmm_ic = TRUE; |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5080 else if (subflags.do_ic == 'I') |
7 | 5081 regmatch.rmm_ic = FALSE; |
5082 | |
5083 sub_firstline = NULL; | |
5084 | |
5085 /* | |
5086 * ~ in the substitute pattern is replaced with the old pattern. | |
5087 * We do it here once to avoid it to be replaced over and over again. | |
5088 * But don't do it when it starts with "\=", then it's an expression. | |
5089 */ | |
5090 if (!(sub[0] == '\\' && sub[1] == '=')) | |
5091 sub = regtilde(sub, p_magic); | |
5092 | |
5093 /* | |
5094 * Check for a match on each line. | |
5095 */ | |
5096 line2 = eap->line2; | |
5097 for (lnum = eap->line1; lnum <= line2 && !(got_quit | |
5098 #if defined(FEAT_EVAL) && defined(FEAT_AUTOCMD) | |
5099 || aborting() | |
5100 #endif | |
5101 ); ++lnum) | |
5102 { | |
1521 | 5103 nmatch = vim_regexec_multi(®match, curwin, curbuf, lnum, |
5104 (colnr_T)0, NULL); | |
7 | 5105 if (nmatch) |
5106 { | |
5107 colnr_T copycol; | |
5108 colnr_T matchcol; | |
5109 colnr_T prev_matchcol = MAXCOL; | |
5110 char_u *new_end, *new_start = NULL; | |
5111 unsigned new_start_len = 0; | |
5112 char_u *p1; | |
5113 int did_sub = FALSE; | |
5114 int lastone; | |
1872 | 5115 int len, copy_len, needed_len; |
7 | 5116 long nmatch_tl = 0; /* nr of lines matched below lnum */ |
5117 int do_again; /* do it again after joining lines */ | |
15 | 5118 int skip_match = FALSE; |
1499 | 5119 linenr_T sub_firstlnum; /* nr of first sub line */ |
7 | 5120 |
5121 /* | |
5122 * The new text is build up step by step, to avoid too much | |
5123 * copying. There are these pieces: | |
1581 | 5124 * sub_firstline The old text, unmodified. |
7 | 5125 * copycol Column in the old text where we started |
5126 * looking for a match; from here old text still | |
5127 * needs to be copied to the new text. | |
5128 * matchcol Column number of the old text where to look | |
5129 * for the next match. It's just after the | |
5130 * previous match or one further. | |
5131 * prev_matchcol Column just after the previous match (if any). | |
5132 * Mostly equal to matchcol, except for the first | |
5133 * match and after skipping an empty match. | |
5134 * regmatch.*pos Where the pattern matched in the old text. | |
5135 * new_start The new text, all that has been produced so | |
5136 * far. | |
5137 * new_end The new text, where to append new text. | |
5138 * | |
1499 | 5139 * lnum The line number where we found the start of |
5140 * the match. Can be below the line we searched | |
5141 * when there is a \n before a \zs in the | |
5142 * pattern. | |
7 | 5143 * sub_firstlnum The line number in the buffer where to look |
5144 * for a match. Can be different from "lnum" | |
5145 * when the pattern or substitute string contains | |
5146 * line breaks. | |
5147 * | |
5148 * Special situations: | |
5149 * - When the substitute string contains a line break, the part up | |
5150 * to the line break is inserted in the text, but the copy of | |
5151 * the original line is kept. "sub_firstlnum" is adjusted for | |
5152 * the inserted lines. | |
5153 * - When the matched pattern contains a line break, the old line | |
5154 * is taken from the line at the end of the pattern. The lines | |
5155 * in the match are deleted later, "sub_firstlnum" is adjusted | |
5156 * accordingly. | |
5157 * | |
5158 * The new text is built up in new_start[]. It has some extra | |
5159 * room to avoid using alloc()/free() too often. new_start_len is | |
1389 | 5160 * the length of the allocated memory at new_start. |
7 | 5161 * |
5162 * Make a copy of the old line, so it won't be taken away when | |
5163 * updating the screen or handling a multi-line match. The "old_" | |
5164 * pointers point into this copy. | |
5165 */ | |
1499 | 5166 sub_firstlnum = lnum; |
7 | 5167 copycol = 0; |
5168 matchcol = 0; | |
5169 | |
5170 /* At first match, remember current cursor position. */ | |
5171 if (!got_match) | |
5172 { | |
5173 setpcmark(); | |
5174 got_match = TRUE; | |
5175 } | |
5176 | |
5177 /* | |
5178 * Loop until nothing more to replace in this line. | |
5179 * 1. Handle match with empty string. | |
5180 * 2. If do_ask is set, ask for confirmation. | |
5181 * 3. substitute the string. | |
5182 * 4. if do_all is set, find next match | |
5183 * 5. break if there isn't another match in this line | |
5184 */ | |
5185 for (;;) | |
5186 { | |
1499 | 5187 /* Advance "lnum" to the line where the match starts. The |
5188 * match does not start in the first line when there is a line | |
5189 * break before \zs. */ | |
5190 if (regmatch.startpos[0].lnum > 0) | |
5191 { | |
5192 lnum += regmatch.startpos[0].lnum; | |
5193 sub_firstlnum += regmatch.startpos[0].lnum; | |
5194 nmatch -= regmatch.startpos[0].lnum; | |
5195 vim_free(sub_firstline); | |
5196 sub_firstline = NULL; | |
5197 } | |
5198 | |
5199 if (sub_firstline == NULL) | |
5200 { | |
5201 sub_firstline = vim_strsave(ml_get(sub_firstlnum)); | |
5202 if (sub_firstline == NULL) | |
5203 { | |
5204 vim_free(new_start); | |
5205 goto outofmem; | |
5206 } | |
5207 } | |
5208 | |
7 | 5209 /* Save the line number of the last change for the final |
5210 * cursor position (just like Vi). */ | |
5211 curwin->w_cursor.lnum = lnum; | |
5212 do_again = FALSE; | |
5213 | |
5214 /* | |
5215 * 1. Match empty string does not count, except for first | |
5216 * match. This reproduces the strange vi behaviour. | |
5217 * This also catches endless loops. | |
5218 */ | |
5219 if (matchcol == prev_matchcol | |
5220 && regmatch.endpos[0].lnum == 0 | |
5221 && matchcol == regmatch.endpos[0].col) | |
5222 { | |
15 | 5223 if (sub_firstline[matchcol] == NUL) |
5224 /* We already were at the end of the line. Don't look | |
5225 * for a match in this line again. */ | |
5226 skip_match = TRUE; | |
5227 else | |
2837 | 5228 { |
5229 /* search for a match at next column */ | |
5230 #ifdef FEAT_MBYTE | |
5231 if (has_mbyte) | |
5232 matchcol += mb_ptr2len(sub_firstline + matchcol); | |
5233 else | |
5234 #endif | |
5235 ++matchcol; | |
5236 } | |
7 | 5237 goto skip; |
5238 } | |
5239 | |
5240 /* Normally we continue searching for a match just after the | |
5241 * previous match. */ | |
5242 matchcol = regmatch.endpos[0].col; | |
5243 prev_matchcol = matchcol; | |
5244 | |
5245 /* | |
170 | 5246 * 2. If do_count is set only increase the counter. |
5247 * If do_ask is set, ask for confirmation. | |
7 | 5248 */ |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5249 if (subflags.do_count) |
170 | 5250 { |
5251 /* For a multi-line match, put matchcol at the NUL at | |
5252 * the end of the line and set nmatch to one, so that | |
5253 * we continue looking for a match on the next line. | |
5254 * Avoids that ":s/\nB\@=//gc" get stuck. */ | |
5255 if (nmatch > 1) | |
5256 { | |
835 | 5257 matchcol = (colnr_T)STRLEN(sub_firstline); |
170 | 5258 nmatch = 1; |
1483 | 5259 skip_match = TRUE; |
170 | 5260 } |
5261 sub_nsubs++; | |
5262 did_sub = TRUE; | |
3736 | 5263 #ifdef FEAT_EVAL |
5264 /* Skip the substitution, unless an expression is used, | |
5265 * then it is evaluated in the sandbox. */ | |
5266 if (!(sub[0] == '\\' && sub[1] == '=')) | |
5267 #endif | |
5268 goto skip; | |
170 | 5269 } |
5270 | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5271 if (subflags.do_ask) |
7 | 5272 { |
1874 | 5273 int typed = 0; |
1872 | 5274 |
7 | 5275 /* change State to CONFIRM, so that the mouse works |
5276 * properly */ | |
5277 save_State = State; | |
5278 State = CONFIRM; | |
5279 #ifdef FEAT_MOUSE | |
5280 setmouse(); /* disable mouse in xterm */ | |
5281 #endif | |
5282 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
|
5283 #ifdef FEAT_CURSORBIND |
21f983648487
patch 8.0.0209: cursor binding does not work with :substitute
Christian Brabandt <cb@256bit.org>
parents:
10575
diff
changeset
|
5284 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
|
5285 do_check_cursorbind(); |
21f983648487
patch 8.0.0209: cursor binding does not work with :substitute
Christian Brabandt <cb@256bit.org>
parents:
10575
diff
changeset
|
5286 #endif |
7 | 5287 |
5288 /* When 'cpoptions' contains "u" don't sync undo when | |
5289 * asking for confirmation. */ | |
5290 if (vim_strchr(p_cpo, CPO_UNDO) != NULL) | |
5291 ++no_u_sync; | |
5292 | |
5293 /* | |
5294 * Loop until 'y', 'n', 'q', CTRL-E or CTRL-Y typed. | |
5295 */ | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5296 while (subflags.do_ask) |
7 | 5297 { |
169 | 5298 if (exmode_active) |
5299 { | |
5300 char_u *resp; | |
5301 colnr_T sc, ec; | |
5302 | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5303 print_line_no_prefix(lnum, |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5304 subflags.do_number, subflags.do_list); |
169 | 5305 |
5306 getvcol(curwin, &curwin->w_cursor, &sc, NULL, NULL); | |
5307 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
|
5308 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
|
5309 curwin->w_cursor.col = 0; |
169 | 5310 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
|
5311 if (subflags.do_number || curwin->w_p_nu) |
5396 | 5312 { |
5313 int numw = number_width(curwin) + 1; | |
5314 sc += numw; | |
5315 ec += numw; | |
5316 } | |
169 | 5317 msg_start(); |
170 | 5318 for (i = 0; i < (long)sc; ++i) |
169 | 5319 msg_putchar(' '); |
170 | 5320 for ( ; i <= (long)ec; ++i) |
169 | 5321 msg_putchar('^'); |
5322 | |
5323 resp = getexmodeline('?', NULL, 0); | |
5324 if (resp != NULL) | |
5325 { | |
1872 | 5326 typed = *resp; |
169 | 5327 vim_free(resp); |
5328 } | |
5329 } | |
5330 else | |
5331 { | |
4076 | 5332 char_u *orig_line = NULL; |
5333 int len_change = 0; | |
7 | 5334 #ifdef FEAT_FOLDING |
169 | 5335 int save_p_fen = curwin->w_p_fen; |
5336 | |
5337 curwin->w_p_fen = FALSE; | |
5338 #endif | |
5339 /* Invert the matched string. | |
5340 * Remove the inversion afterwards. */ | |
5341 temp = RedrawingDisabled; | |
5342 RedrawingDisabled = 0; | |
5343 | |
4076 | 5344 if (new_start != NULL) |
5345 { | |
5346 /* There already was a substitution, we would | |
5347 * like to show this to the user. We cannot | |
5348 * really update the line, it would change | |
5349 * what matches. Temporarily replace the line | |
5350 * and change it back afterwards. */ | |
5351 orig_line = vim_strsave(ml_get(lnum)); | |
5352 if (orig_line != NULL) | |
5353 { | |
5354 char_u *new_line = concat_str(new_start, | |
5355 sub_firstline + copycol); | |
5356 | |
5357 if (new_line == NULL) | |
5358 { | |
5359 vim_free(orig_line); | |
5360 orig_line = NULL; | |
5361 } | |
5362 else | |
5363 { | |
5364 /* Position the cursor relative to the | |
5365 * end of the line, the previous | |
5366 * substitute may have inserted or | |
5367 * deleted characters before the | |
5368 * cursor. */ | |
4086 | 5369 len_change = (int)STRLEN(new_line) |
5370 - (int)STRLEN(orig_line); | |
4076 | 5371 curwin->w_cursor.col += len_change; |
5372 ml_replace(lnum, new_line, FALSE); | |
5373 } | |
5374 } | |
5375 } | |
5376 | |
1499 | 5377 search_match_lines = regmatch.endpos[0].lnum |
5378 - regmatch.startpos[0].lnum; | |
4076 | 5379 search_match_endcol = regmatch.endpos[0].col |
5380 + len_change; | |
169 | 5381 highlight_match = TRUE; |
5382 | |
5383 update_topline(); | |
5384 validate_cursor(); | |
748 | 5385 update_screen(SOME_VALID); |
169 | 5386 highlight_match = FALSE; |
748 | 5387 redraw_later(SOME_VALID); |
7 | 5388 |
5389 #ifdef FEAT_FOLDING | |
169 | 5390 curwin->w_p_fen = save_p_fen; |
5391 #endif | |
5392 if (msg_row == Rows - 1) | |
5393 msg_didout = FALSE; /* avoid a scroll-up */ | |
5394 msg_starthere(); | |
5395 i = msg_scroll; | |
5396 msg_scroll = 0; /* truncate msg when | |
5397 needed */ | |
5398 msg_no_more = TRUE; | |
5399 /* write message same highlighting as for | |
5400 * wait_return */ | |
5401 smsg_attr(hl_attr(HLF_R), | |
5402 (char_u *)_("replace with %s (y/n/a/q/l/^E/^Y)?"), sub); | |
5403 msg_no_more = FALSE; | |
5404 msg_scroll = i; | |
5405 showruler(TRUE); | |
5406 windgoto(msg_row, msg_col); | |
5407 RedrawingDisabled = temp; | |
7 | 5408 |
5409 #ifdef USE_ON_FLY_SCROLL | |
169 | 5410 dont_scroll = FALSE; /* allow scrolling here */ |
5411 #endif | |
5412 ++no_mapping; /* don't map this key */ | |
5413 ++allow_keys; /* allow special keys */ | |
1872 | 5414 typed = plain_vgetc(); |
169 | 5415 --allow_keys; |
5416 --no_mapping; | |
5417 | |
5418 /* clear the question */ | |
5419 msg_didout = FALSE; /* don't scroll up */ | |
5420 msg_col = 0; | |
5421 gotocmdline(TRUE); | |
4076 | 5422 |
5423 /* restore the line */ | |
5424 if (orig_line != NULL) | |
5425 ml_replace(lnum, orig_line, FALSE); | |
169 | 5426 } |
5427 | |
7 | 5428 need_wait_return = FALSE; /* no hit-return prompt */ |
1872 | 5429 if (typed == 'q' || typed == ESC || typed == Ctrl_C |
7 | 5430 #ifdef UNIX |
1872 | 5431 || typed == intr_char |
7 | 5432 #endif |
5433 ) | |
5434 { | |
5435 got_quit = TRUE; | |
5436 break; | |
5437 } | |
1872 | 5438 if (typed == 'n') |
7 | 5439 break; |
1872 | 5440 if (typed == 'y') |
7 | 5441 break; |
1872 | 5442 if (typed == 'l') |
7 | 5443 { |
5444 /* last: replace and then stop */ | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5445 subflags.do_all = FALSE; |
7 | 5446 line2 = lnum; |
5447 break; | |
5448 } | |
1872 | 5449 if (typed == 'a') |
7 | 5450 { |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5451 subflags.do_ask = FALSE; |
7 | 5452 break; |
5453 } | |
5454 #ifdef FEAT_INS_EXPAND | |
1872 | 5455 if (typed == Ctrl_E) |
7 | 5456 scrollup_clamp(); |
1872 | 5457 else if (typed == Ctrl_Y) |
7 | 5458 scrolldown_clamp(); |
5459 #endif | |
5460 } | |
5461 State = save_State; | |
5462 #ifdef FEAT_MOUSE | |
5463 setmouse(); | |
5464 #endif | |
5465 if (vim_strchr(p_cpo, CPO_UNDO) != NULL) | |
5466 --no_u_sync; | |
5467 | |
1872 | 5468 if (typed == 'n') |
7 | 5469 { |
5470 /* For a multi-line match, put matchcol at the NUL at | |
5471 * the end of the line and set nmatch to one, so that | |
5472 * we continue looking for a match on the next line. | |
1091 | 5473 * Avoids that ":%s/\nB\@=//gc" and ":%s/\n/,\r/gc" |
5474 * get stuck when pressing 'n'. */ | |
7 | 5475 if (nmatch > 1) |
5476 { | |
835 | 5477 matchcol = (colnr_T)STRLEN(sub_firstline); |
1091 | 5478 skip_match = TRUE; |
7 | 5479 } |
5480 goto skip; | |
5481 } | |
5482 if (got_quit) | |
4099 | 5483 goto skip; |
7 | 5484 } |
5485 | |
5486 /* Move the cursor to the start of the match, so that we can | |
5487 * use "\=col("."). */ | |
5488 curwin->w_cursor.col = regmatch.startpos[0].col; | |
5489 | |
5490 /* | |
5491 * 3. substitute the string. | |
5492 */ | |
3736 | 5493 #ifdef FEAT_EVAL |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5494 if (subflags.do_count) |
3736 | 5495 { |
3786 | 5496 /* prevent accidentally changing the buffer by a function */ |
3736 | 5497 save_ma = curbuf->b_p_ma; |
5498 curbuf->b_p_ma = FALSE; | |
5499 sandbox++; | |
5500 } | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5501 /* Save flags for recursion. They can change for e.g. |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5502 * :s/^/\=execute("s#^##gn") */ |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5503 subflags_save = subflags; |
3736 | 5504 #endif |
7 | 5505 /* get length of substitution part */ |
1499 | 5506 sublen = vim_regsub_multi(®match, |
5507 sub_firstlnum - regmatch.startpos[0].lnum, | |
7 | 5508 sub, sub_firstline, FALSE, p_magic, TRUE); |
3736 | 5509 #ifdef FEAT_EVAL |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5510 /* Don't keep flags set by a recursive call. */ |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5511 subflags = subflags_save; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5512 if (subflags.do_count) |
3736 | 5513 { |
5514 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
|
5515 if (sandbox > 0) |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5516 sandbox--; |
3736 | 5517 goto skip; |
5518 } | |
5519 #endif | |
7 | 5520 |
533 | 5521 /* When the match included the "$" of the last line it may |
819 | 5522 * go beyond the last line of the buffer. */ |
533 | 5523 if (nmatch > curbuf->b_ml.ml_line_count - sub_firstlnum + 1) |
5524 { | |
5525 nmatch = curbuf->b_ml.ml_line_count - sub_firstlnum + 1; | |
5526 skip_match = TRUE; | |
5527 } | |
5528 | |
7 | 5529 /* Need room for: |
5530 * - result so far in new_start (not for first sub in line) | |
5531 * - original text up to match | |
5532 * - length of substituted part | |
5533 * - original text after match | |
5534 */ | |
5535 if (nmatch == 1) | |
5536 p1 = sub_firstline; | |
5537 else | |
5538 { | |
5539 p1 = ml_get(sub_firstlnum + nmatch - 1); | |
5540 nmatch_tl += nmatch - 1; | |
5541 } | |
1872 | 5542 copy_len = regmatch.startpos[0].col - copycol; |
5543 needed_len = copy_len + ((unsigned)STRLEN(p1) | |
5544 - regmatch.endpos[0].col) + sublen + 1; | |
7 | 5545 if (new_start == NULL) |
5546 { | |
5547 /* | |
5548 * Get some space for a temporary buffer to do the | |
5549 * substitution into (and some extra space to avoid | |
5550 * too many calls to alloc()/free()). | |
5551 */ | |
5552 new_start_len = needed_len + 50; | |
5553 if ((new_start = alloc_check(new_start_len)) == NULL) | |
5554 goto outofmem; | |
5555 *new_start = NUL; | |
5556 new_end = new_start; | |
5557 } | |
5558 else | |
5559 { | |
5560 /* | |
5561 * Check if the temporary buffer is long enough to do the | |
5562 * substitution into. If not, make it larger (with a bit | |
5563 * extra to avoid too many calls to alloc()/free()). | |
5564 */ | |
5565 len = (unsigned)STRLEN(new_start); | |
5566 needed_len += len; | |
1872 | 5567 if (needed_len > (int)new_start_len) |
7 | 5568 { |
5569 new_start_len = needed_len + 50; | |
5570 if ((p1 = alloc_check(new_start_len)) == NULL) | |
5571 { | |
5572 vim_free(new_start); | |
5573 goto outofmem; | |
5574 } | |
5575 mch_memmove(p1, new_start, (size_t)(len + 1)); | |
5576 vim_free(new_start); | |
5577 new_start = p1; | |
5578 } | |
5579 new_end = new_start + len; | |
5580 } | |
5581 | |
5582 /* | |
5583 * copy the text up to the part that matched | |
5584 */ | |
1872 | 5585 mch_memmove(new_end, sub_firstline + copycol, (size_t)copy_len); |
5586 new_end += copy_len; | |
7 | 5587 |
1499 | 5588 (void)vim_regsub_multi(®match, |
5589 sub_firstlnum - regmatch.startpos[0].lnum, | |
7 | 5590 sub, new_end, TRUE, p_magic, TRUE); |
5591 sub_nsubs++; | |
5592 did_sub = TRUE; | |
5593 | |
5594 /* Move the cursor to the start of the line, to avoid that it | |
5595 * is beyond the end of the line after the substitution. */ | |
5596 curwin->w_cursor.col = 0; | |
5597 | |
5598 /* For a multi-line match, make a copy of the last matched | |
5599 * line and continue in that one. */ | |
5600 if (nmatch > 1) | |
5601 { | |
5602 sub_firstlnum += nmatch - 1; | |
5603 vim_free(sub_firstline); | |
5604 sub_firstline = vim_strsave(ml_get(sub_firstlnum)); | |
5605 /* When going beyond the last line, stop substituting. */ | |
5606 if (sub_firstlnum <= line2) | |
5607 do_again = TRUE; | |
5608 else | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5609 subflags.do_all = FALSE; |
7 | 5610 } |
5611 | |
5612 /* Remember next character to be copied. */ | |
5613 copycol = regmatch.endpos[0].col; | |
5614 | |
819 | 5615 if (skip_match) |
5616 { | |
5617 /* Already hit end of the buffer, sub_firstlnum is one | |
5618 * less than what it ought to be. */ | |
5619 vim_free(sub_firstline); | |
5620 sub_firstline = vim_strsave((char_u *)""); | |
5621 copycol = 0; | |
5622 } | |
5623 | |
7 | 5624 /* |
5625 * Now the trick is to replace CTRL-M chars with a real line | |
5626 * break. This would make it impossible to insert a CTRL-M in | |
5627 * the text. The line break can be avoided by preceding the | |
5628 * CTRL-M with a backslash. To be able to insert a backslash, | |
5629 * they must be doubled in the string and are halved here. | |
5630 * That is Vi compatible. | |
5631 */ | |
5632 for (p1 = new_end; *p1; ++p1) | |
5633 { | |
5634 if (p1[0] == '\\' && p1[1] != NUL) /* remove backslash */ | |
1624 | 5635 STRMOVE(p1, p1 + 1); |
7 | 5636 else if (*p1 == CAR) |
5637 { | |
5638 if (u_inssub(lnum) == OK) /* prepare for undo */ | |
5639 { | |
5640 *p1 = NUL; /* truncate up to the CR */ | |
5641 ml_append(lnum - 1, new_start, | |
5642 (colnr_T)(p1 - new_start + 1), FALSE); | |
5643 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
|
5644 if (subflags.do_ask) |
7 | 5645 appended_lines(lnum - 1, 1L); |
5646 else | |
5647 { | |
5648 if (first_line == 0) | |
5649 first_line = lnum; | |
5650 last_line = lnum + 1; | |
5651 } | |
5652 /* All line numbers increase. */ | |
5653 ++sub_firstlnum; | |
5654 ++lnum; | |
5655 ++line2; | |
5656 /* move the cursor to the new line, like Vi */ | |
5657 ++curwin->w_cursor.lnum; | |
1444 | 5658 /* copy the rest */ |
1624 | 5659 STRMOVE(new_start, p1 + 1); |
7 | 5660 p1 = new_start - 1; |
5661 } | |
5662 } | |
5663 #ifdef FEAT_MBYTE | |
5664 else if (has_mbyte) | |
474 | 5665 p1 += (*mb_ptr2len)(p1) - 1; |
7 | 5666 #endif |
5667 } | |
5668 | |
5669 /* | |
5670 * 4. If do_all is set, find next match. | |
5671 * Prevent endless loop with patterns that match empty | |
5672 * strings, e.g. :s/$/pat/g or :s/[a-z]* /(&)/g. | |
5673 * But ":s/\n/#/" is OK. | |
5674 */ | |
5675 skip: | |
5676 /* We already know that we did the last subst when we are at | |
5677 * the end of the line, except that a pattern like | |
1499 | 5678 * "bar\|\nfoo" may match at the NUL. "lnum" can be below |
5679 * "line2" when there is a \zs in the pattern after a line | |
5680 * break. */ | |
15 | 5681 lastone = (skip_match |
5682 || got_int | |
5683 || got_quit | |
1499 | 5684 || lnum > line2 |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5685 || !(subflags.do_all || do_again) |
15 | 5686 || (sub_firstline[matchcol] == NUL && nmatch <= 1 |
5687 && !re_multiline(regmatch.regprog))); | |
7 | 5688 nmatch = -1; |
5689 | |
5690 /* | |
5691 * Replace the line in the buffer when needed. This is | |
5692 * skipped when there are more matches. | |
5693 * The check for nmatch_tl is needed for when multi-line | |
5694 * matching must replace the lines before trying to do another | |
5695 * match, otherwise "\@<=" won't work. | |
1499 | 5696 * When the match starts below where we start searching also |
5697 * need to replace the line first (using \zs after \n). | |
7 | 5698 */ |
5699 if (lastone | |
5700 || nmatch_tl > 0 | |
5701 || (nmatch = vim_regexec_multi(®match, curwin, | |
1521 | 5702 curbuf, sub_firstlnum, |
5703 matchcol, NULL)) == 0 | |
1499 | 5704 || regmatch.startpos[0].lnum > 0) |
7 | 5705 { |
5706 if (new_start != NULL) | |
5707 { | |
5708 /* | |
5709 * Copy the rest of the line, that didn't match. | |
5710 * "matchcol" has to be adjusted, we use the end of | |
5711 * the line as reference, because the substitute may | |
5712 * have changed the number of characters. Same for | |
5713 * "prev_matchcol". | |
5714 */ | |
5715 STRCAT(new_start, sub_firstline + copycol); | |
5716 matchcol = (colnr_T)STRLEN(sub_firstline) - matchcol; | |
5717 prev_matchcol = (colnr_T)STRLEN(sub_firstline) | |
5718 - prev_matchcol; | |
5719 | |
5720 if (u_savesub(lnum) != OK) | |
5721 break; | |
5722 ml_replace(lnum, new_start, TRUE); | |
5723 | |
5724 if (nmatch_tl > 0) | |
5725 { | |
5726 /* | |
5727 * Matched lines have now been substituted and are | |
5728 * useless, delete them. The part after the match | |
5729 * has been appended to new_start, we don't need | |
5730 * it in the buffer. | |
5731 */ | |
5732 ++lnum; | |
5733 if (u_savedel(lnum, nmatch_tl) != OK) | |
5734 break; | |
5735 for (i = 0; i < nmatch_tl; ++i) | |
5736 ml_delete(lnum, (int)FALSE); | |
5737 mark_adjust(lnum, lnum + nmatch_tl - 1, | |
5738 (long)MAXLNUM, -nmatch_tl); | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5739 if (subflags.do_ask) |
7 | 5740 deleted_lines(lnum, nmatch_tl); |
5741 --lnum; | |
5742 line2 -= nmatch_tl; /* nr of lines decreases */ | |
5743 nmatch_tl = 0; | |
5744 } | |
5745 | |
5746 /* When asking, undo is saved each time, must also set | |
5747 * changed flag each time. */ | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5748 if (subflags.do_ask) |
7 | 5749 changed_bytes(lnum, 0); |
5750 else | |
5751 { | |
5752 if (first_line == 0) | |
5753 first_line = lnum; | |
5754 last_line = lnum + 1; | |
5755 } | |
5756 | |
5757 sub_firstlnum = lnum; | |
5758 vim_free(sub_firstline); /* free the temp buffer */ | |
5759 sub_firstline = new_start; | |
5760 new_start = NULL; | |
5761 matchcol = (colnr_T)STRLEN(sub_firstline) - matchcol; | |
5762 prev_matchcol = (colnr_T)STRLEN(sub_firstline) | |
5763 - prev_matchcol; | |
5764 copycol = 0; | |
5765 } | |
5766 if (nmatch == -1 && !lastone) | |
5767 nmatch = vim_regexec_multi(®match, curwin, curbuf, | |
1521 | 5768 sub_firstlnum, matchcol, NULL); |
7 | 5769 |
5770 /* | |
5771 * 5. break if there isn't another match in this line | |
5772 */ | |
5773 if (nmatch <= 0) | |
1499 | 5774 { |
5775 /* If the match found didn't start where we were | |
5776 * searching, do the next search in the line where we | |
5777 * found the match. */ | |
5778 if (nmatch == -1) | |
5779 lnum -= regmatch.startpos[0].lnum; | |
7 | 5780 break; |
1499 | 5781 } |
7 | 5782 } |
5783 | |
5784 line_breakcheck(); | |
5785 } | |
5786 | |
5787 if (did_sub) | |
5788 ++sub_nlines; | |
1720 | 5789 vim_free(new_start); /* for when substitute was cancelled */ |
7 | 5790 vim_free(sub_firstline); /* free the copy of the original line */ |
5791 sub_firstline = NULL; | |
5792 } | |
5793 | |
5794 line_breakcheck(); | |
5795 } | |
5796 | |
5797 if (first_line != 0) | |
5798 { | |
5799 /* Need to subtract the number of added lines from "last_line" to get | |
5800 * the line number before the change (same as adding the number of | |
5801 * deleted lines). */ | |
5802 i = curbuf->b_ml.ml_line_count - old_line_count; | |
5803 changed_lines(first_line, 0, last_line - i, i); | |
5804 } | |
5805 | |
5806 outofmem: | |
5807 vim_free(sub_firstline); /* may have to free allocated copy of the line */ | |
170 | 5808 |
5809 /* ":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
|
5810 if (subflags.do_count) |
170 | 5811 curwin->w_cursor = old_cursor; |
5812 | |
2126
e038754d419a
updated for version 7.2.408
Bram Moolenaar <bram@zimbu.org>
parents:
1929
diff
changeset
|
5813 if (sub_nsubs > start_nsubs) |
7 | 5814 { |
5815 /* Set the '[ and '] marks. */ | |
5816 curbuf->b_op_start.lnum = eap->line1; | |
5817 curbuf->b_op_end.lnum = line2; | |
5818 curbuf->b_op_start.col = curbuf->b_op_end.col = 0; | |
5819 | |
5820 if (!global_busy) | |
5821 { | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5822 /* 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
|
5823 if (!subflags.do_ask) |
3394 | 5824 { |
5825 if (endcolumn) | |
5826 coladvance((colnr_T)MAXCOL); | |
5827 else | |
5828 beginline(BL_WHITE | BL_FIX); | |
5829 } | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5830 if (!do_sub_msg(subflags.do_count) && subflags.do_ask) |
7 | 5831 MSG(""); |
5832 } | |
5833 else | |
5834 global_need_beginline = TRUE; | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5835 if (subflags.do_print) |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5836 print_line(curwin->w_cursor.lnum, |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5837 subflags.do_number, subflags.do_list); |
7 | 5838 } |
5839 else if (!global_busy) | |
5840 { | |
5841 if (got_int) /* interrupted */ | |
5842 EMSG(_(e_interr)); | |
5843 else if (got_match) /* did find something but nothing substituted */ | |
5844 MSG(""); | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5845 else if (subflags.do_error) /* nothing found */ |
7 | 5846 EMSG2(_(e_patnotf2), get_search_pat()); |
5847 } | |
5848 | |
4035 | 5849 #ifdef FEAT_FOLDING |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5850 if (subflags.do_ask && hasAnyFolding(curwin)) |
4035 | 5851 /* Cursor position may require updating */ |
5852 changed_window_setting(); | |
5853 #endif | |
5854 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4613
diff
changeset
|
5855 vim_regfree(regmatch.regprog); |
6789 | 5856 |
5857 /* 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
|
5858 subflags.do_all = save_do_all; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5859 subflags.do_ask = save_do_ask; |
7 | 5860 } |
5861 | |
5862 /* | |
5863 * Give message for number of substitutions. | |
5864 * Can also be used after a ":global" command. | |
5865 * Return TRUE if a message was given. | |
5866 */ | |
484 | 5867 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5868 do_sub_msg( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5869 int count_only) /* used 'n' flag for ":s" */ |
7 | 5870 { |
5871 /* | |
5872 * Only report substitutions when: | |
5873 * - more than 'report' substitutions | |
5874 * - command was typed by user, or number of changed lines > 'report' | |
5875 * - giving messages is not disabled by 'lazyredraw' | |
5876 */ | |
170 | 5877 if (((sub_nsubs > p_report && (KeyTyped || sub_nlines > 1 || p_report < 1)) |
5878 || count_only) | |
7 | 5879 && messaging()) |
5880 { | |
5881 if (got_int) | |
5882 STRCPY(msg_buf, _("(Interrupted) ")); | |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
5883 else |
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
5884 *msg_buf = NUL; |
7 | 5885 if (sub_nsubs == 1) |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2254
diff
changeset
|
5886 vim_snprintf_add((char *)msg_buf, sizeof(msg_buf), |
274 | 5887 "%s", count_only ? _("1 match") : _("1 substitution")); |
7 | 5888 else |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2254
diff
changeset
|
5889 vim_snprintf_add((char *)msg_buf, sizeof(msg_buf), |
170 | 5890 count_only ? _("%ld matches") : _("%ld substitutions"), |
7 | 5891 sub_nsubs); |
5892 if (sub_nlines == 1) | |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2254
diff
changeset
|
5893 vim_snprintf_add((char *)msg_buf, sizeof(msg_buf), |
274 | 5894 "%s", _(" on 1 line")); |
7 | 5895 else |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2254
diff
changeset
|
5896 vim_snprintf_add((char *)msg_buf, sizeof(msg_buf), |
274 | 5897 _(" on %ld lines"), (long)sub_nlines); |
7 | 5898 if (msg(msg_buf)) |
5899 /* save message to display it after redraw */ | |
680 | 5900 set_keep_msg(msg_buf, 0); |
7 | 5901 return TRUE; |
5902 } | |
5903 if (got_int) | |
5904 { | |
5905 EMSG(_(e_interr)); | |
5906 return TRUE; | |
5907 } | |
5908 return FALSE; | |
5909 } | |
5910 | |
5911 /* | |
5912 * Execute a global command of the form: | |
5913 * | |
5914 * g/pattern/X : execute X on all lines where pattern matches | |
5915 * v/pattern/X : execute X on all lines where pattern does not match | |
5916 * | |
5917 * where 'X' is an EX command | |
5918 * | |
5919 * The command character (as well as the trailing slash) is optional, and | |
5920 * is assumed to be 'p' if missing. | |
5921 * | |
5922 * This is implemented in two passes: first we scan the file for the pattern and | |
3786 | 5923 * set a mark for each line that (not) matches. Secondly we execute the command |
7 | 5924 * for each line that has a mark. This is required because after deleting |
5925 * lines we do not know where to search for the next match. | |
5926 */ | |
5927 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5928 ex_global(exarg_T *eap) |
7 | 5929 { |
5930 linenr_T lnum; /* line number according to old situation */ | |
170 | 5931 int ndone = 0; |
7 | 5932 int type; /* first char of cmd: 'v' or 'g' */ |
5933 char_u *cmd; /* command argument */ | |
5934 | |
5935 char_u delim; /* delimiter, normally '/' */ | |
5936 char_u *pat; | |
5937 regmmatch_T regmatch; | |
5938 int match; | |
5939 int which_pat; | |
5940 | |
5941 if (global_busy) | |
5942 { | |
5943 EMSG(_("E147: Cannot do :global recursive")); /* will increment global_busy */ | |
5944 return; | |
5945 } | |
5946 | |
5947 if (eap->forceit) /* ":global!" is like ":vglobal" */ | |
5948 type = 'v'; | |
5949 else | |
5950 type = *eap->cmd; | |
5951 cmd = eap->arg; | |
5952 which_pat = RE_LAST; /* default: use last used regexp */ | |
5953 | |
5954 /* | |
5955 * undocumented vi feature: | |
5956 * "\/" and "\?": use previous search pattern. | |
5957 * "\&": use previous substitute pattern. | |
5958 */ | |
5959 if (*cmd == '\\') | |
5960 { | |
5961 ++cmd; | |
5962 if (vim_strchr((char_u *)"/?&", *cmd) == NULL) | |
5963 { | |
5964 EMSG(_(e_backslash)); | |
5965 return; | |
5966 } | |
5967 if (*cmd == '&') | |
5968 which_pat = RE_SUBST; /* use previous substitute pattern */ | |
5969 else | |
5970 which_pat = RE_SEARCH; /* use previous search pattern */ | |
5971 ++cmd; | |
5972 pat = (char_u *)""; | |
5973 } | |
5974 else if (*cmd == NUL) | |
5975 { | |
5976 EMSG(_("E148: Regular expression missing from global")); | |
5977 return; | |
5978 } | |
5979 else | |
5980 { | |
5981 delim = *cmd; /* get the delimiter */ | |
5982 if (delim) | |
5983 ++cmd; /* skip delimiter if there is one */ | |
5984 pat = cmd; /* remember start of pattern */ | |
5985 cmd = skip_regexp(cmd, delim, p_magic, &eap->arg); | |
5986 if (cmd[0] == delim) /* end delimiter found */ | |
5987 *cmd++ = NUL; /* replace it with a NUL */ | |
5988 } | |
5989 | |
5990 #ifdef FEAT_FKMAP /* when in Farsi mode, reverse the character flow */ | |
5991 if (p_altkeymap && curwin->w_p_rl) | |
5992 lrFswap(pat,0); | |
5993 #endif | |
5994 | |
5995 if (search_regcomp(pat, RE_BOTH, which_pat, SEARCH_HIS, ®match) == FAIL) | |
5996 { | |
5997 EMSG(_(e_invcmd)); | |
5998 return; | |
5999 } | |
6000 | |
6001 /* | |
6002 * pass 1: set marks for each (not) matching line | |
6003 */ | |
6004 for (lnum = eap->line1; lnum <= eap->line2 && !got_int; ++lnum) | |
6005 { | |
6006 /* a match on this line? */ | |
1521 | 6007 match = vim_regexec_multi(®match, curwin, curbuf, lnum, |
6008 (colnr_T)0, NULL); | |
7 | 6009 if ((type == 'g' && match) || (type == 'v' && !match)) |
6010 { | |
6011 ml_setmarked(lnum); | |
6012 ndone++; | |
6013 } | |
6014 line_breakcheck(); | |
6015 } | |
6016 | |
6017 /* | |
6018 * pass 2: execute the command for each line that has been marked | |
6019 */ | |
6020 if (got_int) | |
6021 MSG(_(e_interr)); | |
6022 else if (ndone == 0) | |
6023 { | |
6024 if (type == 'v') | |
274 | 6025 smsg((char_u *)_("Pattern found in every line: %s"), pat); |
7 | 6026 else |
4195 | 6027 smsg((char_u *)_("Pattern not found: %s"), pat); |
7 | 6028 } |
6029 else | |
6116 | 6030 { |
6031 #ifdef FEAT_CLIPBOARD | |
6032 start_global_changes(); | |
6033 #endif | |
7 | 6034 global_exe(cmd); |
6116 | 6035 #ifdef FEAT_CLIPBOARD |
6036 end_global_changes(); | |
6037 #endif | |
6038 } | |
7 | 6039 |
6040 ml_clearmarked(); /* clear rest of the marks */ | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4613
diff
changeset
|
6041 vim_regfree(regmatch.regprog); |
7 | 6042 } |
6043 | |
6044 /* | |
6045 * Execute "cmd" on lines marked with ml_setmarked(). | |
6046 */ | |
6047 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6048 global_exe(char_u *cmd) |
7 | 6049 { |
2819 | 6050 linenr_T old_lcount; /* b_ml.ml_line_count before the command */ |
6051 buf_T *old_buf = curbuf; /* remember what buffer we started in */ | |
6052 linenr_T lnum; /* line number according to old situation */ | |
7 | 6053 |
6054 /* | |
6055 * Set current position only once for a global command. | |
6056 * If global_busy is set, setpcmark() will not do anything. | |
6057 * If there is an error, global_busy will be incremented. | |
6058 */ | |
6059 setpcmark(); | |
6060 | |
6061 /* When the command writes a message, don't overwrite the command. */ | |
6062 msg_didout = TRUE; | |
6063 | |
2127
4e22214f8464
updated for version 7.2.409
Bram Moolenaar <bram@zimbu.org>
parents:
2126
diff
changeset
|
6064 sub_nsubs = 0; |
4e22214f8464
updated for version 7.2.409
Bram Moolenaar <bram@zimbu.org>
parents:
2126
diff
changeset
|
6065 sub_nlines = 0; |
7 | 6066 global_need_beginline = FALSE; |
6067 global_busy = 1; | |
6068 old_lcount = curbuf->b_ml.ml_line_count; | |
6069 while (!got_int && (lnum = ml_firstmarked()) != 0 && global_busy == 1) | |
6070 { | |
6071 curwin->w_cursor.lnum = lnum; | |
6072 curwin->w_cursor.col = 0; | |
6073 if (*cmd == NUL || *cmd == '\n') | |
6074 do_cmdline((char_u *)"p", NULL, NULL, DOCMD_NOWAIT); | |
6075 else | |
6076 do_cmdline(cmd, NULL, NULL, DOCMD_NOWAIT); | |
6077 ui_breakcheck(); | |
6078 } | |
6079 | |
6080 global_busy = 0; | |
6081 if (global_need_beginline) | |
6082 beginline(BL_WHITE | BL_FIX); | |
6083 else | |
6084 check_cursor(); /* cursor may be beyond the end of the line */ | |
6085 | |
39 | 6086 /* the cursor may not have moved in the text but a change in a previous |
6087 * line may move it on the screen */ | |
6088 changed_line_abv_curs(); | |
6089 | |
7 | 6090 /* If it looks like no message was written, allow overwriting the |
6091 * command with the report for number of changes. */ | |
6092 if (msg_col == 0 && msg_scrolled == 0) | |
6093 msg_didout = FALSE; | |
6094 | |
1227 | 6095 /* If substitutes done, report number of substitutes, otherwise report |
2819 | 6096 * number of extra or deleted lines. |
6097 * Don't report extra or deleted lines in the edge case where the buffer | |
6098 * we are in after execution is different from the buffer we started in. */ | |
6099 if (!do_sub_msg(FALSE) && curbuf == old_buf) | |
7 | 6100 msgmore(curbuf->b_ml.ml_line_count - old_lcount); |
6101 } | |
6102 | |
6103 #ifdef FEAT_VIMINFO | |
6104 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6105 read_viminfo_sub_string(vir_T *virp, int force) |
7 | 6106 { |
2690 | 6107 if (force) |
7 | 6108 vim_free(old_sub); |
6109 if (force || old_sub == NULL) | |
6110 old_sub = viminfo_readstring(virp, 1, TRUE); | |
6111 return viminfo_readline(virp); | |
6112 } | |
6113 | |
6114 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6115 write_viminfo_sub_string(FILE *fp) |
7 | 6116 { |
6117 if (get_viminfo_parameter('/') != 0 && old_sub != NULL) | |
6118 { | |
2545
298d8d6e69be
Avoid warnings from the clang compiler. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2394
diff
changeset
|
6119 fputs(_("\n# Last Substitute String:\n$"), fp); |
7 | 6120 viminfo_writestring(fp, old_sub); |
6121 } | |
6122 } | |
6123 #endif /* FEAT_VIMINFO */ | |
6124 | |
359 | 6125 #if defined(EXITFREE) || defined(PROTO) |
6126 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6127 free_old_sub(void) |
359 | 6128 { |
6129 vim_free(old_sub); | |
6130 } | |
6131 #endif | |
6132 | |
7 | 6133 #if (defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)) || defined(PROTO) |
6134 /* | |
6135 * Set up for a tagpreview. | |
735 | 6136 * Return TRUE when it was created. |
7 | 6137 */ |
735 | 6138 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6139 prepare_tagpreview( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6140 int undo_sync) /* sync undo when leaving the window */ |
7 | 6141 { |
6142 win_T *wp; | |
6143 | |
6144 # ifdef FEAT_GUI | |
6145 need_mouse_correct = TRUE; | |
6146 # endif | |
6147 | |
6148 /* | |
6149 * If there is already a preview window open, use that one. | |
6150 */ | |
6151 if (!curwin->w_p_pvw) | |
6152 { | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
6153 FOR_ALL_WINDOWS(wp) |
7 | 6154 if (wp->w_p_pvw) |
6155 break; | |
6156 if (wp != NULL) | |
816 | 6157 win_enter(wp, undo_sync); |
7 | 6158 else |
6159 { | |
6160 /* | |
6161 * There is no preview window open yet. Create one. | |
6162 */ | |
6163 if (win_split(g_do_tagpreview > 0 ? g_do_tagpreview : 0, 0) | |
6164 == FAIL) | |
735 | 6165 return FALSE; |
7 | 6166 curwin->w_p_pvw = TRUE; |
6167 curwin->w_p_wfh = TRUE; | |
2583 | 6168 RESET_BINDING(curwin); /* don't take over 'scrollbind' |
6169 and 'cursorbind' */ | |
7 | 6170 # ifdef FEAT_DIFF |
6171 curwin->w_p_diff = FALSE; /* no 'diff' */ | |
6172 # endif | |
6173 # ifdef FEAT_FOLDING | |
6174 curwin->w_p_fdc = 0; /* no 'foldcolumn' */ | |
6175 # endif | |
735 | 6176 return TRUE; |
7 | 6177 } |
6178 } | |
735 | 6179 return FALSE; |
7 | 6180 } |
6181 | |
6182 #endif | |
6183 | |
6184 | |
6185 /* | |
6186 * ":help": open a read-only window on a help file | |
6187 */ | |
6188 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6189 ex_help(exarg_T *eap) |
7 | 6190 { |
6191 char_u *arg; | |
6192 char_u *tag; | |
6193 FILE *helpfd; /* file descriptor of help file */ | |
6194 int n; | |
6195 int i; | |
6196 #ifdef FEAT_WINDOWS | |
6197 win_T *wp; | |
6198 #endif | |
6199 int num_matches; | |
6200 char_u **matches; | |
6201 char_u *p; | |
6202 int empty_fnum = 0; | |
6203 int alt_fnum = 0; | |
6204 buf_T *buf; | |
6205 #ifdef FEAT_MULTI_LANG | |
6206 int len; | |
9 | 6207 char_u *lang; |
7 | 6208 #endif |
3112 | 6209 #ifdef FEAT_FOLDING |
6210 int old_KeyTyped = KeyTyped; | |
6211 #endif | |
7 | 6212 |
6213 if (eap != NULL) | |
6214 { | |
6215 /* | |
6216 * A ":help" command ends at the first LF, or at a '|' that is | |
6217 * followed by some text. Set nextcmd to the following command. | |
6218 */ | |
6219 for (arg = eap->arg; *arg; ++arg) | |
6220 { | |
6221 if (*arg == '\n' || *arg == '\r' | |
6222 || (*arg == '|' && arg[1] != NUL && arg[1] != '|')) | |
6223 { | |
6224 *arg++ = NUL; | |
6225 eap->nextcmd = arg; | |
6226 break; | |
6227 } | |
6228 } | |
6229 arg = eap->arg; | |
6230 | |
3446 | 6231 if (eap->forceit && *arg == NUL && !curbuf->b_help) |
7 | 6232 { |
6233 EMSG(_("E478: Don't panic!")); | |
6234 return; | |
6235 } | |
6236 | |
6237 if (eap->skip) /* not executing commands */ | |
6238 return; | |
6239 } | |
6240 else | |
6241 arg = (char_u *)""; | |
6242 | |
6243 /* remove trailing blanks */ | |
6244 p = arg + STRLEN(arg) - 1; | |
6245 while (p > arg && vim_iswhite(*p) && p[-1] != '\\') | |
6246 *p-- = NUL; | |
6247 | |
6248 #ifdef FEAT_MULTI_LANG | |
6249 /* Check for a specified language */ | |
9 | 6250 lang = check_help_lang(arg); |
7 | 6251 #endif |
6252 | |
6253 /* When no argument given go to the index. */ | |
6254 if (*arg == NUL) | |
6255 arg = (char_u *)"help.txt"; | |
6256 | |
6257 /* | |
6258 * Check if there is a match for the argument. | |
6259 */ | |
6260 n = find_help_tags(arg, &num_matches, &matches, | |
6261 eap != NULL && eap->forceit); | |
6262 | |
6263 i = 0; | |
6264 #ifdef FEAT_MULTI_LANG | |
6265 if (n != FAIL && lang != NULL) | |
6266 /* Find first item with the requested language. */ | |
6267 for (i = 0; i < num_matches; ++i) | |
6268 { | |
835 | 6269 len = (int)STRLEN(matches[i]); |
7 | 6270 if (len > 3 && matches[i][len - 3] == '@' |
6271 && STRICMP(matches[i] + len - 2, lang) == 0) | |
6272 break; | |
6273 } | |
6274 #endif | |
6275 if (i >= num_matches || n == FAIL) | |
6276 { | |
6277 #ifdef FEAT_MULTI_LANG | |
6278 if (lang != NULL) | |
6279 EMSG3(_("E661: Sorry, no '%s' help for %s"), lang, arg); | |
6280 else | |
6281 #endif | |
6282 EMSG2(_("E149: Sorry, no help for %s"), arg); | |
6283 if (n != FAIL) | |
6284 FreeWild(num_matches, matches); | |
6285 return; | |
6286 } | |
6287 | |
6288 /* The first match (in the requested language) is the best match. */ | |
6289 tag = vim_strsave(matches[i]); | |
6290 FreeWild(num_matches, matches); | |
6291 | |
6292 #ifdef FEAT_GUI | |
6293 need_mouse_correct = TRUE; | |
6294 #endif | |
6295 | |
6296 /* | |
6297 * Re-use an existing help window or open a new one. | |
684 | 6298 * Always open a new one for ":tab help". |
7 | 6299 */ |
684 | 6300 if (!curwin->w_buffer->b_help |
6301 #ifdef FEAT_WINDOWS | |
6302 || cmdmod.tab != 0 | |
6303 #endif | |
6304 ) | |
7 | 6305 { |
6306 #ifdef FEAT_WINDOWS | |
684 | 6307 if (cmdmod.tab != 0) |
6308 wp = NULL; | |
6309 else | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
6310 FOR_ALL_WINDOWS(wp) |
684 | 6311 if (wp->w_buffer != NULL && wp->w_buffer->b_help) |
6312 break; | |
7 | 6313 if (wp != NULL && wp->w_buffer->b_nwindows > 0) |
6314 win_enter(wp, TRUE); | |
6315 else | |
6316 #endif | |
6317 { | |
6318 /* | |
6319 * There is no help window yet. | |
6320 * Try to open the file specified by the "helpfile" option. | |
6321 */ | |
6322 if ((helpfd = mch_fopen((char *)p_hf, READBIN)) == NULL) | |
6323 { | |
274 | 6324 smsg((char_u *)_("Sorry, help file \"%s\" not found"), p_hf); |
7 | 6325 goto erret; |
6326 } | |
6327 fclose(helpfd); | |
6328 | |
6329 #ifdef FEAT_WINDOWS | |
6330 /* Split off help window; put it at far top if no position | |
684 | 6331 * specified, the current window is vertically split and |
6332 * narrow. */ | |
7 | 6333 n = WSP_HELP; |
6334 if (cmdmod.split == 0 && curwin->w_width != Columns | |
684 | 6335 && curwin->w_width < 80) |
7 | 6336 n |= WSP_TOP; |
6337 if (win_split(0, n) == FAIL) | |
684 | 6338 goto erret; |
7 | 6339 #else |
6340 /* use current window */ | |
6341 if (!can_abandon(curbuf, FALSE)) | |
6342 goto erret; | |
684 | 6343 #endif |
7 | 6344 |
6345 #ifdef FEAT_WINDOWS | |
6346 if (curwin->w_height < p_hh) | |
6347 win_setheight((int)p_hh); | |
6348 #endif | |
6349 | |
6350 /* | |
6351 * Open help file (do_ecmd() will set b_help flag, readfile() will | |
6352 * set b_p_ro flag). | |
6353 * Set the alternate file to the previously edited file. | |
6354 */ | |
6355 alt_fnum = curbuf->b_fnum; | |
6356 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_LASTL, | |
1743 | 6357 ECMD_HIDE + ECMD_SET_HELP, |
6358 #ifdef FEAT_WINDOWS | |
6359 NULL /* buffer is still open, don't store info */ | |
6360 #else | |
6361 curwin | |
6362 #endif | |
6363 ); | |
22 | 6364 if (!cmdmod.keepalt) |
6365 curwin->w_alt_fnum = alt_fnum; | |
7 | 6366 empty_fnum = curbuf->b_fnum; |
6367 } | |
6368 } | |
6369 | |
6370 if (!p_im) | |
6371 restart_edit = 0; /* don't want insert mode in help file */ | |
6372 | |
3112 | 6373 #ifdef FEAT_FOLDING |
6374 /* Restore KeyTyped, setting 'filetype=help' may reset it. | |
6375 * It is needed for do_tag top open folds under the cursor. */ | |
6376 KeyTyped = old_KeyTyped; | |
6377 #endif | |
6378 | |
7 | 6379 if (tag != NULL) |
6380 do_tag(tag, DT_HELP, 1, FALSE, TRUE); | |
6381 | |
819 | 6382 /* Delete the empty buffer if we're not using it. Careful: autocommands |
6383 * may have jumped to another window, check that the buffer is not in a | |
6384 * window. */ | |
7 | 6385 if (empty_fnum != 0 && curbuf->b_fnum != empty_fnum) |
6386 { | |
6387 buf = buflist_findnr(empty_fnum); | |
819 | 6388 if (buf != NULL && buf->b_nwindows == 0) |
7 | 6389 wipe_buffer(buf, TRUE); |
6390 } | |
6391 | |
6392 /* keep the previous alternate file */ | |
22 | 6393 if (alt_fnum != 0 && curwin->w_alt_fnum == empty_fnum && !cmdmod.keepalt) |
7 | 6394 curwin->w_alt_fnum = alt_fnum; |
6395 | |
6396 erret: | |
6397 vim_free(tag); | |
6398 } | |
6399 | |
6228 | 6400 /* |
6234 | 6401 * ":helpclose": Close one help window |
6228 | 6402 */ |
6403 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6404 ex_helpclose(exarg_T *eap UNUSED) |
6228 | 6405 { |
6236 | 6406 #if defined(FEAT_WINDOWS) |
6228 | 6407 win_T *win; |
6408 | |
6409 FOR_ALL_WINDOWS(win) | |
6410 { | |
6411 if (win->w_buffer->b_help) | |
6412 { | |
6413 win_close(win, FALSE); | |
6234 | 6414 return; |
6228 | 6415 } |
6416 } | |
6236 | 6417 #endif |
6228 | 6418 } |
7 | 6419 |
9 | 6420 #if defined(FEAT_MULTI_LANG) || defined(PROTO) |
6421 /* | |
6422 * In an argument search for a language specifiers in the form "@xx". | |
6423 * Changes the "@" to NUL if found, and returns a pointer to "xx". | |
6424 * Returns NULL if not found. | |
6425 */ | |
6426 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6427 check_help_lang(char_u *arg) |
9 | 6428 { |
835 | 6429 int len = (int)STRLEN(arg); |
9 | 6430 |
6431 if (len >= 3 && arg[len - 3] == '@' && ASCII_ISALPHA(arg[len - 2]) | |
6432 && ASCII_ISALPHA(arg[len - 1])) | |
6433 { | |
6434 arg[len - 3] = NUL; /* remove the '@' */ | |
6435 return arg + len - 2; | |
6436 } | |
6437 return NULL; | |
6438 } | |
6439 #endif | |
6440 | |
7 | 6441 /* |
6442 * Return a heuristic indicating how well the given string matches. The | |
6443 * smaller the number, the better the match. This is the order of priorities, | |
6444 * from best match to worst match: | |
6445 * - Match with least alpha-numeric characters is better. | |
6446 * - Match with least total characters is better. | |
6447 * - Match towards the start is better. | |
6448 * - Match starting with "+" is worse (feature instead of command) | |
6449 * Assumption is made that the matched_string passed has already been found to | |
6450 * match some string for which help is requested. webb. | |
6451 */ | |
6452 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6453 help_heuristic( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6454 char_u *matched_string, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6455 int offset, /* offset for match */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6456 int wrong_case) /* no matching case */ |
7 | 6457 { |
6458 int num_letters; | |
6459 char_u *p; | |
6460 | |
6461 num_letters = 0; | |
6462 for (p = matched_string; *p; p++) | |
6463 if (ASCII_ISALNUM(*p)) | |
6464 num_letters++; | |
6465 | |
6466 /* | |
6467 * Multiply the number of letters by 100 to give it a much bigger | |
6468 * weighting than the number of characters. | |
6469 * If there only is a match while ignoring case, add 5000. | |
6470 * If the match starts in the middle of a word, add 10000 to put it | |
6471 * somewhere in the last half. | |
6472 * If the match is more than 2 chars from the start, multiply by 200 to | |
6473 * put it after matches at the start. | |
6474 */ | |
6475 if (ASCII_ISALNUM(matched_string[offset]) && offset > 0 | |
6476 && ASCII_ISALNUM(matched_string[offset - 1])) | |
6477 offset += 10000; | |
6478 else if (offset > 2) | |
6479 offset *= 200; | |
6480 if (wrong_case) | |
6481 offset += 5000; | |
6482 /* Features are less interesting than the subjects themselves, but "+" | |
6483 * alone is not a feature. */ | |
6484 if (matched_string[0] == '+' && matched_string[1] != NUL) | |
6485 offset += 100; | |
6486 return (int)(100 * num_letters + STRLEN(matched_string) + offset); | |
6487 } | |
6488 | |
6489 /* | |
6490 * Compare functions for qsort() below, that checks the help heuristics number | |
6491 * that has been put after the tagname by find_tags(). | |
6492 */ | |
6493 static int | |
6494 #ifdef __BORLANDC__ | |
6495 _RTLENTRYF | |
6496 #endif | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6497 help_compare(const void *s1, const void *s2) |
7 | 6498 { |
6499 char *p1; | |
6500 char *p2; | |
6501 | |
6502 p1 = *(char **)s1 + strlen(*(char **)s1) + 1; | |
6503 p2 = *(char **)s2 + strlen(*(char **)s2) + 1; | |
6504 return strcmp(p1, p2); | |
6505 } | |
6506 | |
6507 /* | |
6508 * Find all help tags matching "arg", sort them and return in matches[], with | |
6509 * the number of matches in num_matches. | |
6510 * The matches will be sorted with a "best" match algorithm. | |
6511 * When "keep_lang" is TRUE try keeping the language of the current buffer. | |
6512 */ | |
6513 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6514 find_help_tags( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6515 char_u *arg, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6516 int *num_matches, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6517 char_u ***matches, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6518 int keep_lang) |
7 | 6519 { |
6520 char_u *s, *d; | |
6521 int i; | |
6522 static char *(mtable[]) = {"*", "g*", "[*", "]*", ":*", | |
445 | 6523 "/*", "/\\*", "\"*", "**", |
5269
7d1f89b27103
updated for version 7.4b.011
Bram Moolenaar <bram@vim.org>
parents:
5257
diff
changeset
|
6524 "cpo-*", "/\\(\\)", "/\\%(\\)", |
10853
b760fa91f8b3
patch 8.0.0316: :help z? does not work
Christian Brabandt <cb@256bit.org>
parents:
10851
diff
changeset
|
6525 "?", ":?", "?<CR>", "g?", "g?g?", "g??", |
279 | 6526 "/\\?", "/\\z(\\)", "\\=", ":s\\=", |
10851
256b1b96c2ad
patch 8.0.0315: :help :[range] does not work
Christian Brabandt <cb@256bit.org>
parents:
10638
diff
changeset
|
6527 "[count]", "[quotex]", |
256b1b96c2ad
patch 8.0.0315: :help :[range] does not work
Christian Brabandt <cb@256bit.org>
parents:
10638
diff
changeset
|
6528 "[range]", ":[range]", |
5647 | 6529 "[pattern]", "\\|", "\\%$", |
6530 "s/\\~", "s/\\U", "s/\\L", | |
6531 "s/\\1", "s/\\2", "s/\\3", "s/\\9"}; | |
7 | 6532 static char *(rtable[]) = {"star", "gstar", "[star", "]star", ":star", |
445 | 6533 "/star", "/\\\\star", "quotestar", "starstar", |
5269
7d1f89b27103
updated for version 7.4b.011
Bram Moolenaar <bram@vim.org>
parents:
5257
diff
changeset
|
6534 "cpo-star", "/\\\\(\\\\)", "/\\\\%(\\\\)", |
10853
b760fa91f8b3
patch 8.0.0316: :help z? does not work
Christian Brabandt <cb@256bit.org>
parents:
10851
diff
changeset
|
6535 "?", ":?", "?<CR>", "g?", "g?g?", "g??", |
279 | 6536 "/\\\\?", "/\\\\z(\\\\)", "\\\\=", ":s\\\\=", |
10851
256b1b96c2ad
patch 8.0.0315: :help :[range] does not work
Christian Brabandt <cb@256bit.org>
parents:
10638
diff
changeset
|
6537 "\\[count]", "\\[quotex]", |
256b1b96c2ad
patch 8.0.0315: :help :[range] does not work
Christian Brabandt <cb@256bit.org>
parents:
10638
diff
changeset
|
6538 "\\[range]", ":\\[range]", |
5647 | 6539 "\\[pattern]", "\\\\bar", "/\\\\%\\$", |
5867 | 6540 "s/\\\\\\~", "s/\\\\U", "s/\\\\L", |
5647 | 6541 "s/\\\\1", "s/\\\\2", "s/\\\\3", "s/\\\\9"}; |
7 | 6542 int flags; |
6543 | |
6544 d = IObuff; /* assume IObuff is long enough! */ | |
6545 | |
6546 /* | |
6547 * Recognize a few exceptions to the rule. Some strings that contain '*' | |
6548 * with "star". Otherwise '*' is recognized as a wildcard. | |
6549 */ | |
1872 | 6550 for (i = (int)(sizeof(mtable) / sizeof(char *)); --i >= 0; ) |
7 | 6551 if (STRCMP(arg, mtable[i]) == 0) |
6552 { | |
6553 STRCPY(d, rtable[i]); | |
6554 break; | |
6555 } | |
6556 | |
6557 if (i < 0) /* no match in table */ | |
6558 { | |
6559 /* Replace "\S" with "/\\S", etc. Otherwise every tag is matched. | |
6560 * Also replace "\%^" and "\%(", they match every tag too. | |
6561 * Also "\zs", "\z1", etc. | |
6562 * Also "\@<", "\@=", "\@<=", etc. | |
6563 * And also "\_$" and "\_^". */ | |
6564 if (arg[0] == '\\' | |
6565 && ((arg[1] != NUL && arg[2] == NUL) | |
6566 || (vim_strchr((char_u *)"%_z@", arg[1]) != NULL | |
6567 && arg[2] != NUL))) | |
6568 { | |
6569 STRCPY(d, "/\\\\"); | |
6570 STRCPY(d + 3, arg + 1); | |
6571 /* Check for "/\\_$", should be "/\\_\$" */ | |
6572 if (d[3] == '_' && d[4] == '$') | |
6573 STRCPY(d + 4, "\\$"); | |
6574 } | |
6575 else | |
6576 { | |
3786 | 6577 /* Replace: |
6578 * "[:...:]" with "\[:...:]" | |
6579 * "[++...]" with "\[++...]" | |
5867 | 6580 * "\{" with "\\{" -- matching "} \}" |
3786 | 6581 */ |
6582 if ((arg[0] == '[' && (arg[1] == ':' | |
6583 || (arg[1] == '+' && arg[2] == '+'))) | |
6584 || (arg[0] == '\\' && arg[1] == '{')) | |
7 | 6585 *d++ = '\\'; |
6586 | |
8556
f4dca5239317
commit https://github.com/vim/vim/commit/00f9e0dbbd3472db217d56639fad9346b9eb3b82
Christian Brabandt <cb@256bit.org>
parents:
8544
diff
changeset
|
6587 /* |
f4dca5239317
commit https://github.com/vim/vim/commit/00f9e0dbbd3472db217d56639fad9346b9eb3b82
Christian Brabandt <cb@256bit.org>
parents:
8544
diff
changeset
|
6588 * 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
|
6589 */ |
f4dca5239317
commit https://github.com/vim/vim/commit/00f9e0dbbd3472db217d56639fad9346b9eb3b82
Christian Brabandt <cb@256bit.org>
parents:
8544
diff
changeset
|
6590 if (*arg == '(' && arg[1] == '\'') |
f4dca5239317
commit https://github.com/vim/vim/commit/00f9e0dbbd3472db217d56639fad9346b9eb3b82
Christian Brabandt <cb@256bit.org>
parents:
8544
diff
changeset
|
6591 arg++; |
7 | 6592 for (s = arg; *s; ++s) |
6593 { | |
6594 /* | |
6595 * Replace "|" with "bar" and '"' with "quote" to match the name of | |
6596 * the tags for these commands. | |
6597 * Replace "*" with ".*" and "?" with "." to match command line | |
6598 * completion. | |
6599 * Insert a backslash before '~', '$' and '.' to avoid their | |
6600 * special meaning. | |
6601 */ | |
6602 if (d - IObuff > IOSIZE - 10) /* getting too long!? */ | |
6603 break; | |
6604 switch (*s) | |
6605 { | |
6606 case '|': STRCPY(d, "bar"); | |
6607 d += 3; | |
6608 continue; | |
6609 case '"': STRCPY(d, "quote"); | |
6610 d += 5; | |
6611 continue; | |
6612 case '*': *d++ = '.'; | |
6613 break; | |
6614 case '?': *d++ = '.'; | |
6615 continue; | |
6616 case '$': | |
6617 case '.': | |
6618 case '~': *d++ = '\\'; | |
6619 break; | |
6620 } | |
6621 | |
6622 /* | |
6623 * Replace "^x" by "CTRL-X". Don't do this for "^_" to make | |
6624 * ":help i_^_CTRL-D" work. | |
6625 * Insert '-' before and after "CTRL-X" when applicable. | |
6626 */ | |
6627 if (*s < ' ' || (*s == '^' && s[1] && (ASCII_ISALPHA(s[1]) | |
6628 || vim_strchr((char_u *)"?@[\\]^", s[1]) != NULL))) | |
6629 { | |
5282
8c42772f0543
updated for version 7.4b.017
Bram Moolenaar <bram@vim.org>
parents:
5269
diff
changeset
|
6630 if (d > IObuff && d[-1] != '_' && d[-1] != '\\') |
8c42772f0543
updated for version 7.4b.017
Bram Moolenaar <bram@vim.org>
parents:
5269
diff
changeset
|
6631 *d++ = '_'; /* prepend a '_' to make x_CTRL-x */ |
7 | 6632 STRCPY(d, "CTRL-"); |
6633 d += 5; | |
6634 if (*s < ' ') | |
6635 { | |
6636 #ifdef EBCDIC | |
6637 *d++ = CtrlChar(*s); | |
6638 #else | |
6639 *d++ = *s + '@'; | |
6640 #endif | |
6641 if (d[-1] == '\\') | |
6642 *d++ = '\\'; /* double a backslash */ | |
6643 } | |
6644 else | |
6645 *d++ = *++s; | |
6646 if (s[1] != NUL && s[1] != '_') | |
6647 *d++ = '_'; /* append a '_' */ | |
6648 continue; | |
6649 } | |
6650 else if (*s == '^') /* "^" or "CTRL-^" or "^_" */ | |
6651 *d++ = '\\'; | |
6652 | |
6653 /* | |
6654 * Insert a backslash before a backslash after a slash, for search | |
6655 * pattern tags: "/\|" --> "/\\|". | |
6656 */ | |
6657 else if (s[0] == '\\' && s[1] != '\\' | |
6658 && *arg == '/' && s == arg + 1) | |
6659 *d++ = '\\'; | |
6660 | |
6661 /* "CTRL-\_" -> "CTRL-\\_" to avoid the special meaning of "\_" in | |
6662 * "CTRL-\_CTRL-N" */ | |
6663 if (STRNICMP(s, "CTRL-\\_", 7) == 0) | |
6664 { | |
6665 STRCPY(d, "CTRL-\\\\"); | |
6666 d += 7; | |
6667 s += 6; | |
6668 } | |
6669 | |
6670 *d++ = *s; | |
6671 | |
6672 /* | |
8883
b7de875169e6
commit https://github.com/vim/vim/commit/81edd171a9465cf99cede4fa4a7b7bca3d538b0f
Christian Brabandt <cb@256bit.org>
parents:
8879
diff
changeset
|
6673 * 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
|
6674 * 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
|
6675 */ |
b7de875169e6
commit https://github.com/vim/vim/commit/81edd171a9465cf99cede4fa4a7b7bca3d538b0f
Christian Brabandt <cb@256bit.org>
parents:
8879
diff
changeset
|
6676 if (*s == '(' && (s[1] == '{' || s[1] =='[')) |
b7de875169e6
commit https://github.com/vim/vim/commit/81edd171a9465cf99cede4fa4a7b7bca3d538b0f
Christian Brabandt <cb@256bit.org>
parents:
8879
diff
changeset
|
6677 break; |
b7de875169e6
commit https://github.com/vim/vim/commit/81edd171a9465cf99cede4fa4a7b7bca3d538b0f
Christian Brabandt <cb@256bit.org>
parents:
8879
diff
changeset
|
6678 |
b7de875169e6
commit https://github.com/vim/vim/commit/81edd171a9465cf99cede4fa4a7b7bca3d538b0f
Christian Brabandt <cb@256bit.org>
parents:
8879
diff
changeset
|
6679 /* |
7 | 6680 * If tag starts with ', toss everything after a second '. Fixes |
6681 * CTRL-] on 'option'. (would include the trailing '.'). | |
6682 */ | |
6683 if (*s == '\'' && s > arg && *arg == '\'') | |
6684 break; | |
9234
6e80397a592c
commit https://github.com/vim/vim/commit/28b942a064dd486cc241894b625ab72f5a5c6d1b
Christian Brabandt <cb@256bit.org>
parents:
8883
diff
changeset
|
6685 /* Also '{' and '}'. */ |
6e80397a592c
commit https://github.com/vim/vim/commit/28b942a064dd486cc241894b625ab72f5a5c6d1b
Christian Brabandt <cb@256bit.org>
parents:
8883
diff
changeset
|
6686 if (*s == '}' && s > arg && *arg == '{') |
6e80397a592c
commit https://github.com/vim/vim/commit/28b942a064dd486cc241894b625ab72f5a5c6d1b
Christian Brabandt <cb@256bit.org>
parents:
8883
diff
changeset
|
6687 break; |
7 | 6688 } |
6689 *d = NUL; | |
3480 | 6690 |
6691 if (*IObuff == '`') | |
6692 { | |
6693 if (d > IObuff + 2 && d[-1] == '`') | |
6694 { | |
6695 /* remove the backticks from `command` */ | |
6696 mch_memmove(IObuff, IObuff + 1, STRLEN(IObuff)); | |
6697 d[-2] = NUL; | |
6698 } | |
6699 else if (d > IObuff + 3 && d[-2] == '`' && d[-1] == ',') | |
6700 { | |
6701 /* remove the backticks and comma from `command`, */ | |
6702 mch_memmove(IObuff, IObuff + 1, STRLEN(IObuff)); | |
6703 d[-3] = NUL; | |
6704 } | |
6705 else if (d > IObuff + 4 && d[-3] == '`' | |
6706 && d[-2] == '\\' && d[-1] == '.') | |
6707 { | |
6708 /* remove the backticks and dot from `command`\. */ | |
6709 mch_memmove(IObuff, IObuff + 1, STRLEN(IObuff)); | |
6710 d[-4] = NUL; | |
6711 } | |
6712 } | |
7 | 6713 } |
6714 } | |
6715 | |
6716 *matches = (char_u **)""; | |
6717 *num_matches = 0; | |
6718 flags = TAG_HELP | TAG_REGEXP | TAG_NAMES | TAG_VERBOSE; | |
6719 if (keep_lang) | |
6720 flags |= TAG_KEEP_LANG; | |
1696 | 6721 if (find_tags(IObuff, num_matches, matches, flags, (int)MAXCOL, NULL) == OK |
7 | 6722 && *num_matches > 0) |
1696 | 6723 { |
7 | 6724 /* Sort the matches found on the heuristic number that is after the |
6725 * tag name. */ | |
6726 qsort((void *)*matches, (size_t)*num_matches, | |
6727 sizeof(char_u *), help_compare); | |
1696 | 6728 /* Delete more than TAG_MANY to reduce the size of the listing. */ |
6729 while (*num_matches > TAG_MANY) | |
6730 vim_free((*matches)[--*num_matches]); | |
6731 } | |
7 | 6732 return OK; |
6733 } | |
6734 | |
6735 /* | |
6365 | 6736 * Called when starting to edit a buffer for a help file. |
6737 */ | |
6738 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6739 prepare_help_buffer(void) |
6365 | 6740 { |
6741 char_u *p; | |
6742 | |
6743 curbuf->b_help = TRUE; | |
6744 #ifdef FEAT_QUICKFIX | |
6745 set_string_option_direct((char_u *)"buftype", -1, | |
6746 (char_u *)"help", OPT_FREE|OPT_LOCAL, 0); | |
6747 #endif | |
6748 | |
6749 /* | |
6750 * Always set these options after jumping to a help tag, because the | |
6751 * user may have an autocommand that gets in the way. | |
6752 * Accept all ASCII chars for keywords, except ' ', '*', '"', '|', and | |
6753 * latin1 word characters (for translated help files). | |
6754 * Only set it when needed, buf_init_chartab() is some work. | |
6755 */ | |
6756 p = | |
6757 #ifdef EBCDIC | |
6758 (char_u *)"65-255,^*,^|,^\""; | |
6759 #else | |
6760 (char_u *)"!-~,^*,^|,^\",192-255"; | |
6761 #endif | |
6762 if (STRCMP(curbuf->b_p_isk, p) != 0) | |
6763 { | |
6764 set_string_option_direct((char_u *)"isk", -1, p, OPT_FREE|OPT_LOCAL, 0); | |
6765 check_buf_options(curbuf); | |
6766 (void)buf_init_chartab(curbuf, FALSE); | |
6767 } | |
6768 | |
6415 | 6769 #ifdef FEAT_FOLDING |
6365 | 6770 /* Don't use the global foldmethod.*/ |
6771 set_string_option_direct((char_u *)"fdm", -1, (char_u *)"manual", | |
6772 OPT_FREE|OPT_LOCAL, 0); | |
6415 | 6773 #endif |
6365 | 6774 |
6775 curbuf->b_p_ts = 8; /* 'tabstop' is 8 */ | |
6776 curwin->w_p_list = FALSE; /* no list mode */ | |
6777 | |
6778 curbuf->b_p_ma = FALSE; /* not modifiable */ | |
6779 curbuf->b_p_bin = FALSE; /* reset 'bin' before reading file */ | |
6780 curwin->w_p_nu = 0; /* no line numbers */ | |
6781 curwin->w_p_rnu = 0; /* no relative line numbers */ | |
6782 RESET_BINDING(curwin); /* no scroll or cursor binding */ | |
6783 #ifdef FEAT_ARABIC | |
6784 curwin->w_p_arab = FALSE; /* no arabic mode */ | |
6785 #endif | |
6786 #ifdef FEAT_RIGHTLEFT | |
6787 curwin->w_p_rl = FALSE; /* help window is left-to-right */ | |
6788 #endif | |
6789 #ifdef FEAT_FOLDING | |
6790 curwin->w_p_fen = FALSE; /* No folding in the help window */ | |
6791 #endif | |
6792 #ifdef FEAT_DIFF | |
6793 curwin->w_p_diff = FALSE; /* No 'diff' */ | |
6794 #endif | |
6795 #ifdef FEAT_SPELL | |
6796 curwin->w_p_spell = FALSE; /* No spell checking */ | |
6797 #endif | |
6798 | |
6799 set_buflisted(FALSE); | |
6800 } | |
6801 | |
6802 /* | |
7 | 6803 * After reading a help file: May cleanup a help buffer when syntax |
6804 * highlighting is not used. | |
6805 */ | |
6806 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6807 fix_help_buffer(void) |
7 | 6808 { |
6809 linenr_T lnum; | |
6810 char_u *line; | |
6811 int in_example = FALSE; | |
6812 int len; | |
3141 | 6813 char_u *fname; |
7 | 6814 char_u *p; |
6815 char_u *rt; | |
6816 int mustfree; | |
6817 | |
6818 /* set filetype to "help". */ | |
6819 set_option_value((char_u *)"ft", 0L, (char_u *)"help", OPT_LOCAL); | |
6820 | |
6821 #ifdef FEAT_SYN_HL | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
6822 if (!syntax_present(curwin)) |
7 | 6823 #endif |
6824 { | |
6825 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) | |
6826 { | |
6827 line = ml_get_buf(curbuf, lnum, FALSE); | |
6828 len = (int)STRLEN(line); | |
6829 if (in_example && len > 0 && !vim_iswhite(line[0])) | |
6830 { | |
6831 /* End of example: non-white or '<' in first column. */ | |
6832 if (line[0] == '<') | |
6833 { | |
6834 /* blank-out a '<' in the first column */ | |
6835 line = ml_get_buf(curbuf, lnum, TRUE); | |
6836 line[0] = ' '; | |
6837 } | |
6838 in_example = FALSE; | |
6839 } | |
6840 if (!in_example && len > 0) | |
6841 { | |
6842 if (line[len - 1] == '>' && (len == 1 || line[len - 2] == ' ')) | |
6843 { | |
6844 /* blank-out a '>' in the last column (start of example) */ | |
6845 line = ml_get_buf(curbuf, lnum, TRUE); | |
6846 line[len - 1] = ' '; | |
6847 in_example = TRUE; | |
6848 } | |
6849 else if (line[len - 1] == '~') | |
6850 { | |
6851 /* blank-out a '~' at the end of line (header marker) */ | |
6852 line = ml_get_buf(curbuf, lnum, TRUE); | |
6853 line[len - 1] = ' '; | |
6854 } | |
6855 } | |
6856 } | |
6857 } | |
6858 | |
6859 /* | |
3141 | 6860 * In the "help.txt" and "help.abx" file, add the locally added help |
6861 * files. This uses the very first line in the help file. | |
7 | 6862 */ |
3141 | 6863 fname = gettail(curbuf->b_fname); |
6864 if (fnamecmp(fname, "help.txt") == 0 | |
6865 #ifdef FEAT_MULTI_LANG | |
6866 || (fnamencmp(fname, "help.", 5) == 0 | |
6867 && ASCII_ISALPHA(fname[5]) | |
6868 && ASCII_ISALPHA(fname[6]) | |
6869 && TOLOWER_ASC(fname[7]) == 'x' | |
6870 && fname[8] == NUL) | |
6871 #endif | |
6872 ) | |
7 | 6873 { |
6874 for (lnum = 1; lnum < curbuf->b_ml.ml_line_count; ++lnum) | |
6875 { | |
6876 line = ml_get_buf(curbuf, lnum, FALSE); | |
3141 | 6877 if (strstr((char *)line, "*local-additions*") == NULL) |
6878 continue; | |
6879 | |
6880 /* Go through all directories in 'runtimepath', skipping | |
6881 * $VIMRUNTIME. */ | |
6882 p = p_rtp; | |
6883 while (*p != NUL) | |
7 | 6884 { |
3141 | 6885 copy_option_part(&p, NameBuff, MAXPATHL, ","); |
6886 mustfree = FALSE; | |
6887 rt = vim_getenv((char_u *)"VIMRUNTIME", &mustfree); | |
6888 if (fullpathcmp(rt, NameBuff, FALSE) != FPC_SAME) | |
7 | 6889 { |
3141 | 6890 int fcount; |
6891 char_u **fnames; | |
6892 FILE *fd; | |
6893 char_u *s; | |
6894 int fi; | |
7 | 6895 #ifdef FEAT_MBYTE |
3141 | 6896 vimconv_T vc; |
6897 char_u *cp; | |
6898 #endif | |
6899 | |
6900 /* Find all "doc/ *.txt" files in this directory. */ | |
6901 add_pathsep(NameBuff); | |
6902 #ifdef FEAT_MULTI_LANG | |
6903 STRCAT(NameBuff, "doc/*.??[tx]"); | |
7 | 6904 #else |
3141 | 6905 STRCAT(NameBuff, "doc/*.txt"); |
6906 #endif | |
6907 if (gen_expand_wildcards(1, &NameBuff, &fcount, | |
6908 &fnames, EW_FILE|EW_SILENT) == OK | |
6909 && fcount > 0) | |
6910 { | |
6911 #ifdef FEAT_MULTI_LANG | |
6912 int i1; | |
6913 int i2; | |
6914 char_u *f1; | |
6915 char_u *f2; | |
6916 char_u *t1; | |
6917 char_u *e1; | |
6918 char_u *e2; | |
6919 | |
6920 /* If foo.abx is found use it instead of foo.txt in | |
6921 * the same directory. */ | |
6922 for (i1 = 0; i1 < fcount; ++i1) | |
6923 { | |
6924 for (i2 = 0; i2 < fcount; ++i2) | |
6925 { | |
6926 if (i1 == i2) | |
6927 continue; | |
6928 if (fnames[i1] == NULL || fnames[i2] == NULL) | |
6929 continue; | |
6930 f1 = fnames[i1]; | |
6931 f2 = fnames[i2]; | |
6932 t1 = gettail(f1); | |
6933 if (fnamencmp(f1, f2, t1 - f1) != 0) | |
6934 continue; | |
6935 e1 = vim_strrchr(t1, '.'); | |
6936 e2 = vim_strrchr(gettail(f2), '.'); | |
10299
7b2f95633e28
commit https://github.com/vim/vim/commit/7756e7465d627ff9cd01e59625484a8c302ef853
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
6937 if (e1 == NULL || e2 == NULL) |
3141 | 6938 continue; |
6939 if (fnamecmp(e1, ".txt") != 0 | |
6940 && fnamecmp(e1, fname + 4) != 0) | |
6941 { | |
6942 /* Not .txt and not .abx, remove it. */ | |
6943 vim_free(fnames[i1]); | |
6944 fnames[i1] = NULL; | |
6945 continue; | |
6946 } | |
6947 if (fnamencmp(f1, f2, e1 - f1) != 0) | |
6948 continue; | |
6949 if (fnamecmp(e1, ".txt") == 0 | |
6950 && fnamecmp(e2, fname + 4) == 0) | |
6951 { | |
6952 /* use .abx instead of .txt */ | |
6953 vim_free(fnames[i1]); | |
6954 fnames[i1] = NULL; | |
7 | 6955 } |
6956 } | |
6957 } | |
3141 | 6958 #endif |
6959 for (fi = 0; fi < fcount; ++fi) | |
6960 { | |
6961 if (fnames[fi] == NULL) | |
6962 continue; | |
6963 fd = mch_fopen((char *)fnames[fi], "r"); | |
6964 if (fd != NULL) | |
6965 { | |
6966 vim_fgets(IObuff, IOSIZE, fd); | |
6967 if (IObuff[0] == '*' | |
6968 && (s = vim_strchr(IObuff + 1, '*')) | |
6969 != NULL) | |
6970 { | |
6971 #ifdef FEAT_MBYTE | |
6972 int this_utf = MAYBE; | |
6973 #endif | |
6974 /* Change tag definition to a | |
6975 * reference and remove <CR>/<NL>. */ | |
6976 IObuff[0] = '|'; | |
6977 *s = '|'; | |
6978 while (*s != NUL) | |
6979 { | |
6980 if (*s == '\r' || *s == '\n') | |
6981 *s = NUL; | |
6982 #ifdef FEAT_MBYTE | |
6983 /* The text is utf-8 when a byte | |
6984 * above 127 is found and no | |
6985 * illegal byte sequence is found. | |
6986 */ | |
6987 if (*s >= 0x80 && this_utf != FALSE) | |
6988 { | |
6989 int l; | |
6990 | |
6991 this_utf = TRUE; | |
6992 l = utf_ptr2len(s); | |
6993 if (l == 1) | |
6994 this_utf = FALSE; | |
6995 s += l - 1; | |
6996 } | |
6997 #endif | |
6998 ++s; | |
6999 } | |
7000 #ifdef FEAT_MBYTE | |
7001 /* The help file is latin1 or utf-8; | |
7002 * conversion to the current | |
7003 * 'encoding' may be required. */ | |
7004 vc.vc_type = CONV_NONE; | |
7005 convert_setup(&vc, (char_u *)( | |
7006 this_utf == TRUE ? "utf-8" | |
7007 : "latin1"), p_enc); | |
7008 if (vc.vc_type == CONV_NONE) | |
7009 /* No conversion needed. */ | |
7010 cp = IObuff; | |
7011 else | |
7012 { | |
7013 /* Do the conversion. If it fails | |
7014 * use the unconverted text. */ | |
7015 cp = string_convert(&vc, IObuff, | |
7016 NULL); | |
7017 if (cp == NULL) | |
7018 cp = IObuff; | |
7019 } | |
7020 convert_setup(&vc, NULL, NULL); | |
7021 | |
7022 ml_append(lnum, cp, (colnr_T)0, FALSE); | |
7023 if (cp != IObuff) | |
7024 vim_free(cp); | |
7025 #else | |
7026 ml_append(lnum, IObuff, (colnr_T)0, | |
7027 FALSE); | |
7028 #endif | |
7029 ++lnum; | |
7030 } | |
7031 fclose(fd); | |
7032 } | |
7033 } | |
7034 FreeWild(fcount, fnames); | |
7 | 7035 } |
7036 } | |
3141 | 7037 if (mustfree) |
7038 vim_free(rt); | |
7 | 7039 } |
3141 | 7040 break; |
7 | 7041 } |
7042 } | |
7043 } | |
7044 | |
40 | 7045 /* |
7046 * ":exusage" | |
7047 */ | |
7048 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7049 ex_exusage(exarg_T *eap UNUSED) |
40 | 7050 { |
7051 do_cmdline_cmd((char_u *)"help ex-cmd-index"); | |
7052 } | |
7053 | |
7054 /* | |
7055 * ":viusage" | |
7056 */ | |
7057 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7058 ex_viusage(exarg_T *eap UNUSED) |
40 | 7059 { |
7060 do_cmdline_cmd((char_u *)"help normal-index"); | |
7061 } | |
7062 | |
7 | 7063 /* |
8522
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7064 * Generate tags in one help directory. |
7 | 7065 */ |
7066 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7067 helptags_one( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7068 char_u *dir, /* doc directory */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7069 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
|
7070 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
|
7071 int add_help_tags) /* add "help-tags" tag */ |
7 | 7072 { |
7073 FILE *fd_tags; | |
7074 FILE *fd; | |
7075 garray_T ga; | |
7076 int filecount; | |
7077 char_u **files; | |
7078 char_u *p1, *p2; | |
7079 int fi; | |
7080 char_u *s; | |
7081 int i; | |
7082 char_u *fname; | |
3957 | 7083 int dirlen; |
7 | 7084 # ifdef FEAT_MBYTE |
7085 int utf8 = MAYBE; | |
7086 int this_utf8; | |
7087 int firstline; | |
7088 int mix = FALSE; /* detected mixed encodings */ | |
7089 # endif | |
7090 | |
7091 /* | |
7092 * Find all *.txt files. | |
7093 */ | |
3978 | 7094 dirlen = (int)STRLEN(dir); |
7 | 7095 STRCPY(NameBuff, dir); |
3957 | 7096 STRCAT(NameBuff, "/**/*"); |
7 | 7097 STRCAT(NameBuff, ext); |
7098 if (gen_expand_wildcards(1, &NameBuff, &filecount, &files, | |
7099 EW_FILE|EW_SILENT) == FAIL | |
7100 || filecount == 0) | |
7101 { | |
7102 if (!got_int) | |
9953
9560a2eb7968
commit https://github.com/vim/vim/commit/5b30291785e6b9be1a607504c14bd03c601b59a6
Christian Brabandt <cb@256bit.org>
parents:
9947
diff
changeset
|
7103 EMSG2(_("E151: No match: %s"), NameBuff); |
7 | 7104 return; |
7105 } | |
7106 | |
7107 /* | |
7108 * Open the tags file for writing. | |
7109 * Do this before scanning through all the files. | |
7110 */ | |
7111 STRCPY(NameBuff, dir); | |
7112 add_pathsep(NameBuff); | |
7113 STRCAT(NameBuff, tagfname); | |
531 | 7114 fd_tags = mch_fopen((char *)NameBuff, "w"); |
7 | 7115 if (fd_tags == NULL) |
7116 { | |
7117 EMSG2(_("E152: Cannot open %s for writing"), NameBuff); | |
7118 FreeWild(filecount, files); | |
7119 return; | |
7120 } | |
7121 | |
7122 /* | |
1502 | 7123 * If using the "++t" argument or generating tags for "$VIMRUNTIME/doc" |
7124 * add the "help-tags" tag. | |
7 | 7125 */ |
7126 ga_init2(&ga, (int)sizeof(char_u *), 100); | |
1502 | 7127 if (add_help_tags || fullpathcmp((char_u *)"$VIMRUNTIME/doc", |
7128 dir, FALSE) == FPC_SAME) | |
7 | 7129 { |
7130 if (ga_grow(&ga, 1) == FAIL) | |
7131 got_int = TRUE; | |
7132 else | |
7133 { | |
835 | 7134 s = alloc(18 + (unsigned)STRLEN(tagfname)); |
7 | 7135 if (s == NULL) |
7136 got_int = TRUE; | |
7137 else | |
7138 { | |
7139 sprintf((char *)s, "help-tags\t%s\t1\n", tagfname); | |
7140 ((char_u **)ga.ga_data)[ga.ga_len] = s; | |
7141 ++ga.ga_len; | |
7142 } | |
7143 } | |
7144 } | |
7145 | |
7146 /* | |
7147 * Go over all the files and extract the tags. | |
7148 */ | |
7149 for (fi = 0; fi < filecount && !got_int; ++fi) | |
7150 { | |
531 | 7151 fd = mch_fopen((char *)files[fi], "r"); |
7 | 7152 if (fd == NULL) |
7153 { | |
7154 EMSG2(_("E153: Unable to open %s for reading"), files[fi]); | |
7155 continue; | |
7156 } | |
3957 | 7157 fname = files[fi] + dirlen + 1; |
7 | 7158 |
7159 # ifdef FEAT_MBYTE | |
7160 firstline = TRUE; | |
7161 # endif | |
7162 while (!vim_fgets(IObuff, IOSIZE, fd) && !got_int) | |
7163 { | |
7164 # ifdef FEAT_MBYTE | |
7165 if (firstline) | |
7166 { | |
7167 /* Detect utf-8 file by a non-ASCII char in the first line. */ | |
7168 this_utf8 = MAYBE; | |
7169 for (s = IObuff; *s != NUL; ++s) | |
7170 if (*s >= 0x80) | |
7171 { | |
7172 int l; | |
7173 | |
7174 this_utf8 = TRUE; | |
474 | 7175 l = utf_ptr2len(s); |
7 | 7176 if (l == 1) |
7177 { | |
7178 /* Illegal UTF-8 byte sequence. */ | |
7179 this_utf8 = FALSE; | |
7180 break; | |
7181 } | |
7182 s += l - 1; | |
7183 } | |
7184 if (this_utf8 == MAYBE) /* only ASCII characters found */ | |
7185 this_utf8 = FALSE; | |
7186 if (utf8 == MAYBE) /* first file */ | |
7187 utf8 = this_utf8; | |
7188 else if (utf8 != this_utf8) | |
7189 { | |
7190 EMSG2(_("E670: Mix of help file encodings within a language: %s"), files[fi]); | |
7191 mix = !got_int; | |
7192 got_int = TRUE; | |
7193 } | |
7194 firstline = FALSE; | |
7195 } | |
7196 # endif | |
7197 p1 = vim_strchr(IObuff, '*'); /* find first '*' */ | |
7198 while (p1 != NULL) | |
7199 { | |
3514 | 7200 /* Use vim_strbyte() instead of vim_strchr() so that when |
7201 * 'encoding' is dbcs it still works, don't find '*' in the | |
7202 * second byte. */ | |
7203 p2 = vim_strbyte(p1 + 1, '*'); /* find second '*' */ | |
7 | 7204 if (p2 != NULL && p2 > p1 + 1) /* skip "*" and "**" */ |
7205 { | |
7206 for (s = p1 + 1; s < p2; ++s) | |
7207 if (*s == ' ' || *s == '\t' || *s == '|') | |
7208 break; | |
7209 | |
7210 /* | |
7211 * Only accept a *tag* when it consists of valid | |
7212 * characters, there is white space before it and is | |
7213 * followed by a white character or end-of-line. | |
7214 */ | |
7215 if (s == p2 | |
7216 && (p1 == IObuff || p1[-1] == ' ' || p1[-1] == '\t') | |
7217 && (vim_strchr((char_u *)" \t\n\r", s[1]) != NULL | |
7218 || s[1] == '\0')) | |
7219 { | |
7220 *p2 = '\0'; | |
7221 ++p1; | |
7222 if (ga_grow(&ga, 1) == FAIL) | |
7223 { | |
7224 got_int = TRUE; | |
7225 break; | |
7226 } | |
7227 s = alloc((unsigned)(p2 - p1 + STRLEN(fname) + 2)); | |
7228 if (s == NULL) | |
7229 { | |
7230 got_int = TRUE; | |
7231 break; | |
7232 } | |
7233 ((char_u **)ga.ga_data)[ga.ga_len] = s; | |
7234 ++ga.ga_len; | |
7235 sprintf((char *)s, "%s\t%s", p1, fname); | |
7236 | |
7237 /* find next '*' */ | |
7238 p2 = vim_strchr(p2 + 1, '*'); | |
7239 } | |
7240 } | |
7241 p1 = p2; | |
7242 } | |
7243 line_breakcheck(); | |
7244 } | |
7245 | |
7246 fclose(fd); | |
7247 } | |
7248 | |
7249 FreeWild(filecount, files); | |
7250 | |
7251 if (!got_int) | |
7252 { | |
7253 /* | |
7254 * Sort the tags. | |
7255 */ | |
7009 | 7256 if (ga.ga_data != NULL) |
7257 sort_strings((char_u **)ga.ga_data, ga.ga_len); | |
7 | 7258 |
7259 /* | |
7260 * Check for duplicates. | |
7261 */ | |
7262 for (i = 1; i < ga.ga_len; ++i) | |
7263 { | |
7264 p1 = ((char_u **)ga.ga_data)[i - 1]; | |
7265 p2 = ((char_u **)ga.ga_data)[i]; | |
7266 while (*p1 == *p2) | |
7267 { | |
7268 if (*p2 == '\t') | |
7269 { | |
7270 *p2 = NUL; | |
274 | 7271 vim_snprintf((char *)NameBuff, MAXPATHL, |
7 | 7272 _("E154: Duplicate tag \"%s\" in file %s/%s"), |
7273 ((char_u **)ga.ga_data)[i], dir, p2 + 1); | |
7274 EMSG(NameBuff); | |
7275 *p2 = '\t'; | |
7276 break; | |
7277 } | |
7278 ++p1; | |
7279 ++p2; | |
7280 } | |
7281 } | |
7282 | |
7283 # ifdef FEAT_MBYTE | |
7284 if (utf8 == TRUE) | |
7285 fprintf(fd_tags, "!_TAG_FILE_ENCODING\tutf-8\t//\n"); | |
7286 # endif | |
7287 | |
7288 /* | |
7289 * Write the tags into the file. | |
7290 */ | |
7291 for (i = 0; i < ga.ga_len; ++i) | |
7292 { | |
7293 s = ((char_u **)ga.ga_data)[i]; | |
1325 | 7294 if (STRNCMP(s, "help-tags\t", 10) == 0) |
7 | 7295 /* help-tags entry was added in formatted form */ |
1325 | 7296 fputs((char *)s, fd_tags); |
7 | 7297 else |
7298 { | |
7299 fprintf(fd_tags, "%s\t/*", s); | |
7300 for (p1 = s; *p1 != '\t'; ++p1) | |
7301 { | |
7302 /* insert backslash before '\\' and '/' */ | |
7303 if (*p1 == '\\' || *p1 == '/') | |
7304 putc('\\', fd_tags); | |
7305 putc(*p1, fd_tags); | |
7306 } | |
7307 fprintf(fd_tags, "*\n"); | |
7308 } | |
7309 } | |
7310 } | |
7311 #ifdef FEAT_MBYTE | |
7312 if (mix) | |
7313 got_int = FALSE; /* continue with other languages */ | |
7314 #endif | |
7315 | |
7316 for (i = 0; i < ga.ga_len; ++i) | |
7317 vim_free(((char_u **)ga.ga_data)[i]); | |
7318 ga_clear(&ga); | |
7319 fclose(fd_tags); /* there is no check for an error... */ | |
7320 } | |
7321 | |
8522
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7322 /* |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7323 * 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
|
7324 */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7325 static void |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7326 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
|
7327 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7328 #ifdef FEAT_MULTI_LANG |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7329 int len; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7330 int i, j; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7331 garray_T ga; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7332 char_u lang[2]; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7333 char_u ext[5]; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7334 char_u fname[8]; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7335 int filecount; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7336 char_u **files; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7337 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7338 /* 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
|
7339 STRCPY(NameBuff, dirname); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7340 add_pathsep(NameBuff); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7341 STRCAT(NameBuff, "**"); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7342 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
|
7343 EW_FILE|EW_SILENT) == FAIL |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7344 || filecount == 0) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7345 { |
9953
9560a2eb7968
commit https://github.com/vim/vim/commit/5b30291785e6b9be1a607504c14bd03c601b59a6
Christian Brabandt <cb@256bit.org>
parents:
9947
diff
changeset
|
7346 EMSG2(_("E151: No match: %s"), NameBuff); |
8522
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7347 return; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7348 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7349 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7350 /* 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
|
7351 * present. */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7352 ga_init2(&ga, 1, 10); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7353 for (i = 0; i < filecount; ++i) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7354 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7355 len = (int)STRLEN(files[i]); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7356 if (len > 4) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7357 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7358 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
|
7359 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7360 /* ".txt" -> language "en" */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7361 lang[0] = 'e'; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7362 lang[1] = 'n'; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7363 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7364 else if (files[i][len - 4] == '.' |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7365 && ASCII_ISALPHA(files[i][len - 3]) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7366 && ASCII_ISALPHA(files[i][len - 2]) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7367 && 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
|
7368 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7369 /* ".abx" -> language "ab" */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7370 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
|
7371 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
|
7372 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7373 else |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7374 continue; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7375 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7376 /* Did we find this language already? */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7377 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
|
7378 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
|
7379 break; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7380 if (j == ga.ga_len) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7381 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7382 /* New language, add it. */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7383 if (ga_grow(&ga, 2) == FAIL) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7384 break; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7385 ((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
|
7386 ((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
|
7387 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7388 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7389 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7390 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7391 /* |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7392 * 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
|
7393 */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7394 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
|
7395 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7396 STRCPY(fname, "tags-xx"); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7397 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
|
7398 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
|
7399 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
|
7400 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7401 /* 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
|
7402 fname[4] = NUL; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7403 STRCPY(ext, ".txt"); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7404 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7405 else |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7406 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7407 /* 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
|
7408 STRCPY(ext, ".xxx"); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7409 ext[1] = fname[5]; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7410 ext[2] = fname[6]; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7411 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7412 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
|
7413 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7414 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7415 ga_clear(&ga); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7416 FreeWild(filecount, files); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7417 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7418 #else |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7419 /* 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
|
7420 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
|
7421 #endif |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7422 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7423 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7424 static void |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7425 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
|
7426 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7427 do_helptags(fname, *(int *)cookie); |
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 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7430 /* |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7431 * ":helptags" |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7432 */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7433 void |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7434 ex_helptags(exarg_T *eap) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7435 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7436 expand_T xpc; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7437 char_u *dirname; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7438 int add_help_tags = FALSE; |
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 /* Check for ":helptags ++t {dir}". */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7441 if (STRNCMP(eap->arg, "++t", 3) == 0 && vim_iswhite(eap->arg[3])) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7442 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7443 add_help_tags = TRUE; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7444 eap->arg = skipwhite(eap->arg + 3); |
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 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7447 if (STRCMP(eap->arg, "ALL") == 0) |
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 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
|
7450 helptags_cb, &add_help_tags); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7451 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7452 else |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7453 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7454 ExpandInit(&xpc); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7455 xpc.xp_context = EXPAND_DIRECTORIES; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7456 dirname = ExpandOne(&xpc, eap->arg, NULL, |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7457 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
|
7458 if (dirname == NULL || !mch_isdir(dirname)) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7459 EMSG2(_("E150: Not a directory: %s"), eap->arg); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7460 else |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7461 do_helptags(dirname, add_help_tags); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7462 vim_free(dirname); |
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 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7465 |
7 | 7466 #if defined(FEAT_SIGNS) || defined(PROTO) |
7467 | |
7468 /* | |
7469 * Struct to hold the sign properties. | |
7470 */ | |
7471 typedef struct sign sign_T; | |
7472 | |
7473 struct sign | |
7474 { | |
7475 sign_T *sn_next; /* next sign in list */ | |
2606 | 7476 int sn_typenr; /* type number of sign */ |
7 | 7477 char_u *sn_name; /* name of sign */ |
7478 char_u *sn_icon; /* name of pixmap */ | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7479 # ifdef FEAT_SIGN_ICONS |
7 | 7480 void *sn_image; /* icon image */ |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7481 # endif |
7 | 7482 char_u *sn_text; /* text used instead of pixmap */ |
7483 int sn_line_hl; /* highlight ID for line */ | |
7484 int sn_text_hl; /* highlight ID for text */ | |
7485 }; | |
7486 | |
7487 static sign_T *first_sign = NULL; | |
2605 | 7488 static int next_sign_typenr = 1; |
7 | 7489 |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
7490 static int sign_cmd_idx(char_u *begin_cmd, char_u *end_cmd); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
7491 static void sign_list_defined(sign_T *sp); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
7492 static void sign_undefine(sign_T *sp, sign_T *sp_prev); |
7 | 7493 |
1868 | 7494 static char *cmds[] = { |
7495 "define", | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7496 # define SIGNCMD_DEFINE 0 |
1868 | 7497 "undefine", |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7498 # define SIGNCMD_UNDEFINE 1 |
1868 | 7499 "list", |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7500 # define SIGNCMD_LIST 2 |
1868 | 7501 "place", |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7502 # define SIGNCMD_PLACE 3 |
1868 | 7503 "unplace", |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7504 # define SIGNCMD_UNPLACE 4 |
1868 | 7505 "jump", |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7506 # define SIGNCMD_JUMP 5 |
1868 | 7507 NULL |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7508 # define SIGNCMD_LAST 6 |
1868 | 7509 }; |
7510 | |
7511 /* | |
7512 * Find index of a ":sign" subcmd from its name. | |
7513 * "*end_cmd" must be writable. | |
7514 */ | |
7515 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7516 sign_cmd_idx( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7517 char_u *begin_cmd, /* begin of sign subcmd */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7518 char_u *end_cmd) /* just after sign subcmd */ |
1868 | 7519 { |
7520 int idx; | |
7521 char save = *end_cmd; | |
7522 | |
7523 *end_cmd = NUL; | |
7524 for (idx = 0; ; ++idx) | |
7525 if (cmds[idx] == NULL || STRCMP(begin_cmd, cmds[idx]) == 0) | |
7526 break; | |
7527 *end_cmd = save; | |
7528 return idx; | |
7529 } | |
7530 | |
7 | 7531 /* |
7532 * ":sign" command | |
7533 */ | |
7534 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7535 ex_sign(exarg_T *eap) |
7 | 7536 { |
7537 char_u *arg = eap->arg; | |
7538 char_u *p; | |
7539 int idx; | |
7540 sign_T *sp; | |
7541 sign_T *sp_prev; | |
7542 buf_T *buf; | |
7543 | |
7544 /* Parse the subcommand. */ | |
7545 p = skiptowhite(arg); | |
1868 | 7546 idx = sign_cmd_idx(arg, p); |
7547 if (idx == SIGNCMD_LAST) | |
7548 { | |
7549 EMSG2(_("E160: Unknown sign command: %s"), arg); | |
7550 return; | |
7 | 7551 } |
7552 arg = skipwhite(p); | |
7553 | |
7554 if (idx <= SIGNCMD_LIST) | |
7555 { | |
7556 /* | |
7557 * Define, undefine or list signs. | |
7558 */ | |
7559 if (idx == SIGNCMD_LIST && *arg == NUL) | |
7560 { | |
7561 /* ":sign list": list all defined signs */ | |
3411 | 7562 for (sp = first_sign; sp != NULL && !got_int; sp = sp->sn_next) |
7 | 7563 sign_list_defined(sp); |
7564 } | |
7565 else if (*arg == NUL) | |
7566 EMSG(_("E156: Missing sign name")); | |
7567 else | |
7568 { | |
2605 | 7569 /* Isolate the sign name. If it's a number skip leading zeroes, |
7570 * so that "099" and "99" are the same sign. But keep "0". */ | |
7 | 7571 p = skiptowhite(arg); |
7572 if (*p != NUL) | |
7573 *p++ = NUL; | |
2605 | 7574 while (arg[0] == '0' && arg[1] != NUL) |
7575 ++arg; | |
7576 | |
7 | 7577 sp_prev = NULL; |
7578 for (sp = first_sign; sp != NULL; sp = sp->sn_next) | |
7579 { | |
7580 if (STRCMP(sp->sn_name, arg) == 0) | |
7581 break; | |
7582 sp_prev = sp; | |
7583 } | |
7584 if (idx == SIGNCMD_DEFINE) | |
7585 { | |
7586 /* ":sign define {name} ...": define a sign */ | |
7587 if (sp == NULL) | |
7588 { | |
2605 | 7589 sign_T *lp; |
7590 int start = next_sign_typenr; | |
7591 | |
7 | 7592 /* Allocate a new sign. */ |
7593 sp = (sign_T *)alloc_clear((unsigned)sizeof(sign_T)); | |
7594 if (sp == NULL) | |
7595 return; | |
7596 | |
2605 | 7597 /* Check that next_sign_typenr is not already being used. |
7598 * This only happens after wrapping around. Hopefully | |
7599 * another one got deleted and we can use its number. */ | |
7600 for (lp = first_sign; lp != NULL; ) | |
7 | 7601 { |
2605 | 7602 if (lp->sn_typenr == next_sign_typenr) |
7 | 7603 { |
2605 | 7604 ++next_sign_typenr; |
7605 if (next_sign_typenr == MAX_TYPENR) | |
7606 next_sign_typenr = 1; | |
7607 if (next_sign_typenr == start) | |
7 | 7608 { |
2605 | 7609 vim_free(sp); |
7610 EMSG(_("E612: Too many signs defined")); | |
7611 return; | |
7 | 7612 } |
2605 | 7613 lp = first_sign; /* start all over */ |
7614 continue; | |
7 | 7615 } |
2605 | 7616 lp = lp->sn_next; |
7617 } | |
7618 | |
7619 sp->sn_typenr = next_sign_typenr; | |
7620 if (++next_sign_typenr == MAX_TYPENR) | |
7621 next_sign_typenr = 1; /* wrap around */ | |
7622 | |
7623 sp->sn_name = vim_strsave(arg); | |
7624 if (sp->sn_name == NULL) /* out of memory */ | |
7625 { | |
7626 vim_free(sp); | |
7627 return; | |
7 | 7628 } |
2601 | 7629 |
7630 /* add the new sign to the list of signs */ | |
7631 if (sp_prev == NULL) | |
7632 first_sign = sp; | |
7633 else | |
7634 sp_prev->sn_next = sp; | |
7 | 7635 } |
7636 | |
7637 /* set values for a defined sign. */ | |
7638 for (;;) | |
7639 { | |
7640 arg = skipwhite(p); | |
7641 if (*arg == NUL) | |
7642 break; | |
7643 p = skiptowhite_esc(arg); | |
7644 if (STRNCMP(arg, "icon=", 5) == 0) | |
7645 { | |
7646 arg += 5; | |
7647 vim_free(sp->sn_icon); | |
7648 sp->sn_icon = vim_strnsave(arg, (int)(p - arg)); | |
7649 backslash_halve(sp->sn_icon); | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7650 # ifdef FEAT_SIGN_ICONS |
7 | 7651 if (gui.in_use) |
7652 { | |
7653 out_flush(); | |
7654 if (sp->sn_image != NULL) | |
7655 gui_mch_destroy_sign(sp->sn_image); | |
7656 sp->sn_image = gui_mch_register_sign(sp->sn_icon); | |
7657 } | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7658 # endif |
7 | 7659 } |
7660 else if (STRNCMP(arg, "text=", 5) == 0) | |
7661 { | |
7662 char_u *s; | |
7663 int cells; | |
7664 int len; | |
7665 | |
7666 arg += 5; | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7667 # ifdef FEAT_MBYTE |
7 | 7668 /* Count cells and check for non-printable chars */ |
7669 if (has_mbyte) | |
7670 { | |
7671 cells = 0; | |
474 | 7672 for (s = arg; s < p; s += (*mb_ptr2len)(s)) |
7 | 7673 { |
7674 if (!vim_isprintc((*mb_ptr2char)(s))) | |
7675 break; | |
7676 cells += (*mb_ptr2cells)(s); | |
7677 } | |
7678 } | |
7679 else | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7680 # endif |
7 | 7681 { |
7682 for (s = arg; s < p; ++s) | |
7683 if (!vim_isprintc(*s)) | |
7684 break; | |
835 | 7685 cells = (int)(s - arg); |
7 | 7686 } |
7687 /* Currently must be one or two display cells */ | |
7688 if (s != p || cells < 1 || cells > 2) | |
7689 { | |
7690 *p = NUL; | |
7691 EMSG2(_("E239: Invalid sign text: %s"), arg); | |
7692 return; | |
7693 } | |
7694 | |
7695 vim_free(sp->sn_text); | |
7696 /* Allocate one byte more if we need to pad up | |
7697 * with a space. */ | |
835 | 7698 len = (int)(p - arg + ((cells == 1) ? 1 : 0)); |
7 | 7699 sp->sn_text = vim_strnsave(arg, len); |
7700 | |
7701 if (sp->sn_text != NULL && cells == 1) | |
7702 STRCPY(sp->sn_text + len - 1, " "); | |
7703 } | |
7704 else if (STRNCMP(arg, "linehl=", 7) == 0) | |
7705 { | |
7706 arg += 7; | |
7707 sp->sn_line_hl = syn_check_group(arg, (int)(p - arg)); | |
7708 } | |
7709 else if (STRNCMP(arg, "texthl=", 7) == 0) | |
7710 { | |
7711 arg += 7; | |
7712 sp->sn_text_hl = syn_check_group(arg, (int)(p - arg)); | |
7713 } | |
7714 else | |
7715 { | |
7716 EMSG2(_(e_invarg2), arg); | |
7717 return; | |
7718 } | |
7719 } | |
7720 } | |
7721 else if (sp == NULL) | |
7722 EMSG2(_("E155: Unknown sign: %s"), arg); | |
7723 else if (idx == SIGNCMD_LIST) | |
7724 /* ":sign list {name}" */ | |
7725 sign_list_defined(sp); | |
7726 else | |
7727 /* ":sign undefine {name}" */ | |
1828 | 7728 sign_undefine(sp, sp_prev); |
7 | 7729 } |
7730 } | |
7731 else | |
7732 { | |
7733 int id = -1; | |
7734 linenr_T lnum = -1; | |
7735 char_u *sign_name = NULL; | |
7736 char_u *arg1; | |
7737 | |
7738 if (*arg == NUL) | |
7739 { | |
7740 if (idx == SIGNCMD_PLACE) | |
7741 { | |
7742 /* ":sign place": list placed signs in all buffers */ | |
7743 sign_list_placed(NULL); | |
7744 } | |
7745 else if (idx == SIGNCMD_UNPLACE) | |
7746 { | |
7747 /* ":sign unplace": remove placed sign at cursor */ | |
7748 id = buf_findsign_id(curwin->w_buffer, curwin->w_cursor.lnum); | |
7749 if (id > 0) | |
7750 { | |
7751 buf_delsign(curwin->w_buffer, id); | |
7752 update_debug_sign(curwin->w_buffer, curwin->w_cursor.lnum); | |
7753 } | |
7754 else | |
7755 EMSG(_("E159: Missing sign number")); | |
7756 } | |
7757 else | |
7758 EMSG(_(e_argreq)); | |
7759 return; | |
7760 } | |
7761 | |
7762 if (idx == SIGNCMD_UNPLACE && arg[0] == '*' && arg[1] == NUL) | |
7763 { | |
7764 /* ":sign unplace *": remove all placed signs */ | |
7765 buf_delete_all_signs(); | |
7766 return; | |
7767 } | |
7768 | |
7769 /* first arg could be placed sign id */ | |
7770 arg1 = arg; | |
7771 if (VIM_ISDIGIT(*arg)) | |
7772 { | |
7773 id = getdigits(&arg); | |
7774 if (!vim_iswhite(*arg) && *arg != NUL) | |
7775 { | |
7776 id = -1; | |
7777 arg = arg1; | |
7778 } | |
7779 else | |
7780 { | |
7781 arg = skipwhite(arg); | |
7782 if (idx == SIGNCMD_UNPLACE && *arg == NUL) | |
7783 { | |
7784 /* ":sign unplace {id}": remove placed sign by number */ | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
7785 FOR_ALL_BUFFERS(buf) |
7 | 7786 if ((lnum = buf_delsign(buf, id)) != 0) |
7787 update_debug_sign(buf, lnum); | |
7788 return; | |
7789 } | |
7790 } | |
7791 } | |
7792 | |
7793 /* | |
7794 * Check for line={lnum} name={name} and file={fname} or buffer={nr}. | |
7795 * Leave "arg" pointing to {fname}. | |
7796 */ | |
7797 for (;;) | |
7798 { | |
7799 if (STRNCMP(arg, "line=", 5) == 0) | |
7800 { | |
7801 arg += 5; | |
7802 lnum = atoi((char *)arg); | |
7803 arg = skiptowhite(arg); | |
7804 } | |
3672 | 7805 else if (STRNCMP(arg, "*", 1) == 0 && idx == SIGNCMD_UNPLACE) |
7806 { | |
7807 if (id != -1) | |
7808 { | |
7809 EMSG(_(e_invarg)); | |
7810 return; | |
7811 } | |
7812 id = -2; | |
7813 arg = skiptowhite(arg + 1); | |
7814 } | |
7 | 7815 else if (STRNCMP(arg, "name=", 5) == 0) |
7816 { | |
7817 arg += 5; | |
7818 sign_name = arg; | |
7819 arg = skiptowhite(arg); | |
7820 if (*arg != NUL) | |
7821 *arg++ = NUL; | |
2605 | 7822 while (sign_name[0] == '0' && sign_name[1] != NUL) |
7823 ++sign_name; | |
7 | 7824 } |
7825 else if (STRNCMP(arg, "file=", 5) == 0) | |
7826 { | |
7827 arg += 5; | |
7828 buf = buflist_findname(arg); | |
7829 break; | |
7830 } | |
7831 else if (STRNCMP(arg, "buffer=", 7) == 0) | |
7832 { | |
7833 arg += 7; | |
7834 buf = buflist_findnr((int)getdigits(&arg)); | |
7835 if (*skipwhite(arg) != NUL) | |
7836 EMSG(_(e_trailing)); | |
7837 break; | |
7838 } | |
7839 else | |
7840 { | |
7841 EMSG(_(e_invarg)); | |
7842 return; | |
7843 } | |
7844 arg = skipwhite(arg); | |
7845 } | |
7846 | |
7847 if (buf == NULL) | |
7848 { | |
7849 EMSG2(_("E158: Invalid buffer name: %s"), arg); | |
7850 } | |
3672 | 7851 else if (id <= 0 && !(idx == SIGNCMD_UNPLACE && id == -2)) |
7 | 7852 { |
7853 if (lnum >= 0 || sign_name != NULL) | |
7854 EMSG(_(e_invarg)); | |
7855 else | |
7856 /* ":sign place file={fname}": list placed signs in one file */ | |
7857 sign_list_placed(buf); | |
7858 } | |
7859 else if (idx == SIGNCMD_JUMP) | |
7860 { | |
7861 /* ":sign jump {id} file={fname}" */ | |
7862 if (lnum >= 0 || sign_name != NULL) | |
7863 EMSG(_(e_invarg)); | |
7864 else if ((lnum = buf_findsign(buf, id)) > 0) | |
7865 { /* goto a sign ... */ | |
7866 if (buf_jump_open_win(buf) != NULL) | |
7867 { /* ... in a current window */ | |
7868 curwin->w_cursor.lnum = lnum; | |
7869 check_cursor_lnum(); | |
7870 beginline(BL_WHITE); | |
7871 } | |
7872 else | |
7873 { /* ... not currently in a window */ | |
7874 char_u *cmd; | |
7875 | |
9902
5a667a3a3743
commit https://github.com/vim/vim/commit/bfd096d02087a10e8e2f4bdfb74e0435506fa8bb
Christian Brabandt <cb@256bit.org>
parents:
9890
diff
changeset
|
7876 if (buf->b_fname == NULL) |
5a667a3a3743
commit https://github.com/vim/vim/commit/bfd096d02087a10e8e2f4bdfb74e0435506fa8bb
Christian Brabandt <cb@256bit.org>
parents:
9890
diff
changeset
|
7877 { |
5a667a3a3743
commit https://github.com/vim/vim/commit/bfd096d02087a10e8e2f4bdfb74e0435506fa8bb
Christian Brabandt <cb@256bit.org>
parents:
9890
diff
changeset
|
7878 EMSG(_("E934: Cannot jump to a buffer that does not have a name")); |
5a667a3a3743
commit https://github.com/vim/vim/commit/bfd096d02087a10e8e2f4bdfb74e0435506fa8bb
Christian Brabandt <cb@256bit.org>
parents:
9890
diff
changeset
|
7879 return; |
5a667a3a3743
commit https://github.com/vim/vim/commit/bfd096d02087a10e8e2f4bdfb74e0435506fa8bb
Christian Brabandt <cb@256bit.org>
parents:
9890
diff
changeset
|
7880 } |
7 | 7881 cmd = alloc((unsigned)STRLEN(buf->b_fname) + 25); |
7882 if (cmd == NULL) | |
7883 return; | |
7884 sprintf((char *)cmd, "e +%ld %s", (long)lnum, buf->b_fname); | |
7885 do_cmdline_cmd(cmd); | |
7886 vim_free(cmd); | |
7887 } | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7888 # ifdef FEAT_FOLDING |
7 | 7889 foldOpenCursor(); |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7890 # endif |
7 | 7891 } |
7892 else | |
7893 EMSGN(_("E157: Invalid sign ID: %ld"), id); | |
7894 } | |
7895 else if (idx == SIGNCMD_UNPLACE) | |
7896 { | |
7897 if (lnum >= 0 || sign_name != NULL) | |
7898 EMSG(_(e_invarg)); | |
3672 | 7899 else if (id == -2) |
7900 { | |
7901 /* ":sign unplace * file={fname}" */ | |
7902 redraw_buf_later(buf, NOT_VALID); | |
7903 buf_delete_signs(buf); | |
7904 } | |
7 | 7905 else |
7906 { | |
3672 | 7907 /* ":sign unplace {id} file={fname}" */ |
7 | 7908 lnum = buf_delsign(buf, id); |
7909 update_debug_sign(buf, lnum); | |
7910 } | |
7911 } | |
7912 /* idx == SIGNCMD_PLACE */ | |
7913 else if (sign_name != NULL) | |
7914 { | |
7915 for (sp = first_sign; sp != NULL; sp = sp->sn_next) | |
7916 if (STRCMP(sp->sn_name, sign_name) == 0) | |
7917 break; | |
7918 if (sp == NULL) | |
7919 { | |
7920 EMSG2(_("E155: Unknown sign: %s"), sign_name); | |
7921 return; | |
7922 } | |
7923 if (lnum > 0) | |
7924 /* ":sign place {id} line={lnum} name={name} file={fname}": | |
7925 * place a sign */ | |
7926 buf_addsign(buf, id, lnum, sp->sn_typenr); | |
7927 else | |
7928 /* ":sign place {id} file={fname}": change sign type */ | |
7929 lnum = buf_change_sign_type(buf, id, sp->sn_typenr); | |
5865 | 7930 if (lnum > 0) |
7931 update_debug_sign(buf, lnum); | |
7932 else | |
7933 EMSG2(_("E885: Not possible to change sign %s"), sign_name); | |
7 | 7934 } |
7935 else | |
7936 EMSG(_(e_invarg)); | |
7937 } | |
7938 } | |
7939 | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7940 # if defined(FEAT_SIGN_ICONS) || defined(PROTO) |
7 | 7941 /* |
7942 * Allocate the icons. Called when the GUI has started. Allows defining | |
7943 * signs before it starts. | |
7944 */ | |
7945 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7946 sign_gui_started(void) |
7 | 7947 { |
7948 sign_T *sp; | |
7949 | |
7950 for (sp = first_sign; sp != NULL; sp = sp->sn_next) | |
7951 if (sp->sn_icon != NULL) | |
7952 sp->sn_image = gui_mch_register_sign(sp->sn_icon); | |
7953 } | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7954 # endif |
7 | 7955 |
7956 /* | |
7957 * List one sign. | |
7958 */ | |
7959 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7960 sign_list_defined(sign_T *sp) |
7 | 7961 { |
7962 char_u *p; | |
7963 | |
274 | 7964 smsg((char_u *)"sign %s", sp->sn_name); |
7 | 7965 if (sp->sn_icon != NULL) |
7966 { | |
7967 MSG_PUTS(" icon="); | |
7968 msg_outtrans(sp->sn_icon); | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7969 # ifdef FEAT_SIGN_ICONS |
7 | 7970 if (sp->sn_image == NULL) |
7971 MSG_PUTS(_(" (NOT FOUND)")); | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7972 # else |
7 | 7973 MSG_PUTS(_(" (not supported)")); |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7974 # endif |
7 | 7975 } |
7976 if (sp->sn_text != NULL) | |
7977 { | |
7978 MSG_PUTS(" text="); | |
7979 msg_outtrans(sp->sn_text); | |
7980 } | |
7981 if (sp->sn_line_hl > 0) | |
7982 { | |
7983 MSG_PUTS(" linehl="); | |
7984 p = get_highlight_name(NULL, sp->sn_line_hl - 1); | |
7985 if (p == NULL) | |
7986 MSG_PUTS("NONE"); | |
7987 else | |
7988 msg_puts(p); | |
7989 } | |
7990 if (sp->sn_text_hl > 0) | |
7991 { | |
7992 MSG_PUTS(" texthl="); | |
7993 p = get_highlight_name(NULL, sp->sn_text_hl - 1); | |
7994 if (p == NULL) | |
7995 MSG_PUTS("NONE"); | |
7996 else | |
7997 msg_puts(p); | |
7998 } | |
7999 } | |
8000 | |
8001 /* | |
1828 | 8002 * Undefine a sign and free its memory. |
8003 */ | |
8004 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8005 sign_undefine(sign_T *sp, sign_T *sp_prev) |
1828 | 8006 { |
8007 vim_free(sp->sn_name); | |
8008 vim_free(sp->sn_icon); | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8009 # ifdef FEAT_SIGN_ICONS |
1828 | 8010 if (sp->sn_image != NULL) |
8011 { | |
8012 out_flush(); | |
8013 gui_mch_destroy_sign(sp->sn_image); | |
8014 } | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8015 # endif |
1828 | 8016 vim_free(sp->sn_text); |
8017 if (sp_prev == NULL) | |
8018 first_sign = sp->sn_next; | |
8019 else | |
8020 sp_prev->sn_next = sp->sn_next; | |
8021 vim_free(sp); | |
8022 } | |
8023 | |
8024 /* | |
7 | 8025 * Get highlighting attribute for sign "typenr". |
8026 * If "line" is TRUE: line highl, if FALSE: text highl. | |
8027 */ | |
8028 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8029 sign_get_attr(int typenr, int line) |
7 | 8030 { |
8031 sign_T *sp; | |
8032 | |
8033 for (sp = first_sign; sp != NULL; sp = sp->sn_next) | |
8034 if (sp->sn_typenr == typenr) | |
8035 { | |
8036 if (line) | |
8037 { | |
8038 if (sp->sn_line_hl > 0) | |
8039 return syn_id2attr(sp->sn_line_hl); | |
8040 } | |
8041 else | |
8042 { | |
8043 if (sp->sn_text_hl > 0) | |
8044 return syn_id2attr(sp->sn_text_hl); | |
8045 } | |
8046 break; | |
8047 } | |
8048 return 0; | |
8049 } | |
8050 | |
8051 /* | |
8052 * Get text mark for sign "typenr". | |
8053 * Returns NULL if there isn't one. | |
8054 */ | |
8055 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8056 sign_get_text(int typenr) |
7 | 8057 { |
8058 sign_T *sp; | |
8059 | |
8060 for (sp = first_sign; sp != NULL; sp = sp->sn_next) | |
8061 if (sp->sn_typenr == typenr) | |
8062 return sp->sn_text; | |
8063 return NULL; | |
8064 } | |
8065 | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8066 # if defined(FEAT_SIGN_ICONS) || defined(PROTO) |
7 | 8067 void * |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8068 sign_get_image( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8069 int typenr) /* the attribute which may have a sign */ |
7 | 8070 { |
8071 sign_T *sp; | |
8072 | |
8073 for (sp = first_sign; sp != NULL; sp = sp->sn_next) | |
8074 if (sp->sn_typenr == typenr) | |
8075 return sp->sn_image; | |
8076 return NULL; | |
8077 } | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8078 # endif |
7 | 8079 |
8080 /* | |
8081 * Get the name of a sign by its typenr. | |
8082 */ | |
8083 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8084 sign_typenr2name(int typenr) |
7 | 8085 { |
8086 sign_T *sp; | |
8087 | |
8088 for (sp = first_sign; sp != NULL; sp = sp->sn_next) | |
8089 if (sp->sn_typenr == typenr) | |
8090 return sp->sn_name; | |
8091 return (char_u *)_("[Deleted]"); | |
8092 } | |
8093 | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8094 # if defined(EXITFREE) || defined(PROTO) |
1828 | 8095 /* |
8096 * Undefine/free all signs. | |
8097 */ | |
8098 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8099 free_signs(void) |
1828 | 8100 { |
8101 while (first_sign != NULL) | |
8102 sign_undefine(first_sign, NULL); | |
8103 } | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8104 # endif |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8105 |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8106 # if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
1868 | 8107 static enum |
8108 { | |
8109 EXP_SUBCMD, /* expand :sign sub-commands */ | |
8110 EXP_DEFINE, /* expand :sign define {name} args */ | |
8111 EXP_PLACE, /* expand :sign place {id} args */ | |
8112 EXP_UNPLACE, /* expand :sign unplace" */ | |
8113 EXP_SIGN_NAMES /* expand with name of placed signs */ | |
8114 } expand_what; | |
8115 | |
8116 /* | |
8117 * Function given to ExpandGeneric() to obtain the sign command | |
8118 * expansion. | |
8119 */ | |
8120 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8121 get_sign_name(expand_T *xp UNUSED, int idx) |
1868 | 8122 { |
8123 sign_T *sp; | |
8124 int current_idx; | |
8125 | |
8126 switch (expand_what) | |
8127 { | |
8128 case EXP_SUBCMD: | |
8129 return (char_u *)cmds[idx]; | |
8130 case EXP_DEFINE: | |
8131 { | |
8132 char *define_arg[] = | |
8133 { | |
8134 "icon=", "linehl=", "text=", "texthl=", NULL | |
8135 }; | |
8136 return (char_u *)define_arg[idx]; | |
8137 } | |
8138 case EXP_PLACE: | |
8139 { | |
8140 char *place_arg[] = | |
8141 { | |
8142 "line=", "name=", "file=", "buffer=", NULL | |
8143 }; | |
8144 return (char_u *)place_arg[idx]; | |
8145 } | |
8146 case EXP_UNPLACE: | |
8147 { | |
8148 char *unplace_arg[] = { "file=", "buffer=", NULL }; | |
8149 return (char_u *)unplace_arg[idx]; | |
8150 } | |
8151 case EXP_SIGN_NAMES: | |
8152 /* Complete with name of signs already defined */ | |
8153 current_idx = 0; | |
8154 for (sp = first_sign; sp != NULL; sp = sp->sn_next) | |
8155 if (current_idx++ == idx) | |
8156 return sp->sn_name; | |
8157 return NULL; | |
8158 default: | |
8159 return NULL; | |
8160 } | |
8161 } | |
8162 | |
8163 /* | |
8164 * Handle command line completion for :sign command. | |
8165 */ | |
8166 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8167 set_context_in_sign_cmd(expand_T *xp, char_u *arg) |
1868 | 8168 { |
8169 char_u *p; | |
8170 char_u *end_subcmd; | |
8171 char_u *last; | |
8172 int cmd_idx; | |
8173 char_u *begin_subcmd_args; | |
8174 | |
8175 /* Default: expand subcommands. */ | |
8176 xp->xp_context = EXPAND_SIGN; | |
8177 expand_what = EXP_SUBCMD; | |
8178 xp->xp_pattern = arg; | |
8179 | |
8180 end_subcmd = skiptowhite(arg); | |
8181 if (*end_subcmd == NUL) | |
8182 /* expand subcmd name | |
8183 * :sign {subcmd}<CTRL-D>*/ | |
8184 return; | |
8185 | |
8186 cmd_idx = sign_cmd_idx(arg, end_subcmd); | |
8187 | |
8188 /* :sign {subcmd} {subcmd_args} | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2290
diff
changeset
|
8189 * | |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2290
diff
changeset
|
8190 * begin_subcmd_args */ |
1868 | 8191 begin_subcmd_args = skipwhite(end_subcmd); |
8192 p = skiptowhite(begin_subcmd_args); | |
8193 if (*p == NUL) | |
8194 { | |
8195 /* | |
8196 * Expand first argument of subcmd when possible. | |
8197 * For ":jump {id}" and ":unplace {id}", we could | |
8198 * possibly expand the ids of all signs already placed. | |
8199 */ | |
8200 xp->xp_pattern = begin_subcmd_args; | |
8201 switch (cmd_idx) | |
8202 { | |
8203 case SIGNCMD_LIST: | |
8204 case SIGNCMD_UNDEFINE: | |
8205 /* :sign list <CTRL-D> | |
8206 * :sign undefine <CTRL-D> */ | |
8207 expand_what = EXP_SIGN_NAMES; | |
8208 break; | |
8209 default: | |
8210 xp->xp_context = EXPAND_NOTHING; | |
8211 } | |
8212 return; | |
8213 } | |
8214 | |
8215 /* expand last argument of subcmd */ | |
8216 | |
8217 /* :sign define {name} {args}... | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2290
diff
changeset
|
8218 * | |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2290
diff
changeset
|
8219 * p */ |
1868 | 8220 |
8221 /* Loop until reaching last argument. */ | |
8222 do | |
8223 { | |
8224 p = skipwhite(p); | |
8225 last = p; | |
8226 p = skiptowhite(p); | |
8227 } while (*p != NUL); | |
8228 | |
8229 p = vim_strchr(last, '='); | |
8230 | |
8231 /* :sign define {name} {args}... {last}= | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2290
diff
changeset
|
8232 * | | |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2290
diff
changeset
|
8233 * last p */ |
10299
7b2f95633e28
commit https://github.com/vim/vim/commit/7756e7465d627ff9cd01e59625484a8c302ef853
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
8234 if (p == NULL) |
1868 | 8235 { |
8236 /* Expand last argument name (before equal sign). */ | |
8237 xp->xp_pattern = last; | |
8238 switch (cmd_idx) | |
8239 { | |
8240 case SIGNCMD_DEFINE: | |
8241 expand_what = EXP_DEFINE; | |
8242 break; | |
8243 case SIGNCMD_PLACE: | |
8244 expand_what = EXP_PLACE; | |
8245 break; | |
8246 case SIGNCMD_JUMP: | |
8247 case SIGNCMD_UNPLACE: | |
8248 expand_what = EXP_UNPLACE; | |
8249 break; | |
8250 default: | |
8251 xp->xp_context = EXPAND_NOTHING; | |
8252 } | |
8253 } | |
8254 else | |
8255 { | |
8256 /* Expand last argument value (after equal sign). */ | |
8257 xp->xp_pattern = p + 1; | |
8258 switch (cmd_idx) | |
8259 { | |
8260 case SIGNCMD_DEFINE: | |
8261 if (STRNCMP(last, "texthl", p - last) == 0 || | |
8262 STRNCMP(last, "linehl", p - last) == 0) | |
8263 xp->xp_context = EXPAND_HIGHLIGHT; | |
8264 else if (STRNCMP(last, "icon", p - last) == 0) | |
8265 xp->xp_context = EXPAND_FILES; | |
8266 else | |
8267 xp->xp_context = EXPAND_NOTHING; | |
8268 break; | |
8269 case SIGNCMD_PLACE: | |
8270 if (STRNCMP(last, "name", p - last) == 0) | |
8271 expand_what = EXP_SIGN_NAMES; | |
8272 else | |
8273 xp->xp_context = EXPAND_NOTHING; | |
8274 break; | |
8275 default: | |
8276 xp->xp_context = EXPAND_NOTHING; | |
8277 } | |
8278 } | |
8279 } | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8280 # endif |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8281 #endif |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8282 |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8283 /* |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8284 * Make the user happy. |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8285 */ |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8286 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8287 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
|
8288 { |
8879
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8289 static char *code[] = { |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8290 "\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
|
8291 "\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
|
8292 }; |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8293 char *p; |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8294 int n; |
8879
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8295 int i; |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8296 |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8297 msg_start(); |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8298 msg_putchar('\n'); |
8879
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8299 for (i = 0; i < 2; ++i) |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8300 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
|
8301 if (*p == 'x') |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8302 msg_putchar('\n'); |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8303 else |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8304 for (n = *p++; n > 0; --n) |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8305 if (*p == 'o' || *p == '$') |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8306 msg_putchar_attr(*p, hl_attr(HLF_L)); |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8307 else |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8308 msg_putchar(*p); |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8309 msg_clr_eos(); |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8310 } |
7 | 8311 |
8312 #if defined(FEAT_GUI) || defined(FEAT_CLIENTSERVER) || defined(PROTO) | |
8313 /* | |
8314 * ":drop" | |
8315 * Opens the first argument in a window. When there are two or more arguments | |
8316 * the argument list is redefined. | |
8317 */ | |
8318 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8319 ex_drop(exarg_T *eap) |
7 | 8320 { |
8321 int split = FALSE; | |
8322 win_T *wp; | |
8323 buf_T *buf; | |
735 | 8324 # ifdef FEAT_WINDOWS |
8325 tabpage_T *tp; | |
8326 # endif | |
7 | 8327 |
8328 /* | |
8329 * Check if the first argument is already being edited in a window. If | |
8330 * so, jump to that window. | |
8331 * We would actually need to check all arguments, but that's complicated | |
8332 * and mostly only one file is dropped. | |
8333 * This also ignores wildcards, since it is very unlikely the user is | |
8334 * editing a file name with a wildcard character. | |
8335 */ | |
735 | 8336 set_arglist(eap->arg); |
8337 | |
1067 | 8338 /* |
8339 * Expanding wildcards may result in an empty argument list. E.g. when | |
8340 * editing "foo.pyc" and ".pyc" is in 'wildignore'. Assume that we | |
8341 * already did an error message for this. | |
8342 */ | |
8343 if (ARGCOUNT == 0) | |
8344 return; | |
8345 | |
7 | 8346 # ifdef FEAT_WINDOWS |
735 | 8347 if (cmdmod.tab) |
8348 { | |
8349 /* ":tab drop file ...": open a tab for each argument that isn't | |
8350 * edited in a window yet. It's like ":tab all" but without closing | |
8351 * windows or tabs. */ | |
8352 ex_all(eap); | |
8353 } | |
8354 else | |
7 | 8355 # endif |
735 | 8356 { |
8357 /* ":drop file ...": Edit the first argument. Jump to an existing | |
8358 * window if possible, edit in current window if the current buffer | |
8359 * can be abandoned, otherwise open a new window. */ | |
8360 buf = buflist_findnr(ARGLIST[0].ae_fnum); | |
8361 | |
8362 FOR_ALL_TAB_WINDOWS(tp, wp) | |
8363 { | |
8364 if (wp->w_buffer == buf) | |
7 | 8365 { |
735 | 8366 # ifdef FEAT_WINDOWS |
825 | 8367 goto_tabpage_win(tp, wp); |
735 | 8368 # endif |
7 | 8369 curwin->w_arg_idx = 0; |
8370 return; | |
8371 } | |
8372 } | |
735 | 8373 |
8374 /* | |
8375 * Check whether the current buffer is changed. If so, we will need | |
8376 * to split the current window or data could be lost. | |
8377 * Skip the check if the 'hidden' option is set, as in this case the | |
8378 * buffer won't be lost. | |
8379 */ | |
8380 if (!P_HID(curbuf)) | |
8381 { | |
7 | 8382 # ifdef FEAT_WINDOWS |
735 | 8383 ++emsg_off; |
7 | 8384 # endif |
5464 | 8385 split = check_changed(curbuf, CCGD_AW | CCGD_EXCMD); |
7 | 8386 # ifdef FEAT_WINDOWS |
735 | 8387 --emsg_off; |
7 | 8388 # else |
735 | 8389 if (split) |
8390 return; | |
7 | 8391 # endif |
735 | 8392 } |
8393 | |
8394 /* Fake a ":sfirst" or ":first" command edit the first argument. */ | |
8395 if (split) | |
8396 { | |
8397 eap->cmdidx = CMD_sfirst; | |
8398 eap->cmd[0] = 's'; | |
8399 } | |
8400 else | |
8401 eap->cmdidx = CMD_first; | |
8402 ex_rewind(eap); | |
8403 } | |
7 | 8404 } |
8405 #endif | |
9915
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8406 |
9931
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8407 /* |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8408 * 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
|
8409 * 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
|
8410 * 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
|
8411 * 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
|
8412 * 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
|
8413 */ |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8414 char_u * |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8415 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
|
8416 { |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8417 int c; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8418 |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8419 if (vim_isIDc(*p)) |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8420 { |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8421 /* ":vimgrep pattern fname" */ |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8422 if (s != NULL) |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8423 *s = p; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8424 p = skiptowhite(p); |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8425 if (s != NULL && *p != NUL) |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8426 *p++ = NUL; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8427 } |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8428 else |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8429 { |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8430 /* ":vimgrep /pattern/[g][j] fname" */ |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8431 if (s != NULL) |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8432 *s = p + 1; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8433 c = *p; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8434 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
|
8435 if (*p != c) |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8436 return NULL; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8437 |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8438 /* Truncate the pattern. */ |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8439 if (s != NULL) |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8440 *p = NUL; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8441 ++p; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8442 |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8443 /* Find the flags */ |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8444 while (*p == 'g' || *p == 'j') |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8445 { |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8446 if (flags != NULL) |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8447 { |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8448 if (*p == 'g') |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8449 *flags |= VGR_GLOBAL; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8450 else |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8451 *flags |= VGR_NOJUMP; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8452 } |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8453 ++p; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8454 } |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8455 } |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8456 return p; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8457 } |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8458 |
9915
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8459 #if defined(FEAT_EVAL) || defined(PROTO) |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8460 /* |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8461 * 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
|
8462 */ |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8463 void |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8464 ex_oldfiles(exarg_T *eap UNUSED) |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8465 { |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8466 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
|
8467 listitem_T *li; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8468 int nr = 0; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8469 char_u *fname; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8470 |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8471 if (l == NULL) |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8472 msg((char_u *)_("No old files")); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8473 else |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8474 { |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8475 msg_start(); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8476 msg_scroll = TRUE; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8477 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
|
8478 { |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8479 ++nr; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8480 fname = get_tv_string(&li->li_tv); |
9945
d63a89b526ea
commit https://github.com/vim/vim/commit/d6f2ee32dcfa18c781ef157918b524318a2215a2
Christian Brabandt <cb@256bit.org>
parents:
9931
diff
changeset
|
8481 if (!message_filtered(fname)) |
9915
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8482 { |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8483 msg_outnum((long)nr); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8484 MSG_PUTS(": "); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8485 msg_outtrans(fname); |
10021
5fc4bec66c33
commit https://github.com/vim/vim/commit/885c00eabe6d1fd757d4f0eb531ad3a15a35ec04
Christian Brabandt <cb@256bit.org>
parents:
9980
diff
changeset
|
8486 msg_clr_eos(); |
9915
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8487 msg_putchar('\n'); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8488 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
|
8489 ui_breakcheck(); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8490 } |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8491 } |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8492 |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8493 /* 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
|
8494 got_int = FALSE; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8495 |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8496 # ifdef FEAT_BROWSE_CMD |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8497 if (cmdmod.browse) |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8498 { |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8499 quit_more = FALSE; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8500 nr = prompt_for_number(FALSE); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8501 msg_starthere(); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8502 if (nr > 0) |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8503 { |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8504 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
|
8505 (long)nr); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8506 |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8507 if (p != NULL) |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8508 { |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8509 p = expand_env_save(p); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8510 eap->arg = p; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8511 eap->cmdidx = CMD_edit; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8512 cmdmod.browse = FALSE; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8513 do_exedit(eap, NULL); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8514 vim_free(p); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8515 } |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8516 } |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8517 } |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8518 # endif |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8519 } |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8520 } |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8521 #endif |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8522 |